Index: firmware/App/Services/Download.c =================================================================== diff -u -r5a58fd72ededee8a718098b53448a2c921c57f49 -r5645305f9349c5c64be5560982bdf1abd5edb0fb --- firmware/App/Services/Download.c (.../Download.c) (revision 5a58fd72ededee8a718098b53448a2c921c57f49) +++ firmware/App/Services/Download.c (.../Download.c) (revision 5645305f9349c5c64be5560982bdf1abd5edb0fb) @@ -9,6 +9,7 @@ #include "NVDataMgmt.h" #include "OperationModes.h" #include "SystemComm.h" +#include "Timers.h" #include "Utilities.h" /** @@ -18,7 +19,7 @@ // ********** private definitions ********** -static const U32 NUM_OF_CAN_BYTES_FOR_UPDATE = SW_UPDATE_FLASH_BUFFER_SIZE + CAN_MESSAGE_FRAME_SIZE; ///< Number of CAN bytes for update. +static const U32 NUM_OF_CAN_BYTES_FOR_UPDATE = SW_UPDATE_FLASH_BUFFER_SIZE + CAN_MESSAGE_FRAME_SIZE_BYTES; ///< Number of CAN bytes for update. // ********** private data ********** @@ -57,16 +58,26 @@ SW_UPDATE_CMD_T cmd; ///< Software update command (e.g. update, verify) } SW_UPDATE_SPECS_T; +/// Software update firmware FPGA broadcast status structure +typedef struct +{ + U16 msgID; ///< Message ID. + U16 reserved; ///< Reserved space. + U32 msgCRC; ///< Message CRC. +} SW_UPDATE_FFU_BROADCAST_STATUS_T; + static SW_UPDATE_RCV_STATUS_T SWUpdateRCVStatus; ///< Software update receive status. -static U32 fpgaPayloadLengthBytes; ///< FPGA payload lenght in bytes. +static U32 fpgaPayloadLengthBytes; ///< FPGA payload length in bytes. static SW_UPDATE_SPECS_T SWUpdateSpecs; ///< Software update specifications. +static U32 SWUpdateLastBroadcastTimeMS; ///< Software update last broadcast time stamp in milliseconds. static U32 REMOVETHEVAR = 0; // TODO remove // ********** private function prototypes ********** static void handleIncomingCmdMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ); static void handleIncomingUpdateMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ); +static void handleIncomingBroadcastMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ); static void prepareAndSendFWResponseMessage( U16 respOfMsgID, ACK_NACK_STATUS_T ackNack ); static void clearSWUpdateBuffer( void ); static ACK_NACK_STATUS_T handleFirmwareUpdate( void ); @@ -83,6 +94,8 @@ { clearSWUpdateBuffer(); clearSWUpdateSpecs(); + // Initialize the last broadcast to a value to make sure it does not timeout immediately. + SWUpdateLastBroadcastTimeMS = getMSTimerCount(); } /*********************************************************************//** @@ -98,6 +111,7 @@ handleIncomingCmdMessage( SW_UPDATE_COMMAD ); handleIncomingUpdateMessage( thisStackMailBox ); + handleIncomingBroadcastMessage( SW_UPDATE_FFU_BROADCAST ); } /*********************************************************************//** @@ -158,6 +172,19 @@ clearCommBuffer( thisStackMailBox ); } +/*********************************************************************//** + * @brief + * The getLastBroadcastMessageTimeStampMS function returns the last software + * update message broadcast in milliseconds. + * @details \b Inputs: SWUpdateLastBroadcastTimeMS + * @details \b Outputs: none + * @return last software update last broadcast time in milliseconds + *************************************************************************/ +U32 getLastBroadcastMessageTimeStampMS( void ) +{ + return SWUpdateLastBroadcastTimeMS; +} + U08 getTempRemoveMSGID() { return SWUpdateRCVStatus.msgID; @@ -281,6 +308,39 @@ /*********************************************************************//** * @brief + * The handleIncomingBroadcastMessage function handles the incoming broadcast + * message from the CAN bus. Once the update message is received and the CRC + * has passed the software update last broadcast time is updated. + * @details \b Inputs: none + * @details \b Outputs: SWUpdateLastBroadcastTimeMS + * @param mailbox of the buffer that has been received + * @return none + *************************************************************************/ +static void handleIncomingBroadcastMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ) +{ + if ( TRUE == isMessageComplete( mailBox ) ) + { + SW_UPDATE_FFU_BROADCAST_STATUS_T SWUpdateFFUBroadcastStatus; + + getCommBuffer( mailBox, (U08*)&SWUpdateFFUBroadcastStatus, sizeof( SW_UPDATE_FFU_BROADCAST_STATUS_T ) ); + + BOOL hasCRCPassed = FALSE; + U32 calcCRC = 0; + + calcCRC = crc32( calcCRC, (U08*)&SWUpdateFFUBroadcastStatus, sizeof( SW_UPDATE_FFU_BROADCAST_STATUS_T ) - sizeof( U32 ) ); + hasCRCPassed = ( SWUpdateFFUBroadcastStatus.msgCRC == calcCRC ? TRUE : FALSE ); + + if ( TRUE == hasCRCPassed ) + { + SWUpdateLastBroadcastTimeMS = getMSTimerCount(); + } + + clearCommBuffer( mailBox ); + } +} + +/*********************************************************************//** + * @brief * The prepareAndSendFWResponseMessage function prepares the message body that is * used to respond to the updater app and sends it. * @details \b Inputs: none