From 4f0d883774adc44f681d1bfa013a6921039d9c2f Mon Sep 17 00:00:00 2001 From: MikeBland Date: Fri, 24 Mar 2017 00:03:57 +0000 Subject: [PATCH] "c4" sources --- radio/ersky9x/src/ersky9x.cpp | 32 +++- radio/ersky9x/src/ersky9x.h | 1 + radio/ersky9x/src/maintenance.cpp | 305 ++++++++++++++++++++++++++++-- radio/ersky9x/src/menus.cpp | 60 +++++- radio/ersky9x/src/pdi.cpp | 12 +- 5 files changed, 373 insertions(+), 37 deletions(-) diff --git a/radio/ersky9x/src/ersky9x.cpp b/radio/ersky9x/src/ersky9x.cpp index 3c5b474..7a2802b 100644 --- a/radio/ersky9x/src/ersky9x.cpp +++ b/radio/ersky9x/src/ersky9x.cpp @@ -805,7 +805,7 @@ void update_mode(void* pdata) while (1) { - if ( g_menuStack[0] == menuUpdate ) + if ( (g_menuStackPtr==0) && (g_menuStack[0] == menuUpdate) ) { if ( ( check_soft_power() == POWER_OFF )/* || ( goto_usb ) */ ) // power now off { @@ -869,6 +869,7 @@ extern void checkRotaryEncoder() ; evt = EnterMenu ; EnterMenu = 0 ; } + Tevent = evt ; g_menuStack[g_menuStackPtr](evt); // Only update display every 40mS, improves SPort update throughput if ( ++displayTimer >= 4 ) @@ -1765,9 +1766,16 @@ uint32_t updateSlave() ; #endif // At this point, check for "maintenance mode" +#ifdef PCBSKY + if ( ( ( read_trims() & 0x81 )== 0x81 ) || ( GPBR->SYS_GPBR0 == 0x5555AAAA ) ) +#else if ( ( read_trims() & 0x81 )== 0x81 ) +#endif { // Do maintenance mode +#ifdef PCBSKY + GPBR->SYS_GPBR0 = 0 ; +#endif #ifndef SIMU CoInitOS(); @@ -3534,6 +3542,19 @@ void speakModelVoice() } } +void prepareForShutdown() +{ + if ( LogsRunning & 1 ) + { + closeLogs() ; + } + g_eeGeneral.unexpectedShutdown = 0 ; + STORE_MODELVARS ; // To make sure we write model persistent timer + STORE_GENERALVARS ; // To make sure we write "unexpectedShutdown" + +} + + // This is the main task for the RTOS void main_loop(void* pdata) { @@ -3739,12 +3760,6 @@ extern uint8_t ModelImageValid ; // Wait for OK to turn off // Currently wait 1 sec, needs to check eeprom finished - if ( LogsRunning & 1 ) - { - closeLogs() ; - } - - g_eeGeneral.unexpectedShutdown = 0; #ifdef PCBSKY if ( ( g_eeGeneral.ar9xBoard == 0 ) && ( g_eeGeneral.extraPotsSource[0] != 2 ) && ( g_eeGeneral.extraPotsSource[1] != 2 ) ) { @@ -3755,8 +3770,7 @@ extern uint8_t ModelImageValid ; } } #endif - STORE_MODELVARS ; // To make sure we write model persistent timer - STORE_GENERALVARS ; // To make sure we write "unexpectedShutdown" + prepareForShutdown() ; uint16_t tgtime = get_tmr10ms() ; uint16_t long_tgtime = tgtime ; diff --git a/radio/ersky9x/src/ersky9x.h b/radio/ersky9x/src/ersky9x.h index e713f3c..6a8ccab 100644 --- a/radio/ersky9x/src/ersky9x.h +++ b/radio/ersky9x/src/ersky9x.h @@ -992,6 +992,7 @@ extern const char *get_switches_string( void ) ; void putsDblSizeName( uint8_t y ) ; void clearKeyEvents( void ) ; void speakModelVoice( void ) ; +void prepareForShutdown( void ) ; extern void interrupt5ms() ; extern uint16_t getTmr2MHz( void ) ; diff --git a/radio/ersky9x/src/maintenance.cpp b/radio/ersky9x/src/maintenance.cpp index 16cbf16..c316754 100644 --- a/radio/ersky9x/src/maintenance.cpp +++ b/radio/ersky9x/src/maintenance.cpp @@ -121,11 +121,12 @@ extern uchar PdiErrors8 ; extern void frsky_receive_byte( uint8_t data ) ; uint16_t crc16_ccitt( uint8_t *buf, uint32_t len ) ; +uint8_t checkIndexed( uint8_t y, const prog_char * s, uint8_t value, uint8_t edit ) ; extern void copyFileName( char *dest, char *source, uint32_t size ) ; #ifdef PCBSKY - #ifndef REVX void init_mtwi( void ) ; + #ifndef REVX uint32_t check_ready( void ) ; uint32_t write_CoProc( uint32_t coInternalAddr, uint8_t *buf, uint32_t number ) ; uint32_t coProcBoot( void ) ; @@ -134,6 +135,9 @@ uint32_t read_status_CoProc( uint32_t bufaddr, uint32_t number ) ; uint8_t Twi_rx_buf[26] ; uint8_t CoProresult ; #endif +#ifdef REVX +uint32_t clearMfp() ; +#endif #endif uint32_t sportUpdate( uint32_t external ) ; @@ -165,8 +169,14 @@ uint8_t MaintenanceRunning = 0 ; uint8_t BlockInUse ; uint8_t SportVerValid ; uint8_t MultiResult ; +uint8_t MultiType ; uint8_t SportVersion[4] ; uint32_t FirmwareSize ; +uint32_t HexFileIndex ; +uint32_t HexFileRead ; + +//uint16_t HexCount ; +//uint16_t HexDebug ; const uint8_t SportIds[28] = {0x00, 0xA1, 0x22, 0x83, 0xE4, 0x45, 0xC6, 0x67, 0x48, 0xE9, 0x6A, 0xCB, 0xAC, 0x0D, 0x8E, 0x2F, @@ -226,6 +236,10 @@ void initMultiMode() #ifdef PCBSKY SET_TX_BIT() ; configure_pins( PIO_PA17, PIN_ENABLE | PIN_OUTPUT | PIN_PORTA | PIN_HIGH ) ; +#ifdef REVX + init_mtwi() ; + clearMfp() ; +#endif #endif #ifdef PCB9XT EXTERNAL_RF_ON() ; @@ -963,6 +977,28 @@ void displayXmegaData() lcd_outhex4( 100, 7*FH, Fuses[7] ) ; } +void menuUpMulti(uint8_t event) +{ + TITLE( "Multi Options" ) ; + static MState2 mstate2 ; + mstate2.check_columns(event, 1 ) ; + uint32_t sub = mstate2.m_posVert ; + uint32_t subN = 0 ; + uint32_t y = FH ; + lcd_putsAtt(0, y, XPSTR("Update"), (sub==subN) ? INVERS : 0 ) ; + if(sub==subN) + { + if ( event == EVT_KEY_BREAK(KEY_MENU) ) + { + popMenu() ; + chainMenu(menuUp1) ; + } + } + y += FH ; + subN += 1 ; + lcd_puts_Pleft( y, XPSTR("File Type") ) ; + MultiType = checkIndexed( y, XPSTR("\110\001\003BINHEX"), MultiType, (sub==subN) ) ; +} void menuUp1(uint8_t event) { @@ -1083,7 +1119,7 @@ void menuUp1(uint8_t event) fr = f_opendir( &Dj, (TCHAR *) "." ) ; if ( fr == FR_OK ) { - if ( (UpdateItem > 1 ) && (UpdateItem != 5 ) && (UpdateItem != 6 ) && (UpdateItem != 7) ) + if ( (UpdateItem == UPDATE_TYPE_SPORT_INT ) || (UpdateItem == UPDATE_TYPE_SPORT_EXT ) ) { fc->ext[0] = 'F' ; fc->ext[1] = 'R' ; @@ -1091,9 +1127,18 @@ void menuUp1(uint8_t event) } else { - fc->ext[0] = 'B' ; - fc->ext[1] = 'I' ; - fc->ext[2] = 'N' ; + if ( (UpdateItem == UPDATE_TYPE_MULTI ) && MultiType ) + { + fc->ext[0] = 'H' ; + fc->ext[1] = 'E' ; + fc->ext[2] = 'X' ; + } + else + { + fc->ext[0] = 'B' ; + fc->ext[1] = 'I' ; + fc->ext[2] = 'N' ; + } } fc->ext[3] = 0 ; fc->index = 0 ; @@ -1473,6 +1518,23 @@ void menuUp1(uint8_t event) width /= FirmwareSize ; lcd_outhex4( 0, 7*FH, (XmegaSignature[0] << 8) | XmegaSignature[1] ) ; lcd_outhex4( 25, 7*FH, (XmegaSignature[2] << 8) | XmegaSignature[3] ) ; +// lcd_outhex4( 50, 7*FH, (UpdateItem << 8) + MultiState ) ; +// lcd_outhex4( 75, 7*FH, HexCount++ ) ; + +// lcd_outhex4( 100, 6*FH, HexDebug ) ; +// lcd_outhex4( 100, 5*FH, BlockCount ) ; +// lcd_outhex4( 100, 4*FH, XblockCount ) ; +// lcd_outhex4( 100, 3*FH, HexFileRead ) ; +// lcd_outhex4( 100, 2*FH, BytesFlashed ) ; +// lcd_outhex4( 100, 1*FH, FirmwareSize ) ; + +// Temporary + if (event == EVT_KEY_FIRST(KEY_EXIT)) + { + chainMenu(menuUpdate) ; + killEvents(event) ; + } + } else // Internal/External Sport { @@ -1660,7 +1722,7 @@ void menuUpdate(uint8_t event) if ( position == 7*FH ) { UpdateItem = UPDATE_TYPE_MULTI ; - chainMenu(menuUp1) ; + pushMenu(menuUpMulti) ; } #else if ( position == 3*FH ) @@ -1681,7 +1743,7 @@ void menuUpdate(uint8_t event) if ( position == 6*FH ) { UpdateItem = UPDATE_TYPE_MULTI ; - chainMenu(menuUp1) ; + pushMenu(menuUpMulti) ; } #endif #endif @@ -1709,7 +1771,7 @@ void menuUpdate(uint8_t event) if ( position == 7*FH ) { UpdateItem = UPDATE_TYPE_MULTI ; - chainMenu(menuUp1) ; + pushMenu(menuUpMulti) ; } #endif #ifdef PCB9XT @@ -1731,7 +1793,7 @@ void menuUpdate(uint8_t event) if ( position == 6*FH ) { UpdateItem = UPDATE_TYPE_MULTI ; - chainMenu(menuUp1) ; + pushMenu(menuUpMulti) ; } #endif killEvents(event) ; @@ -2246,7 +2308,7 @@ uint32_t eat( uint8_t byte ) uint16_t rxchar ; time = getTmr2MHz() ; - while ( (uint16_t) (getTmr2MHz() - time) < 4000 ) // 2mS + while ( (uint16_t) (getTmr2MHz() - time) < 15000 ) // 7.5mS { if ( ( rxchar = get_fifo64( &CaptureRx_fifo ) ) != 0xFFFF ) { @@ -2259,6 +2321,190 @@ uint32_t eat( uint8_t byte ) return 0 ; } + +//void hexDebug( uint8_t x, uint8_t y ) +//{ +// lcd_putc( 0, 0, x ) ; +// lcd_putc( 6, 0, y ) ; +// HexDebug = (x << 8 ) | y ; +//} + + +uint32_t hexFileNextByte() +{ + if ( HexFileIndex >= XblockCount ) + { + if ( XblockCount < 1024 ) + { + + return 0 ; + } + f_read( &FlashFile, (BYTE *)ExtraFileData, 1024, &XblockCount ) ; + HexFileRead += XblockCount ; + HexFileIndex = 0 ; + + } + return ExtraFileData[HexFileIndex++] ; +} + +uint32_t fromHex( uint32_t data ) +{ + if ( data > 0x60 ) + { + data -= 0x20 ; + } + data -= '0' ; + if ( data > 9 ) + { + data -= 7 ; + } + return data ; +} + +uint8_t recordSize ; +uint8_t inRecord ; +uint8_t recordOffset ; +uint16_t recordAddress ; +uint8_t recordData[32] ; + +#define RECORD_START 0 +#define RECORD_LENGTH1 1 +#define RECORD_LENGTH2 2 +#define RECORD_ADD1 3 +#define RECORD_ADD2 4 +#define RECORD_ADD3 5 +#define RECORD_ADD4 6 +#define RECORD_DATA1 7 +#define RECORD_DATA2 8 +#define RECORD_DONE 9 + +void hexFileReadRecord() +{ + uint32_t data ; + uint32_t state = RECORD_START ; + uint32_t length = 0 ; + uint32_t byte = 0 ; + recordOffset = 0 ; + recordSize = 0 ; + + while ( state != RECORD_DONE ) + { + data = hexFileNextByte() ; + if ( data == 0 ) + { + // End of File + return ; + } + else + { + switch ( state ) + { + case RECORD_START : + if ( data == ':' ) + { + state = RECORD_LENGTH1 ; + } + break ; + + case RECORD_LENGTH1 : + length = fromHex( data ) ; + state = RECORD_LENGTH2 ; + break ; + case RECORD_LENGTH2 : + length = (length << 4) + fromHex( data ) ; + if ( length == 0 ) + { + return ; + } +// state = RECORD_ADD1 ; +// break ; +// case RECORD_ADD1 : +//// length = (length << 4) + fromHex( data ) ; +// state = RECORD_ADD2 ; +// break ; +// case RECORD_ADD2 : +//// length = (length << 4) + fromHex( data ) ; +// state = RECORD_ADD3 ; +// break ; +// case RECORD_ADD3 : +//// length = (length << 4) + fromHex( data ) ; +// state = RECORD_ADD4 ; +// break ; +// case RECORD_ADD4 : +//// length = (length << 4) + fromHex( data ) ; + hexFileNextByte() ; // skip four characters + hexFileNextByte() ; // address + hexFileNextByte() ; // address + hexFileNextByte() ; // address + hexFileNextByte() ; // skip two characters + hexFileNextByte() ; // (record type) + state = RECORD_DATA1 ; + break ; + case RECORD_DATA1 : + byte = fromHex( data ) ; + state = RECORD_DATA2 ; + break ; + case RECORD_DATA2 : + byte = (byte << 4) + fromHex( data ) ; + recordData[recordSize++] = byte ; + length -= 1 ; + if ( length == 0 ) + { + return ; + } + if ( recordSize >= 32 ) + { + return ; + } + state = RECORD_DATA1 ; + break ; + } + } + } +} + +void hexFileStart() +{ + + recordSize = 0 ; + inRecord = 0 ; + HexFileIndex = 0 ; + memmove(ExtraFileData, FileData, 1024 ) ; // Hex data to here + XblockCount = 1024 ; + HexFileRead = 1024 ; +} + +// Read file data to ExtraFileData, put binary into FileData +void hexFileRead1024( uint32_t address, UINT *blockCount ) +{ + + uint32_t i ; + i = 0 ; + while ( i < 1024 ) + { + if ( inRecord ) + { + FileData[i++] = recordData[recordOffset++] ; + if ( recordOffset >= recordSize ) + { + inRecord = 0 ; + } + } + else + { + hexFileReadRecord() ; + if ( recordSize == 0 ) + { + *blockCount = i ; + return ; + } + inRecord = 1 ; + } + } + *blockCount = i ; + return ; +} + uint32_t multiUpdate() { uint32_t i ; @@ -2273,6 +2519,11 @@ uint32_t multiUpdate() initMultiMode() ; BytesFlashed = 0 ; AllSubState = 0 ; + if ( MultiType ) // Hex file + { + hexFileStart() ; + hexFileRead1024( 0, &BlockCount ) ; + } MultiState = MULTI_WAIT1 ; break ; @@ -2305,7 +2556,7 @@ uint32_t multiUpdate() } else { - if ( ++AllSubState > 10 ) + if ( ++AllSubState > 80 ) { MultiResult = 1 ; MultiState = MULTI_DONE ; @@ -2349,6 +2600,7 @@ uint32_t multiUpdate() else { MultiState = MULTI_FLASHING ; + MultiPageSize = 128 ; if ( XmegaSignature[2] == 0x42 ) { MultiPageSize = 256 ; @@ -2402,15 +2654,33 @@ uint32_t multiUpdate() BlockOffset += MultiPageSize ; if ( BytesFlashed >= ByteEnd ) { - f_read( &FlashFile, (BYTE *)FileData, 1024, &BlockCount ) ; + if ( MultiType ) // Hex file + { + hexFileRead1024( BytesFlashed, &BlockCount ) ; + } + else + { + f_read( &FlashFile, (BYTE *)FileData, 1024, &BlockCount ) ; + } BlockOffset = 0 ; ByteEnd += BlockCount ; wdt_reset() ; } - if ( BytesFlashed >= FirmwareSize ) + if ( MultiType ) { - MultiState = MULTI_DONE ; - BytesFlashed = FirmwareSize ; + if ( BlockCount == 0 ) + { + MultiState = MULTI_DONE ; + BytesFlashed = FirmwareSize ; + } + } + else + { + if ( BytesFlashed >= FirmwareSize ) + { + MultiState = MULTI_DONE ; + BytesFlashed = FirmwareSize ; + } } } break ; @@ -2425,11 +2695,11 @@ uint32_t multiUpdate() //#ifdef PCB9XT // EXTERNAL_RF_OFF() ; //#endif - BytesFlashed = FirmwareSize + 1 ; + HexFileRead = BytesFlashed = FirmwareSize + 1 ; break ; } - return BytesFlashed ; + return MultiType ? HexFileRead : BytesFlashed ; } @@ -2560,6 +2830,7 @@ uint32_t sportUpdate( uint32_t external ) #endif #ifdef PCBSKY #ifdef REVX + init_mtwi() ; clearMfp() ; #endif com1_Configure( 57600, SERIAL_NORM, SERIAL_NO_PARITY ) ; diff --git a/radio/ersky9x/src/menus.cpp b/radio/ersky9x/src/menus.cpp index 1e6e558..66aed35 100644 --- a/radio/ersky9x/src/menus.cpp +++ b/radio/ersky9x/src/menus.cpp @@ -22,6 +22,7 @@ #ifdef PCBSKY #include "AT91SAM3S4.h" +#include "core_cm3.h" #endif #include "ersky9x.h" #include "myeeprom.h" @@ -1948,6 +1949,7 @@ void DisplayScreenIndex(uint8_t index, uint8_t count, uint8_t attr) uint8_t g_posHorz ; uint8_t M_longMenuTimer ; uint8_t M_lastVerticalPosition ; +uint8_t MaskRotaryLong ; //#define MAXCOL(row) (horTab ? pgm_read_byte(horTab+min(row, horTabMax)) : (const uint8_t)0) @@ -2215,7 +2217,11 @@ uint8_t MState2::check(uint8_t event, uint8_t curr, MenuFuncP *menuTab, uint8_t break; //fallthrough case EVT_KEY_LONG(BTN_RE): - killEvents(event); + if ( MaskRotaryLong ) + { + break ; + } + killEvents(event) ; case EVT_KEY_BREAK(KEY_EXIT): if(s_editMode) { s_editMode = false; @@ -2273,6 +2279,7 @@ uint8_t MState2::check(uint8_t event, uint8_t curr, MenuFuncP *menuTab, uint8_t g_posHorz = l_posHorz ; InverseBlink = (s_editMode) ? BLINK : INVERS ; Columns = 0 ; + MaskRotaryLong = 0 ; return event ; } @@ -4866,7 +4873,8 @@ void menuProcSafetySwitches(uint8_t event) if(active) { sd->opt.vs.vval = checkIncDec16( sd->opt.vs.vval, 0, max, EE_MODEL); - if ( event==EVT_KEY_LONG(KEY_MENU)) + MaskRotaryLong = 1 ; + if ( ( event==EVT_KEY_LONG(KEY_MENU)) || ( event==EVT_KEY_LONG(BTN_RE) ) ) { if ( sd->opt.vs.vval <= 250 ) { @@ -5496,7 +5504,8 @@ void menuProcVoiceOne(uint8_t event) alphaEditName( 12*FW, y, (uint8_t *)pvad->file.name, sizeof(pvad->file.name), attr | ALPHA_NO_NAME, (uint8_t *)XPSTR( "FileName") ) ; if( attr ) { - if (event == EVT_KEY_LONG(KEY_MENU) ) + MaskRotaryLong = 1 ; + if ( ( event==EVT_KEY_LONG(KEY_MENU)) || ( event==EVT_KEY_LONG(BTN_RE) ) ) { VoiceFileType = VOICE_FILE_TYPE_USER ; pushMenu( menuProcSelectVoiceFile ) ; @@ -5553,7 +5562,8 @@ void menuProcVoiceOne(uint8_t event) } if (attr) { - if ( event == EVT_KEY_LONG(KEY_MENU) ) + MaskRotaryLong = 1 ; + if ( ( event==EVT_KEY_LONG(KEY_MENU)) || ( event==EVT_KEY_LONG(BTN_RE) ) ) { if ( pvad->file.vfile <= 500) { @@ -5579,7 +5589,8 @@ void menuProcVoiceOne(uint8_t event) lcd_putsAtt( 12*FW, y, XPSTR("MENU LONG"), attr ) ; if( attr ) { - if (event == EVT_KEY_LONG(KEY_MENU) ) + MaskRotaryLong = 1 ; + if ( ( event==EVT_KEY_LONG(KEY_MENU)) || ( event==EVT_KEY_LONG(BTN_RE) ) ) { pvad->source = 0 ; pvad->func = 0 ; @@ -7788,7 +7799,8 @@ void menuProcProtocol(uint8_t event) pModule->failsafeMode = checkIndexed( y, XPSTR(FWx9"\004""\007Not Set Rx Custom HoldNoPulse"), pModule->failsafeMode, sub==subN ) ; if ( sub == subN ) { - if (event == EVT_KEY_LONG(KEY_MENU) ) + MaskRotaryLong = 1 ; + if ( ( event==EVT_KEY_LONG(KEY_MENU)) || ( event==EVT_KEY_LONG(BTN_RE) ) ) { s_currIdx = module ; pushMenu( menuSetFailsafe ) ; @@ -7853,8 +7865,9 @@ void menuProcProtocol(uint8_t event) if(sub==subN) { + MaskRotaryLong = 1 ; lcd_char_inverse( 0, y, 4*FW, 0 ) ; - if ( event==EVT_KEY_LONG(KEY_MENU)) + if ( ( event==EVT_KEY_LONG(KEY_MENU)) || ( event==EVT_KEY_LONG(BTN_RE) ) ) { PxxFlag[module] = PXX_BIND ; //send bind code or range check code s_currIdx = module ; @@ -7869,6 +7882,7 @@ void menuProcProtocol(uint8_t event) { if(t_pgOfs<=subN) { + MaskRotaryLong = 1 ; lcd_puts_Pleft( y, PSTR(STR_RANGE) ) ; if ( (pModule->protocol == PROTO_MULTI ) && ( PrivateData[1] ) ) { @@ -7885,7 +7899,7 @@ void menuProcProtocol(uint8_t event) if(sub==subN) { lcd_char_inverse( 0, y, 11*FW, 0 ) ; - if ( event==EVT_KEY_LONG(KEY_MENU)) + if ( ( event==EVT_KEY_LONG(KEY_MENU)) || event==( EVT_KEY_LONG(BTN_RE) ) ) { PxxFlag[module] = PXX_RANGE_CHECK ; //send bind code or range check code s_currIdx = module ; @@ -7993,7 +8007,8 @@ void menuProcTrainProtocol(uint8_t event) if(sub==subN) { CHECK_INCDEC_H_MODELVAR_0( value, 4 ) ; - if ( ( value > 0) && ( event == EVT_KEY_LONG(KEY_MENU) ) ) + MaskRotaryLong = 1 ; + if ( ( value > 0) && ( ( event==EVT_KEY_LONG(KEY_MENU)) || ( event==EVT_KEY_LONG(BTN_RE) ) ) ) { SingleExpoChan = 1 ; s_expoChan = value-1 ; @@ -15554,7 +15569,11 @@ STR_DiagAna { uint8_t subN = 0 ; #if defined(PCBSKY) || defined(PCB9XT) +#ifdef PCBSKY + IlinesCount = 9 ; +#else IlinesCount = 8 ; +#endif #else IlinesCount = 7 ; #endif @@ -15631,6 +15650,29 @@ STR_DiagAna y += FH ; subN += 1 ; +#ifdef PCBSKY + lcd_putsAtt(0, y, XPSTR("Run Maintenance"), (sub==subN) ? INVERS : 0 ) ; + if(sub==subN) + { + if ( event == EVT_KEY_LONG(KEY_MENU) ) + { + GPBR->SYS_GPBR0 = 0x5555AAAA ; + // save EEPROM and reboot + prepareForShutdown() ; + uint16_t tgtime = get_tmr10ms() ; + while( (uint16_t)(get_tmr10ms() - tgtime ) < 50 ) // 50 - Half second + { + wdt_reset() ; + if ( ee32_check_finished() ) + { + break ; + } + } + NVIC_SystemReset() ; + } + } +#endif + #if defined(PCBSKY) || defined(PCB9XT) } #endif diff --git a/radio/ersky9x/src/pdi.cpp b/radio/ersky9x/src/pdi.cpp index a3546af..e423270 100644 --- a/radio/ersky9x/src/pdi.cpp +++ b/radio/ersky9x/src/pdi.cpp @@ -605,7 +605,7 @@ uchar pdiWriteFuse( uint32_t address, uint8_t value ) register_address = XNVM_FUSE_BASE + address ; - memmove((uint8_t*)®ister_address, (cmd + 1), 4); + memmove((cmd + 1), (uint8_t*)®ister_address, 4); cmd[5] = value; pdiSendBytes(cmd,6); @@ -747,6 +747,7 @@ uint8_t pdiWritePageMemory( uint32_t writeAddress, uint8_t* writeBuffer, uint16_ { // Wait until the NVM controller is no longer busy uint8_t status = pdiWaitNVM() ; + uint32_t boot = writeAddress >= 0x8000 ? 1 : 0 ; if (status != PDI_STATUS_OK ) { pdiEnableTimerClock(); @@ -805,7 +806,14 @@ uint8_t pdiWritePageMemory( uint32_t writeAddress, uint8_t* writeBuffer, uint16_ return status ; } // Send the memory write command to the target */ - pdiWriteCtrl( NVM_COMMAND_REG, XNVM_CMD_ERASE_AND_WRITE_APP_SECTION) ; + if ( boot ) + { + pdiWriteCtrl( NVM_COMMAND_REG, XNVM_CMD_ERASE_AND_WRITE_BOOT_PAGE) ; + } + else + { + pdiWriteCtrl( NVM_COMMAND_REG, XNVM_CMD_ERASE_AND_WRITE_APP_SECTION) ; + } // Send the address of the first page location to write the memory page */ pdiWriteCtrl( writeAddress, 0 ) ;