clean up error handlng code

This commit is contained in:
Robin Müller 2023-05-15 14:40:14 +02:00
parent ae6b5b491b
commit 178a2183a2
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
7 changed files with 121 additions and 116 deletions

View File

@ -345,7 +345,6 @@ void scheduling::initTasks() {
} }
#endif /* OBSW_ADD_STAR_TRACKER == 1 */ #endif /* OBSW_ADD_STAR_TRACKER == 1 */
// TODO: Use regular scheduler for this task
#if OBSW_ADD_PLOC_MPSOC == 1 #if OBSW_ADD_PLOC_MPSOC == 1
PeriodicTaskIF* mpsocHelperTask = factory->createPeriodicTask( PeriodicTaskIF* mpsocHelperTask = factory->createPeriodicTask(
"PLOC_MPSOC_HELPER", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc); "PLOC_MPSOC_HELPER", 0, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
@ -472,6 +471,9 @@ void scheduling::initTasks() {
#if OBSW_ADD_PLOC_SUPERVISOR == 1 #if OBSW_ADD_PLOC_SUPERVISOR == 1
supvHelperTask->startTask(); supvHelperTask->startTask();
#endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */ #endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */
#if OBSW_ADD_PLOC_MPSOC == 1
mpsocHelperTask->startTask();
#endif
plTask->startTask(); plTask->startTask();
#if OBSW_ADD_TEST_CODE == 1 #if OBSW_ADD_TEST_CODE == 1

View File

@ -136,6 +136,7 @@ ReturnValue_t PlocMPSoCHandler::executeAction(ActionId_t actionId, MessageQueueI
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
plocMPSoCHelper->setSequenceCount(&sequenceCount);
result = plocMPSoCHelper->startFlashWrite(flashWritePusCmd.getObcFile(), result = plocMPSoCHelper->startFlashWrite(flashWritePusCmd.getObcFile(),
flashWritePusCmd.getMPSoCFile()); flashWritePusCmd.getMPSoCFile());
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -150,6 +151,9 @@ ReturnValue_t PlocMPSoCHandler::executeAction(ActionId_t actionId, MessageQueueI
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
sif::debug << "starting flash read" << std::endl;
sif::debug << "sequence count: " << sequenceCount.get() << std::endl;
plocMPSoCHelper->setSequenceCount(&sequenceCount);
result = plocMPSoCHelper->startFlashRead(flashReadPusCmd.getObcFile(), result = plocMPSoCHelper->startFlashRead(flashReadPusCmd.getObcFile(),
flashReadPusCmd.getMPSoCFile(), flashReadPusCmd.getMPSoCFile(),
flashReadPusCmd.getReadSize()); flashReadPusCmd.getReadSize());
@ -158,7 +162,6 @@ ReturnValue_t PlocMPSoCHandler::executeAction(ActionId_t actionId, MessageQueueI
} }
plocMPSoCHelperExecuting = true; plocMPSoCHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
break;
} }
case (mpsoc::OBSW_RESET_SEQ_COUNT): { case (mpsoc::OBSW_RESET_SEQ_COUNT): {
sequenceCount = 0; sequenceCount = 0;
@ -790,7 +793,7 @@ ReturnValue_t PlocMPSoCHandler::handleAckReport(const uint8_t* data) {
sif::debug << "PlocMPSoCHandler::handleAckReport: Received Ack failure report" << std::endl; sif::debug << "PlocMPSoCHandler::handleAckReport: Received Ack failure report" << std::endl;
DeviceCommandId_t commandId = getPendingCommand(); DeviceCommandId_t commandId = getPendingCommand();
uint16_t status = getStatus(data); uint16_t status = getStatus(data);
printStatus(data); sif::warning << "Verification report status: " << mpsoc::getStatusString(status) << std::endl;
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) { if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
triggerEvent(ACK_FAILURE, commandId, status); triggerEvent(ACK_FAILURE, commandId, status);
} }
@ -836,13 +839,12 @@ ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) {
sif::warning << "PlocMPSoCHandler::handleExecutionReport: Received execution failure report" sif::warning << "PlocMPSoCHandler::handleExecutionReport: Received execution failure report"
<< std::endl; << std::endl;
DeviceCommandId_t commandId = getPendingCommand(); DeviceCommandId_t commandId = getPendingCommand();
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) { if (commandId == DeviceHandlerIF::NO_COMMAND_ID) {
uint16_t status = getStatus(data);
triggerEvent(EXE_FAILURE, commandId, status);
} else {
sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl; sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl;
} }
printStatus(data); uint16_t status = getStatus(data);
sif::warning << "Verification report status: " << mpsoc::getStatusString(status) << std::endl;
triggerEvent(EXE_FAILURE, commandId, status);
sendFailureReport(mpsoc::EXE_REPORT, MPSoCReturnValuesIF::RECEIVED_EXE_FAILURE); sendFailureReport(mpsoc::EXE_REPORT, MPSoCReturnValuesIF::RECEIVED_EXE_FAILURE);
result = IGNORE_REPLY_DATA; result = IGNORE_REPLY_DATA;
cmdDoneHandler(false, MPSoCReturnValuesIF::RECEIVED_EXE_FAILURE); cmdDoneHandler(false, MPSoCReturnValuesIF::RECEIVED_EXE_FAILURE);
@ -1428,11 +1430,6 @@ void PlocMPSoCHandler::disableExeReportReply() {
info->command->second.expectedReplies = 0; info->command->second.expectedReplies = 0;
} }
void PlocMPSoCHandler::printStatus(const uint8_t* data) {
uint16_t status = (*(data + STATUS_OFFSET) << 8) | *(data + STATUS_OFFSET + 1);
sif::info << "Verification report status: " << getStatusString(status) << std::endl;
}
uint16_t PlocMPSoCHandler::getStatus(const uint8_t* data) { uint16_t PlocMPSoCHandler::getStatus(const uint8_t* data) {
return (*(data + STATUS_OFFSET) << 8) | *(data + STATUS_OFFSET + 1); return (*(data + STATUS_OFFSET) << 8) | *(data + STATUS_OFFSET + 1);
} }
@ -1494,90 +1491,3 @@ void PlocMPSoCHandler::cmdDoneHandler(bool success, ReturnValue_t result) {
} }
disableAllReplies(); disableAllReplies();
} }
std::string PlocMPSoCHandler::getStatusString(uint16_t status) {
switch (status) {
case (mpsoc::status_code::UNKNOWN_APID): {
return "Unknown APID";
break;
}
case (mpsoc::status_code::INCORRECT_LENGTH): {
return "Incorrect length";
break;
}
case (mpsoc::status_code::INCORRECT_CRC): {
return "Incorrect crc";
break;
}
case (mpsoc::status_code::INCORRECT_PKT_SEQ_CNT): {
return "Incorrect packet sequence count";
break;
}
case (mpsoc::status_code::TC_NOT_ALLOWED_IN_MODE): {
return "TC not allowed in this mode";
break;
}
case (mpsoc::status_code::TC_EXEUTION_DISABLED): {
return "TC execution disabled";
break;
}
case (mpsoc::status_code::FLASH_MOUNT_FAILED): {
return "Flash mount failed";
break;
}
case (mpsoc::status_code::FLASH_FILE_ALREADY_CLOSED): {
return "Flash file already closed";
break;
}
case (mpsoc::status_code::FLASH_FILE_OPEN_FAILED): {
return "Flash file open failed";
break;
}
case (mpsoc::status_code::FLASH_FILE_NOT_OPEN): {
return "Flash file not open";
break;
}
case (mpsoc::status_code::FLASH_UNMOUNT_FAILED): {
return "Flash unmount failed";
break;
}
case (mpsoc::status_code::HEAP_ALLOCATION_FAILED): {
return "Heap allocation failed";
break;
}
case (mpsoc::status_code::INVALID_PARAMETER): {
return "Invalid parameter";
break;
}
case (mpsoc::status_code::NOT_INITIALIZED): {
return "Not initialized";
break;
}
case (mpsoc::status_code::REBOOT_IMMINENT): {
return "Reboot imminent";
break;
}
case (mpsoc::status_code::CORRUPT_DATA): {
return "Corrupt data";
break;
}
case (mpsoc::status_code::FLASH_CORRECTABLE_MISMATCH): {
return "Flash correctable mismatch";
break;
}
case (mpsoc::status_code::FLASH_UNCORRECTABLE_MISMATCH): {
return "Flash uncorrectable mismatch";
break;
}
case (mpsoc::status_code::DEFAULT_ERROR_CODE): {
return "Default error code";
break;
}
default:
std::stringstream ss;
ss << "0x" << std::hex << status;
return ss.str();
break;
}
return "";
}

View File

@ -297,8 +297,6 @@ class PlocMPSoCHandler : public DeviceHandlerBase, public CommandsActionsIF {
*/ */
void disableExeReportReply(); void disableExeReportReply();
void printStatus(const uint8_t* data);
ReturnValue_t prepareTcModeReplay(); ReturnValue_t prepareTcModeReplay();
uint16_t getStatus(const uint8_t* data); uint16_t getStatus(const uint8_t* data);
@ -306,8 +304,6 @@ class PlocMPSoCHandler : public DeviceHandlerBase, public CommandsActionsIF {
void cmdDoneHandler(bool success, ReturnValue_t result); void cmdDoneHandler(bool success, ReturnValue_t result);
void handleActionCommandFailure(ActionId_t actionId); void handleActionCommandFailure(ActionId_t actionId);
std::string getStatusString(uint16_t status);
}; };
#endif /* BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_ */ #endif /* BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_ */

View File

@ -38,6 +38,7 @@ ReturnValue_t PlocMPSoCHelper::performOperation(uint8_t operationCode) {
#endif #endif
switch (internalState) { switch (internalState) {
case InternalState::IDLE: { case InternalState::IDLE: {
sif::debug << "ploc mpsoc helper idle" << std::endl;
semaphore.acquire(); semaphore.acquire();
break; break;
} }
@ -84,32 +85,35 @@ void PlocMPSoCHelper::setSequenceCount(SourceSequenceCounter* sequenceCount_) {
} }
ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string mpsocFile) { ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string mpsocFile) {
if (internalState != InternalState::IDLE) {
return returnvalue::FAILED;
}
ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile)); ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile));
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
internalState = InternalState::FLASH_WRITE; internalState = InternalState::FLASH_WRITE;
return result; return semaphore.release();
} }
ReturnValue_t PlocMPSoCHelper::startFlashRead(std::string obcFile, std::string mpsocFile, ReturnValue_t PlocMPSoCHelper::startFlashRead(std::string obcFile, std::string mpsocFile,
size_t readFileSize) { size_t readFileSize) {
if (internalState != InternalState::IDLE) {
return returnvalue::FAILED;
}
ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile)); ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile));
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
flashReadAndWrite.totalReadSize = readFileSize; flashReadAndWrite.totalReadSize = readFileSize;
internalState = InternalState::FLASH_READ; internalState = InternalState::FLASH_READ;
return result; return semaphore.release();
} }
ReturnValue_t PlocMPSoCHelper::resetHelper() { void PlocMPSoCHelper::resetHelper() {
ReturnValue_t result = returnvalue::OK;
semaphore.release();
spParams.buf = commandBuffer; spParams.buf = commandBuffer;
terminate = false; terminate = false;
result = uartComIF->flushUartRxBuffer(comCookie); uartComIF->flushUartRxBuffer(comCookie);
return result;
} }
void PlocMPSoCHelper::stopProcess() { terminate = true; } void PlocMPSoCHelper::stopProcess() { terminate = true; }
@ -169,11 +173,13 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
} }
ReturnValue_t PlocMPSoCHelper::performFlashRead() { ReturnValue_t PlocMPSoCHelper::performFlashRead() {
sif::debug << "performing flash read" << std::endl;
std::error_code e; std::error_code e;
std::ofstream ofile(flashReadAndWrite.obcFile, std::ios::trunc | std::ios::binary); std::ofstream ofile(flashReadAndWrite.obcFile, std::ios::trunc | std::ios::binary);
if (ofile.bad()) { if (ofile.bad()) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
sif::debug << "Sequence count: " << sequenceCount->get() << std::endl;
ReturnValue_t result = flashfopen(); ReturnValue_t result = flashfopen();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
std::filesystem::remove(flashReadAndWrite.obcFile, e); std::filesystem::remove(flashReadAndWrite.obcFile, e);
@ -191,11 +197,13 @@ ReturnValue_t PlocMPSoCHelper::performFlashRead() {
if (flashReadAndWrite.totalReadSize - readSoFar < mpsoc::MAX_FLASH_READ_DATA_SIZE) { if (flashReadAndWrite.totalReadSize - readSoFar < mpsoc::MAX_FLASH_READ_DATA_SIZE) {
nextReadSize = flashReadAndWrite.totalReadSize - readSoFar; nextReadSize = flashReadAndWrite.totalReadSize - readSoFar;
} }
sif::debug << "reading " << nextReadSize << " bytes from offset " << readSoFar << std::endl;
if (ofile.bad() or not ofile.is_open()) { if (ofile.bad() or not ofile.is_open()) {
std::filesystem::remove(flashReadAndWrite.obcFile, e); std::filesystem::remove(flashReadAndWrite.obcFile, e);
flashfclose(); flashfclose();
return FILE_READ_ERROR; return FILE_READ_ERROR;
} }
(*sequenceCount)++;
mpsoc::TcFlashRead flashReadRequest(spParams, *sequenceCount); mpsoc::TcFlashRead flashReadRequest(spParams, *sequenceCount);
result = flashReadRequest.buildPacket(nextReadSize); result = flashReadRequest.buildPacket(nextReadSize);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -215,9 +223,9 @@ ReturnValue_t PlocMPSoCHelper::performFlashRead() {
flashfclose(); flashfclose();
return result; return result;
} }
(*sequenceCount)++;
readSoFar += nextReadSize; readSoFar += nextReadSize;
} }
sif::debug << "read file done" << std::endl;
return result; return result;
} }
@ -439,7 +447,8 @@ ReturnValue_t PlocMPSoCHelper::startFlashReadOrWriteBase(std::string obcFile,
flashReadAndWrite.obcFile = std::move(obcFile); flashReadAndWrite.obcFile = std::move(obcFile);
flashReadAndWrite.mpsocFile = std::move(mpsocFile); flashReadAndWrite.mpsocFile = std::move(mpsocFile);
return resetHelper(); resetHelper();
return returnvalue::OK;
} }
ReturnValue_t PlocMPSoCHelper::checkReceivedTm(SpTmReader& reader) { ReturnValue_t PlocMPSoCHelper::checkReceivedTm(SpTmReader& reader) {
@ -456,12 +465,13 @@ ReturnValue_t PlocMPSoCHelper::checkReceivedTm(SpTmReader& reader) {
triggerEvent(MPSOC_TM_CRC_MISSMATCH, *sequenceCount); triggerEvent(MPSOC_TM_CRC_MISSMATCH, *sequenceCount);
return result; return result;
} }
(*sequenceCount)++;
uint16_t recvSeqCnt = reader.getSequenceCount(); uint16_t recvSeqCnt = reader.getSequenceCount();
if (recvSeqCnt != *sequenceCount) { if (recvSeqCnt != *sequenceCount) {
triggerEvent(MPSOC_HELPER_SEQ_CNT_MISMATCH, *sequenceCount, recvSeqCnt); triggerEvent(MPSOC_HELPER_SEQ_CNT_MISMATCH, *sequenceCount, recvSeqCnt);
*sequenceCount = recvSeqCnt; *sequenceCount = recvSeqCnt;
} }
// This sequence count ping pong does not make any sense but it is how the MPSoC expects it.
(*sequenceCount)++;
return returnvalue::OK; return returnvalue::OK;
} }

View File

@ -172,7 +172,7 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
// Sequence count, must be set by Ploc MPSoC Handler // Sequence count, must be set by Ploc MPSoC Handler
SourceSequenceCounter* sequenceCount = nullptr; SourceSequenceCounter* sequenceCount = nullptr;
ReturnValue_t resetHelper(); void resetHelper();
ReturnValue_t performFlashWrite(); ReturnValue_t performFlashWrite();
ReturnValue_t performFlashRead(); ReturnValue_t performFlashRead();
ReturnValue_t flashfopen(); ReturnValue_t flashfopen();

View File

@ -989,6 +989,93 @@ class HkReport : public StaticLocalDataSet<36> {
lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::REBOOT_MPSOC_REQUIRED, this); lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::REBOOT_MPSOC_REQUIRED, this);
}; };
const char* getStatusString(uint16_t status) {
switch (status) {
case (mpsoc::status_code::UNKNOWN_APID): {
return "Unknown APID";
break;
}
case (mpsoc::status_code::INCORRECT_LENGTH): {
return "Incorrect length";
break;
}
case (mpsoc::status_code::INCORRECT_CRC): {
return "Incorrect crc";
break;
}
case (mpsoc::status_code::INCORRECT_PKT_SEQ_CNT): {
return "Incorrect packet sequence count";
break;
}
case (mpsoc::status_code::TC_NOT_ALLOWED_IN_MODE): {
return "TC not allowed in this mode";
break;
}
case (mpsoc::status_code::TC_EXEUTION_DISABLED): {
return "TC execution disabled";
break;
}
case (mpsoc::status_code::FLASH_MOUNT_FAILED): {
return "Flash mount failed";
break;
}
case (mpsoc::status_code::FLASH_FILE_ALREADY_CLOSED): {
return "Flash file already closed";
break;
}
case (mpsoc::status_code::FLASH_FILE_OPEN_FAILED): {
return "Flash file open failed";
break;
}
case (mpsoc::status_code::FLASH_FILE_NOT_OPEN): {
return "Flash file not open";
break;
}
case (mpsoc::status_code::FLASH_UNMOUNT_FAILED): {
return "Flash unmount failed";
break;
}
case (mpsoc::status_code::HEAP_ALLOCATION_FAILED): {
return "Heap allocation failed";
break;
}
case (mpsoc::status_code::INVALID_PARAMETER): {
return "Invalid parameter";
break;
}
case (mpsoc::status_code::NOT_INITIALIZED): {
return "Not initialized";
break;
}
case (mpsoc::status_code::REBOOT_IMMINENT): {
return "Reboot imminent";
break;
}
case (mpsoc::status_code::CORRUPT_DATA): {
return "Corrupt data";
break;
}
case (mpsoc::status_code::FLASH_CORRECTABLE_MISMATCH): {
return "Flash correctable mismatch";
break;
}
case (mpsoc::status_code::FLASH_UNCORRECTABLE_MISMATCH): {
return "Flash uncorrectable mismatch";
break;
}
case (mpsoc::status_code::DEFAULT_ERROR_CODE): {
return "Default error code";
break;
}
default:
std::stringstream ss;
ss << "0x" << std::hex << status;
return ss.str();
break;
}
return "";
}
} // namespace mpsoc } // namespace mpsoc
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */ #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */

2
tmtc

@ -1 +1 @@
Subproject commit dd3e4c649b687ea6b9444389439f3f2d5a558ad2 Subproject commit 280c72439effa1b4290dc500dade2c62a9d6e3f7