Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -19,7 +19,7 @@ // ********** private definitions ********** -#define WAIT_FOR_UPDATE_FROM_UI_MS 1000 ///< Wait for update timeout in milliseconds. +#define WAIT_FOR_UPDATE_FROM_UI_MS 3000000 ///< Wait for update timeout in milliseconds. // ********** private data ********** @@ -58,7 +58,7 @@ { initStandbyMode(); - return 0; + return standbyCurrentState; } /*********************************************************************//** @@ -70,8 +70,7 @@ *************************************************************************/ U32 execStandbyMode( void ) { - // If the bootloader is the standby mode and and update request is received at any time, request a transition to update mode - // TODO what if we are in the check image process, should we transition to update upon the request? + // If the bootloader is in standby mode and update request is received at any time, request a transition to update mode if ( ( UPDATE_CMD_START == getSWUpdateCommandState() ) || ( TRUE == hasUpdateBeenRequested() ) ) { // TODO if we are here because of the FPGA register, clear it so it won't be called again. @@ -114,8 +113,9 @@ static MODE_STANDBY_STATE_T handleStandbyModeCheckForUpdateState( void ) { MODE_STANDBY_STATE_T state = STANDBY_CHECK_FOR_UPDATE_STATE; + SW_UPDATE_CMD_T cmd = getSWUpdateCommandState(); - switch ( getSWUpdateCommandState() ) + switch ( cmd ) { case UPDATE_CMD_ABORT: state = STANDBY_IDLE_STATE; @@ -130,7 +130,7 @@ break; } - if ( TRUE == didTimeout( waitForUpdateMsgStartTimeMS, 3000000 /*WAIT_FOR_UPDATE_FROM_UI_MS*/ ) ) // TODO a high number if timeout for development + if ( TRUE == didTimeout( waitForUpdateMsgStartTimeMS, WAIT_FOR_UPDATE_FROM_UI_MS ) ) { state = STANDBY_CHECK_FW_AND_FPGA_IMAGES_STATE; } @@ -144,42 +144,34 @@ * check firmware and FPGA images state. * This state checks the integrity of the firmware as well as the FPGA header * to make sure the images are valid. - * @details \b Inputs: waitForUpdateMsgStartTimeMS + * @details \b Inputs: none * @details \b Outputs: none * @return next state of the standby mode state machine *************************************************************************/ static MODE_STANDBY_STATE_T handleStandbyModeCheckFWAndFPGAImages( void ) { - MODE_STANDBY_STATE_T state = STANDBY_CHECK_FW_AND_FPGA_IMAGES_STATE; + MODE_STANDBY_STATE_T state = STANDBY_IDLE_STATE; BOOL isFirmwareImageValid = FALSE; BOOL isFPGAImageValid = FALSE; - // TODo timeout and wait for a while prior to transitioning // TODO why a bad code passes the CRC? - _disable_IRQ(); + // TODO send the results back (pass/fail) up to be sent to the cloud. if ( TRUE == isFWCRCTableValid() ) { isFirmwareImageValid = runFWIntegrityTest(); } - _enable_IRQ(); if ( TRUE == isFPGAIDValid() ) { isFPGAImageValid = TRUE; } + // NOTE: If either of the images (firmware or FPGA) failed, go to the idle state until another update request is received if ( ( TRUE == isFirmwareImageValid ) && ( TRUE == isFPGAImageValid ) ) { // All good, jump to application jumpToApplication(); } - else - { - // TODO do we need to try a few times prior to tansitioning to Idle? - // If either of the images (firmware or FPGA) failed, go to the idle state until another update request is received - state = STANDBY_IDLE_STATE; - } - return state; } Index: firmware/App/Modes/ModeUpdate.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Modes/ModeUpdate.c (.../ModeUpdate.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Modes/ModeUpdate.c (.../ModeUpdate.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -39,7 +39,7 @@ * @brief * The transitionToUpdateMode function prepares for transition to Update Mode. * @details \b Inputs: none - * @details \b Outputs: Standby Mode unit re-initialized + * @details \b Outputs: Update Mode unit re-initialized * @return none *************************************************************************/ U32 transitionToUpdateMode( void ) @@ -51,7 +51,7 @@ // Got the update command so we are in the update mode. Clear the command clearSWUpdateCommandState(); - return 0; + return updateCurrentState; } /*********************************************************************//** @@ -82,7 +82,7 @@ break; } - return 0; + return updateCurrentState; } /*********************************************************************//** @@ -96,8 +96,9 @@ static MODE_SW_UPDATE_STATE_T handleUpdateModeUpdateState( void ) { MODE_SW_UPDATE_STATE_T state = SW_UPDATE_UPDATE_STATE; + SW_UPDATE_CMD_T cmd = getSWUpdateCommandState(); - switch( getSWUpdateCommandState() ) + switch( cmd ) { case UPDATE_CMD_VERIFY: state = SW_UPDATE_VERIFY_STATE; @@ -129,8 +130,9 @@ static MODE_SW_UPDATE_STATE_T handleUpdateModeVerifyState( void ) { MODE_SW_UPDATE_STATE_T state = SW_UPDATE_VERIFY_STATE; + SW_UPDATE_DESINTATION_T dest = getSWUpdateDestination(); - switch( getSWUpdateDestination() ) + switch( dest ) { case UPDATE_FPGA: if ( TRUE == isFPGAFlashComplete() ) Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -57,15 +57,16 @@ switch ( currentMode ) { case MODE_STAND: - execStandbyMode(); + currentMode = (BL_OP_MODE_T)execStandbyMode(); break; case MODE_UPDATE: - execUpdateMode(); + currentMode = (BL_OP_MODE_T)execUpdateMode(); break; default: // Do nothing + // TODO alarm? break; } } @@ -102,15 +103,16 @@ switch ( newMode ) { case MODE_STAND: - transitionToStandbyMode(); + currentMode = (BL_OP_MODE_T)transitionToStandbyMode(); break; case MODE_UPDATE: - transitionToUpdateMode(); + currentMode = (BL_OP_MODE_T)transitionToUpdateMode(); break; default: // Do nothing for now + // TODO alarm? break; } } Index: firmware/App/Services/Comm.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Services/Comm.c (.../Comm.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Services/Comm.c (.../Comm.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -64,3 +64,5 @@ { scilinREG->CLEARINT = SCI_DMA_TRANSMIT_INT; } + +/**@}*/ Index: firmware/App/Services/CommBuffers.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -11,17 +11,17 @@ // ********** private definitions ********** -#define MAX_NUM_OF_CAN_BYTES ( SW_UPDATE_FLASH_BUFFER_SIZE + CAN_MESSAGE_PAYLOAD_SIZE ) ///< Maximum number of CAN bytes. +#define UPDATE_PACKET_SIZE_BYTES ( SW_UPDATE_FLASH_BUFFER_SIZE + CAN_MESSAGE_PAYLOAD_SIZE ) ///< Software update packet size in bytes. -// ********** private data ********** - /// Software update buffer structure typedef struct { U32 SWUpdateFrameCount; ///< Software update frame count. - U08 SWUpdateBuffer[ MAX_NUM_OF_CAN_BYTES ]; ///< Software update buffer. + U08 SWUpdateBuffer[ UPDATE_PACKET_SIZE_BYTES ]; ///< Software update buffer. } SW_UPDATE_BUFFER_T; +// ********** private data ********** + static SW_UPDATE_BUFFER_T SWUpdateBuffer[ NUM_OF_SW_UPDATE_MBOXES ]; ///< Software update buffer array. // ********** private function prototypes ******** @@ -47,7 +47,6 @@ * @brief * The addToCommBuffer function adds data of specified length to a given * communication buffer. - * @note This function will add to the active side of the double buffer. * @note This function is thread safe. IRQ interrupts are disabled during * buffer operations. * @details Inputs: SWUpdateBuffer[] @@ -67,7 +66,7 @@ U32 currentFrameCount = SWUpdateBuffer[ mailBox ].SWUpdateFrameCount; // Check if the number of bytes is less than the allowed bytes in the mailbox buffer. - if ( ( currentFrameCount * CAN_MESSAGE_PAYLOAD_SIZE ) <= MAX_NUM_OF_CAN_BYTES ) + if ( ( currentFrameCount * CAN_MESSAGE_PAYLOAD_SIZE ) <= UPDATE_PACKET_SIZE_BYTES ) { U32 currentBufferIndex = currentFrameCount * len; @@ -89,7 +88,6 @@ * The getFromCommBuffer function fills a given byte array with a specified * number of bytes from a given buffer and returns the number of bytes * retrieved from the buffer. - * @note This function will draw from the inactive side of the double buffer * and, if needed, switch double buffers to draw the rest of the requested data. * @note This function is thread safe. IRQ interrupts are disabled during buffer * operations. @@ -104,7 +102,7 @@ { BOOL status = FALSE; - if ( ( mailBox < NUM_OF_SW_UPDATE_MBOXES ) && ( len <= MAX_NUM_OF_CAN_BYTES ) ) + if ( ( mailBox < NUM_OF_SW_UPDATE_MBOXES ) && ( len <= UPDATE_PACKET_SIZE_BYTES ) ) { _disable_IRQ(); memcpy( data, SWUpdateBuffer[ mailBox ].SWUpdateBuffer, len ); @@ -118,8 +116,7 @@ /*********************************************************************//** * @brief * The getNumberOfBytesInBuffer function determines how many bytes - * are currently contained in a given comm buffer. Both sides of the - * double buffers are considered for this. + * are currently contained in a given comm buffer. * @details Inputs: SWUpdateBuffer[] * @details Outputs: none * @param mailbox ID of buffer to get byte count for Index: firmware/App/Services/Download.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Services/Download.c (.../Download.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Services/Download.c (.../Download.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -20,10 +20,10 @@ #define SW_UPDATE_FINAL_MSG_INDEX 0xFFFF ///< Software update final message index. #define SHIFT_BITS_TO_GET_TARGET 4 ///< Shift bits by 4 to get the update target. -// ********** private data ********** - static const U32 NUM_OF_CAN_BYTES_FOR_UPDATE = SW_UPDATE_FLASH_BUFFER_SIZE + CAN_MESSAGE_PAYLOAD_SIZE; ///< Number of CAN bytes for update. +// ********** private data ********** + /// Software update response status structure typedef struct { @@ -88,11 +88,10 @@ * The execDownload function executes the download state machine. * @details \b Inputs: none * @details \b Outputs: none - * @return none TODO change the design to a state machine + * @return none *************************************************************************/ void execDownload( void ) { - // TODO make this a state machine handleIncomingCmdMessage( SW_UPDATE_COMMAD ); handleIncomingUpdateMessage( thisStackMailBox ); } @@ -386,7 +385,3 @@ return ackStatus; } - - - - Index: firmware/App/Services/FPGA.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -175,7 +175,8 @@ /// FPGA stack ID for TD, DD, RO. static const U08 STACK_FPGA_ID[ NUM_OF_FW_STACKS ] = { 0x5A, 0x61, 0xFF }; // TODO update with the real FPGA IDs -static const U16 DISABLE_UPDATE_REG_CMD = 5; ///< FPGA disable update register command. // TODO what is this value? 0? +// TODO what is this value? 0? +static const U16 DISABLE_UPDATE_REG_CMD = 5; ///< FPGA disable update register command. static const U08 FPGA_RESET_FLASH_CMD = 0x01; ///< FPGA reset flash command. static const U08 FPGA_ERASE_FIFO_CMD = 0x08; ///< FPGA erase FIFO command. static const U08 FPGA_ENABLE_FLASH_CMD = 0x00; ///< FPGA enable flash command. @@ -366,7 +367,7 @@ * TRUE if the flash is complete, otherwise, FALSE. * @details \b Inputs: fpgaFlashStatus * @details \b Outputs: none - * @return the status of the FPGA flash + * @return TRUE if flash is complete otherwise, FALSE *************************************************************************/ BOOL isFPGAFlashComplete( void ) { Index: firmware/App/Tasks/TaskBG.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Tasks/TaskBG.c (.../TaskBG.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Tasks/TaskBG.c (.../TaskBG.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -25,6 +25,8 @@ #endif { execDownload(); + + // TODo add watchdog } } Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -22,6 +22,8 @@ void taskGeneral( void ) { execOperationModes(); + + // TODo add watchdog } /**@}*/ Index: firmware/App/Tasks/TaskPriority.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -22,6 +22,8 @@ void taskPriority( void ) { execFPGA(); + + // TODo add watchdog } /**@}*/ Index: firmware/App/Tasks/TaskPriority.h =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/App/Tasks/TaskPriority.h (.../TaskPriority.h) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/App/Tasks/TaskPriority.h (.../TaskPriority.h) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -14,6 +14,8 @@ // Public definitions +#define TASK_PRIORITY_INTERVAL (10) ///< Priority task timer interrupt interval (in ms). + // Public function prototypes void taskPriority( void ); Index: firmware/source/sys_main.c =================================================================== diff -u -rc74c1d99a011dd0fb7f98f183faecda675221fce -radea34db9066bdc0dbb20f49bdf66c9331a7037c --- firmware/source/sys_main.c (.../sys_main.c) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) +++ firmware/source/sys_main.c (.../sys_main.c) (revision adea34db9066bdc0dbb20f49bdf66c9331a7037c) @@ -77,6 +77,11 @@ */ /* USER CODE BEGIN (2) */ +/* + * For reference: + * https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/403240/change-load-address-when-debugging-with-tm4c129cnczad + * https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1218850/rm46l852-booting-main-application-from-can-bootloader-results-in-prefetchentry-system-interrupt + */ static void initProcessor( void ); static void initSoftware( void ); static void initTasks( void );