From 471a981ccfe145871eddaaecb4f8aff74087d342 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Sat, 26 Mar 2022 20:47:25 +0100 Subject: [PATCH] mpsoc flash write command --- bsp_q7s/core/ObjectFactory.cpp | 94 -- bsp_te0720_1cfa/ObjectFactory.cpp | 87 +- .../devicedefinitions/PlocMPSoCDefinitions.h | 824 +++++++++--------- linux/devices/ploc/PlocMPSoCHandler.cpp | 27 +- linux/devices/ploc/PlocMPSoCHelper.cpp | 104 ++- linux/devices/ploc/PlocMPSoCHelper.h | 223 ++--- linux/fsfwconfig/OBSWConfig.h.in | 11 +- 7 files changed, 690 insertions(+), 680 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 5dd1698e..27b5faa1 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -1203,100 +1203,6 @@ void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) { #if BOARD_TE0720 == 0 new Q7STestTask(objects::TEST_TASK); #endif - -#if BOARD_TE0720 == 1 && OBSW_TEST_LIBGPIOD == 1 -#if OBSW_TEST_GPIO_OPEN_BYLABEL == 1 - /* Configure MIO0 as input */ - GpiodRegular* testGpio = new GpiodRegular("MIO0", Direction::OUT, 0, "/amba_pl/gpio@41200000", 0); -#elif OBSW_TEST_GPIO_OPEN_BY_LINE_NAME - GpiodRegularByLineName* testGpio = - new GpiodRegularByLineName("test-name", "gpio-test", Direction::OUT, 0); -#else - /* Configure MIO0 as input */ - GpiodRegular* testGpio = new GpiodRegular("gpiochip0", 0, "MIO0", gpio::IN, 0); -#endif /* OBSW_TEST_GPIO_LABEL == 1 */ - GpioCookie* gpioCookie = new GpioCookie; - gpioCookie->addGpio(gpioIds::TEST_ID_0, testGpio); - new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); -#endif - -#if BOARD_TE0720 == 1 && OBSW_TEST_SUS == 1 - GpioCookie* gpioCookieSus = new GpioCookie; - GpiodRegular* chipSelectSus = new GpiodRegular( - std::string("gpiochip1"), 9, std::string("Chip Select Sus Sensor"), Direction::OUT, 1); - gpioCookieSus->addGpio(gpioIds::CS_SUS_0, chipSelectSus); - gpioComIF->addGpios(gpioCookieSus); - - SpiCookie* spiCookieSus = - new SpiCookie(addresses::SUS_0, std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, - spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - - new SusHandler(objects::SUS_0, objects::SPI_COM_IF, spiCookieSus, gpioComIF, gpioIds::CS_SUS_0); -#endif - -#if BOARD_TE0720 == 1 && OBSW_TEST_CCSDS_BRIDGE == 1 - GpioCookie* gpioCookieCcsdsIp = new GpioCookie; - GpiodRegular* papbBusyN = - new GpiodRegular(std::string("gpiochip0"), 0, std::string("PAPBBusy_VC0")); - gpioCookieCcsdsIp->addGpio(gpioIds::PAPB_BUSY_N, papbBusyN); - GpiodRegular* papbEmpty = - new GpiodRegular(std::string("gpiochip0"), 1, std::string("PAPBEmpty_VC0")); - gpioCookieCcsdsIp->addGpio(gpioIds::PAPB_EMPTY, papbEmpty); - gpioComIF->addGpios(gpioCookieCcsdsIp); - - new CCSDSIPCoreBridge(objects::CCSDS_IP_CORE_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR, - objects::TM_STORE, objects::TC_STORE, gpioComIF, std::string("/dev/uio0"), - gpioIds::PAPB_BUSY_N, gpioIds::PAPB_EMPTY); -#endif - -#if BOARD_TE0720 == 1 && OBSW_TEST_RAD_SENSOR == 1 - GpioCookie* gpioCookieRadSensor = new GpioCookie; - GpiodRegular* chipSelectRadSensor = new GpiodRegular( - std::string("gpiochip1"), 0, std::string("Chip select radiation sensor"), Direction::OUT, 1); - gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); - gpioComIF->addGpios(gpioCookieRadSensor); - - SpiCookie* spiCookieRadSensor = - new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string("/dev/spidev1.0"), - SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - - RadiationSensorHandler* radSensor = - new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); - radSensor->setStartUpImmediately(); -#endif - -#if BOARD_TE0720 == 1 && OBSW_ADD_PLOC_MPSOC == 1 - UartCookie* mpsocUartCookie = - new UartCookie(objects::PLOC_MPSOC_HANDLER, std::string("/dev/ttyPS2"), - UartModes::NON_CANONICAL, 115200, mpsoc::MAX_REPLY_SIZE); - /* Testing PlocMPSoCHandler on TE0720-03-1CFA */ - PlocMPSoCHelper* plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER); - PlocMPSoCHandler* plocMPSoCHandler = new PlocMPSoCHandler( - objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocUartCookie, plocMpsocHelper); - plocMPSoCHandler->setStartUpImmediately(); -#endif - -#if BOARD_TE0720 == 1 && OBSW_TEST_TE7020_HEATER == 1 - /* Configuration for MIO0 on TE0720-03-1CFA */ - GpiodRegular* heaterGpio = - new GpiodRegular(std::string("gpiochip0"), 0, std::string("MIO0"), gpio::IN, 0); - GpioCookie* gpioCookie = new GpioCookie; - gpioCookie->addGpio(gpioIds::HEATER_0, heaterGpio); - new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, - pcduSwitches::TCS_BOARD_8V_HEATER_IN); -#endif - -#if BOARD_TE0720 == 1 && OBSW_ADD_PLOC_SUPERVISOR == 1 - /* Configuration for MIO0 on TE0720-03-1CFA */ - UartCookie* plocSupervisorCookie = - new UartCookie(objects::PLOC_SUPERVISOR_HANDLER, std::string("/dev/ttyPS1"), - UartModes::NON_CANONICAL, 115200, PLOC_SPV::MAX_PACKET_SIZE * 20); - plocSupervisorCookie->setNoFixedSizeReply(); - PlocSupervisorHandler* plocSupervisor = new PlocSupervisorHandler( - objects::PLOC_SUPERVISOR_HANDLER, objects::UART_COM_IF, plocSupervisorCookie); - plocSupervisor->setStartUpImmediately(); -#endif - #if OBSW_ADD_SPI_TEST_CODE == 1 new SpiTestClass(objects::SPI_TEST, gpioComIF); #endif diff --git a/bsp_te0720_1cfa/ObjectFactory.cpp b/bsp_te0720_1cfa/ObjectFactory.cpp index 08cd246e..73243b83 100644 --- a/bsp_te0720_1cfa/ObjectFactory.cpp +++ b/bsp_te0720_1cfa/ObjectFactory.cpp @@ -39,12 +39,95 @@ void ObjectFactory::produce(void* args) { #if OBSW_ADD_PLOC_MPSOC == 1 UartCookie* mpsocUartCookie = - new UartCookie(objects::PLOC_MPSOC_HANDLER, te0720_1cfa::MPSOC_UART, - UartModes::NON_CANONICAL, uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE); + new UartCookie(objects::PLOC_MPSOC_HANDLER, te0720_1cfa::MPSOC_UART, UartModes::NON_CANONICAL, + uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE); + mpsocUartCookie->setNoFixedSizeReply(); PlocMPSoCHelper* plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER); new UartComIF(objects::UART_COM_IF); PlocMPSoCHandler* plocMPSoCHandler = new PlocMPSoCHandler( objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocUartCookie, plocMpsocHelper); plocMPSoCHandler->setStartUpImmediately(); #endif /* OBSW_ADD_PLOC_MPSOC == 1 */ + +#if OBSW_TEST_LIBGPIOD == 1 +#if OBSW_TEST_GPIO_OPEN_BYLABEL == 1 + /* Configure MIO0 as input */ + GpiodRegular* testGpio = new GpiodRegular("MIO0", Direction::OUT, 0, "/amba_pl/gpio@41200000", 0); +#elif OBSW_TEST_GPIO_OPEN_BY_LINE_NAME + GpiodRegularByLineName* testGpio = + new GpiodRegularByLineName("test-name", "gpio-test", Direction::OUT, 0); +#else + /* Configure MIO0 as input */ + GpiodRegular* testGpio = new GpiodRegular("gpiochip0", 0, "MIO0", gpio::IN, 0); +#endif /* OBSW_TEST_GPIO_LABEL == 1 */ + GpioCookie* gpioCookie = new GpioCookie; + gpioCookie->addGpio(gpioIds::TEST_ID_0, testGpio); + new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); +#endif + +#if OBSW_TEST_SUS == 1 + GpioCookie* gpioCookieSus = new GpioCookie; + GpiodRegular* chipSelectSus = new GpiodRegular( + std::string("gpiochip1"), 9, std::string("Chip Select Sus Sensor"), Direction::OUT, 1); + gpioCookieSus->addGpio(gpioIds::CS_SUS_0, chipSelectSus); + gpioComIF->addGpios(gpioCookieSus); + + SpiCookie* spiCookieSus = + new SpiCookie(addresses::SUS_0, std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, + spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + + new SusHandler(objects::SUS_0, objects::SPI_COM_IF, spiCookieSus, gpioComIF, gpioIds::CS_SUS_0); +#endif + +#if OBSW_TEST_CCSDS_BRIDGE == 1 + GpioCookie* gpioCookieCcsdsIp = new GpioCookie; + GpiodRegular* papbBusyN = + new GpiodRegular(std::string("gpiochip0"), 0, std::string("PAPBBusy_VC0")); + gpioCookieCcsdsIp->addGpio(gpioIds::PAPB_BUSY_N, papbBusyN); + GpiodRegular* papbEmpty = + new GpiodRegular(std::string("gpiochip0"), 1, std::string("PAPBEmpty_VC0")); + gpioCookieCcsdsIp->addGpio(gpioIds::PAPB_EMPTY, papbEmpty); + gpioComIF->addGpios(gpioCookieCcsdsIp); + + new CCSDSIPCoreBridge(objects::CCSDS_IP_CORE_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR, + objects::TM_STORE, objects::TC_STORE, gpioComIF, std::string("/dev/uio0"), + gpioIds::PAPB_BUSY_N, gpioIds::PAPB_EMPTY); +#endif + +#if OBSW_TEST_RAD_SENSOR == 1 + GpioCookie* gpioCookieRadSensor = new GpioCookie; + GpiodRegular* chipSelectRadSensor = new GpiodRegular( + std::string("gpiochip1"), 0, std::string("Chip select radiation sensor"), Direction::OUT, 1); + gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); + gpioComIF->addGpios(gpioCookieRadSensor); + + SpiCookie* spiCookieRadSensor = + new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string("/dev/spidev1.0"), + SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + + RadiationSensorHandler* radSensor = + new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); + radSensor->setStartUpImmediately(); +#endif + +#if OBSW_TEST_TE7020_HEATER == 1 + /* Configuration for MIO0 on TE0720-03-1CFA */ + GpiodRegular* heaterGpio = + new GpiodRegular(std::string("gpiochip0"), 0, std::string("MIO0"), gpio::IN, 0); + GpioCookie* gpioCookie = new GpioCookie; + gpioCookie->addGpio(gpioIds::HEATER_0, heaterGpio); + new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, + pcduSwitches::TCS_BOARD_8V_HEATER_IN); +#endif + +#if OBSW_ADD_PLOC_SUPERVISOR == 1 + /* Configuration for MIO0 on TE0720-03-1CFA */ + UartCookie* plocSupervisorCookie = + new UartCookie(objects::PLOC_SUPERVISOR_HANDLER, std::string("/dev/ttyPS1"), + UartModes::NON_CANONICAL, 115200, PLOC_SPV::MAX_PACKET_SIZE * 20); + plocSupervisorCookie->setNoFixedSizeReply(); + PlocSupervisorHandler* plocSupervisor = new PlocSupervisorHandler( + objects::PLOC_SUPERVISOR_HANDLER, objects::UART_COM_IF, plocSupervisorCookie); + plocSupervisor->setStartUpImmediately(); +#endif } diff --git a/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h b/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h index b7f617d0..111004d5 100644 --- a/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h +++ b/linux/devices/devicedefinitions/PlocMPSoCDefinitions.h @@ -1,11 +1,12 @@ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ -#include "OBSWConfig.h" -#include "MPSoCReturnValuesIF.h" -#include #include #include +#include + +#include "MPSoCReturnValuesIF.h" +#include "OBSWConfig.h" namespace mpsoc { @@ -37,28 +38,29 @@ static const uint16_t SIZE_TM_MEM_READ_REPORT = 18; * SpacePacket apids of PLOC telecommands and telemetry. */ namespace apid { - static const uint16_t TC_REPLAY_START = 0x110; - static const uint16_t TC_REPLAY_STOP = 0x111; - static const uint16_t TC_REPLAY_WRITE_SEQUENCE = 0x112; - static const uint16_t TC_DOWNLINK_PWR_ON = 0x113; - static const uint16_t TC_MEM_WRITE = 0x114; - static const uint16_t TC_MEM_READ = 0x115; - static const uint16_t TC_FLASHWRITE = 0x117; - static const uint16_t TC_FLASHFOPEN = 0x119; - static const uint16_t TC_FLASHFCLOSE = 0x11A; - static const uint16_t TC_FLASHDELETE = 0x11C; - static const uint16_t TC_MODE_REPLAY = 0x11F; - static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124; - static const uint16_t TM_MEMORY_READ_REPORT = 0x404; - static const uint16_t ACK_SUCCESS = 0x400; - static const uint16_t ACK_FAILURE = 0x401; - static const uint16_t EXE_SUCCESS = 0x402; - static const uint16_t EXE_FAILURE = 0x403; -} +static const uint16_t TC_REPLAY_START = 0x110; +static const uint16_t TC_REPLAY_STOP = 0x111; +static const uint16_t TC_REPLAY_WRITE_SEQUENCE = 0x112; +static const uint16_t TC_DOWNLINK_PWR_ON = 0x113; +static const uint16_t TC_MEM_WRITE = 0x114; +static const uint16_t TC_MEM_READ = 0x115; +static const uint16_t TC_FLASHWRITE = 0x117; +static const uint16_t TC_FLASHFOPEN = 0x119; +static const uint16_t TC_FLASHFCLOSE = 0x11A; +static const uint16_t TC_FLASHDELETE = 0x11C; +static const uint16_t TC_MODE_REPLAY = 0x11F; +static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124; +static const uint16_t TM_MEMORY_READ_REPORT = 0x404; +static const uint16_t ACK_SUCCESS = 0x400; +static const uint16_t ACK_FAILURE = 0x401; +static const uint16_t EXE_SUCCESS = 0x402; +static const uint16_t EXE_FAILURE = 0x403; +} // namespace apid /** Offset from first byte in space packet to first byte of data field */ static const uint8_t DATA_FIELD_OFFSET = 6; static const size_t MEM_READ_RPT_LEN_OFFSET = 10; +static const char NULL_TERMINATOR = '\0'; /** * The size of payload data which will be forwarded to the requesting object. e.g. PUS Service @@ -81,504 +83,488 @@ static const size_t MAX_DATA_SIZE = 1016; /** * The replay write sequence command has a maximum delay for the execution report which amounts to - * 30 seconds (60 cycles * 0.5 seconds). + * 30 seconds. (80 cycles * 0.5 seconds = 40 seconds). */ -static const uint16_t TC_WRITE_SEQ_EXECUTION_DELAY = 60; +static const uint16_t TC_WRITE_SEQ_EXECUTION_DELAY = 80; +// Requires approx. 2 seconds for execution. 8 => 4 seconds +static const uint16_t TC_DOWNLINK_PWR_ON_EXECUTION_DELAY = 8; /** * @brief Abstract base class for TC space packet of MPSoC. */ class TcBase : public SpacePacket, public MPSoCReturnValuesIF { -public: + public: + // Initial length field of space packet. Will always be updated when packet is created. + static const uint16_t INIT_LENGTH = 1; - // Initial length field of space packet. Will always be updated when packet is created. - static const uint16_t INIT_LENGTH = 1; + /** + * @brief Constructor + * + * @param sequenceCount Sequence count of space packet which will be incremented with each + * sent and received packets. + */ + TcBase(uint16_t apid, uint16_t sequenceCount) + : SpacePacket(INIT_LENGTH, true, apid, sequenceCount) {} - /** - * @brief Constructor - * - * @param sequenceCount Sequence count of space packet which will be incremented with each - * sent and received packets. - */ - TcBase(uint16_t apid, uint16_t sequenceCount) : - SpacePacket(INIT_LENGTH, true, apid, sequenceCount) { + /** + * @brief Function to initialize the space packet + * + * @param commandData Pointer to command specific data + * @param commandDataLen Length of command data + * + * @return RETURN_OK if packet creation was successful, otherwise error return value + */ + virtual ReturnValue_t createPacket(const uint8_t* commandData, size_t commandDataLen) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = initPacket(commandData, commandDataLen); + if (result != HasReturnvaluesIF::HasReturnvaluesIF::RETURN_OK) { + return result; } - - /** - * @brief Function to initialize the space packet - * - * @param commandData Pointer to command specific data - * @param commandDataLen Length of command data - * - * @return RETURN_OK if packet creation was successful, otherwise error return value - */ - virtual ReturnValue_t createPacket(const uint8_t* commandData, size_t commandDataLen) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = initPacket(commandData, commandDataLen); - if (result != HasReturnvaluesIF::HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = addCrc(); - if (result != HasReturnvaluesIF::HasReturnvaluesIF::RETURN_OK) { - return result; - } - return result; + result = addCrc(); + if (result != HasReturnvaluesIF::HasReturnvaluesIF::RETURN_OK) { + return result; } + return result; + } -protected: - /** - * @brief Must be overwritten by the child class to define the command specific parameters - * - * @param commandData Pointer to received command data - * @param commandDataLen Length of received command data - */ - virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { - return HasReturnvaluesIF::RETURN_OK; - } + protected: + /** + * @brief Must be overwritten by the child class to define the command specific parameters + * + * @param commandData Pointer to received command data + * @param commandDataLen Length of received command data + */ + virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { + return HasReturnvaluesIF::RETURN_OK; + } - /** - * @brief Calculates and adds the CRC - */ - ReturnValue_t addCrc() { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - size_t serializedSize = 0; - uint32_t full_size = getFullSize(); - uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE); - result = SerializeAdapter::serialize(&crc, - this->localData.byteStream + full_size - CRC_SIZE, &serializedSize, sizeof(crc), - SerializeIF::Endianness::BIG); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::debug << "TcBase::addCrc: Failed to serialize crc field" << std::endl; - } - return result; + /** + * @brief Calculates and adds the CRC + */ + ReturnValue_t addCrc() { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + size_t serializedSize = 0; + uint32_t full_size = getFullSize(); + uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE); + result = SerializeAdapter::serialize( + &crc, this->localData.byteStream + full_size - CRC_SIZE, &serializedSize, sizeof(crc), + SerializeIF::Endianness::BIG); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::debug << "TcBase::addCrc: Failed to serialize crc field" << std::endl; } + return result; + } }; /** * @brief Class for handling tm replies of the PLOC MPSoC. */ class TmPacket : public SpacePacket, public MPSoCReturnValuesIF { -public: + public: + /** + * @brief Constructor creates idle packet and sets length field to maximum allowed size. + */ + TmPacket() : SpacePacket(PACKET_MAX_SIZE) {} - /** - * @brief Constructor creates idle packet and sets length field to maximum allowed size. - */ - TmPacket() : SpacePacket(PACKET_MAX_SIZE) { - } - - ReturnValue_t checkCrc() { - uint8_t* crcPtr = this->getPacketData() + this->getPacketDataLength() - 1; - uint16_t receivedCrc = *(crcPtr) << 8 | *(crcPtr + 1); - uint16_t recalculatedCrc = CRC::crc16ccitt(this->localData.byteStream, this->getFullSize()); - if (recalculatedCrc != receivedCrc) { - return CRC_FAILURE; - } - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t checkCrc() { + uint8_t* crcPtr = this->getPacketData() + this->getPacketDataLength() - 1; + uint16_t receivedCrc = *(crcPtr) << 8 | *(crcPtr + 1); + uint16_t recalculatedCrc = + CRC::crc16ccitt(this->localData.byteStream, this->getFullSize() - CRC_SIZE); + if (recalculatedCrc != receivedCrc) { + return CRC_FAILURE; } + return HasReturnvaluesIF::RETURN_OK; + } }; /** * @brief This class helps to build the memory read command for the PLOC. */ -class TcMemRead: public TcBase { -public: +class TcMemRead : public TcBase { + public: + /** + * @brief Constructor + */ + TcMemRead(uint16_t sequenceCount) : TcBase(apid::TC_MEM_READ, sequenceCount) { + this->setPacketDataLength(PACKET_LENGTH); + } - /** - * @brief Constructor - */ - TcMemRead(uint16_t sequenceCount) : - TcBase(apid::TC_MEM_READ, sequenceCount) { - this->setPacketDataLength(PACKET_LENGTH); + uint16_t getMemLen() const { return memLen; } + + protected: + ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = lengthCheck(commandDataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } - - uint16_t getMemLen() const { - return memLen; + std::memcpy(this->localData.fields.buffer, commandData, MEM_ADDRESS_SIZE); + std::memcpy(this->localData.fields.buffer + MEM_ADDRESS_SIZE, commandData + MEM_ADDRESS_SIZE, + MEM_LEN_SIZE); + size_t size = sizeof(memLen); + const uint8_t* memLenPtr = commandData + MEM_ADDRESS_SIZE; + result = + SerializeAdapter::deSerialize(&memLen, &memLenPtr, &size, SerializeIF::Endianness::BIG); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + return result; + } -protected: + private: + static const size_t COMMAND_LENGTH = 6; + static const size_t MEM_ADDRESS_SIZE = 4; + static const size_t MEM_LEN_SIZE = 2; + static const uint16_t PACKET_LENGTH = 7; - ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = lengthCheck(commandDataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - std::memcpy(this->localData.fields.buffer, commandData, MEM_ADDRESS_SIZE); - std::memcpy(this->localData.fields.buffer + MEM_ADDRESS_SIZE, - commandData + MEM_ADDRESS_SIZE, MEM_LEN_SIZE); - size_t size = sizeof(memLen); - const uint8_t* memLenPtr = commandData + MEM_ADDRESS_SIZE; - result = SerializeAdapter::deSerialize(&memLen, &memLenPtr, &size, - SerializeIF::Endianness::BIG); - if(result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - return result; - } - -private: - - static const size_t COMMAND_LENGTH = 6; - static const size_t MEM_ADDRESS_SIZE = 4; - static const size_t MEM_LEN_SIZE = 2; - static const uint16_t PACKET_LENGTH = 7; - - uint16_t memLen = 0; - - ReturnValue_t lengthCheck(size_t commandDataLen) { - if (commandDataLen != COMMAND_LENGTH){ - return INVALID_LENGTH; - } - return HasReturnvaluesIF::RETURN_OK; + uint16_t memLen = 0; + + ReturnValue_t lengthCheck(size_t commandDataLen) { + if (commandDataLen != COMMAND_LENGTH) { + return INVALID_LENGTH; } + return HasReturnvaluesIF::RETURN_OK; + } }; /** * @brief This class helps to generate the space packet to write data to a memory address within * the PLOC. */ -class TcMemWrite: public TcBase { -public: - /** - * @brief Constructor - */ - TcMemWrite(uint16_t sequenceCount) : TcBase(apid::TC_MEM_WRITE, sequenceCount) { +class TcMemWrite : public TcBase { + public: + /** + * @brief Constructor + */ + TcMemWrite(uint16_t sequenceCount) : TcBase(apid::TC_MEM_WRITE, sequenceCount) {} + + protected: + ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = lengthCheck(commandDataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); + uint16_t memLen = + *(commandData + MEM_ADDRESS_SIZE) << 8 | *(commandData + MEM_ADDRESS_SIZE + 1); + this->setPacketDataLength(memLen * 4 + FIX_LENGTH - 1); + return result; + } -protected: + private: + // Min length consists of 4 byte address, 2 byte mem length field, 4 byte data (1 word) + static const size_t MIN_COMMAND_DATA_LENGTH = 10; + static const size_t MEM_ADDRESS_SIZE = 4; + static const size_t FIX_LENGTH = 8; - ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = lengthCheck(commandDataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); - uint16_t memLen = *(commandData + MEM_ADDRESS_SIZE) << 8 - | *(commandData + MEM_ADDRESS_SIZE + 1); - this->setPacketDataLength(memLen * 4 + FIX_LENGTH - 1); - return result; - } - -private: - - // Min length consists of 4 byte address, 2 byte mem length field, 4 byte data (1 word) - static const size_t MIN_COMMAND_DATA_LENGTH = 10; - static const size_t MEM_ADDRESS_SIZE = 4; - static const size_t FIX_LENGTH = 8; - - ReturnValue_t lengthCheck(size_t commandDataLen) { - if (commandDataLen < MIN_COMMAND_DATA_LENGTH) { - sif::warning << "TcMemWrite: Command has invalid length " << commandDataLen << std::endl; - return INVALID_LENGTH; - } - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t lengthCheck(size_t commandDataLen) { + if (commandDataLen < MIN_COMMAND_DATA_LENGTH) { + sif::warning << "TcMemWrite: Command has invalid length " << commandDataLen << std::endl; + return INVALID_LENGTH; } + return HasReturnvaluesIF::RETURN_OK; + } }; /** * @brief Class to help creation of flash fopen command. */ class FlashFopen : public TcBase { -public: + public: + FlashFopen(uint16_t sequenceCount) : TcBase(apid::TC_FLASHFOPEN, sequenceCount) {} - FlashFopen(uint16_t sequenceCount) : - TcBase(apid::TC_FLASHFOPEN, sequenceCount) { + static const char APPEND = 'a'; + static const char WRITE = 'w'; + static const char READ = 'r'; + + ReturnValue_t createPacket(std::string filename, char accessMode_) { + accessMode = accessMode_; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + size_t nameSize = filename.size(); + std::memcpy(this->getPacketData(), filename.c_str(), nameSize); + *(this->getPacketData() + nameSize) = NULL_TERMINATOR; + std::memcpy(this->getPacketData() + nameSize + sizeof(NULL_TERMINATOR), &accessMode, + sizeof(accessMode)); + this->setPacketDataLength(nameSize + sizeof(NULL_TERMINATOR) + sizeof(accessMode) + CRC_SIZE - + 1); + result = addCrc(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + return result; + } - static const char APPEND = 'a'; - static const char WRITE = 'w'; - static const char READ = 'r'; - - ReturnValue_t createPacket(std::string filename, char accessMode) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - size_t nameSize = filename.size(); - std::memcpy(this->getPacketData(), filename.c_str(), - nameSize); - std::memcpy(this->getPacketData() + nameSize + 1, &accessMode, - sizeof(accessMode)); - this->setPacketDataLength(nameSize + CRC_SIZE - 1); - result = addCrc(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - return result; - } + private: + char accessMode = APPEND; }; /** * @brief Class to help creation of flash fclose command. */ -class FlashFclose: public TcBase { -public: +class FlashFclose : public TcBase { + public: + FlashFclose(uint16_t sequenceCount) : TcBase(apid::TC_FLASHFCLOSE, sequenceCount) {} - FlashFclose(uint16_t sequenceCount) : - TcBase(apid::TC_FLASHFCLOSE, sequenceCount) { - } - - ReturnValue_t createPacket(std::string filename) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - size_t nameSize = filename.size(); - std::memcpy(this->getPacketData(), filename.c_str(), nameSize); - this->setPacketDataLength(nameSize + CRC_SIZE - 1); - result = addCrc(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - return result; - } + ReturnValue_t createPacket(std::string filename) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + size_t nameSize = filename.size(); + std::memcpy(this->getPacketData(), filename.c_str(), nameSize); + *(this->getPacketData() + nameSize) = NULL_TERMINATOR; + this->setPacketDataLength(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE - 1); + result = addCrc(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return result; + } }; /** * @brief Class to build flash write space packet. */ class TcFlashWrite : public TcBase { -public: + public: + TcFlashWrite(uint16_t sequenceCount) : TcBase(apid::TC_FLASHWRITE, sequenceCount) {} - TcFlashWrite(uint16_t sequenceCount) : - TcBase(apid::TC_FLASHWRITE, sequenceCount) { + ReturnValue_t createPacket(const uint8_t* writeData, uint32_t writeLen_) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + writeLen = writeLen_; + if (writeLen > MAX_DATA_SIZE) { + sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; } + size_t serializedSize = 0; + result = + SerializeAdapter::serialize(&writeLen, this->getPacketData(), &serializedSize, + sizeof(writeLen), SerializeIF::Endianness::BIG); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + std::memcpy(this->getPacketData() + sizeof(writeLen), writeData, writeLen); + this->setPacketDataLength(static_cast(writeLen + CRC_SIZE - 1)); + result = addCrc(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return HasReturnvaluesIF::RETURN_OK; + } - ReturnValue_t createPacket(uint8_t* writeData, uint32_t writeLen) { - if (writeLen > MAX_DATA_SIZE) { - sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; - } - std::memcpy(this->getPacketData(), &writeLen, sizeof(writeLen)); - std::memcpy(this->getPacketData() + sizeof(writeLen), writeData, writeLen); - this->setPacketDataLength(static_cast(writeLen + CRC_SIZE - 1)); - ReturnValue_t result = addCrc(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - return HasReturnvaluesIF::RETURN_OK; - } + private: + uint32_t writeLen = 0; }; /** * @brief Class to help creation of flash delete command. */ -class TcFlashDelete: public TcBase { -public: +class TcFlashDelete : public TcBase { + public: + TcFlashDelete(uint16_t sequenceCount) : TcBase(apid::TC_FLASHDELETE, sequenceCount) {} - TcFlashDelete(uint16_t sequenceCount) : - TcBase(apid::TC_FLASHDELETE , sequenceCount) { - } - - ReturnValue_t createPacket(std::string filename) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - size_t nameSize = filename.size(); - std::memcpy(this->getPacketData(), filename.c_str(), nameSize); - this->setPacketDataLength(nameSize + CRC_SIZE - 1); - result = addCrc(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - return result; - } + ReturnValue_t createPacket(std::string filename) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + size_t nameSize = filename.size(); + std::memcpy(this->getPacketData(), filename.c_str(), nameSize); + *(this->getPacketData() + nameSize) = NULL_TERMINATOR; + this->setPacketDataLength(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE - 1); + result = addCrc(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return result; + } }; /** * @brief Class to build replay stop space packet. */ class TcReplayStop : public TcBase { -public: + public: + TcReplayStop(uint16_t sequenceCount) : TcBase(apid::TC_REPLAY_STOP, sequenceCount) {} - TcReplayStop(uint16_t sequenceCount) : - TcBase(apid::TC_REPLAY_STOP, sequenceCount) { - } - - ReturnValue_t createPacket() { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = addCrc(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - this->setPacketDataLength(static_cast(CRC_SIZE - 1)); - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t createPacket() { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = addCrc(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + this->setPacketDataLength(static_cast(CRC_SIZE - 1)); + return HasReturnvaluesIF::RETURN_OK; + } }; /** * @brief This class helps to build the replay start command. */ -class TcReplayStart: public TcBase { -public: - /** - * @brief Constructor - */ - TcReplayStart(uint16_t sequenceCount) : TcBase(apid::TC_REPLAY_START, sequenceCount) { +class TcReplayStart : public TcBase { + public: + /** + * @brief Constructor + */ + TcReplayStart(uint16_t sequenceCount) : TcBase(apid::TC_REPLAY_START, sequenceCount) {} + + protected: + ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = lengthCheck(commandDataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } - -protected: - - ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = lengthCheck(commandDataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = checkData(*commandData); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); - this->setPacketDataLength(commandDataLen + CRC_SIZE - 1); - return result; + result = checkData(*commandData); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); + this->setPacketDataLength(commandDataLen + CRC_SIZE - 1); + return result; + } -private: + private: + static const size_t COMMAND_DATA_LENGTH = 1; + static const uint8_t REPEATING = 0; + static const uint8_t ONCE = 1; - static const size_t COMMAND_DATA_LENGTH = 1; - static const uint8_t REPEATING = 0; - static const uint8_t ONCE = 1; - - ReturnValue_t lengthCheck(size_t commandDataLen) { - if (commandDataLen != COMMAND_DATA_LENGTH) { - sif::warning << "TcReplayStart: Command has invalid length " << commandDataLen << std::endl; - return INVALID_LENGTH; - } - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t lengthCheck(size_t commandDataLen) { + if (commandDataLen != COMMAND_DATA_LENGTH) { + sif::warning << "TcReplayStart: Command has invalid length " << commandDataLen << std::endl; + return INVALID_LENGTH; } + return HasReturnvaluesIF::RETURN_OK; + } - ReturnValue_t checkData(uint8_t replay) { - if (replay != REPEATING && replay != ONCE) { - sif::warning << "TcReplayStart::checkData: Invalid replay value" << std::endl; - return INVALID_PARAMETER; - } - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t checkData(uint8_t replay) { + if (replay != REPEATING && replay != ONCE) { + sif::warning << "TcReplayStart::checkData: Invalid replay value" << std::endl; + return INVALID_PARAMETER; } + return HasReturnvaluesIF::RETURN_OK; + } }; /** * @brief This class helps to build downlink power on command. */ -class TcDownlinkPwrOn: public TcBase { -public: - /** - * @brief Constructor - */ - TcDownlinkPwrOn(uint16_t sequenceCount) : TcBase(apid::TC_DOWNLINK_PWR_ON, sequenceCount) { +class TcDownlinkPwrOn : public TcBase { + public: + /** + * @brief Constructor + */ + TcDownlinkPwrOn(uint16_t sequenceCount) : TcBase(apid::TC_DOWNLINK_PWR_ON, sequenceCount) {} + + protected: + ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = lengthCheck(commandDataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } - -protected: - - ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = lengthCheck(commandDataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = modeCheck(*commandData); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = laneRateCheck(*(commandData + 1)); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); - std::memcpy(this->localData.fields.buffer + commandDataLen, &MAX_AMPLITUDE, - sizeof(MAX_AMPLITUDE)); - this->setPacketDataLength(commandDataLen + sizeof(MAX_AMPLITUDE) + CRC_SIZE - 1); - return result; + result = modeCheck(*commandData); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } - -private: - - static const uint8_t INTERFACE_ID = CLASS_ID::DWLPWRON_CMD; - - //! [EXPORT] : [COMMENT] Received command has invalid JESD mode (valid modes are 0 - 5) - static const ReturnValue_t INVALID_MODE = MAKE_RETURN_CODE(0xE0); - //! [EXPORT] : [COMMENT] Received command has invalid lane rate (valid lane rate are 0 - 9) - static const ReturnValue_t INVALID_LANE_RATE = MAKE_RETURN_CODE(0xE1); - - static const size_t COMMAND_DATA_LENGTH = 2; - static const uint8_t MAX_MODE = 5; - static const uint8_t MAX_LANE_RATE = 9; - static const uint16_t MAX_AMPLITUDE = 0; - - ReturnValue_t lengthCheck(size_t commandDataLen) { - if (commandDataLen != COMMAND_DATA_LENGTH) { - sif::warning << "TcDownlinkPwrOn: Command has invalid length " << commandDataLen << std::endl; - return INVALID_LENGTH; - } - return HasReturnvaluesIF::RETURN_OK; + result = laneRateCheck(*(commandData + 1)); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); + std::memcpy(this->localData.fields.buffer + commandDataLen, &MAX_AMPLITUDE, + sizeof(MAX_AMPLITUDE)); + this->setPacketDataLength(commandDataLen + sizeof(MAX_AMPLITUDE) + CRC_SIZE - 1); + return result; + } - ReturnValue_t modeCheck(uint8_t mode) { - if (mode > MAX_MODE) { - sif::warning << "TcDwonlinkPwrOn::modeCheck: Invalid JESD mode" << std::endl; - return INVALID_MODE; - } - return HasReturnvaluesIF::RETURN_OK; - } + private: + static const uint8_t INTERFACE_ID = CLASS_ID::DWLPWRON_CMD; - ReturnValue_t laneRateCheck(uint8_t laneRate) { - if (laneRate > MAX_LANE_RATE) { - sif::warning << "TcReplayStart::laneRateCheck: Invalid lane rate" << std::endl; - return INVALID_LANE_RATE; - } - return HasReturnvaluesIF::RETURN_OK; + //! [EXPORT] : [COMMENT] Received command has invalid JESD mode (valid modes are 0 - 5) + static const ReturnValue_t INVALID_MODE = MAKE_RETURN_CODE(0xE0); + //! [EXPORT] : [COMMENT] Received command has invalid lane rate (valid lane rate are 0 - 9) + static const ReturnValue_t INVALID_LANE_RATE = MAKE_RETURN_CODE(0xE1); + + static const size_t COMMAND_DATA_LENGTH = 2; + static const uint8_t MAX_MODE = 5; + static const uint8_t MAX_LANE_RATE = 9; + static const uint16_t MAX_AMPLITUDE = 0; + + ReturnValue_t lengthCheck(size_t commandDataLen) { + if (commandDataLen != COMMAND_DATA_LENGTH) { + sif::warning << "TcDownlinkPwrOn: Command has invalid length " << commandDataLen << std::endl; + return INVALID_LENGTH; } + return HasReturnvaluesIF::RETURN_OK; + } + + ReturnValue_t modeCheck(uint8_t mode) { + if (mode > MAX_MODE) { + sif::warning << "TcDwonlinkPwrOn::modeCheck: Invalid JESD mode" << std::endl; + return INVALID_MODE; + } + return HasReturnvaluesIF::RETURN_OK; + } + + ReturnValue_t laneRateCheck(uint8_t laneRate) { + if (laneRate > MAX_LANE_RATE) { + sif::warning << "TcReplayStart::laneRateCheck: Invalid lane rate" << std::endl; + return INVALID_LANE_RATE; + } + return HasReturnvaluesIF::RETURN_OK; + } }; /** * @brief Class to build replay stop space packet. */ class TcDownlinkPwrOff : public TcBase { -public: + public: + TcDownlinkPwrOff(uint16_t sequenceCount) : TcBase(apid::TC_DOWNLINK_PWR_OFF, sequenceCount) {} - TcDownlinkPwrOff(uint16_t sequenceCount) : - TcBase(apid::TC_DOWNLINK_PWR_OFF, sequenceCount) { - } - - ReturnValue_t createPacket() { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = addCrc(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - this->setPacketDataLength(static_cast(CRC_SIZE - 1)); - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t createPacket() { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = addCrc(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + this->setPacketDataLength(static_cast(CRC_SIZE - 1)); + return HasReturnvaluesIF::RETURN_OK; + } }; - /** * @brief This class helps to build the replay start command. */ -class TcReplayWriteSeq: public TcBase { -public: - /** - * @brief Constructor - */ - TcReplayWriteSeq(uint16_t sequenceCount) : TcBase(apid::TC_REPLAY_WRITE_SEQUENCE, sequenceCount) {} +class TcReplayWriteSeq : public TcBase { + public: + /** + * @brief Constructor + */ + TcReplayWriteSeq(uint16_t sequenceCount) + : TcBase(apid::TC_REPLAY_WRITE_SEQUENCE, sequenceCount) {} -protected: - - ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = lengthCheck(commandDataLen); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); - this->setPacketDataLength(commandDataLen + CRC_SIZE - 1); - return result; + protected: + ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = lengthCheck(commandDataLen); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + std::memcpy(this->localData.fields.buffer, commandData, commandDataLen); + *(this->localData.fields.buffer + commandDataLen) = NULL_TERMINATOR; + this->setPacketDataLength(commandDataLen + sizeof(NULL_TERMINATOR) + CRC_SIZE - 1); + return result; + } -private: + private: + static const size_t USE_DECODING_LENGTH = 1; - static const size_t USE_DECODING_LENGTH = 1; - - ReturnValue_t lengthCheck(size_t commandDataLen) { - if (commandDataLen > USE_DECODING_LENGTH + MAX_FILENAME_SIZE) { - sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen << std::endl; - return INVALID_LENGTH; - } - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t lengthCheck(size_t commandDataLen) { + if (commandDataLen > USE_DECODING_LENGTH + MAX_FILENAME_SIZE) { + sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen + << std::endl; + return INVALID_LENGTH; } + return HasReturnvaluesIF::RETURN_OK; + } }; class FlashWritePusCmd : public MPSoCReturnValuesIF { @@ -587,30 +573,25 @@ class FlashWritePusCmd : public MPSoCReturnValuesIF { ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) { if (commandDataLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE + MAX_FILENAME_SIZE)) { - return INVALID_LENGTH; + return INVALID_LENGTH; } obcFile = std::string(reinterpret_cast(commandData)); if (obcFile.size() > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE)) { - return FILENAME_TOO_LONG; + return FILENAME_TOO_LONG; } mpsocFile = std::string( reinterpret_cast(commandData + obcFile.size() + SIZE_NULL_TERMINATOR)); if (mpsocFile.size() > MAX_FILENAME_SIZE) { - return MPSOC_FILENAME_TOO_LONG; + return MPSOC_FILENAME_TOO_LONG; } return HasReturnvaluesIF::RETURN_OK; } - std::string getObcFile() { - return obcFile; - } + std::string getObcFile() { return obcFile; } - std::string getMPSoCFile() { - return mpsocFile; - } + std::string getMPSoCFile() { return mpsocFile; } private: - static const size_t SIZE_NULL_TERMINATOR = 1; std::string obcFile = ""; std::string mpsocFile = ""; @@ -620,25 +601,20 @@ class FlashWritePusCmd : public MPSoCReturnValuesIF { * @brief Class to build replay stop space packet. */ class TcModeReplay : public TcBase { -public: + public: + TcModeReplay(uint16_t sequenceCount) : TcBase(apid::TC_MODE_REPLAY, sequenceCount) {} - TcModeReplay(uint16_t sequenceCount) : - TcBase(apid::TC_MODE_REPLAY, sequenceCount) { - } - - ReturnValue_t createPacket() { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - result = addCrc(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - this->setPacketDataLength(static_cast(CRC_SIZE - 1)); - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t createPacket() { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + result = addCrc(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; } + this->setPacketDataLength(static_cast(CRC_SIZE - 1)); + return HasReturnvaluesIF::RETURN_OK; + } }; -} - - +} // namespace mpsoc #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */ diff --git a/linux/devices/ploc/PlocMPSoCHandler.cpp b/linux/devices/ploc/PlocMPSoCHandler.cpp index ed592352..51eaf274 100644 --- a/linux/devices/ploc/PlocMPSoCHandler.cpp +++ b/linux/devices/ploc/PlocMPSoCHandler.cpp @@ -507,10 +507,10 @@ ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) { case (mpsoc::apid::EXE_FAILURE): { // TODO: Interpretation of status field in execution report sif::warning << "PlocMPSoCHandler::handleExecutionReport: Received execution failure report" - << std::endl; + << std::endl; DeviceCommandId_t commandId = getPendingCommand(); if (commandId != DeviceHandlerIF::NO_COMMAND_ID) { - uint16_t status = getStatus(data); + uint16_t status = getStatus(data); triggerEvent(EXE_FAILURE, commandId, status); } else { sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl; @@ -536,7 +536,7 @@ ReturnValue_t PlocMPSoCHandler::handleMemoryReadReport(const uint8_t* data) { result = verifyPacket(data, tmMemReadReport.rememberRequestedSize); if (result == MPSoCReturnValuesIF::CRC_FAILURE) { sif::warning << "PlocMPSoCHandler::handleMemoryReadReport: Memory read report has invalid crc" - << std::endl; + << std::endl; } uint16_t memLen = *(data + mpsoc::MEM_READ_RPT_LEN_OFFSET) << 8 | *(data + mpsoc::MEM_READ_RPT_LEN_OFFSET + 1); @@ -603,13 +603,15 @@ ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator switch (command->first) { case mpsoc::TC_REPLAY_WRITE_SEQUENCE: { DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT); - if (iter != deviceReplyMap.end()) { - // Overwrite delay cycles because replay write sequence command can required up to - // 30 seconds for execution - iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY; - } else { - sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Unknown reply id" << std::endl; - } + // Overwrite delay cycles because replay write sequence command can required up to + // 30 seconds for execution + iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY; + break; + } + case mpsoc::TC_DOWNLINK_PWR_ON: { + DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT); + // + iter->second.delayCycles = mpsoc::TC_DOWNLINK_PWR_ON; break; } default: @@ -719,6 +721,7 @@ void PlocMPSoCHandler::disableAllReplies() { /* We must always disable the execution report reply here */ disableExeReportReply(); + nextReplyId = mpsoc::NONE; } void PlocMPSoCHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) { @@ -743,7 +746,7 @@ void PlocMPSoCHandler::disableExeReportReply() { DeviceReplyInfo* info = &(iter->second); info->delayCycles = 0; info->command = deviceCommandMap.end(); - /* Expected replies is set to one here. The value will set to 0 in replyToReply() */ + /* Expected replies is set to one here. The value will be set to 0 in replyToReply() */ info->command->second.expectedReplies = 0; } @@ -753,5 +756,5 @@ void PlocMPSoCHandler::printStatus(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); } diff --git a/linux/devices/ploc/PlocMPSoCHelper.cpp b/linux/devices/ploc/PlocMPSoCHelper.cpp index cb604a81..8f3493e6 100644 --- a/linux/devices/ploc/PlocMPSoCHelper.cpp +++ b/linux/devices/ploc/PlocMPSoCHelper.cpp @@ -67,8 +67,9 @@ void PlocMPSoCHelper::setSequenceCount(SourceSequenceCounter* sequenceCount_) { } ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string mpsocFile) { + ReturnValue_t result = RETURN_OK; #ifdef XIPHOS_Q7S - ReturnValue_t result = FilesystemHelper::checkPath(obcFile); + result = FilesystemHelper::checkPath(obcFile); if (result != RETURN_OK) { return result; } @@ -80,7 +81,7 @@ ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string #ifdef TE0720_1CFA if (not std::filesystem::exists(obcFile)) { sif::warning << "PlocMPSoCHelper::startFlashWrite: File " << obcFile << "does not exist" - << std::endl; + << std::endl; return RETURN_FAILED; } #endif @@ -88,9 +89,19 @@ ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string flashWrite.obcFile = obcFile; flashWrite.mpsocFile = mpsocFile; internalState = InternalState::FLASH_WRITE; + result = resetHelper(); + if (result != RETURN_OK) { + return result; + } + return result; +} + +ReturnValue_t PlocMPSoCHelper::resetHelper() { + ReturnValue_t result = RETURN_OK; semaphore.release(); terminate = false; - return RETURN_OK; + result = uartComIF->flushUartRxBuffer(comCookie); + return result; } void PlocMPSoCHelper::stopProcess() { terminate = true; } @@ -99,7 +110,7 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() { ReturnValue_t result = RETURN_OK; result = flashfopen(); if (result != RETURN_OK) { - return result; + return result; } uint8_t tempData[mpsoc::MAX_DATA_SIZE]; std::ifstream file(flashWrite.obcFile, std::ifstream::binary); @@ -108,6 +119,7 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() { // tellg returns position of character in input stream size_t remainingSize = file.tellg(); size_t dataLength = 0; + size_t bytesRead = 0; while (remainingSize > 0) { if (terminate) { return RETURN_OK; @@ -117,26 +129,25 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() { } else { dataLength = remainingSize; } - file.read(reinterpret_cast(tempData), dataLength); + if (file.is_open()) { + file.seekg(bytesRead, file.beg); + file.read(reinterpret_cast(tempData), dataLength); + bytesRead += dataLength; + remainingSize -= dataLength; + } else { + return FILE_CLOSED_ACCIDENTALLY; + } (*sequenceCount)++; mpsoc::TcFlashWrite tc(*sequenceCount); tc.createPacket(tempData, dataLength); - result = sendCommand(&tc); - if (result != RETURN_OK) { - return result; - } - result = handleAck(); - if (result != RETURN_OK) { - return result; - } - result = handleExe(); + result = handlePacketTransmission(tc); if (result != RETURN_OK) { return result; } } result = flashfclose(); if (result != RETURN_OK) { - return result; + return result; } return result; } @@ -149,7 +160,7 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() { if (result != RETURN_OK) { return result; } - result = sendCommand(&flashFopen); + result = handlePacketTransmission(flashFopen); if (result != RETURN_OK) { return result; } @@ -157,23 +168,40 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() { } ReturnValue_t PlocMPSoCHelper::flashfclose() { - ReturnValue_t result = RETURN_OK; - (*sequenceCount)++; - mpsoc::FlashFclose flashFclose(*sequenceCount); - result = flashFclose.createPacket(flashWrite.mpsocFile); - if (result != RETURN_OK) { - return result; - } - result = sendCommand(&flashFclose); - if (result != RETURN_OK) { - return result; - } - return RETURN_OK; + ReturnValue_t result = RETURN_OK; + (*sequenceCount)++; + mpsoc::FlashFclose flashFclose(*sequenceCount); + result = flashFclose.createPacket(flashWrite.mpsocFile); + if (result != RETURN_OK) { + return result; + } + result = handlePacketTransmission(flashFclose); + if (result != RETURN_OK) { + return result; + } + return RETURN_OK; } -ReturnValue_t PlocMPSoCHelper::sendCommand(mpsoc::TcBase* tc) { +ReturnValue_t PlocMPSoCHelper::handlePacketTransmission(mpsoc::TcBase& tc) { ReturnValue_t result = RETURN_OK; - result = uartComIF->sendMessage(comCookie, tc->getWholeData(), tc->getFullSize()); + result = sendCommand(tc); + if (result != RETURN_OK) { + return result; + } + result = handleAck(); + if (result != RETURN_OK) { + return result; + } + result = handleExe(); + if (result != RETURN_OK) { + return result; + } + return RETURN_OK; +} + +ReturnValue_t PlocMPSoCHelper::sendCommand(mpsoc::TcBase& tc) { + ReturnValue_t result = RETURN_OK; + result = uartComIF->sendMessage(comCookie, tc.getWholeData(), tc.getFullSize()); if (result != RETURN_OK) { sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl; triggerEvent(SENDING_COMMAND_FAILED, result, static_cast(internalState)); @@ -231,7 +259,7 @@ void PlocMPSoCHelper::handleExeApidFailure(uint16_t apid) { << "report" << std::endl; } else { triggerEvent(EXE_INVALID_APID, apid, static_cast(internalState)); - sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Expected execution report " + sif::warning << "PlocMPSoCHelper::handleExeApidFailure: Expected execution report " << "but received space packet with apid " << std::hex << apid << std::endl; } } @@ -239,12 +267,14 @@ void PlocMPSoCHelper::handleExeApidFailure(uint16_t apid) { ReturnValue_t PlocMPSoCHelper::handleTmReception(mpsoc::TmPacket* tmPacket, size_t remainingBytes) { ReturnValue_t result = RETURN_OK; size_t readBytes = 0; + size_t currentBytes = 0; for (int retries = 0; retries < RETRIES; retries++) { - result = receive(tmPacket->getWholeData(), &readBytes, remainingBytes); + result = receive(tmPacket->getWholeData() + readBytes, ¤tBytes, remainingBytes); if (result != RETURN_OK) { return result; } - remainingBytes = remainingBytes - readBytes; + readBytes += currentBytes; + remainingBytes = remainingBytes - currentBytes; if (remainingBytes == 0) { break; } @@ -259,17 +289,18 @@ ReturnValue_t PlocMPSoCHelper::handleTmReception(mpsoc::TmPacket* tmPacket, size sif::warning << "PlocMPSoCHelper::handleTmReception: CRC check failed" << std::endl; return result; } + (*sequenceCount)++; uint16_t recvSeqCnt = tmPacket->getPacketSequenceCount(); if (recvSeqCnt != *sequenceCount) { triggerEvent(MPSOC_HELPER_SEQ_CNT_MISMATCH, *sequenceCount, recvSeqCnt); *sequenceCount = recvSeqCnt; - return result; } return result; } ReturnValue_t PlocMPSoCHelper::receive(uint8_t* data, size_t* readBytes, size_t requestBytes) { ReturnValue_t result = RETURN_OK; + uint8_t* buffer = nullptr; result = uartComIF->requestReceiveMessage(comCookie, requestBytes); if (result != RETURN_OK) { sif::warning << "PlocMPSoCHelper::receive: Failed to request reply" << std::endl; @@ -277,11 +308,14 @@ ReturnValue_t PlocMPSoCHelper::receive(uint8_t* data, size_t* readBytes, size_t static_cast(static_cast(internalState))); return RETURN_FAILED; } - result = uartComIF->readReceivedMessage(comCookie, &data, readBytes); + result = uartComIF->readReceivedMessage(comCookie, &buffer, readBytes); if (result != RETURN_OK) { sif::warning << "PlocMPSoCHelper::receive: Failed to read received message" << std::endl; triggerEvent(MPSOC_HELPER_READING_REPLY_FAILED, result, static_cast(internalState)); return RETURN_FAILED; } + if (*readBytes > 0) { + std::memcpy(data, buffer, *readBytes); + } return result; } diff --git a/linux/devices/ploc/PlocMPSoCHelper.h b/linux/devices/ploc/PlocMPSoCHelper.h index 0655f5dd..4cb882c7 100644 --- a/linux/devices/ploc/PlocMPSoCHelper.h +++ b/linux/devices/ploc/PlocMPSoCHelper.h @@ -2,13 +2,14 @@ #define BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_ #include + +#include "fsfw/devicehandlers/CookieIF.h" +#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/osal/linux/BinarySemaphore.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" -#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/tasks/ExecutableObjectIF.h" -#include "fsfw_hal/linux/uart/UartComIF.h" -#include "fsfw/devicehandlers/CookieIF.h" #include "fsfw/tmtcservices/SourceSequenceCounter.h" +#include "fsfw_hal/linux/uart/UartComIF.h" #include "linux/devices/devicedefinitions/PlocMPSoCDefinitions.h" #ifdef XIPHOS_Q7S #include "bsp_q7s/memory/SdCardManager.h" @@ -19,134 +20,134 @@ * MPSoC and OBC. * @author J. Meier */ -class PlocMPSoCHelper: public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF { -public: +class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF { + public: + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HELPER; - static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HELPER; + //! [EXPORT] : [COMMENT] Flash write fails + static const Event MPSOC_FLASH_WRITE_FAILED = MAKE_EVENT(0, severity::LOW); + //! [EXPORT] : [COMMENT] Flash write successful + static const Event MPSOC_FLASH_WRITE_SUCCESSFUL = MAKE_EVENT(1, severity::LOW); + //! [EXPORT] : [COMMENT] Communication interface returned failure when trying to send the command + //! ot the PLOC + //! P1: Return value returned by the communication interface sendMessage function + //! P2: Internal state of MPSoC helper + static const Event SENDING_COMMAND_FAILED = MAKE_EVENT(2, severity::LOW); + //! [EXPORT] : [COMMENT] Request receive message of communication interface failed + //! P1: Return value returned by the communication interface requestReceiveMessage function + //! P2: Internal state of MPSoC helper + static const Event MPSOC_HELPER_REQUESTING_REPLY_FAILED = MAKE_EVENT(3, severity::LOW); + //! [EXPORT] : [COMMENT] Reading receive message of communication interface failed + //! P1: Return value returned by the communication interface readingReceivedMessage function + //! P2: Internal state of MPSoC helper + static const Event MPSOC_HELPER_READING_REPLY_FAILED = MAKE_EVENT(4, severity::LOW); + //! [EXPORT] : [COMMENT] Did not receive acknowledgement report + //! P1: Number of bytes missing + //! P2: Internal state of MPSoC helper + static const Event MISSING_ACK = MAKE_EVENT(5, severity::LOW); + //! [EXPORT] : [COMMENT] Did not receive execution report + //! P1: Number of bytes missing + //! P2: Internal state of MPSoC helper + static const Event MISSING_EXE = MAKE_EVENT(6, severity::LOW); + //! [EXPORT] : [COMMENT] Received acknowledgement failure report + //! P1: Internal state of MPSoC + static const Event ACK_FAILURE_REPORT = MAKE_EVENT(7, severity::LOW); + //! [EXPORT] : [COMMENT] Received execution failure report + //! P1: Internal state of MPSoC + static const Event EXE_FAILURE_REPORT = MAKE_EVENT(8, severity::LOW); + //! [EXPORT] : [COMMENT] Expected acknowledgement report but received space packet with other apid + //! P1: Apid of received space packet + //! P2: Internal state of MPSoC + static const Event ACK_INVALID_APID = MAKE_EVENT(9, severity::LOW); + //! [EXPORT] : [COMMENT] Expected execution report but received space packet with other apid + //! P1: Apid of received space packet + //! P2: Internal state of MPSoC + static const Event EXE_INVALID_APID = MAKE_EVENT(10, severity::LOW); + //! [EXPORT] : [COMMENT] Received sequence count does not match expected sequence count + //! P1: Expected sequence count + //! P2: Received sequence count + static const Event MPSOC_HELPER_SEQ_CNT_MISMATCH = MAKE_EVENT(11, severity::LOW); - //! [EXPORT] : [COMMENT] Flash write fails - static const Event MPSOC_FLASH_WRITE_FAILED = MAKE_EVENT(0, severity::LOW); - //! [EXPORT] : [COMMENT] Flash write successful - static const Event MPSOC_FLASH_WRITE_SUCCESSFUL = MAKE_EVENT(1, severity::LOW); - //! [EXPORT] : [COMMENT] Communication interface returned failure when trying to send the command ot the PLOC - //!P1: Return value returned by the communication interface sendMessage function - //!P2: Internal state of MPSoC helper - static const Event SENDING_COMMAND_FAILED = MAKE_EVENT(2, severity::LOW); - //! [EXPORT] : [COMMENT] Request receive message of communication interface failed - //!P1: Return value returned by the communication interface requestReceiveMessage function - //!P2: Internal state of MPSoC helper - static const Event MPSOC_HELPER_REQUESTING_REPLY_FAILED = MAKE_EVENT(3, severity::LOW); - //! [EXPORT] : [COMMENT] Reading receive message of communication interface failed - //!P1: Return value returned by the communication interface readingReceivedMessage function - //!P2: Internal state of MPSoC helper - static const Event MPSOC_HELPER_READING_REPLY_FAILED = MAKE_EVENT(4, severity::LOW); - //! [EXPORT] : [COMMENT] Did not receive acknowledgement report - //!P1: Number of bytes missing - //!P2: Internal state of MPSoC helper - static const Event MISSING_ACK = MAKE_EVENT(5, severity::LOW); - //! [EXPORT] : [COMMENT] Did not receive execution report - //!P1: Number of bytes missing - //!P2: Internal state of MPSoC helper - static const Event MISSING_EXE = MAKE_EVENT(6, severity::LOW); - //! [EXPORT] : [COMMENT] Received acknowledgement failure report - //!P1: Internal state of MPSoC - static const Event ACK_FAILURE_REPORT = MAKE_EVENT(7, severity::LOW); - //! [EXPORT] : [COMMENT] Received execution failure report - //!P1: Internal state of MPSoC - static const Event EXE_FAILURE_REPORT = MAKE_EVENT(8, severity::LOW); - //! [EXPORT] : [COMMENT] Expected acknowledgement report but received space packet with other apid - //!P1: Apid of received space packet - //!P2: Internal state of MPSoC - static const Event ACK_INVALID_APID = MAKE_EVENT(9, severity::LOW); - //! [EXPORT] : [COMMENT] Expected execution report but received space packet with other apid - //!P1: Apid of received space packet - //!P2: Internal state of MPSoC - static const Event EXE_INVALID_APID = MAKE_EVENT(10, severity::LOW); - //! [EXPORT] : [COMMENT] Received sequence count does not match expected sequence count - //!P1: Expected sequence count - //!P2: Received sequence count - static const Event MPSOC_HELPER_SEQ_CNT_MISMATCH = MAKE_EVENT(11, severity::LOW); + PlocMPSoCHelper(object_id_t objectId); + virtual ~PlocMPSoCHelper(); - PlocMPSoCHelper(object_id_t objectId); - virtual ~PlocMPSoCHelper(); + ReturnValue_t initialize() override; + ReturnValue_t performOperation(uint8_t operationCode = 0) override; - ReturnValue_t initialize() override; - ReturnValue_t performOperation(uint8_t operationCode = 0) override; + ReturnValue_t setComIF(DeviceCommunicationIF* communicationInterface_); + void setComCookie(CookieIF* comCookie_); - ReturnValue_t setComIF(DeviceCommunicationIF* communicationInterface_); - void setComCookie(CookieIF* comCookie_); + /** + * @brief Starts flash write sequence + * + * @param obcFile File where to read from the data + * @param mpsocFile The file of the MPSoC where should be written to + * + * @return RETURN_OK if successful, otherwise error return value + */ + ReturnValue_t startFlashWrite(std::string obcFile, std::string mpsocFile); - /** - * @brief Starts flash write sequence - * - * @param obcFile File where to read from the data - * @param mpsocFile The file of the MPSoC where should be written to - * - * @return RETURN_OK if successful, otherwise error return value - */ - ReturnValue_t startFlashWrite(std::string obcFile, std::string mpsocFile); + /** + * @brief Can be used to interrupt a running data transfer. + */ + void stopProcess(); - /** - * @brief Can be used to interrupt a running data transfer. - */ - void stopProcess(); + /** + * @brief Sets the sequence count object responsible for the sequence count handling + */ + void setSequenceCount(SourceSequenceCounter* sequenceCount_); - /** - * @brief Sets the sequence count object responsible for the sequence count handling - */ - void setSequenceCount(SourceSequenceCounter* sequenceCount_); + private: + static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HELPER; -private: + //! [EXPORT] : [COMMENT] File accidentally close + static const ReturnValue_t FILE_CLOSED_ACCIDENTALLY = MAKE_RETURN_CODE(0xA0); - static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HELPER; + // Maximum number of times the communication interface retries polling data from the reply + // buffer + static const int RETRIES = 10000; - // Maximum number of times the communication interface retries polling data from the reply - // buffer - static const int RETRIES = 3; + struct FlashWrite { + std::string obcFile; + std::string mpsocFile; + }; - struct FlashWrite { - std::string obcFile; - std::string mpsocFile; - }; + struct FlashWrite flashWrite; - struct FlashWrite flashWrite; + enum class InternalState { IDLE, FLASH_WRITE, FLASH_READ }; - enum class InternalState { - IDLE, - FLASH_WRITE, - FLASH_READ - }; + InternalState internalState = InternalState::IDLE; - InternalState internalState = InternalState::IDLE; - - BinarySemaphore semaphore; + BinarySemaphore semaphore; #ifdef XIPHOS_Q7S - SdCardManager* sdcMan = nullptr; + SdCardManager* sdcMan = nullptr; #endif - uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE]; + uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE]; - bool terminate = false; + bool terminate = false; - /** - * Communication interface of MPSoC responsible for low level access. Must be set by the - * MPSoC Handler. - */ - UartComIF* uartComIF = nullptr; - // Communication cookie. Must be set by the MPSoC Handler - CookieIF* comCookie = nullptr; - // Sequence count, must be set by Ploc MPSoC Handler - SourceSequenceCounter* sequenceCount; + /** + * Communication interface of MPSoC responsible for low level access. Must be set by the + * MPSoC Handler. + */ + UartComIF* uartComIF = nullptr; + // Communication cookie. Must be set by the MPSoC Handler + CookieIF* comCookie = nullptr; + // Sequence count, must be set by Ploc MPSoC Handler + SourceSequenceCounter* sequenceCount; - ReturnValue_t performFlashWrite(); - ReturnValue_t flashfopen(); - ReturnValue_t flashfclose(); - ReturnValue_t sendCommand(mpsoc::TcBase* tc); - ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes); - ReturnValue_t handleAck(); - ReturnValue_t handleExe(); - void handleAckApidFailure(uint16_t apid); - void handleExeApidFailure(uint16_t apid); - ReturnValue_t handleTmReception(mpsoc::TmPacket* tmPacket, size_t remainingBytes); + ReturnValue_t resetHelper(); + ReturnValue_t performFlashWrite(); + ReturnValue_t flashfopen(); + ReturnValue_t flashfclose(); + ReturnValue_t handlePacketTransmission(mpsoc::TcBase& tc); + ReturnValue_t sendCommand(mpsoc::TcBase& tc); + ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes); + ReturnValue_t handleAck(); + ReturnValue_t handleExe(); + void handleAckApidFailure(uint16_t apid); + void handleExeApidFailure(uint16_t apid); + ReturnValue_t handleTmReception(mpsoc::TmPacket* tmPacket, size_t remainingBytes); }; #endif /* BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_ */ diff --git a/linux/fsfwconfig/OBSWConfig.h.in b/linux/fsfwconfig/OBSWConfig.h.in index 2bfbb2d4..dabbcaae 100644 --- a/linux/fsfwconfig/OBSWConfig.h.in +++ b/linux/fsfwconfig/OBSWConfig.h.in @@ -102,6 +102,7 @@ debugging. */ #define OBSW_STAR_TRACKER_GROUND_CONFIG 1 #define OBSW_ENABLE_PERIODIC_HK 0 #define OBSW_PRINT_CORE_HK 0 +#define OBSW_INITIALIZE_SWITCHES 0 #endif @@ -154,10 +155,16 @@ debugging. */ #define OBSW_DEBUG_SYRLINKS 0 #define OBSW_DEBUG_IMTQ 0 #define OBSW_DEBUG_RW 0 -#define OBSW_DEBUG_PLOC_MPSOC 0 -#define OBSW_DEBUG_PLOC_SUPERVISOR 0 #define OBSW_DEBUG_PDEC_HANDLER 0 +#ifdef TE0720_1CFA +#define OBSW_DEBUG_PLOC_SUPERVISOR 1 +#define OBSW_DEBUG_PLOC_MPSOC 1 +#else +#define OBSW_DEBUG_PLOC_SUPERVISOR 0 +#define OBSW_DEBUG_PLOC_MPSOC 0 +#endif + #ifdef EGSE #define OBSW_DEBUG_STARTRACKER 1 #else