fix STR bugs and improve code

- Reset reply size after returning a reply
- Reset data link layer and flush RX for regular commands and before
  performing special commands to ensure consistent start state
- Clean up DHB a bit
- Set STR dev to OFF in assembly when it is faulty.
This commit is contained in:
2023-04-04 01:35:05 +02:00
parent afbab6d3f2
commit 9270165bf8
5 changed files with 72 additions and 59 deletions

View File

@ -42,7 +42,6 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
while (true) {
lock->lockMutex();
state = InternalState::SLEEPING;
datalinkLayer.reset();
lock->unlockMutex();
semaphore.acquire();
switch (state) {
@ -58,6 +57,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
}
case InternalState::UPLOAD_IMAGE: {
replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performImageUpload();
if (result == returnvalue::OK) {
triggerEvent(IMAGE_UPLOAD_SUCCESSFUL);
@ -68,6 +68,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
}
case InternalState::DOWNLOAD_IMAGE: {
replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performImageDownload();
if (result == returnvalue::OK) {
triggerEvent(IMAGE_DOWNLOAD_SUCCESSFUL);
@ -78,6 +79,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
}
case InternalState::FLASH_READ: {
replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performFlashRead();
if (result == returnvalue::OK) {
triggerEvent(FLASH_READ_SUCCESSFUL);
@ -88,6 +90,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
}
case InternalState::FIRMWARE_UPDATE: {
replyTimeout.setTimeout(200);
resetReplyHandlingState();
result = performFirmwareUpdate();
if (result == returnvalue::OK) {
triggerEvent(FIRMWARE_UPDATE_SUCCESSFUL);
@ -645,7 +648,8 @@ ReturnValue_t StrComHandler::sendMessage(CookieIF* cookie, const uint8_t* sendDa
return BUSY;
}
}
serial::flushRxBuf(serialPort);
// Ensure consistent state.
resetReplyHandlingState();
const uint8_t* txFrame;
size_t frameLen;
@ -697,6 +701,7 @@ ReturnValue_t StrComHandler::readReceivedMessage(CookieIF* cookie, uint8_t** buf
*buffer = const_cast<uint8_t*>(replyPtr);
*size = replyLen;
}
replyLen = 0;
return replyResult;
}
@ -781,3 +786,8 @@ ReturnValue_t StrComHandler::readOneReply(uint32_t failParameter) {
}
}
}
void StrComHandler::resetReplyHandlingState() {
serial::flushRxBuf(serialPort);
datalinkLayer.reset();
}