mpsoc flash write command

This commit is contained in:
Jakob Meier 2022-03-26 20:47:25 +01:00
parent 47a3804145
commit 471a981ccf
7 changed files with 690 additions and 680 deletions

View File

@ -1203,100 +1203,6 @@ void ObjectFactory::createTestComponents(LinuxLibgpioIF* gpioComIF) {
#if BOARD_TE0720 == 0 #if BOARD_TE0720 == 0
new Q7STestTask(objects::TEST_TASK); new Q7STestTask(objects::TEST_TASK);
#endif #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 #if OBSW_ADD_SPI_TEST_CODE == 1
new SpiTestClass(objects::SPI_TEST, gpioComIF); new SpiTestClass(objects::SPI_TEST, gpioComIF);
#endif #endif

View File

@ -39,12 +39,95 @@ void ObjectFactory::produce(void* args) {
#if OBSW_ADD_PLOC_MPSOC == 1 #if OBSW_ADD_PLOC_MPSOC == 1
UartCookie* mpsocUartCookie = UartCookie* mpsocUartCookie =
new UartCookie(objects::PLOC_MPSOC_HANDLER, te0720_1cfa::MPSOC_UART, new UartCookie(objects::PLOC_MPSOC_HANDLER, te0720_1cfa::MPSOC_UART, UartModes::NON_CANONICAL,
UartModes::NON_CANONICAL, uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE); uart::PLOC_MPSOC_BAUD, mpsoc::MAX_REPLY_SIZE);
mpsocUartCookie->setNoFixedSizeReply();
PlocMPSoCHelper* plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER); PlocMPSoCHelper* plocMpsocHelper = new PlocMPSoCHelper(objects::PLOC_MPSOC_HELPER);
new UartComIF(objects::UART_COM_IF); new UartComIF(objects::UART_COM_IF);
PlocMPSoCHandler* plocMPSoCHandler = new PlocMPSoCHandler( PlocMPSoCHandler* plocMPSoCHandler = new PlocMPSoCHandler(
objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocUartCookie, plocMpsocHelper); objects::PLOC_MPSOC_HANDLER, objects::UART_COM_IF, mpsocUartCookie, plocMpsocHelper);
plocMPSoCHandler->setStartUpImmediately(); plocMPSoCHandler->setStartUpImmediately();
#endif /* OBSW_ADD_PLOC_MPSOC == 1 */ #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
} }

View File

@ -1,11 +1,12 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
#include "OBSWConfig.h"
#include "MPSoCReturnValuesIF.h"
#include <fsfw/tmtcpacket/SpacePacket.h>
#include <fsfw/globalfunctions/CRC.h> #include <fsfw/globalfunctions/CRC.h>
#include <fsfw/serialize/SerializeAdapter.h> #include <fsfw/serialize/SerializeAdapter.h>
#include <fsfw/tmtcpacket/SpacePacket.h>
#include "MPSoCReturnValuesIF.h"
#include "OBSWConfig.h"
namespace mpsoc { namespace mpsoc {
@ -37,28 +38,29 @@ static const uint16_t SIZE_TM_MEM_READ_REPORT = 18;
* SpacePacket apids of PLOC telecommands and telemetry. * SpacePacket apids of PLOC telecommands and telemetry.
*/ */
namespace apid { namespace apid {
static const uint16_t TC_REPLAY_START = 0x110; static const uint16_t TC_REPLAY_START = 0x110;
static const uint16_t TC_REPLAY_STOP = 0x111; static const uint16_t TC_REPLAY_STOP = 0x111;
static const uint16_t TC_REPLAY_WRITE_SEQUENCE = 0x112; static const uint16_t TC_REPLAY_WRITE_SEQUENCE = 0x112;
static const uint16_t TC_DOWNLINK_PWR_ON = 0x113; static const uint16_t TC_DOWNLINK_PWR_ON = 0x113;
static const uint16_t TC_MEM_WRITE = 0x114; static const uint16_t TC_MEM_WRITE = 0x114;
static const uint16_t TC_MEM_READ = 0x115; static const uint16_t TC_MEM_READ = 0x115;
static const uint16_t TC_FLASHWRITE = 0x117; static const uint16_t TC_FLASHWRITE = 0x117;
static const uint16_t TC_FLASHFOPEN = 0x119; static const uint16_t TC_FLASHFOPEN = 0x119;
static const uint16_t TC_FLASHFCLOSE = 0x11A; static const uint16_t TC_FLASHFCLOSE = 0x11A;
static const uint16_t TC_FLASHDELETE = 0x11C; static const uint16_t TC_FLASHDELETE = 0x11C;
static const uint16_t TC_MODE_REPLAY = 0x11F; static const uint16_t TC_MODE_REPLAY = 0x11F;
static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124; static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124;
static const uint16_t TM_MEMORY_READ_REPORT = 0x404; static const uint16_t TM_MEMORY_READ_REPORT = 0x404;
static const uint16_t ACK_SUCCESS = 0x400; static const uint16_t ACK_SUCCESS = 0x400;
static const uint16_t ACK_FAILURE = 0x401; static const uint16_t ACK_FAILURE = 0x401;
static const uint16_t EXE_SUCCESS = 0x402; static const uint16_t EXE_SUCCESS = 0x402;
static const uint16_t EXE_FAILURE = 0x403; static const uint16_t EXE_FAILURE = 0x403;
} } // namespace apid
/** Offset from first byte in space packet to first byte of data field */ /** Offset from first byte in space packet to first byte of data field */
static const uint8_t DATA_FIELD_OFFSET = 6; static const uint8_t DATA_FIELD_OFFSET = 6;
static const size_t MEM_READ_RPT_LEN_OFFSET = 10; 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 * 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 * 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. * @brief Abstract base class for TC space packet of MPSoC.
*/ */
class TcBase : public SpacePacket, public MPSoCReturnValuesIF { 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 * @brief Function to initialize the space packet
* *
* @param sequenceCount Sequence count of space packet which will be incremented with each * @param commandData Pointer to command specific data
* sent and received packets. * @param commandDataLen Length of command data
*/ *
TcBase(uint16_t apid, uint16_t sequenceCount) : * @return RETURN_OK if packet creation was successful, otherwise error return value
SpacePacket(INIT_LENGTH, true, apid, sequenceCount) { */
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) {
* @brief Function to initialize the space packet return result;
*
* @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;
} }
return result;
}
protected: protected:
/** /**
* @brief Must be overwritten by the child class to define the command specific parameters * @brief Must be overwritten by the child class to define the command specific parameters
* *
* @param commandData Pointer to received command data * @param commandData Pointer to received command data
* @param commandDataLen Length of received command data * @param commandDataLen Length of received command data
*/ */
virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
/** /**
* @brief Calculates and adds the CRC * @brief Calculates and adds the CRC
*/ */
ReturnValue_t addCrc() { ReturnValue_t addCrc() {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
size_t serializedSize = 0; size_t serializedSize = 0;
uint32_t full_size = getFullSize(); uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE); uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
result = SerializeAdapter::serialize<uint16_t>(&crc, result = SerializeAdapter::serialize<uint16_t>(
this->localData.byteStream + full_size - CRC_SIZE, &serializedSize, sizeof(crc), &crc, this->localData.byteStream + full_size - CRC_SIZE, &serializedSize, sizeof(crc),
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "TcBase::addCrc: Failed to serialize crc field" << std::endl; sif::debug << "TcBase::addCrc: Failed to serialize crc field" << std::endl;
}
return result;
} }
return result;
}
}; };
/** /**
* @brief Class for handling tm replies of the PLOC MPSoC. * @brief Class for handling tm replies of the PLOC MPSoC.
*/ */
class TmPacket : public SpacePacket, public MPSoCReturnValuesIF { 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) {}
/** ReturnValue_t checkCrc() {
* @brief Constructor creates idle packet and sets length field to maximum allowed size. uint8_t* crcPtr = this->getPacketData() + this->getPacketDataLength() - 1;
*/ uint16_t receivedCrc = *(crcPtr) << 8 | *(crcPtr + 1);
TmPacket() : SpacePacket(PACKET_MAX_SIZE) { uint16_t recalculatedCrc =
} CRC::crc16ccitt(this->localData.byteStream, this->getFullSize() - CRC_SIZE);
if (recalculatedCrc != receivedCrc) {
ReturnValue_t checkCrc() { return CRC_FAILURE;
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;
} }
return HasReturnvaluesIF::RETURN_OK;
}
}; };
/** /**
* @brief This class helps to build the memory read command for the PLOC. * @brief This class helps to build the memory read command for the PLOC.
*/ */
class TcMemRead: public TcBase { class TcMemRead : public TcBase {
public: public:
/**
* @brief Constructor
*/
TcMemRead(uint16_t sequenceCount) : TcBase(apid::TC_MEM_READ, sequenceCount) {
this->setPacketDataLength(PACKET_LENGTH);
}
/** uint16_t getMemLen() const { return memLen; }
* @brief Constructor
*/ protected:
TcMemRead(uint16_t sequenceCount) : ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
TcBase(apid::TC_MEM_READ, sequenceCount) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
this->setPacketDataLength(PACKET_LENGTH); result = lengthCheck(commandDataLen);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
} }
std::memcpy(this->localData.fields.buffer, commandData, MEM_ADDRESS_SIZE);
uint16_t getMemLen() const { std::memcpy(this->localData.fields.buffer + MEM_ADDRESS_SIZE, commandData + MEM_ADDRESS_SIZE,
return memLen; 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) { uint16_t memLen = 0;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
result = lengthCheck(commandDataLen); ReturnValue_t lengthCheck(size_t commandDataLen) {
if (result != HasReturnvaluesIF::RETURN_OK) { if (commandDataLen != COMMAND_LENGTH) {
return result; return INVALID_LENGTH;
}
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;
} }
return HasReturnvaluesIF::RETURN_OK;
}
}; };
/** /**
* @brief This class helps to generate the space packet to write data to a memory address within * @brief This class helps to generate the space packet to write data to a memory address within
* the PLOC. * the PLOC.
*/ */
class TcMemWrite: public TcBase { class TcMemWrite : public TcBase {
public: public:
/** /**
* @brief Constructor * @brief Constructor
*/ */
TcMemWrite(uint16_t sequenceCount) : TcBase(apid::TC_MEM_WRITE, sequenceCount) { 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 lengthCheck(size_t commandDataLen) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; if (commandDataLen < MIN_COMMAND_DATA_LENGTH) {
result = lengthCheck(commandDataLen); sif::warning << "TcMemWrite: Command has invalid length " << commandDataLen << std::endl;
if (result != HasReturnvaluesIF::RETURN_OK) { return INVALID_LENGTH;
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;
} }
return HasReturnvaluesIF::RETURN_OK;
}
}; };
/** /**
* @brief Class to help creation of flash fopen command. * @brief Class to help creation of flash fopen command.
*/ */
class FlashFopen : public TcBase { class FlashFopen : public TcBase {
public: public:
FlashFopen(uint16_t sequenceCount) : TcBase(apid::TC_FLASHFOPEN, sequenceCount) {}
FlashFopen(uint16_t sequenceCount) : static const char APPEND = 'a';
TcBase(apid::TC_FLASHFOPEN, sequenceCount) { 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'; private:
static const char WRITE = 'w'; char accessMode = APPEND;
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;
}
}; };
/** /**
* @brief Class to help creation of flash fclose command. * @brief Class to help creation of flash fclose command.
*/ */
class FlashFclose: public TcBase { class FlashFclose : public TcBase {
public: public:
FlashFclose(uint16_t sequenceCount) : TcBase(apid::TC_FLASHFCLOSE, sequenceCount) {}
FlashFclose(uint16_t sequenceCount) : ReturnValue_t createPacket(std::string filename) {
TcBase(apid::TC_FLASHFCLOSE, sequenceCount) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
} size_t nameSize = filename.size();
std::memcpy(this->getPacketData(), filename.c_str(), nameSize);
ReturnValue_t createPacket(std::string filename) { *(this->getPacketData() + nameSize) = NULL_TERMINATOR;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; this->setPacketDataLength(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE - 1);
size_t nameSize = filename.size(); result = addCrc();
std::memcpy(this->getPacketData(), filename.c_str(), nameSize); if (result != HasReturnvaluesIF::RETURN_OK) {
this->setPacketDataLength(nameSize + CRC_SIZE - 1); return result;
result = addCrc(); }
if (result != HasReturnvaluesIF::RETURN_OK) { return result;
return result; }
}
return result;
}
}; };
/** /**
* @brief Class to build flash write space packet. * @brief Class to build flash write space packet.
*/ */
class TcFlashWrite : public TcBase { class TcFlashWrite : public TcBase {
public: public:
TcFlashWrite(uint16_t sequenceCount) : TcBase(apid::TC_FLASHWRITE, sequenceCount) {}
TcFlashWrite(uint16_t sequenceCount) : ReturnValue_t createPacket(const uint8_t* writeData, uint32_t writeLen_) {
TcBase(apid::TC_FLASHWRITE, sequenceCount) { 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<uint32_t>(&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<uint16_t>(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) { private:
if (writeLen > MAX_DATA_SIZE) { uint32_t writeLen = 0;
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<uint16_t>(writeLen + CRC_SIZE - 1));
ReturnValue_t result = addCrc();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
}; };
/** /**
* @brief Class to help creation of flash delete command. * @brief Class to help creation of flash delete command.
*/ */
class TcFlashDelete: public TcBase { class TcFlashDelete : public TcBase {
public: public:
TcFlashDelete(uint16_t sequenceCount) : TcBase(apid::TC_FLASHDELETE, sequenceCount) {}
TcFlashDelete(uint16_t sequenceCount) : ReturnValue_t createPacket(std::string filename) {
TcBase(apid::TC_FLASHDELETE , sequenceCount) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
} size_t nameSize = filename.size();
std::memcpy(this->getPacketData(), filename.c_str(), nameSize);
ReturnValue_t createPacket(std::string filename) { *(this->getPacketData() + nameSize) = NULL_TERMINATOR;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; this->setPacketDataLength(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE - 1);
size_t nameSize = filename.size(); result = addCrc();
std::memcpy(this->getPacketData(), filename.c_str(), nameSize); if (result != HasReturnvaluesIF::RETURN_OK) {
this->setPacketDataLength(nameSize + CRC_SIZE - 1); return result;
result = addCrc(); }
if (result != HasReturnvaluesIF::RETURN_OK) { return result;
return result; }
}
return result;
}
}; };
/** /**
* @brief Class to build replay stop space packet. * @brief Class to build replay stop space packet.
*/ */
class TcReplayStop : public TcBase { class TcReplayStop : public TcBase {
public: public:
TcReplayStop(uint16_t sequenceCount) : TcBase(apid::TC_REPLAY_STOP, sequenceCount) {}
TcReplayStop(uint16_t sequenceCount) : ReturnValue_t createPacket() {
TcBase(apid::TC_REPLAY_STOP, sequenceCount) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
} result = addCrc();
if (result != HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t createPacket() { return result;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
result = addCrc();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
return HasReturnvaluesIF::RETURN_OK;
} }
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
return HasReturnvaluesIF::RETURN_OK;
}
}; };
/** /**
* @brief This class helps to build the replay start command. * @brief This class helps to build the replay start command.
*/ */
class TcReplayStart: public TcBase { class TcReplayStart : public TcBase {
public: public:
/** /**
* @brief Constructor * @brief Constructor
*/ */
TcReplayStart(uint16_t sequenceCount) : TcBase(apid::TC_REPLAY_START, sequenceCount) { 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;
} }
result = checkData(*commandData);
protected: if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
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;
} }
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; ReturnValue_t lengthCheck(size_t commandDataLen) {
static const uint8_t REPEATING = 0; if (commandDataLen != COMMAND_DATA_LENGTH) {
static const uint8_t ONCE = 1; sif::warning << "TcReplayStart: Command has invalid length " << commandDataLen << std::endl;
return INVALID_LENGTH;
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;
} }
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t checkData(uint8_t replay) { ReturnValue_t checkData(uint8_t replay) {
if (replay != REPEATING && replay != ONCE) { if (replay != REPEATING && replay != ONCE) {
sif::warning << "TcReplayStart::checkData: Invalid replay value" << std::endl; sif::warning << "TcReplayStart::checkData: Invalid replay value" << std::endl;
return INVALID_PARAMETER; return INVALID_PARAMETER;
}
return HasReturnvaluesIF::RETURN_OK;
} }
return HasReturnvaluesIF::RETURN_OK;
}
}; };
/** /**
* @brief This class helps to build downlink power on command. * @brief This class helps to build downlink power on command.
*/ */
class TcDownlinkPwrOn: public TcBase { class TcDownlinkPwrOn : public TcBase {
public: public:
/** /**
* @brief Constructor * @brief Constructor
*/ */
TcDownlinkPwrOn(uint16_t sequenceCount) : TcBase(apid::TC_DOWNLINK_PWR_ON, sequenceCount) { 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;
} }
result = modeCheck(*commandData);
protected: if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
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 = laneRateCheck(*(commandData + 1));
private: if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
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;
} }
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) { private:
if (mode > MAX_MODE) { static const uint8_t INTERFACE_ID = CLASS_ID::DWLPWRON_CMD;
sif::warning << "TcDwonlinkPwrOn::modeCheck: Invalid JESD mode" << std::endl;
return INVALID_MODE;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t laneRateCheck(uint8_t laneRate) { //! [EXPORT] : [COMMENT] Received command has invalid JESD mode (valid modes are 0 - 5)
if (laneRate > MAX_LANE_RATE) { static const ReturnValue_t INVALID_MODE = MAKE_RETURN_CODE(0xE0);
sif::warning << "TcReplayStart::laneRateCheck: Invalid lane rate" << std::endl; //! [EXPORT] : [COMMENT] Received command has invalid lane rate (valid lane rate are 0 - 9)
return INVALID_LANE_RATE; static const ReturnValue_t INVALID_LANE_RATE = MAKE_RETURN_CODE(0xE1);
}
return HasReturnvaluesIF::RETURN_OK; 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. * @brief Class to build replay stop space packet.
*/ */
class TcDownlinkPwrOff : public TcBase { class TcDownlinkPwrOff : public TcBase {
public: public:
TcDownlinkPwrOff(uint16_t sequenceCount) : TcBase(apid::TC_DOWNLINK_PWR_OFF, sequenceCount) {}
TcDownlinkPwrOff(uint16_t sequenceCount) : ReturnValue_t createPacket() {
TcBase(apid::TC_DOWNLINK_PWR_OFF, sequenceCount) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
} result = addCrc();
if (result != HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t createPacket() { return result;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
result = addCrc();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
return HasReturnvaluesIF::RETURN_OK;
} }
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
return HasReturnvaluesIF::RETURN_OK;
}
}; };
/** /**
* @brief This class helps to build the replay start command. * @brief This class helps to build the replay start command.
*/ */
class TcReplayWriteSeq: public TcBase { class TcReplayWriteSeq : public TcBase {
public: public:
/** /**
* @brief Constructor * @brief Constructor
*/ */
TcReplayWriteSeq(uint16_t sequenceCount) : TcBase(apid::TC_REPLAY_WRITE_SEQUENCE, sequenceCount) {} TcReplayWriteSeq(uint16_t sequenceCount)
: TcBase(apid::TC_REPLAY_WRITE_SEQUENCE, sequenceCount) {}
protected: protected:
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; result = lengthCheck(commandDataLen);
result = lengthCheck(commandDataLen); if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != HasReturnvaluesIF::RETURN_OK) { return result;
return result;
}
std::memcpy(this->localData.fields.buffer, commandData, commandDataLen);
this->setPacketDataLength(commandDataLen + CRC_SIZE - 1);
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) {
ReturnValue_t lengthCheck(size_t commandDataLen) { sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen
if (commandDataLen > USE_DECODING_LENGTH + MAX_FILENAME_SIZE) { << std::endl;
sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen << std::endl; return INVALID_LENGTH;
return INVALID_LENGTH;
}
return HasReturnvaluesIF::RETURN_OK;
} }
return HasReturnvaluesIF::RETURN_OK;
}
}; };
class FlashWritePusCmd : public MPSoCReturnValuesIF { class FlashWritePusCmd : public MPSoCReturnValuesIF {
@ -587,30 +573,25 @@ class FlashWritePusCmd : public MPSoCReturnValuesIF {
ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) { ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) {
if (commandDataLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE + MAX_FILENAME_SIZE)) { if (commandDataLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE + MAX_FILENAME_SIZE)) {
return INVALID_LENGTH; return INVALID_LENGTH;
} }
obcFile = std::string(reinterpret_cast<const char*>(commandData)); obcFile = std::string(reinterpret_cast<const char*>(commandData));
if (obcFile.size() > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE)) { if (obcFile.size() > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE)) {
return FILENAME_TOO_LONG; return FILENAME_TOO_LONG;
} }
mpsocFile = std::string( mpsocFile = std::string(
reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR)); reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR));
if (mpsocFile.size() > MAX_FILENAME_SIZE) { if (mpsocFile.size() > MAX_FILENAME_SIZE) {
return MPSOC_FILENAME_TOO_LONG; return MPSOC_FILENAME_TOO_LONG;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
std::string getObcFile() { std::string getObcFile() { return obcFile; }
return obcFile;
}
std::string getMPSoCFile() { std::string getMPSoCFile() { return mpsocFile; }
return mpsocFile;
}
private: private:
static const size_t SIZE_NULL_TERMINATOR = 1; static const size_t SIZE_NULL_TERMINATOR = 1;
std::string obcFile = ""; std::string obcFile = "";
std::string mpsocFile = ""; std::string mpsocFile = "";
@ -620,25 +601,20 @@ class FlashWritePusCmd : public MPSoCReturnValuesIF {
* @brief Class to build replay stop space packet. * @brief Class to build replay stop space packet.
*/ */
class TcModeReplay : public TcBase { class TcModeReplay : public TcBase {
public: public:
TcModeReplay(uint16_t sequenceCount) : TcBase(apid::TC_MODE_REPLAY, sequenceCount) {}
TcModeReplay(uint16_t sequenceCount) : ReturnValue_t createPacket() {
TcBase(apid::TC_MODE_REPLAY, sequenceCount) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
} result = addCrc();
if (result != HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t createPacket() { return result;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
result = addCrc();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
return HasReturnvaluesIF::RETURN_OK;
} }
this->setPacketDataLength(static_cast<uint16_t>(CRC_SIZE - 1));
return HasReturnvaluesIF::RETURN_OK;
}
}; };
} } // namespace mpsoc
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */ #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */

View File

@ -507,10 +507,10 @@ ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) {
case (mpsoc::apid::EXE_FAILURE): { case (mpsoc::apid::EXE_FAILURE): {
// TODO: Interpretation of status field in execution report // TODO: Interpretation of status field in execution report
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); uint16_t status = getStatus(data);
triggerEvent(EXE_FAILURE, commandId, status); triggerEvent(EXE_FAILURE, commandId, status);
} else { } else {
sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl; 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); result = verifyPacket(data, tmMemReadReport.rememberRequestedSize);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) { if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleMemoryReadReport: Memory read report has invalid crc" sif::warning << "PlocMPSoCHandler::handleMemoryReadReport: Memory read report has invalid crc"
<< std::endl; << std::endl;
} }
uint16_t memLen = uint16_t memLen =
*(data + mpsoc::MEM_READ_RPT_LEN_OFFSET) << 8 | *(data + mpsoc::MEM_READ_RPT_LEN_OFFSET + 1); *(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) { switch (command->first) {
case mpsoc::TC_REPLAY_WRITE_SEQUENCE: { case mpsoc::TC_REPLAY_WRITE_SEQUENCE: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT); DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
if (iter != deviceReplyMap.end()) { // Overwrite delay cycles because replay write sequence command can required up to
// Overwrite delay cycles because replay write sequence command can required up to // 30 seconds for execution
// 30 seconds for execution iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY;
iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY; break;
} else { }
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Unknown reply id" << std::endl; case mpsoc::TC_DOWNLINK_PWR_ON: {
} DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
//
iter->second.delayCycles = mpsoc::TC_DOWNLINK_PWR_ON;
break; break;
} }
default: default:
@ -719,6 +721,7 @@ void PlocMPSoCHandler::disableAllReplies() {
/* We must always disable the execution report reply here */ /* We must always disable the execution report reply here */
disableExeReportReply(); disableExeReportReply();
nextReplyId = mpsoc::NONE;
} }
void PlocMPSoCHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) { void PlocMPSoCHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) {
@ -743,7 +746,7 @@ void PlocMPSoCHandler::disableExeReportReply() {
DeviceReplyInfo* info = &(iter->second); DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0; info->delayCycles = 0;
info->command = deviceCommandMap.end(); 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; info->command->second.expectedReplies = 0;
} }
@ -753,5 +756,5 @@ void PlocMPSoCHandler::printStatus(const uint8_t* data) {
} }
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);
} }

View File

@ -67,8 +67,9 @@ 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) {
ReturnValue_t result = RETURN_OK;
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t result = FilesystemHelper::checkPath(obcFile); result = FilesystemHelper::checkPath(obcFile);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -80,7 +81,7 @@ ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string
#ifdef TE0720_1CFA #ifdef TE0720_1CFA
if (not std::filesystem::exists(obcFile)) { if (not std::filesystem::exists(obcFile)) {
sif::warning << "PlocMPSoCHelper::startFlashWrite: File " << obcFile << "does not exist" sif::warning << "PlocMPSoCHelper::startFlashWrite: File " << obcFile << "does not exist"
<< std::endl; << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} }
#endif #endif
@ -88,9 +89,19 @@ ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string
flashWrite.obcFile = obcFile; flashWrite.obcFile = obcFile;
flashWrite.mpsocFile = mpsocFile; flashWrite.mpsocFile = mpsocFile;
internalState = InternalState::FLASH_WRITE; 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(); semaphore.release();
terminate = false; terminate = false;
return RETURN_OK; result = uartComIF->flushUartRxBuffer(comCookie);
return result;
} }
void PlocMPSoCHelper::stopProcess() { terminate = true; } void PlocMPSoCHelper::stopProcess() { terminate = true; }
@ -99,7 +110,7 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = flashfopen(); result = flashfopen();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
uint8_t tempData[mpsoc::MAX_DATA_SIZE]; uint8_t tempData[mpsoc::MAX_DATA_SIZE];
std::ifstream file(flashWrite.obcFile, std::ifstream::binary); std::ifstream file(flashWrite.obcFile, std::ifstream::binary);
@ -108,6 +119,7 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
// tellg returns position of character in input stream // tellg returns position of character in input stream
size_t remainingSize = file.tellg(); size_t remainingSize = file.tellg();
size_t dataLength = 0; size_t dataLength = 0;
size_t bytesRead = 0;
while (remainingSize > 0) { while (remainingSize > 0) {
if (terminate) { if (terminate) {
return RETURN_OK; return RETURN_OK;
@ -117,26 +129,25 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
} else { } else {
dataLength = remainingSize; dataLength = remainingSize;
} }
file.read(reinterpret_cast<char*>(tempData), dataLength); if (file.is_open()) {
file.seekg(bytesRead, file.beg);
file.read(reinterpret_cast<char*>(tempData), dataLength);
bytesRead += dataLength;
remainingSize -= dataLength;
} else {
return FILE_CLOSED_ACCIDENTALLY;
}
(*sequenceCount)++; (*sequenceCount)++;
mpsoc::TcFlashWrite tc(*sequenceCount); mpsoc::TcFlashWrite tc(*sequenceCount);
tc.createPacket(tempData, dataLength); tc.createPacket(tempData, dataLength);
result = sendCommand(&tc); result = handlePacketTransmission(tc);
if (result != RETURN_OK) {
return result;
}
result = handleAck();
if (result != RETURN_OK) {
return result;
}
result = handleExe();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
} }
result = flashfclose(); result = flashfclose();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
return result; return result;
} }
@ -149,7 +160,7 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() {
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
result = sendCommand(&flashFopen); result = handlePacketTransmission(flashFopen);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -157,23 +168,40 @@ ReturnValue_t PlocMPSoCHelper::flashfopen() {
} }
ReturnValue_t PlocMPSoCHelper::flashfclose() { ReturnValue_t PlocMPSoCHelper::flashfclose() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
(*sequenceCount)++; (*sequenceCount)++;
mpsoc::FlashFclose flashFclose(*sequenceCount); mpsoc::FlashFclose flashFclose(*sequenceCount);
result = flashFclose.createPacket(flashWrite.mpsocFile); result = flashFclose.createPacket(flashWrite.mpsocFile);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
result = sendCommand(&flashFclose); result = handlePacketTransmission(flashFclose);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t PlocMPSoCHelper::sendCommand(mpsoc::TcBase* tc) { ReturnValue_t PlocMPSoCHelper::handlePacketTransmission(mpsoc::TcBase& tc) {
ReturnValue_t result = RETURN_OK; 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) { if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl; sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl;
triggerEvent(SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState)); triggerEvent(SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState));
@ -231,7 +259,7 @@ void PlocMPSoCHelper::handleExeApidFailure(uint16_t apid) {
<< "report" << std::endl; << "report" << std::endl;
} else { } else {
triggerEvent(EXE_INVALID_APID, apid, static_cast<uint32_t>(internalState)); triggerEvent(EXE_INVALID_APID, apid, static_cast<uint32_t>(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; << "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 PlocMPSoCHelper::handleTmReception(mpsoc::TmPacket* tmPacket, size_t remainingBytes) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
size_t readBytes = 0; size_t readBytes = 0;
size_t currentBytes = 0;
for (int retries = 0; retries < RETRIES; retries++) { for (int retries = 0; retries < RETRIES; retries++) {
result = receive(tmPacket->getWholeData(), &readBytes, remainingBytes); result = receive(tmPacket->getWholeData() + readBytes, &currentBytes, remainingBytes);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
remainingBytes = remainingBytes - readBytes; readBytes += currentBytes;
remainingBytes = remainingBytes - currentBytes;
if (remainingBytes == 0) { if (remainingBytes == 0) {
break; break;
} }
@ -259,17 +289,18 @@ ReturnValue_t PlocMPSoCHelper::handleTmReception(mpsoc::TmPacket* tmPacket, size
sif::warning << "PlocMPSoCHelper::handleTmReception: CRC check failed" << std::endl; sif::warning << "PlocMPSoCHelper::handleTmReception: CRC check failed" << std::endl;
return result; return result;
} }
(*sequenceCount)++;
uint16_t recvSeqCnt = tmPacket->getPacketSequenceCount(); uint16_t recvSeqCnt = tmPacket->getPacketSequenceCount();
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;
return result;
} }
return result; return result;
} }
ReturnValue_t PlocMPSoCHelper::receive(uint8_t* data, size_t* readBytes, size_t requestBytes) { ReturnValue_t PlocMPSoCHelper::receive(uint8_t* data, size_t* readBytes, size_t requestBytes) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
uint8_t* buffer = nullptr;
result = uartComIF->requestReceiveMessage(comCookie, requestBytes); result = uartComIF->requestReceiveMessage(comCookie, requestBytes);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::receive: Failed to request reply" << std::endl; 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<uint32_t>(static_cast<uint32_t>(internalState))); static_cast<uint32_t>(static_cast<uint32_t>(internalState)));
return RETURN_FAILED; return RETURN_FAILED;
} }
result = uartComIF->readReceivedMessage(comCookie, &data, readBytes); result = uartComIF->readReceivedMessage(comCookie, &buffer, readBytes);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocMPSoCHelper::receive: Failed to read received message" << std::endl; sif::warning << "PlocMPSoCHelper::receive: Failed to read received message" << std::endl;
triggerEvent(MPSOC_HELPER_READING_REPLY_FAILED, result, static_cast<uint32_t>(internalState)); triggerEvent(MPSOC_HELPER_READING_REPLY_FAILED, result, static_cast<uint32_t>(internalState));
return RETURN_FAILED; return RETURN_FAILED;
} }
if (*readBytes > 0) {
std::memcpy(data, buffer, *readBytes);
}
return result; return result;
} }

View File

@ -2,13 +2,14 @@
#define BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_ #define BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_
#include <string> #include <string>
#include "fsfw/devicehandlers/CookieIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/osal/linux/BinarySemaphore.h" #include "fsfw/osal/linux/BinarySemaphore.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tasks/ExecutableObjectIF.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/tmtcservices/SourceSequenceCounter.h"
#include "fsfw_hal/linux/uart/UartComIF.h"
#include "linux/devices/devicedefinitions/PlocMPSoCDefinitions.h" #include "linux/devices/devicedefinitions/PlocMPSoCDefinitions.h"
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
#include "bsp_q7s/memory/SdCardManager.h" #include "bsp_q7s/memory/SdCardManager.h"
@ -19,134 +20,134 @@
* MPSoC and OBC. * MPSoC and OBC.
* @author J. Meier * @author J. Meier
*/ */
class PlocMPSoCHelper: public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF { class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF {
public: 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 PlocMPSoCHelper(object_id_t objectId);
static const Event MPSOC_FLASH_WRITE_FAILED = MAKE_EVENT(0, severity::LOW); virtual ~PlocMPSoCHelper();
//! [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); ReturnValue_t initialize() override;
virtual ~PlocMPSoCHelper(); ReturnValue_t performOperation(uint8_t operationCode = 0) override;
ReturnValue_t initialize() override; ReturnValue_t setComIF(DeviceCommunicationIF* communicationInterface_);
ReturnValue_t performOperation(uint8_t operationCode = 0) override; 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 * @brief Can be used to interrupt a running data transfer.
* */
* @param obcFile File where to read from the data void stopProcess();
* @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. * @brief Sets the sequence count object responsible for the sequence count handling
*/ */
void stopProcess(); void setSequenceCount(SourceSequenceCounter* sequenceCount_);
/** private:
* @brief Sets the sequence count object responsible for the sequence count handling static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HELPER;
*/
void setSequenceCount(SourceSequenceCounter* sequenceCount_);
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 struct FlashWrite {
// buffer std::string obcFile;
static const int RETRIES = 3; std::string mpsocFile;
};
struct FlashWrite { struct FlashWrite flashWrite;
std::string obcFile;
std::string mpsocFile;
};
struct FlashWrite flashWrite; enum class InternalState { IDLE, FLASH_WRITE, FLASH_READ };
enum class InternalState { InternalState internalState = InternalState::IDLE;
IDLE,
FLASH_WRITE,
FLASH_READ
};
InternalState internalState = InternalState::IDLE; BinarySemaphore semaphore;
BinarySemaphore semaphore;
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
SdCardManager* sdcMan = nullptr; SdCardManager* sdcMan = nullptr;
#endif #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 * Communication interface of MPSoC responsible for low level access. Must be set by the
* MPSoC Handler. * MPSoC Handler.
*/ */
UartComIF* uartComIF = nullptr; UartComIF* uartComIF = nullptr;
// Communication cookie. Must be set by the MPSoC Handler // Communication cookie. Must be set by the MPSoC Handler
CookieIF* comCookie = nullptr; CookieIF* comCookie = nullptr;
// Sequence count, must be set by Ploc MPSoC Handler // Sequence count, must be set by Ploc MPSoC Handler
SourceSequenceCounter* sequenceCount; SourceSequenceCounter* sequenceCount;
ReturnValue_t performFlashWrite(); ReturnValue_t resetHelper();
ReturnValue_t flashfopen(); ReturnValue_t performFlashWrite();
ReturnValue_t flashfclose(); ReturnValue_t flashfopen();
ReturnValue_t sendCommand(mpsoc::TcBase* tc); ReturnValue_t flashfclose();
ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes); ReturnValue_t handlePacketTransmission(mpsoc::TcBase& tc);
ReturnValue_t handleAck(); ReturnValue_t sendCommand(mpsoc::TcBase& tc);
ReturnValue_t handleExe(); ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes);
void handleAckApidFailure(uint16_t apid); ReturnValue_t handleAck();
void handleExeApidFailure(uint16_t apid); ReturnValue_t handleExe();
ReturnValue_t handleTmReception(mpsoc::TmPacket* tmPacket, size_t remainingBytes); 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_ */ #endif /* BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_ */

View File

@ -102,6 +102,7 @@ debugging. */
#define OBSW_STAR_TRACKER_GROUND_CONFIG 1 #define OBSW_STAR_TRACKER_GROUND_CONFIG 1
#define OBSW_ENABLE_PERIODIC_HK 0 #define OBSW_ENABLE_PERIODIC_HK 0
#define OBSW_PRINT_CORE_HK 0 #define OBSW_PRINT_CORE_HK 0
#define OBSW_INITIALIZE_SWITCHES 0
#endif #endif
@ -154,10 +155,16 @@ debugging. */
#define OBSW_DEBUG_SYRLINKS 0 #define OBSW_DEBUG_SYRLINKS 0
#define OBSW_DEBUG_IMTQ 0 #define OBSW_DEBUG_IMTQ 0
#define OBSW_DEBUG_RW 0 #define OBSW_DEBUG_RW 0
#define OBSW_DEBUG_PLOC_MPSOC 0
#define OBSW_DEBUG_PLOC_SUPERVISOR 0
#define OBSW_DEBUG_PDEC_HANDLER 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 #ifdef EGSE
#define OBSW_DEBUG_STARTRACKER 1 #define OBSW_DEBUG_STARTRACKER 1
#else #else