2021-07-13 08:32:14 +02:00
|
|
|
#include "PlocMPSoCHandler.h"
|
2021-05-17 16:37:29 +02:00
|
|
|
#include "OBSWConfig.h"
|
2021-03-29 14:37:52 +02:00
|
|
|
|
|
|
|
#include <fsfw/globalfunctions/CRC.h>
|
|
|
|
#include <fsfw/datapool/PoolReadGuard.h>
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
PlocMPSoCHandler::PlocMPSoCHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) :
|
2021-04-11 12:04:13 +02:00
|
|
|
DeviceHandlerBase(objectId, comIF, comCookie) {
|
2021-03-29 14:37:52 +02:00
|
|
|
if (comCookie == NULL) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::error << "PlocMPSoCHandler: Invalid com cookie" << std::endl;
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
PlocMPSoCHandler::~PlocMPSoCHandler() {
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::doStartUp(){
|
2021-03-29 14:37:52 +02:00
|
|
|
if(mode == _MODE_START_UP){
|
|
|
|
setMode(MODE_ON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::doShutDown(){
|
2021-03-29 14:37:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::buildNormalDeviceCommand(
|
2021-03-29 14:37:52 +02:00
|
|
|
DeviceCommandId_t * id) {
|
2021-04-11 12:04:13 +02:00
|
|
|
return RETURN_OK;
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::buildTransitionDeviceCommand(
|
2021-03-29 14:37:52 +02:00
|
|
|
DeviceCommandId_t * id){
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(
|
2021-03-29 14:37:52 +02:00
|
|
|
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
|
|
|
|
size_t commandDataLen) {
|
|
|
|
switch(deviceCommand) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case(PLOC_MPSOC::TC_MEM_WRITE): {
|
2021-04-15 13:17:15 +02:00
|
|
|
return prepareTcMemWriteCommand(commandData, commandDataLen);
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
case(PLOC_MPSOC::TC_MEM_READ): {
|
2021-04-15 13:17:15 +02:00
|
|
|
return prepareTcMemReadCommand(commandData, commandDataLen);
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
default:
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::buildCommandFromCommand: Command not implemented" << std::endl;
|
2021-03-29 14:37:52 +02:00
|
|
|
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::fillCommandAndReplyMap() {
|
|
|
|
this->insertInCommandMap(PLOC_MPSOC::TC_MEM_WRITE);
|
|
|
|
this->insertInCommandMap(PLOC_MPSOC::TC_MEM_READ);
|
|
|
|
this->insertInReplyMap(PLOC_MPSOC::ACK_REPORT, 1, nullptr, PLOC_MPSOC::SIZE_ACK_REPORT);
|
|
|
|
this->insertInReplyMap(PLOC_MPSOC::EXE_REPORT, 3, nullptr, PLOC_MPSOC::SIZE_EXE_REPORT);
|
|
|
|
this->insertInReplyMap(PLOC_MPSOC::TM_MEMORY_READ_REPORT, 2, nullptr, PLOC_MPSOC::SIZE_TM_MEM_READ_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::scanForReply(const uint8_t *start,
|
2021-04-22 17:32:39 +02:00
|
|
|
size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
|
|
|
|
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK;
|
|
|
|
|
|
|
|
switch(apid) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case(PLOC_MPSOC::APID_ACK_SUCCESS):
|
|
|
|
*foundLen = PLOC_MPSOC::SIZE_ACK_REPORT;
|
|
|
|
*foundId = PLOC_MPSOC::ACK_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
case(PLOC_MPSOC::APID_ACK_FAILURE):
|
|
|
|
*foundLen = PLOC_MPSOC::SIZE_ACK_REPORT;
|
|
|
|
*foundId = PLOC_MPSOC::ACK_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
case(PLOC_MPSOC::APID_TM_MEMORY_READ_REPORT):
|
|
|
|
*foundLen = PLOC_MPSOC::SIZE_TM_MEM_READ_REPORT;
|
|
|
|
*foundId = PLOC_MPSOC::TM_MEMORY_READ_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
case(PLOC_MPSOC::APID_EXE_SUCCESS):
|
|
|
|
*foundLen = PLOC_MPSOC::SIZE_EXE_REPORT;
|
|
|
|
*foundId = PLOC_MPSOC::EXE_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
case(PLOC_MPSOC::APID_EXE_FAILURE):
|
|
|
|
*foundLen = PLOC_MPSOC::SIZE_EXE_REPORT;
|
|
|
|
*foundId = PLOC_MPSOC::EXE_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
|
|
|
default: {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::scanForReply: Reply has invalid apid" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
*foundLen = remainingSize;
|
2021-04-27 12:18:04 +02:00
|
|
|
return INVALID_APID;
|
2021-04-22 17:32:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 12:18:04 +02:00
|
|
|
/**
|
|
|
|
* This should normally never fail. However, this function is also responsible for incrementing
|
|
|
|
* the packet sequence count why it is called here.
|
|
|
|
*/
|
|
|
|
result = checkPacketSequenceCount(start);
|
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::interpretDeviceReply(DeviceCommandId_t id,
|
2021-04-22 17:32:39 +02:00
|
|
|
const uint8_t *packet) {
|
|
|
|
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
switch (id) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::ACK_REPORT: {
|
2021-04-22 17:32:39 +02:00
|
|
|
result = handleAckReport(packet);
|
|
|
|
break;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
case (PLOC_MPSOC::TM_MEMORY_READ_REPORT): {
|
2021-04-22 17:32:39 +02:00
|
|
|
result = handleMemoryReadReport(packet);
|
|
|
|
break;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
case (PLOC_MPSOC::EXE_REPORT): {
|
2021-04-22 17:32:39 +02:00
|
|
|
result = handleExecutionReport(packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::interpretDeviceReply: Unknown device reply id" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::setNormalDatapoolEntriesInvalid(){
|
2021-04-22 17:32:39 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
uint32_t PlocMPSoCHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){
|
2021-04-22 17:32:39 +02:00
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
2021-04-22 17:32:39 +02:00
|
|
|
LocalDataPoolManager& poolManager) {
|
|
|
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::setModeNormal() {
|
2021-04-22 17:32:39 +02:00
|
|
|
mode = MODE_NORMAL;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::prepareTcMemWriteCommand(const uint8_t * commandData,
|
2021-04-15 13:17:15 +02:00
|
|
|
size_t commandDataLen) {
|
|
|
|
const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16
|
|
|
|
| *(commandData + 2) << 8 | *(commandData + 3);
|
|
|
|
const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16
|
|
|
|
| *(commandData + 6) << 8 | *(commandData + 7);
|
2021-04-27 17:34:50 +02:00
|
|
|
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
|
2021-07-13 08:32:14 +02:00
|
|
|
PLOC_MPSOC::TcMemWrite tcMemWrite(memoryAddress, memoryData, packetSequenceCount);
|
|
|
|
if (tcMemWrite.getFullSize() > PLOC_MPSOC::MAX_COMMAND_SIZE) {
|
|
|
|
sif::debug << "PlocMPSoCHandler::prepareTcMemWriteCommand: Command too big" << std::endl;
|
2021-04-15 13:17:15 +02:00
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
memcpy(commandBuffer, tcMemWrite.getWholeData(), tcMemWrite.getFullSize());
|
|
|
|
rawPacket = commandBuffer;
|
|
|
|
rawPacketLen = tcMemWrite.getFullSize();
|
2021-07-13 08:32:14 +02:00
|
|
|
nextReplyId = PLOC_MPSOC::ACK_REPORT;
|
2021-04-15 13:17:15 +02:00
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::prepareTcMemReadCommand(const uint8_t * commandData,
|
2021-04-15 13:17:15 +02:00
|
|
|
size_t commandDataLen) {
|
|
|
|
const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16
|
|
|
|
| *(commandData + 2) << 8 | *(commandData + 3);
|
2021-04-27 17:34:50 +02:00
|
|
|
packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK;
|
2021-07-13 08:32:14 +02:00
|
|
|
PLOC_MPSOC::TcMemRead tcMemRead(memoryAddress, packetSequenceCount);
|
|
|
|
if (tcMemRead.getFullSize() > PLOC_MPSOC::MAX_COMMAND_SIZE) {
|
|
|
|
sif::debug << "PlocMPSoCHandler::prepareTcMemReadCommand: Command too big" << std::endl;
|
2021-04-15 13:17:15 +02:00
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
memcpy(commandBuffer, tcMemRead.getWholeData(), tcMemRead.getFullSize());
|
|
|
|
rawPacket = commandBuffer;
|
|
|
|
rawPacketLen = tcMemRead.getFullSize();
|
2021-07-13 08:32:14 +02:00
|
|
|
nextReplyId = PLOC_MPSOC::ACK_REPORT;
|
2021-04-26 11:28:19 +02:00
|
|
|
|
2021-04-15 13:17:15 +02:00
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
|
2021-04-15 13:17:15 +02:00
|
|
|
|
|
|
|
uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1);
|
2021-04-11 12:04:13 +02:00
|
|
|
|
2021-04-26 11:28:19 +02:00
|
|
|
uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2);
|
2021-04-11 12:04:13 +02:00
|
|
|
|
2021-04-15 13:17:15 +02:00
|
|
|
if (receivedCrc != recalculatedCrc) {
|
2021-04-11 12:04:13 +02:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::handleAckReport(const uint8_t* data) {
|
2021-04-15 13:17:15 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-04-15 13:17:15 +02:00
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
result = verifyPacket(data, PLOC_MPSOC::SIZE_ACK_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
if(result == CRC_FAILURE) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::error << "PlocMPSoCHandler::handleAckReport: CRC failure" << std::endl;
|
|
|
|
nextReplyId = PLOC_MPSOC::NONE;
|
|
|
|
replyRawReplyIfnotWiretapped(data, PLOC_MPSOC::SIZE_ACK_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
triggerEvent(CRC_FAILURE_EVENT);
|
2021-07-13 08:32:14 +02:00
|
|
|
sendFailureReport(PLOC_MPSOC::ACK_REPORT, CRC_FAILURE);
|
2021-04-22 17:32:39 +02:00
|
|
|
disableAllReplies();
|
|
|
|
return IGNORE_REPLY_DATA;
|
2021-04-15 13:17:15 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
|
|
|
|
|
|
|
|
switch(apid) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::APID_ACK_FAILURE: {
|
2021-04-22 17:32:39 +02:00
|
|
|
//TODO: Interpretation of status field in acknowledgment report
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::handleAckReport: Received Ack failure report" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
|
|
|
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
|
|
|
|
triggerEvent(ACK_FAILURE, commandId);
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
sendFailureReport(PLOC_MPSOC::ACK_REPORT, RECEIVED_ACK_FAILURE);
|
2021-04-22 17:32:39 +02:00
|
|
|
disableAllReplies();
|
2021-07-13 08:32:14 +02:00
|
|
|
nextReplyId = PLOC_MPSOC::NONE;
|
2021-04-22 17:32:39 +02:00
|
|
|
result = IGNORE_REPLY_DATA;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::APID_ACK_SUCCESS: {
|
2021-04-22 17:32:39 +02:00
|
|
|
setNextReplyId();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::handleAckReport: Invalid APID in Ack report" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
return result;
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) {
|
2021-04-11 12:04:13 +02:00
|
|
|
|
2021-04-15 13:17:15 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
result = verifyPacket(data, PLOC_MPSOC::SIZE_EXE_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
if(result == CRC_FAILURE) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::error << "PlocMPSoCHandler::handleExecutionReport: CRC failure" << std::endl;
|
|
|
|
nextReplyId = PLOC_MPSOC::NONE;
|
2021-04-15 13:17:15 +02:00
|
|
|
return result;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
|
2021-04-11 12:04:13 +02:00
|
|
|
|
|
|
|
switch (apid) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case (PLOC_MPSOC::APID_EXE_SUCCESS): {
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
case (PLOC_MPSOC::APID_EXE_FAILURE): {
|
2021-04-11 12:04:13 +02:00
|
|
|
//TODO: Interpretation of status field in execution report
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::error << "PlocMPSoCHandler::handleExecutionReport: Received execution failure report"
|
2021-04-11 12:04:13 +02:00
|
|
|
<< std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
|
|
|
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
|
|
|
|
triggerEvent(EXE_FAILURE, commandId);
|
|
|
|
}
|
|
|
|
else {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
sendFailureReport(PLOC_MPSOC::EXE_REPORT, RECEIVED_EXE_FAILURE);
|
2021-04-22 17:32:39 +02:00
|
|
|
disableExeReportReply();
|
|
|
|
result = IGNORE_REPLY_DATA;
|
|
|
|
break;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
2021-04-22 17:32:39 +02:00
|
|
|
default: {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::error << "PlocMPSoCHandler::handleExecutionReport: Unknown APID" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
2021-04-22 17:32:39 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
nextReplyId = PLOC_MPSOC::NONE;
|
2021-04-22 17:32:39 +02:00
|
|
|
|
|
|
|
return result;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::handleMemoryReadReport(const uint8_t* data) {
|
2021-04-11 12:04:13 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-04-11 12:04:13 +02:00
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
result = verifyPacket(data, PLOC_MPSOC::SIZE_TM_MEM_READ_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
|
|
|
|
if(result == CRC_FAILURE) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::error << "PlocMPSoCHandler::handleMemoryReadReport: Memory read report has invalid crc"
|
2021-04-11 12:04:13 +02:00
|
|
|
<< std::endl;
|
|
|
|
}
|
2021-04-22 17:32:39 +02:00
|
|
|
/** Send data to commanding queue */
|
2021-07-13 08:32:14 +02:00
|
|
|
handleDeviceTM(data + PLOC_MPSOC::DATA_FIELD_OFFSET, PLOC_MPSOC::SIZE_MEM_READ_REPORT_DATA,
|
|
|
|
PLOC_MPSOC::TM_MEMORY_READ_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
nextReplyId = PLOC_MPSOC::EXE_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
|
2021-04-22 17:32:39 +02:00
|
|
|
uint8_t expectedReplies, bool useAlternateId,
|
|
|
|
DeviceCommandId_t alternateReplyID) {
|
|
|
|
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
uint8_t enabledReplies = 0;
|
|
|
|
|
|
|
|
switch (command->first) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::TC_MEM_WRITE:
|
2021-04-22 17:32:39 +02:00
|
|
|
enabledReplies = 2;
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::TC_MEM_READ: {
|
2021-04-22 17:32:39 +02:00
|
|
|
enabledReplies = 3;
|
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
|
2021-07-13 08:32:14 +02:00
|
|
|
PLOC_MPSOC::TM_MEMORY_READ_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
if (result != RETURN_OK) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_MPSOC::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Every command causes at least one acknowledgment and one execution report. Therefore both
|
|
|
|
* replies will be enabled here.
|
|
|
|
*/
|
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command,
|
2021-07-13 08:32:14 +02:00
|
|
|
enabledReplies, true, PLOC_MPSOC::ACK_REPORT);
|
2021-04-11 12:04:13 +02:00
|
|
|
if (result != RETURN_OK) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << PLOC_MPSOC::ACK_REPORT
|
2021-04-22 17:32:39 +02:00
|
|
|
<< " not in replyMap" << std::endl;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command,
|
2021-07-13 08:32:14 +02:00
|
|
|
enabledReplies, true, PLOC_MPSOC::EXE_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
if (result != RETURN_OK) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << PLOC_MPSOC::EXE_REPORT
|
2021-04-22 17:32:39 +02:00
|
|
|
<< " not in replyMap" << std::endl;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::setNextReplyId() {
|
2021-04-22 17:32:39 +02:00
|
|
|
switch(getPendingCommand()) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::TC_MEM_READ:
|
|
|
|
nextReplyId = PLOC_MPSOC::TM_MEMORY_READ_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* If no telemetry is expected the next reply is always the execution report */
|
2021-07-13 08:32:14 +02:00
|
|
|
nextReplyId = PLOC_MPSOC::EXE_REPORT;
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
size_t PlocMPSoCHandler::getNextReplyLength(DeviceCommandId_t commandId){
|
2021-04-22 17:32:39 +02:00
|
|
|
|
|
|
|
size_t replyLen = 0;
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
if (nextReplyId == PLOC_MPSOC::NONE) {
|
2021-04-22 17:32:39 +02:00
|
|
|
return replyLen;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
DeviceReplyIter iter = deviceReplyMap.find(nextReplyId);
|
|
|
|
if (iter != deviceReplyMap.end()) {
|
|
|
|
if (iter->second.delayCycles == 0) {
|
|
|
|
/* Reply inactive */
|
|
|
|
return replyLen;
|
|
|
|
}
|
|
|
|
replyLen = iter->second.replyLen;
|
|
|
|
}
|
|
|
|
else {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::getNextReplyLength: No entry for reply with reply id "
|
2021-04-22 17:32:39 +02:00
|
|
|
<< std::hex << nextReplyId << " in deviceReplyMap" << std::endl;
|
|
|
|
}
|
2021-04-11 12:04:13 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
return replyLen;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId) {
|
2021-04-11 12:04:13 +02:00
|
|
|
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
2021-04-25 15:54:48 +02:00
|
|
|
if (wiretappingMode == RAW) {
|
|
|
|
/* Data already sent in doGetRead() */
|
2021-04-26 17:50:36 +02:00
|
|
|
return;
|
2021-04-25 15:54:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-11 12:04:13 +02:00
|
|
|
DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId);
|
|
|
|
if (iter == deviceReplyMap.end()) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::handleDeviceTM: Unknown reply id" << std::endl;
|
2021-04-11 12:04:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
|
|
|
|
|
|
|
|
if (queueId == NO_COMMANDER) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-12 10:16:59 +02:00
|
|
|
result = actionHelper.reportData(queueId, replyId, data, dataSize);
|
2021-04-11 12:04:13 +02:00
|
|
|
if (result != RETURN_OK) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::handleDeviceTM: Failed to report data" << std::endl;
|
2021-04-11 12:04:13 +02:00
|
|
|
}
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::disableAllReplies() {
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
DeviceReplyMap::iterator iter;
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
/* Disable ack reply */
|
2021-07-13 08:32:14 +02:00
|
|
|
iter = deviceReplyMap.find(PLOC_MPSOC::ACK_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
DeviceReplyInfo *info = &(iter->second);
|
|
|
|
info->delayCycles = 0;
|
|
|
|
info->command = deviceCommandMap.end();
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
2021-03-29 14:37:52 +02:00
|
|
|
|
2021-04-22 17:32:39 +02:00
|
|
|
/* If the command expects a telemetry packet the appropriate tm reply will be disabled here */
|
|
|
|
switch (commandId) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::TC_MEM_WRITE:
|
2021-04-22 17:32:39 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_MPSOC::TC_MEM_READ: {
|
|
|
|
iter = deviceReplyMap.find(PLOC_MPSOC::TM_MEMORY_READ_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
info = &(iter->second);
|
|
|
|
info->delayCycles = 0;
|
|
|
|
info->command = deviceCommandMap.end();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::disableAllReplies: Unknown command id" << commandId
|
2021-04-22 17:32:39 +02:00
|
|
|
<< std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We must always disable the execution report reply here */
|
|
|
|
disableExeReportReply();
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) {
|
2021-04-22 17:32:39 +02:00
|
|
|
|
|
|
|
DeviceReplyIter iter = deviceReplyMap.find(replyId);
|
|
|
|
|
|
|
|
if (iter == deviceReplyMap.end()) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::sendFailureReport: Reply not in reply map" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceCommandInfo* info = &(iter->second.command->second);
|
|
|
|
|
|
|
|
if (info == nullptr) {
|
2021-07-13 08:32:14 +02:00
|
|
|
sif::debug << "PlocMPSoCHandler::sendFailureReport: Reply has no active command" << std::endl;
|
2021-04-22 17:32:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->sendReplyTo != NO_COMMANDER) {
|
|
|
|
actionHelper.finish(false, info->sendReplyTo, iter->first, status);
|
|
|
|
}
|
|
|
|
info->isExecuting = false;
|
2021-03-29 14:37:52 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocMPSoCHandler::disableExeReportReply() {
|
|
|
|
DeviceReplyIter iter = deviceReplyMap.find(PLOC_MPSOC::EXE_REPORT);
|
2021-04-22 17:32:39 +02:00
|
|
|
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() */
|
|
|
|
info->command->second.expectedReplies = 0;
|
|
|
|
}
|
2021-04-27 12:18:04 +02:00
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocMPSoCHandler::checkPacketSequenceCount(const uint8_t* data) {
|
2021-04-27 17:34:50 +02:00
|
|
|
uint16_t receivedSequenceCount = (*(data + 2) << 8 | *(data + 3)) & PACKET_SEQUENCE_COUNT_MASK;
|
|
|
|
uint16_t expectedPacketSequenceCount = ((packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK);
|
|
|
|
if (receivedSequenceCount != expectedPacketSequenceCount) {
|
|
|
|
sif::debug
|
2021-07-13 08:32:14 +02:00
|
|
|
<< "PlocMPSoCHandler::checkPacketSequenceCount: Packet sequence count mismatch. "
|
2021-04-27 12:18:04 +02:00
|
|
|
<< std::endl;
|
2021-04-27 17:34:50 +02:00
|
|
|
sif::debug << "Received sequence count: " << receivedSequenceCount << ". OBSW sequence "
|
|
|
|
<< "count: " << expectedPacketSequenceCount << std::endl;
|
2021-04-27 12:18:04 +02:00
|
|
|
}
|
2021-04-27 17:34:50 +02:00
|
|
|
packetSequenceCount = receivedSequenceCount;
|
2021-04-27 12:18:04 +02:00
|
|
|
return RETURN_OK;
|
|
|
|
}
|