From cc79ffc57bec8fbdad4b22aed3dbeec86de869f3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Nov 2022 18:32:23 +0100 Subject: [PATCH] some remaining bugfixes --- .../PlocSupervisorDefinitions.h | 7 +--- linux/devices/ploc/PlocSupervisorHandler.cpp | 37 +++++++++---------- linux/devices/ploc/PlocSupervisorHandler.h | 8 ++-- linux/devices/ploc/PlocSupvUartMan.cpp | 5 +++ linux/devices/ploc/PlocSupvUartMan.h | 3 +- tmtc | 2 +- 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index 18e92ccb..8c638c83 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -1681,7 +1681,7 @@ class UpdateStatusReport { if (not tmReader.crcIsOk()) { return result::CRC_FAILURE; } - if (tmReader.getApid() != Apid::MEM_MAN) { + if (tmReader.getModuleApid() != Apid::MEM_MAN) { return result::INVALID_APID; } if (tmReader.getBufSize() < MIN_TMTC_LEN + PAYLOAD_LEN or @@ -1690,10 +1690,7 @@ class UpdateStatusReport { << std::endl; return result::BUF_TOO_SMALL; } - size_t remLen = PAYLOAD_LEN; - if (remLen < PAYLOAD_LEN) { - return result::INVALID_REPLY_LENGTH; - } + size_t remLen = tmReader.getPayloadLen(); const uint8_t* dataFieldPtr = tmReader.getPayloadStart(); SerializeAdapter::deSerialize(&memoryId, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&n, &dataFieldPtr, &remLen, SerializeIF::Endianness::BIG); diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index bd027e37..3a8565eb 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -84,7 +85,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, break; } - if (plocSupvHelperExecuting) { + if (uartManager.longerRequestActive()) { return result::SUPV_HELPER_EXECUTING; } @@ -98,6 +99,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) { return result::FILENAME_TOO_LONG; } + shutdownCmdSent = false; UpdateParams params; result = extractUpdateCommand(data, size, params); if (result != returnvalue::OK) { @@ -107,15 +109,15 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, if (result != returnvalue::OK) { return result; } - plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } case CONTINUE_UPDATE: { + shutdownCmdSent = false; uartManager.initiateUpdateContinuation(); - plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } case MEMORY_CHECK_WITH_FILE: { + shutdownCmdSent = false; UpdateParams params; ReturnValue_t result = extractBaseParams(&data, size, params); if (result != returnvalue::OK) { @@ -125,7 +127,6 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, return HasFileSystemIF::FILE_DOES_NOT_EXIST; } uartManager.performMemCheck(params.file, params.memId, params.startAddr); - plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } default: @@ -777,7 +778,6 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) { Event event = eventMessage->getEvent(); switch (objectId) { case objects::PLOC_SUPERVISOR_HELPER: { - plocSupvHelperExecuting = false; // After execution of update procedure, PLOC is in a state where it draws approx. 700 mA of // current. To leave this state the shutdown MPSoC command must be sent here. if (event == PlocSupvUartManager::SUPV_UPDATE_FAILED || @@ -786,13 +786,18 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) { event == PlocSupvUartManager::SUPV_CONTINUE_UPDATE_SUCCESSFUL || event == PlocSupvUartManager::SUPV_MEM_CHECK_FAIL || event == PlocSupvUartManager::SUPV_MEM_CHECK_OK) { - result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0); - if (result != returnvalue::OK) { - triggerEvent(SUPV_MPSOC_SHUWDOWN_BUILD_FAILED); - sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown " - "command" - << std::endl; - return; + // Wait for a short period for the uart state machine to adjust + // TaskFactory::delayTask(5); + if (not shutdownCmdSent) { + shutdownCmdSent = true; + result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0); + if (result != returnvalue::OK) { + triggerEvent(SUPV_MPSOC_SHUTDOWN_BUILD_FAILED); + sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown " + "command" + << std::endl; + return; + } } } break; @@ -1217,14 +1222,6 @@ size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) { return replyLen; } -ReturnValue_t PlocSupervisorHandler::doSendReadHook() { - // Prevent DHB from polling UART during commands executed by the supervisor helper task - if (plocSupvHelperExecuting) { - return returnvalue::FAILED; - } - return returnvalue::OK; -} - void PlocSupervisorHandler::doOffActivity() {} void PlocSupervisorHandler::handleDeviceTm(const uint8_t* data, size_t dataSize, diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index 557639e1..4ffe4166 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -59,7 +59,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { uint8_t expectedReplies = 1, bool useAlternateId = false, DeviceCommandId_t alternateReplyID = 0) override; size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override; - ReturnValue_t doSendReadHook() override; + // ReturnValue_t doSendReadHook() override; void doOffActivity() override; private: @@ -81,7 +81,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { //! [EXPORT] : [COMMENT] Supervisor helper currently executing a command static const Event SUPV_HELPER_EXECUTING = MAKE_EVENT(7, severity::LOW); //! [EXPORT] : [COMMENT] Failed to build the command to shutdown the MPSoC - static const Event SUPV_MPSOC_SHUWDOWN_BUILD_FAILED = MAKE_EVENT(8, severity::LOW); + static const Event SUPV_MPSOC_SHUTDOWN_BUILD_FAILED = MAKE_EVENT(8, severity::LOW); static const uint16_t APID_MASK = 0x7FF; static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; @@ -119,6 +119,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { SerialComIF* uartComIf = nullptr; LinuxLibgpioIF* gpioComIF = nullptr; Gpio uartIsolatorSwitch; + bool shutdownCmdSent = false; supv::HkSet hkset; supv::BootStatusReport bootStatusReport; @@ -151,9 +152,6 @@ class PlocSupervisorHandler : public DeviceHandlerBase { std::string supervisorFilePath = "ploc/supervisor"; std::string activeMramFile; - // Supervisor helper class currently executing a command - bool plocSupvHelperExecuting = false; - Countdown executionReportTimeout = Countdown(EXECUTION_DEFAULT_TIMEOUT, false); Countdown acknowledgementReportTimeout = Countdown(ACKNOWLEDGE_DEFAULT_TIMEOUT, false); // Vorago nees some time to boot properly diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index ee91554e..6d938efe 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -1148,3 +1148,8 @@ int PlocSupvUartManager::removeHdlcFramingWithCrcCheck(const uint8_t* src, size_ *dlen = tlen - 2; return 0; } + +bool PlocSupvUartManager::longerRequestActive() const { + MutexGuard mg(lock); + return state == InternalState::DEDICATED_REQUEST; +} diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index 0d191b7e..d36a9cd4 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -159,6 +159,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, * @brief Can be used to start the UART reception */ void start(); + bool longerRequestActive() const; static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); static uint32_t buildApidServiceParam1(uint8_t apid, uint8_t serviceId); @@ -252,7 +253,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, std::array tmBuf{}; - bool debugMode = true; + bool debugMode = false; bool timestamping = true; // Remembers APID to know at which command a procedure failed diff --git a/tmtc b/tmtc index ac2b9cb7..70a1d492 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit ac2b9cb712405ee07b9de1950fd6c923a6f184b5 +Subproject commit 70a1d49246b5bd5297c22d336e9dd8f58f019f90