diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index c384c7ad..10c9e46d 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -95,13 +95,13 @@ void ObjectFactory::produce(void* args) { #if OBSW_ADD_PLOC_SUPERVISOR == 1 std::string plocSupvString = "/dev/ploc_supv"; auto supervisorCookie = - new UartCookie(objects::PLOC_SUPERVISOR_HANDLER, plocSupvString, uart::PLOC_SUPV_BAUD, - supv::MAX_PACKET_SIZE * 20, UartModes::NON_CANONICAL); + new SerialCookie(objects::PLOC_SUPERVISOR_HANDLER, plocSupvString, uart::PLOC_SUPV_BAUD, + supv::MAX_PACKET_SIZE * 20, UartModes::NON_CANONICAL); supervisorCookie->setNoFixedSizeReply(); auto supvHelper = new PlocSupvUartManager(objects::PLOC_SUPERVISOR_HELPER); new PlocSupervisorHandler(objects::PLOC_SUPERVISOR_HANDLER, objects::PLOC_SUPERVISOR_HELPER, supervisorCookie, Gpio(gpioIds::ENABLE_SUPV_UART, dummyGpioIF), - pcdu::PDU1_CH6_PLOC_12V, supvHelper); + pcdu::PDU1_CH6_PLOC_12V, *supvHelper); #endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */ #endif diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 9e9653ed..f2a7c5fe 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -20,7 +20,7 @@ using namespace returnvalue; PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF* comCookie, Gpio uartIsolatorSwitch, power::Switch_t powerSwitch, - PlocSupvUartManager* supvHelper) + PlocSupvUartManager& supvHelper) : DeviceHandlerBase(objectId, uartComIFid, comCookie), uartIsolatorSwitch(uartIsolatorSwitch), hkset(this), @@ -33,9 +33,6 @@ PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t u if (comCookie == nullptr) { sif::error << "PlocSupervisorHandler: Invalid com cookie" << std::endl; } - if (supvHelper == nullptr) { - sif::error << "PlocSupervisorHandler: Invalid PlocSupvHelper object" << std::endl; - } spParams.buf = commandBuffer; spParams.maxSize = sizeof(commandBuffer); eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); @@ -52,10 +49,6 @@ ReturnValue_t PlocSupervisorHandler::initialize() { #ifdef XIPHOS_Q7S sdcMan = SdCardManager::instance(); #endif /* TE0720_1CFA */ - if (supvHelper == nullptr) { - sif::warning << "PlocSupervisorHandler::initialize: Invalid supervisor helper" << std::endl; - return ObjectManagerIF::CHILD_INIT_FAILED; - } result = eventSubscription(); if (result != returnvalue::OK) { @@ -87,10 +80,6 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, ReturnValue_t result = returnvalue::OK; switch (actionId) { - case TERMINATE_SUPV_HELPER: { - supvHelper->stop(); - return EXECUTION_FINISHED; - } default: break; } @@ -114,7 +103,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, if (result != returnvalue::OK) { return result; } - result = supvHelper->performUpdate(params); + result = supvHelper.performUpdate(params); if (result != returnvalue::OK) { return result; } @@ -122,7 +111,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, return EXECUTION_FINISHED; } case CONTINUE_UPDATE: { - supvHelper->initiateUpdateContinuation(); + supvHelper.initiateUpdateContinuation(); plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } @@ -135,7 +124,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, if (not std::filesystem::exists(params.file)) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; } - supvHelper->performMemCheck(params.file, params.memId, params.startAddr); + supvHelper.performMemCheck(params.file, params.memId, params.startAddr); plocSupvHelperExecuting = true; return EXECUTION_FINISHED; } @@ -150,6 +139,7 @@ void PlocSupervisorHandler::doStartUp() { switch (startupState) { case StartupState::OFF: { bootTimeout.resetTimer(); + supvHelper.start(); startupState = StartupState::BOOTING; break; } @@ -177,6 +167,7 @@ void PlocSupervisorHandler::doStartUp() { void PlocSupervisorHandler::doShutDown() { setMode(_MODE_POWER_DOWN); + supvHelper.stop(); uartIsolatorSwitch.pullLow(); startupState = StartupState::OFF; } diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index a152349c..c5034c03 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -34,7 +34,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { public: PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF* comCookie, Gpio uartIsolatorSwitch, power::Switch_t powerSwitch, - PlocSupvUartManager* supvHelper); + PlocSupvUartManager& supvHelper); virtual ~PlocSupervisorHandler(); virtual ReturnValue_t initialize() override; @@ -130,7 +130,7 @@ class PlocSupervisorHandler : public DeviceHandlerBase { const power::Switch_t powerSwitch = power::NO_SWITCH; supv::TmBase tmReader; - PlocSupvUartManager* supvHelper = nullptr; + PlocSupvUartManager& supvHelper; MessageQueueIF* eventQueue = nullptr; /** Number of expected replies following the MRAM dump command */ diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index f17033a7..cdf74027 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -94,6 +94,9 @@ ReturnValue_t PlocSupvUartManager::initialize() { ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) { bool putTaskToSleep = false; while (true) { + lock->lockMutex(); + state = InternalState::SLEEPING; + lock->unlockMutex(); semaphore->acquire(); while (true) { putTaskToSleep = handleUartReception(); @@ -289,6 +292,14 @@ void PlocSupvUartManager::stop() { state = InternalState::GO_TO_SLEEP; } +void PlocSupvUartManager::start() { + MutexGuard mg(lock); + if (state == InternalState::SLEEPING or state == InternalState::GO_TO_SLEEP) { + return; + } + semaphore->release(); +} + void PlocSupvUartManager::executeFullCheckMemoryCommand() { ReturnValue_t result; if (update.crcShouldBeChecked) { diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index fcf49949..da8bb176 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -148,10 +148,15 @@ class PlocSupvUartManager : public DeviceCommunicationIF, // ReturnValue_t startEventBufferRequest(std::string path); /** - * @brief Can be used to interrupt a running data transfer. + * @brief Can be used to stop the UART reception and put the task to sleep */ void stop(); + /** + * @brief Can be used to start the UART reception + */ + void start(); + static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); static uint32_t buildApidServiceParam1(uint8_t apid, uint8_t serviceId);