Index: firmware/App/Services/Download.c =================================================================== diff -u -rec37f8c4308fb2ab322706bd8b5f1af013cd18c9 -r0595b4b31cef5980bc589ff7ce39a4e97bc81d8d --- firmware/App/Services/Download.c (.../Download.c) (revision ec37f8c4308fb2ab322706bd8b5f1af013cd18c9) +++ firmware/App/Services/Download.c (.../Download.c) (revision 0595b4b31cef5980bc589ff7ce39a4e97bc81d8d) @@ -9,6 +9,7 @@ #include "CommBuffers.h" #include "Download.h" +#include "FPGA.h" #include "NVDataMgmt.h" #include "SystemComm.h" #include "Utilities.h" @@ -51,8 +52,9 @@ static void processIncomingUpdateMessage( 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 clearSWUpdateBuffer( void ); +static ACK_NACK_STATUS_T handleFirmwareUpdate( void ); +static ACK_NACK_STATUS_T handleFPGAUpdate( void ); - void initDownload( void ) { thisStackMailBox = RECEIVE_MSG_ID[ BL_STACK_ID ]; @@ -110,7 +112,7 @@ if ( UPDATE_FPGA == dest ) { - // signal FPGA to get ready in parallel + signalFPGAToPrepareForUpdate(); } } @@ -128,10 +130,10 @@ { SW_UPDATE_RESP_STATUS_T resp; - BOOL status = FALSE; - U32 calcCRC = 0; - BOOL hasCRCPassed = FALSE; - ACK_NACK_STATUS_T ackStatus = NACK; + BOOL status = FALSE; + U32 calcCRC = 0; + BOOL hasCRCPassed = FALSE; + ACK_NACK_STATUS_T ackNackStatus = NACK; getCommBuffer( mailBox, (U08*)&SWUpdateRCVStatus, NUM_OF_CAN_BYTES_FOR_UPDATE ); @@ -147,18 +149,11 @@ switch ( SWUpdateRCVStatus.updateDest ) { case UPDATE_FIRMWARE: - if ( SWUpdateRCVStatus.cyberIndex != SW_UPDATE_FINAL_MSG_INDEX ) - { - _disable_IRQ(); - status = handleUpdatingFlash( SWUpdateRCVStatus.SWUpdateBuffer ); - ackStatus = ( TRUE == status ? ACK : NACK ); - _enable_IRQ(); - } + ackNackStatus = handleFirmwareUpdate(); break; case UPDATE_FPGA: - // TODO update FPGA - // TODo FPGA last page done + ackNackStatus = handleFPGAUpdate(); break; default: @@ -167,9 +162,9 @@ } } - prepareResponseMessage( SWUpdateRCVStatus.msgID, ackStatus, &resp ); + prepareResponseMessage( SWUpdateRCVStatus.msgID, ackNackStatus, &resp ); status = sendAckNackStatusFromFirmware( (U08*)&resp ); // TODO do we have to retry if send failed? - clearCommBuffer( mailBox ); // TODo does this need to here? How about resync? + clearCommBuffer( mailBox ); // TODo does this need to be here? How about resync? clearSWUpdateBuffer(); } } @@ -189,5 +184,44 @@ memset( &SWUpdateRCVStatus, 0x0, sizeof( SW_UPDATE_RCV_STATUS_T ) ); } +static ACK_NACK_STATUS_T handleFirmwareUpdate( void ) +{ + ACK_NACK_STATUS_T ackStatus = NACK; + if ( SWUpdateRCVStatus.cyberIndex != SW_UPDATE_FINAL_MSG_INDEX ) + { + _disable_IRQ(); + BOOL status = handleUpdatingFlash( SWUpdateRCVStatus.SWUpdateBuffer ); + ackStatus = ( TRUE == status ? ACK : NACK ); + _enable_IRQ(); + } + return ackStatus; +} + +static ACK_NACK_STATUS_T handleFPGAUpdate( void ) +{ + ACK_NACK_STATUS_T ackStatus = NACK; + + if ( FPGA_UPDATE_READY == getFPGAFlashState() ) + { + if ( SWUpdateRCVStatus.cyberIndex != SW_UPDATE_FINAL_MSG_INDEX ) + { + U08 removeThis; + + for ( removeThis = 0; removeThis < SW_UPDATE_FLASH_BUFFER_SIZE; removeThis++ ) + { + // TODO this is temporary until the ROTTING is removed from the APP + SWUpdateRCVStatus.SWUpdateBuffer[ removeThis ] = 0xFF & ( SWUpdateRCVStatus.SWUpdateBuffer[removeThis] - 27 ); + } + + signalFPGAToWriteToFlash( SWUpdateRCVStatus.SWUpdateBuffer, sizeof( SWUpdateRCVStatus.SWUpdateBuffer ) ); + } + } + + return ackStatus; +} + + + +