Index: sources/update/MsgLink.h =================================================================== diff -u -r7cf31f6cfef97bb564a103c263821a3b722c8a2b -r2ee835c4c687263fd8852a431db1223cc0e8055c --- sources/update/MsgLink.h (.../MsgLink.h) (revision 7cf31f6cfef97bb564a103c263821a3b722c8a2b) +++ sources/update/MsgLink.h (.../MsgLink.h) (revision 2ee835c4c687263fd8852a431db1223cc0e8055c) @@ -61,6 +61,13 @@ */ const std::chrono::duration g_ms_pause(20); +/*! + * \brief Convert ACK value to milliseconds. + * + * 0=NACK 1= ACK no wait, else ms = (ack-1)*scale. + */ +const uint32 gAckSleepScale = 200; + /*! * This is 2x the line speed transfer of a * message relative to kbps of the line in milliseconds. @@ -149,6 +156,9 @@ // We are expecting data. _expecting = true; + // Default no extra sleep. + _extraSleep = 0; + _wasData = (msgId == SwUpdateCanMsgIds::DataBufferId_HD_FW) || (msgId == SwUpdateCanMsgIds::DataBufferId_HD_FPGA) || @@ -189,8 +199,11 @@ this->sendPacket(msgId, msg, length); // Wait to either retry or success. - if (_ew.wait()) { + if (_ew.wait()) { _expecting = false; + if (_extraSleep != 0) { + _ew.sleep(_extraSleep); + } return true; } _retries++; @@ -277,13 +290,22 @@ // T T F | F For the thread not an ack. // T T T | T For this thread and an ack. if (msgId == SwUpdateCanMsgIds::ResponseId) { - SwUpdateResponse *resp = (SwUpdateResponse *)pData; + SwUpdateResponse *resp = (SwUpdateResponse *)pData; + if (resp->id == _msgIdSlot) { + if (resp->ackNack >= 1) { + rv = true; + if (resp->ackNack != 1) { + _extraSleep = (uint16_t)(resp->ackNack * gAckSleepScale); + } + } + } rv = ((resp->id == _msgIdSlot) && (resp->ackNack == 1)); } else { rv = true; } } } + // It's good? fire event. if (rv) { _ew.fireEvent(); @@ -298,6 +320,7 @@ uint32 _retries; ///< Total number of retries. uint16 _expectedId; ///< Expected message Id. uint8 _msgIdSlot; ///< Message slot. + uint16 _extraSleep; ///< Extra sleep request from FW. bool _wasData; ///< Was data. SwUpdateDataBuffer _dataBuf; ///< Data buffer.