Index: firmware/App/Services/Download.c =================================================================== diff -u -r0c085209bea23f66011059a7c19796c1e4b246fa -r292265111b911fa79c52bb4589911dfb60c921bf --- firmware/App/Services/Download.c (.../Download.c) (revision 0c085209bea23f66011059a7c19796c1e4b246fa) +++ firmware/App/Services/Download.c (.../Download.c) (revision 292265111b911fa79c52bb4589911dfb60c921bf) @@ -10,6 +10,8 @@ #include "SystemComm.h" #include "Utilities.h" +#include "OperationModes.h" + /** * @addtogroup Download * @{ @@ -63,7 +65,7 @@ static void handleIncomingCmdMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ); static void handleIncomingUpdateMessage( SW_UPDATE_CAN_MAIL_BOX_T mailBox ); -static void prepareResponseMessage( U08 respOfMsgID, ACK_NACK_STATUS_T ackNack, SW_UPDATE_RESP_STATUS_T* respBuffer ); +static void prepareAndSendFWResponseMessage( U08 respOfMsgID, ACK_NACK_STATUS_T ackNack ); static void clearSWUpdateBuffer( void ); static ACK_NACK_STATUS_T handleFirmwareUpdate( void ); static ACK_NACK_STATUS_T handleFPGAUpdate( void ); @@ -146,10 +148,7 @@ *************************************************************************/ void sendFPGAAckNackStatus( ACK_NACK_STATUS_T ackNackStatus ) { - SW_UPDATE_RESP_STATUS_T resp; - - prepareResponseMessage( SWUpdateRCVStatus.msgID, ackNackStatus, &resp ); - sendAckNackStatusFromFirmware( (U08*)&resp ); + prepareAndSendFWResponseMessage( SWUpdateRCVStatus.msgID, ackNackStatus ); clearCommBuffer( thisStackMailBox ); } @@ -179,7 +178,6 @@ { // If the command buffer has been received, get it from the comm buffer and process it SW_UPDATE_CMD_STATUS_T SWUpdateCmdStatus; - SW_UPDATE_RESP_STATUS_T resp; getCommBuffer( mailBox, (U08*)&SWUpdateCmdStatus, sizeof( SW_UPDATE_CMD_STATUS_T ) ); @@ -193,10 +191,6 @@ calcCRC = crc32( calcCRC, (U08*)&SWUpdateCmdStatus, sizeof( SW_UPDATE_CMD_STATUS_T ) - sizeof( U32 ) ); hasCRCPassed = ( SWUpdateCmdStatus.msgCRC == calcCRC ? TRUE : FALSE ); - // TODO remove - hasCRCPassed = TRUE; - // TODO remove - if ( TRUE == hasCRCPassed ) { ackStatus = ACK; @@ -210,8 +204,7 @@ } // Send the result of the command received - prepareResponseMessage( msgID, ackStatus, &resp ); - sendAckNackStatusFromFirmware( (U08*)&resp ); + prepareAndSendFWResponseMessage( msgID, ackStatus ); clearCommBuffer( mailBox ); } } @@ -231,15 +224,14 @@ // Peek into the comm buffer to see if the entire data has been received S32 bytesInBuffer = getNumberOfBytesInBuffer( mailBox ); - if ( bytesInBuffer == NUM_OF_CAN_BYTES_FOR_UPDATE ) + if ( ( bytesInBuffer == NUM_OF_CAN_BYTES_FOR_UPDATE ) && ( MODE_UPDATE == getCurrentOpMode() ) ) { - SW_UPDATE_RESP_STATUS_T resp; U08 bufferWithNoCRC[ SW_UPDATE_FLASH_BUFFER_SIZE + sizeof( U32 ) ]; - BOOL status = FALSE; - U32 calcCRC = 0; - BOOL hasCRCPassed = FALSE; - ACK_NACK_STATUS_T ackNackStatus = NACK; + U32 calcCRC = 0; + BOOL hasCRCPassed = FALSE; + ACK_NACK_STATUS_T ackStatus = NACK; + U08 msgID = 0; getCommBuffer( mailBox, (U08*)&SWUpdateRCVStatus, NUM_OF_CAN_BYTES_FOR_UPDATE ); @@ -250,22 +242,25 @@ // Calculate the CRC of the local copied buffer and compare it against the message CRC calcCRC = crc32( calcCRC, bufferWithNoCRC, sizeof( bufferWithNoCRC ) ); hasCRCPassed = ( SWUpdateRCVStatus.msgCRC == calcCRC ? TRUE : FALSE ); + msgID = SWUpdateRCVStatus.msgID; - // TODO remove - hasCRCPassed = TRUE; - // TODO remove + if ( FALSE == hasCRCPassed ) + { + BOOL test = TRUE; + } + if ( TRUE == hasCRCPassed ) { // CRC passed, call the corresponding the handlers to update either FPGA or firmware switch ( SWUpdateRCVStatus.updateDest ) { case UPDATE_FIRMWARE: - ackNackStatus = handleFirmwareUpdate(); + ackStatus = handleFirmwareUpdate(); break; case UPDATE_FPGA: - ackNackStatus = handleFPGAUpdate(); + ackStatus = handleFPGAUpdate(); break; default: @@ -274,35 +269,33 @@ } } - // TODo send nack if the CRC failed - - //prepareResponseMessage( SWUpdateRCVStatus.msgID, ackNackStatus, &resp ); - //status = sendAckNackStatusFromFirmware( (U08*)&resp ); // TODO do we have to retry if send failed? + prepareAndSendFWResponseMessage( msgID, ackStatus ); clearCommBuffer( mailBox ); // TODo does this need to be here? How about resync? - //clearSWUpdateBuffer(); // TODO uncomment + clearSWUpdateBuffer(); // TODO uncomment } } /*********************************************************************//** * @brief - * The prepareResponseMessage function prepares the message body that is - * used to respond to the updater app. + * The prepareAndSendFWResponseMessage function prepares the message body that is + * used to respond to the updater app and sends it. * @details \b Inputs: none * @details \b Outputs: none * @param message ID that is being responded for * @param ack nack status - * @param response buffer which is the pointer to the buffer that is used - * to be sent to the app * @return none *************************************************************************/ -static void prepareResponseMessage( U08 respOfMsgID, ACK_NACK_STATUS_T ackNack, SW_UPDATE_RESP_STATUS_T* respBuffer ) +static void prepareAndSendFWResponseMessage( U08 respOfMsgID, ACK_NACK_STATUS_T ackNack ) { + SW_UPDATE_RESP_STATUS_T resp; U32 calcCRC = 0; - respBuffer->msgID = respOfMsgID; - respBuffer->msgAckNackStatus = ackNack; - respBuffer->cyberRandom = 0; - respBuffer->msgCRC = crc32( calcCRC, (U08*)&respBuffer, sizeof( SW_UPDATE_RESP_STATUS_T ) - sizeof( U32 ) ); + resp.msgID = respOfMsgID; + resp.msgAckNackStatus = ackNack; + resp.cyberRandom = 0; + resp.msgCRC = crc32( calcCRC, (U08*)&resp, sizeof( SW_UPDATE_RESP_STATUS_T ) - sizeof( U32 ) ); + + sendAckNackStatusFromFirmware( (U08*)&resp ); // TODO do we have to retry if send failed? } /*********************************************************************//** @@ -328,8 +321,6 @@ *************************************************************************/ static ACK_NACK_STATUS_T handleFirmwareUpdate( void ) { - SW_UPDATE_RESP_STATUS_T resp; - ACK_NACK_STATUS_T ackStatus = ACK; BOOL status = FALSE; @@ -341,10 +332,6 @@ _enable_IRQ(); } - prepareResponseMessage( SWUpdateRCVStatus.msgID, ackStatus, &resp ); - status = sendAckNackStatusFromFirmware( (U08*)&resp ); // TODO do we have to retry if send failed? - clearCommBuffer( thisStackMailBox ); // TODo does this need to be here? How about resync? - return ackStatus; } @@ -377,10 +364,7 @@ } else { - SW_UPDATE_RESP_STATUS_T resp; - - prepareResponseMessage( SWUpdateRCVStatus.msgID, ACK, &resp ); - sendAckNackStatusFromFirmware( (U08*)&resp ); + prepareAndSendFWResponseMessage( SWUpdateRCVStatus.msgID, ACK ); } return ackStatus;