eive-obsw/mission/devices/devicedefinitions/PlocMPSoCDefinitions.h

173 lines
7.0 KiB
C
Raw Normal View History

#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
2021-04-11 12:04:13 +02:00
#include <fsfw/tmtcpacket/SpacePacket.h>
#include <fsfw/globalfunctions/CRC.h>
2021-04-15 13:17:15 +02:00
#include <fsfw/serialize/SerializeAdapter.h>
2021-04-11 12:04:13 +02:00
namespace PLOC_MPSOC {
2021-04-11 12:04:13 +02:00
static const DeviceCommandId_t NONE = 0x0;
static const DeviceCommandId_t TC_MEM_WRITE = 0x1;
static const DeviceCommandId_t TC_MEM_READ = 0x2;
static const DeviceCommandId_t ACK_REPORT = 0x3;
static const DeviceCommandId_t EXE_REPORT = 0x5;
static const DeviceCommandId_t TM_MEMORY_READ_REPORT = 0x6;
2021-04-11 12:04:13 +02:00
static const uint16_t SIZE_ACK_REPORT = 14;
static const uint16_t SIZE_EXE_REPORT = 14;
static const uint16_t SIZE_TM_MEM_READ_REPORT = 18;
/**
* SpacePacket apids of PLOC telecommands and telemetry.
*/
static const uint16_t APID_TC_MEM_WRITE = 0x714;
2021-04-12 10:16:59 +02:00
static const uint16_t APID_TC_MEM_READ = 0x715;
static const uint16_t APID_TM_MEMORY_READ_REPORT = 0x404;
2021-04-15 13:17:15 +02:00
static const uint16_t APID_ACK_SUCCESS = 0x400;
static const uint16_t APID_ACK_FAILURE = 0x401;
2021-04-11 12:04:13 +02:00
static const uint16_t APID_EXE_SUCCESS = 0x402;
static const uint16_t APID_EXE_FAILURE = 0x403;
/** Offset from first byte in Space packet to first byte of data field */
static const uint8_t DATA_FIELD_OFFSET = 6;
/**
* The size of payload data which will be forwarded to the requesting object. e.g. PUS Service
* 8.
*/
static const uint8_t SIZE_MEM_READ_REPORT_DATA = 10;
2021-04-11 12:04:13 +02:00
/**
* PLOC space packet length for fixed size packets. This is the size of the whole packet data
* field. For the length field in the space packet this size will be substracted by one.
*/
static const uint16_t LENGTH_TC_MEM_WRITE = 12;
static const uint16_t LENGTH_TC_MEM_READ = 8;
static const size_t MAX_REPLY_SIZE = SIZE_TM_MEM_READ_REPORT;
2021-04-15 13:17:15 +02:00
static const size_t MAX_COMMAND_SIZE = 18;
2021-04-11 12:04:13 +02:00
/**
* @brief This class helps to build the memory read command for the PLOC.
*
* @details The last two bytes of the packet data field contain a CRC calculated over the whole
* space packet. This is the CRC-16-CCITT as specified in
2021-05-17 19:39:35 +02:00
* ECSS-E-ST-70-41C Telemetry and telecommand packet utilization.
2021-04-11 12:04:13 +02:00
*/
class TcMemRead : public SpacePacket {
public:
2021-04-15 13:17:15 +02:00
2021-04-11 12:04:13 +02:00
/**
* @brief Constructor
*
* @param memAddr The memory address to read from.
*/
2021-04-26 11:28:19 +02:00
TcMemRead(const uint32_t memAddr, uint16_t sequenceCount) :
SpacePacket(LENGTH_TC_MEM_READ - 1, true, APID_TC_MEM_READ, sequenceCount) {
fillPacketDataField(&memAddr);
}
2021-04-11 12:04:13 +02:00
private:
/**
* @brief This function builds the packet data field for the mem read command.
*
* @param memAddrPtr Pointer to the memory address to read from.
*/
void fillPacketDataField(const uint32_t* memAddrPtr) {
/* Add memAddr to packet data field */
2021-04-15 13:17:15 +02:00
size_t serializedSize = 0;
uint8_t* memoryAddressPos = this->localData.fields.buffer;
SerializeAdapter::serialize<uint32_t>(memAddrPtr, &memoryAddressPos, &serializedSize,
2021-04-26 11:28:19 +02:00
sizeof(*memAddrPtr), SerializeIF::Endianness::LITTLE);
2021-04-15 13:17:15 +02:00
2021-04-11 12:04:13 +02:00
/* Add memLen to packet data field */
2021-04-26 11:28:19 +02:00
this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 1;
this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 0;
2021-04-15 13:17:15 +02:00
/* Calculate crc */
2021-04-11 12:04:13 +02:00
uint16_t crc = CRC::crc16ccitt(this->localData.byteStream,
2021-04-26 11:28:19 +02:00
sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_READ - CRC_SIZE);
2021-04-15 13:17:15 +02:00
2021-04-11 12:04:13 +02:00
/* Add crc to packet data field of space packet */
2021-04-15 13:17:15 +02:00
serializedSize = 0;
uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET;
SerializeAdapter::serialize<uint16_t>(&crc, &crcPos, &serializedSize,
sizeof(crc), SerializeIF::Endianness::BIG);
2021-04-11 12:04:13 +02:00
}
2021-04-15 13:17:15 +02:00
static const uint8_t OFFSET_MEM_LEN_FIELD = 4;
static const uint8_t CRC_OFFSET = 6;
2021-04-11 12:04:13 +02:00
};
/**
* @brief This class helps to generate the space packet to write to a memory address within
* the PLOC.
* @details The last two bytes of the packet data field contain a CRC calculated over the whole
* space packet. This is the CRC-16-CCITT as specified in
2021-05-17 19:39:35 +02:00
* ECSS-E-ST-70-41C Telemetry and telecommand packet utilization.
2021-04-11 12:04:13 +02:00
*/
class TcMemWrite : public SpacePacket {
public:
/**
* @brief Constructor
*
* @param memAddr The PLOC memory address where to write to.
* @param memoryData The data to write to the specified memory address.
2021-04-26 11:28:19 +02:00
* @param sequenceCount The subsequence count. Must be incremented with each new packet.
2021-04-11 12:04:13 +02:00
*/
2021-04-26 11:28:19 +02:00
TcMemWrite(const uint32_t memAddr, const uint32_t memoryData, uint16_t sequenceCount) :
SpacePacket(LENGTH_TC_MEM_WRITE - 1, true, APID_TC_MEM_WRITE, sequenceCount) {
2021-04-11 12:04:13 +02:00
fillPacketDataField(&memAddr, &memoryData);
}
private:
/**
* @brief This function builds the packet data field for the mem write command.
*
* @param memAddrPtr Pointer to the PLOC memory address where to write to.
* @param memoryDataPtr Pointer to the memoryData to write
*/
void fillPacketDataField(const uint32_t* memAddrPtr, const uint32_t* memoryDataPtr) {
2021-04-15 13:17:15 +02:00
2021-04-11 12:04:13 +02:00
/* Add memAddr to packet data field */
2021-04-15 13:17:15 +02:00
size_t serializedSize = 0;
uint8_t* memoryAddressPos = this->localData.fields.buffer;
SerializeAdapter::serialize<uint32_t>(memAddrPtr, &memoryAddressPos, &serializedSize,
sizeof(*memAddrPtr), SerializeIF::Endianness::BIG);
2021-04-11 12:04:13 +02:00
/* Add memLen to packet data field */
2021-04-26 11:28:19 +02:00
this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 1;
this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 0;
2021-04-15 13:17:15 +02:00
2021-04-11 12:04:13 +02:00
/* Add memData to packet data field */
2021-04-15 13:17:15 +02:00
serializedSize = 0;
uint8_t* memoryDataPos = this->localData.fields.buffer + OFFSET_MEM_DATA_FIELD;
SerializeAdapter::serialize<uint32_t>(memoryDataPtr, &memoryDataPos, &serializedSize,
sizeof(*memoryDataPtr), SerializeIF::Endianness::BIG);
/* Calculate crc */
2021-04-11 12:04:13 +02:00
uint16_t crc = CRC::crc16ccitt(this->localData.byteStream,
2021-04-26 11:28:19 +02:00
sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_WRITE - CRC_SIZE);
2021-04-15 13:17:15 +02:00
serializedSize = 0;
uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET;
2021-04-11 12:04:13 +02:00
/* Add crc to packet data field of space packet */
2021-04-15 13:17:15 +02:00
SerializeAdapter::serialize<uint16_t>(&crc, &crcPos, &serializedSize,
sizeof(crc), SerializeIF::Endianness::BIG);
2021-04-11 12:04:13 +02:00
}
2021-04-15 13:17:15 +02:00
/** Offsets from base address of packet data field */
static const uint8_t OFFSET_MEM_LEN_FIELD = 4;
static const uint8_t OFFSET_MEM_DATA_FIELD = 6;
static const uint8_t CRC_OFFSET = 10;
2021-04-11 12:04:13 +02:00
};
}
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */