eive-obsw/linux/payload/PlocMpsocHandler.cpp
Robin Mueller 329027f9f8
Some checks are pending
EIVE/eive-obsw/pipeline/head Build started...
EIVE/eive-obsw/pipeline/pr-main This commit looks good
request HK regularly now
2023-05-03 14:19:15 +02:00

1456 lines
50 KiB
C++

#include <linux/payload/PlocMpsocHandler.h>
#include <linux/payload/plocSupvDefs.h>
#include <sstream>
#include "OBSWConfig.h"
#include "fsfw/datapool/PoolReadGuard.h"
#include "fsfw/globalfunctions/CRC.h"
PlocMPSoCHandler::PlocMPSoCHandler(object_id_t objectId, object_id_t uartComIFid,
CookieIF* comCookie, PlocMPSoCHelper* plocMPSoCHelper,
Gpio uartIsolatorSwitch, object_id_t supervisorHandler)
: DeviceHandlerBase(objectId, uartComIFid, comCookie),
hkReport(this),
plocMPSoCHelper(plocMPSoCHelper),
uartIsolatorSwitch(uartIsolatorSwitch),
supervisorHandler(supervisorHandler),
commandActionHelper(this) {
if (comCookie == nullptr) {
sif::error << "PlocMPSoCHandler: Invalid communication cookie" << std::endl;
}
eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
commandActionHelperQueue =
QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
spParams.maxSize = sizeof(commandBuffer);
spParams.buf = commandBuffer;
}
PlocMPSoCHandler::~PlocMPSoCHandler() {}
ReturnValue_t PlocMPSoCHandler::initialize() {
ReturnValue_t result = returnvalue::OK;
result = DeviceHandlerBase::initialize();
if (result != returnvalue::OK) {
return result;
}
uartComIf = dynamic_cast<SerialComIF*>(communicationInterface);
if (uartComIf == nullptr) {
sif::warning << "PlocMPSoCHandler::initialize: Invalid uart com if" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
if (manager == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PlocMPSoCHandler::initialize: Invalid event manager" << std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
;
}
result = manager->registerListener(eventQueue->getId());
if (result != returnvalue::OK) {
return result;
}
result = manager->subscribeToEventRange(
eventQueue->getId(), event::getEventId(PlocMPSoCHelper::MPSOC_FLASH_WRITE_FAILED),
event::getEventId(PlocMPSoCHelper::MPSOC_FLASH_WRITE_SUCCESSFUL));
if (result != returnvalue::OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "PlocMPSoCHandler::initialize: Failed to subscribe to events from "
" ploc mpsoc helper"
<< std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
}
result = plocMPSoCHelper->setComIF(communicationInterface);
if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
plocMPSoCHelper->setComCookie(comCookie);
plocMPSoCHelper->setSequenceCount(&sequenceCount);
result = commandActionHelper.initialize();
if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
return result;
}
void PlocMPSoCHandler::performOperationHook() {
EventMessage event;
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == returnvalue::OK;
result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE:
handleEvent(&event);
break;
default:
sif::debug << "PlocMPSoCHandler::performOperationHook: Did not subscribe to this event"
<< " message" << std::endl;
break;
}
}
CommandMessage message;
for (ReturnValue_t result = commandActionHelperQueue->receiveMessage(&message);
result == returnvalue::OK; result = commandActionHelperQueue->receiveMessage(&message)) {
result = commandActionHelper.handleReply(&message);
if (result == returnvalue::OK) {
continue;
}
}
}
ReturnValue_t PlocMPSoCHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) {
ReturnValue_t result = returnvalue::OK;
switch (actionId) {
case mpsoc::SET_UART_TX_TRISTATE: {
uartIsolatorSwitch.pullLow();
return EXECUTION_FINISHED;
break;
}
case mpsoc::RELEASE_UART_TX: {
uartIsolatorSwitch.pullHigh();
return EXECUTION_FINISHED;
break;
default:
break;
}
}
if (plocMPSoCHelperExecuting) {
return MPSoCReturnValuesIF::MPSOC_HELPER_EXECUTING;
}
switch (actionId) {
case mpsoc::TC_FLASHWRITE: {
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return MPSoCReturnValuesIF::FILENAME_TOO_LONG;
}
mpsoc::FlashWritePusCmd flashWritePusCmd;
result = flashWritePusCmd.extractFields(data, size);
if (result != returnvalue::OK) {
return result;
}
result = plocMPSoCHelper->startFlashWrite(flashWritePusCmd.getObcFile(),
flashWritePusCmd.getMPSoCFile());
if (result != returnvalue::OK) {
return result;
}
plocMPSoCHelperExecuting = true;
return EXECUTION_FINISHED;
}
case (mpsoc::OBSW_RESET_SEQ_COUNT): {
sequenceCount = 0;
return EXECUTION_FINISHED;
}
default:
break;
}
return DeviceHandlerBase::executeAction(actionId, commandedBy, data, size);
}
void PlocMPSoCHandler::doStartUp() {
#ifdef XIPHOS_Q7S
#if not OBSW_MPSOC_JTAG_BOOT == 1
switch (powerState) {
case PowerState::OFF:
commandActionHelper.commandAction(supervisorHandler, supv::START_MPSOC);
powerState = PowerState::BOOTING;
break;
case PowerState::ON:
setMode(_MODE_TO_ON);
uartIsolatorSwitch.pullHigh();
break;
default:
break;
}
#else
powerState = PowerState::ON;
setMode(_MODE_TO_ON);
uartIsolatorSwitch.pullHigh();
#endif /* not MSPOC_JTAG_BOOT == 1 */
#else
powerState = PowerState::ON;
setMode(_MODE_TO_ON);
#endif /* XIPHOS_Q7S */
}
void PlocMPSoCHandler::doShutDown() {
#ifdef XIPHOS_Q7S
#if not OBSW_MPSOC_JTAG_BOOT == 1
switch (powerState) {
case PowerState::ON:
uartIsolatorSwitch.pullLow();
commandActionHelper.commandAction(supervisorHandler, supv::SHUTDOWN_MPSOC);
powerState = PowerState::SHUTDOWN;
break;
case PowerState::OFF:
sequenceCount = 0;
setMode(_MODE_POWER_DOWN);
break;
default:
break;
}
#else
sequenceCount = 0;
uartIsolatorSwitch.pullLow();
setMode(_MODE_POWER_DOWN);
powerState = PowerState::OFF;
#endif
#endif
}
ReturnValue_t PlocMPSoCHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
*id = mpsoc::TC_GET_HK_REPORT;
return buildCommandFromCommand(*id, nullptr, 0);
}
ReturnValue_t PlocMPSoCHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
return NOTHING_TO_SEND;
}
ReturnValue_t PlocMPSoCHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData,
size_t commandDataLen) {
spParams.buf = commandBuffer;
ReturnValue_t result = returnvalue::OK;
switch (deviceCommand) {
case (mpsoc::TC_MEM_WRITE): {
result = prepareTcMemWrite(commandData, commandDataLen);
break;
}
case (mpsoc::TC_MEM_READ): {
result = prepareTcMemRead(commandData, commandDataLen);
break;
}
case (mpsoc::TC_FLASHDELETE): {
result = prepareTcFlashDelete(commandData, commandDataLen);
break;
}
case (mpsoc::TC_REPLAY_START): {
result = prepareTcReplayStart(commandData, commandDataLen);
break;
}
case (mpsoc::TC_REPLAY_STOP): {
result = prepareTcReplayStop();
break;
}
case (mpsoc::TC_DOWNLINK_PWR_ON): {
result = prepareTcDownlinkPwrOn(commandData, commandDataLen);
break;
}
case (mpsoc::TC_DOWNLINK_PWR_OFF): {
result = prepareTcDownlinkPwrOff();
break;
}
case (mpsoc::TC_REPLAY_WRITE_SEQUENCE): {
result = prepareTcReplayWriteSequence(commandData, commandDataLen);
break;
}
case (mpsoc::TC_GET_HK_REPORT): {
result = prepareTcGetHkReport();
break;
}
case (mpsoc::TC_MODE_REPLAY): {
result = prepareTcModeReplay();
break;
}
case (mpsoc::TC_MODE_IDLE): {
result = prepareTcModeIdle();
break;
}
case (mpsoc::TC_CAM_CMD_SEND): {
result = prepareTcCamCmdSend(commandData, commandDataLen);
break;
}
case (mpsoc::TC_CAM_TAKE_PIC): {
result = prepareTcCamTakePic(commandData, commandDataLen);
break;
}
case (mpsoc::TC_SIMPLEX_SEND_FILE): {
result = prepareTcSimplexSendFile(commandData, commandDataLen);
break;
}
case (mpsoc::TC_DOWNLINK_DATA_MODULATE): {
result = prepareTcDownlinkDataModulate(commandData, commandDataLen);
break;
}
case (mpsoc::TC_MODE_SNAPSHOT): {
result = prepareTcModeSnapshot();
break;
}
default:
sif::debug << "PlocMPSoCHandler::buildCommandFromCommand: Command not implemented"
<< std::endl;
result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
break;
}
if (result == returnvalue::OK) {
/**
* Flushing the receive buffer to make sure there are no data left from a faulty reply.
*/
uartComIf->flushUartRxBuffer(comCookie);
}
return result;
}
void PlocMPSoCHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(mpsoc::TC_MEM_WRITE);
this->insertInCommandMap(mpsoc::TC_MEM_READ);
this->insertInCommandMap(mpsoc::TC_FLASHDELETE);
this->insertInCommandMap(mpsoc::TC_REPLAY_START);
this->insertInCommandMap(mpsoc::TC_REPLAY_STOP);
this->insertInCommandMap(mpsoc::TC_DOWNLINK_PWR_ON);
this->insertInCommandMap(mpsoc::TC_DOWNLINK_PWR_OFF);
this->insertInCommandMap(mpsoc::TC_REPLAY_WRITE_SEQUENCE);
this->insertInCommandMap(mpsoc::TC_MODE_REPLAY);
this->insertInCommandMap(mpsoc::TC_MODE_IDLE);
this->insertInCommandMap(mpsoc::TC_CAM_CMD_SEND);
this->insertInCommandMap(mpsoc::TC_GET_HK_REPORT);
this->insertInCommandMap(mpsoc::RELEASE_UART_TX);
this->insertInCommandMap(mpsoc::SET_UART_TX_TRISTATE);
this->insertInCommandMap(mpsoc::TC_CAM_TAKE_PIC);
this->insertInCommandMap(mpsoc::TC_SIMPLEX_SEND_FILE);
this->insertInCommandMap(mpsoc::TC_DOWNLINK_DATA_MODULATE);
this->insertInCommandMap(mpsoc::TC_MODE_SNAPSHOT);
this->insertInReplyMap(mpsoc::ACK_REPORT, 3, nullptr, mpsoc::SIZE_ACK_REPORT);
this->insertInReplyMap(mpsoc::EXE_REPORT, 3, nullptr, mpsoc::SIZE_EXE_REPORT);
this->insertInReplyMap(mpsoc::TM_MEMORY_READ_REPORT, 2, nullptr, mpsoc::SIZE_TM_MEM_READ_REPORT);
this->insertInReplyMap(mpsoc::TM_GET_HK_REPORT, 2, nullptr, 0);
this->insertInReplyMap(mpsoc::TM_CAM_CMD_RPT, 2, nullptr, mpsoc::SP_MAX_SIZE);
}
ReturnValue_t PlocMPSoCHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
ReturnValue_t result = returnvalue::OK;
SpacePacketReader spacePacket;
spacePacket.setReadOnlyData(start, remainingSize);
if (spacePacket.isNull()) {
return returnvalue::FAILED;
}
auto res = spacePacket.checkSize();
if (res != returnvalue::OK) {
return res;
}
uint16_t apid = spacePacket.getApid();
switch (apid) {
case (mpsoc::apid::ACK_SUCCESS):
*foundLen = mpsoc::SIZE_ACK_REPORT;
*foundId = mpsoc::ACK_REPORT;
break;
case (mpsoc::apid::ACK_FAILURE):
*foundLen = mpsoc::SIZE_ACK_REPORT;
*foundId = mpsoc::ACK_REPORT;
break;
case (mpsoc::apid::TM_MEMORY_READ_REPORT):
*foundLen = tmMemReadReport.rememberRequestedSize;
*foundId = mpsoc::TM_MEMORY_READ_REPORT;
break;
case (mpsoc::apid::TM_CAM_CMD_RPT):
*foundLen = spacePacket.getFullPacketLen();
foundPacketLen = *foundLen;
*foundId = mpsoc::TM_CAM_CMD_RPT;
break;
case (mpsoc::apid::TM_HK_GET_REPORT): {
*foundLen = spacePacket.getFullPacketLen();
foundPacketLen = *foundLen;
*foundId = mpsoc::TM_GET_HK_REPORT;
break;
}
case (mpsoc::apid::EXE_SUCCESS):
*foundLen = mpsoc::SIZE_EXE_REPORT;
*foundId = mpsoc::EXE_REPORT;
break;
case (mpsoc::apid::EXE_FAILURE):
*foundLen = mpsoc::SIZE_EXE_REPORT;
*foundId = mpsoc::EXE_REPORT;
break;
default: {
sif::debug << "PlocMPSoCHandler::scanForReply: Reply has invalid apid" << std::endl;
*foundLen = remainingSize;
return MPSoCReturnValuesIF::INVALID_APID;
}
}
uint16_t recvSeqCnt = (*(start + 2) << 8 | *(start + 3)) & PACKET_SEQUENCE_COUNT_MASK;
if (recvSeqCnt != sequenceCount) {
triggerEvent(MPSOC_HANDLER_SEQUENCE_COUNT_MISMATCH, sequenceCount, recvSeqCnt);
sequenceCount = recvSeqCnt;
}
// This sequence count ping pong does not make any sense but it is how the MPSoC expects it.
sequenceCount++;
return result;
}
ReturnValue_t PlocMPSoCHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
ReturnValue_t result = returnvalue::OK;
switch (id) {
case mpsoc::ACK_REPORT: {
result = handleAckReport(packet);
break;
}
case (mpsoc::TM_MEMORY_READ_REPORT): {
result = handleMemoryReadReport(packet);
break;
}
case (mpsoc::TM_GET_HK_REPORT): {
result = handleGetHkReport(packet);
break;
}
case (mpsoc::TM_CAM_CMD_RPT): {
result = handleCamCmdRpt(packet);
break;
}
case (mpsoc::EXE_REPORT): {
result = handleExecutionReport(packet);
break;
}
default: {
sif::debug << "PlocMPSoCHandler::interpretDeviceReply: Unknown device reply id" << std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return result;
}
void PlocMPSoCHandler::setNormalDatapoolEntriesInvalid() {}
uint32_t PlocMPSoCHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 5000; }
ReturnValue_t PlocMPSoCHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(mpsoc::poolid::STATUS, &peStatus);
localDataPoolMap.emplace(mpsoc::poolid::MODE, &peMode);
localDataPoolMap.emplace(mpsoc::poolid::DOWNLINK_PWR_ON, &peDownlinkPwrOn);
localDataPoolMap.emplace(mpsoc::poolid::DOWNLINK_JESD_SYNC_STATUS, &peDownlinkJesdSyncStatus);
localDataPoolMap.emplace(mpsoc::poolid::DOWNLINK_DAC_STATUS, &peDownlinkDacStatus);
localDataPoolMap.emplace(mpsoc::poolid::CAM_STATUS, &peCameraStatus);
localDataPoolMap.emplace(mpsoc::poolid::CAM_SDI_STATUS, &peCameraSdiStatus);
localDataPoolMap.emplace(mpsoc::poolid::CAM_FPGA_TEMP, &peCameraFpgaTemp);
localDataPoolMap.emplace(mpsoc::poolid::CAM_SOC_TEMP, &peCameraSocTemp);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_TEMP, &peSysmonTemp);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCINT, &peSysmonVccInt);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCAUX, &peSysmonVccAux);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCBRAM, &peSysmonVccBram);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCPAUX, &peSysmonVccPaux);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCPINT, &peSysmonVccPint);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCPDRO, &peSysmonVccPdro);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_MB12V, &peSysmonMb12V);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_MB3V3, &peSysmonMb3V3);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_MB1V8, &peSysmonMb1V8);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC12V, &peSysmonVcc12V);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC3V3, &peSysmonVcc3V3);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC3V3VA, &peSysmonVcc3V3VA);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC2V5DDR, &peSysmonVcc2V5DDR);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC1V2DDR, &peSysmonVcc1V2DDR);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC0V9, &peSysmonVcc0V9);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC0V6VTT, &peSysmonVcc0V6VTT);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_SAFE_COTS_CUR, &peSysmonSafeCotsCur);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_NVM4_XO_CUR, &peSysmonNvm4XoCur);
localDataPoolMap.emplace(mpsoc::poolid::SEM_UNCORRECTABLE_ERRS, &peSemUncorrectableErrs);
localDataPoolMap.emplace(mpsoc::poolid::SEM_CORRECTABLE_ERRS, &peSemCorrectableErrs);
localDataPoolMap.emplace(mpsoc::poolid::SEM_STATUS, &peSemStatus);
localDataPoolMap.emplace(mpsoc::poolid::REBOOT_MPSOC_REQUIRED, &peRebootMpsocRequired);
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(hkReport.getSid(), false, 10.0));
return returnvalue::OK;
}
void PlocMPSoCHandler::handleEvent(EventMessage* eventMessage) {
object_id_t objectId = eventMessage->getReporter();
switch (objectId) {
case objects::PLOC_MPSOC_HELPER: {
plocMPSoCHelperExecuting = false;
break;
}
default:
sif::debug << "PlocMPSoCHandler::handleEvent: Did not subscribe to this event" << std::endl;
break;
}
}
ReturnValue_t PlocMPSoCHandler::prepareTcMemWrite(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcMemWrite tcMemWrite(spParams, sequenceCount);
result = tcMemWrite.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcMemWrite.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcMemRead(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcMemRead tcMemRead(spParams, sequenceCount);
result = tcMemRead.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcMemRead.getFullPacketLen());
tmMemReadReport.rememberRequestedSize = tcMemRead.getMemLen() * 4 + TmMemReadReport::FIX_SIZE;
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcFlashDelete(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return MPSoCReturnValuesIF::NAME_TOO_LONG;
}
ReturnValue_t result = returnvalue::OK;
mpsoc::TcFlashDelete tcFlashDelete(spParams, sequenceCount);
result = tcFlashDelete.buildPacket(
std::string(reinterpret_cast<const char*>(commandData), commandDataLen));
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcFlashDelete.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcReplayStart(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcReplayStart tcReplayStart(spParams, sequenceCount);
result = tcReplayStart.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcReplayStart.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcReplayStop() {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcReplayStop tcReplayStop(spParams, sequenceCount);
result = tcReplayStop.buildPacket();
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcReplayStop.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcDownlinkPwrOn(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcDownlinkPwrOn tcDownlinkPwrOn(spParams, sequenceCount);
result = tcDownlinkPwrOn.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcDownlinkPwrOn.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcDownlinkPwrOff() {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcDownlinkPwrOff tcDownlinkPwrOff(spParams, sequenceCount);
result = tcDownlinkPwrOff.buildPacket();
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcDownlinkPwrOff.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcGetHkReport() {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcGetHkReport tcDownlinkPwrOff(spParams, sequenceCount);
result = tcDownlinkPwrOff.buildPacket();
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcDownlinkPwrOff.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcReplayWriteSequence(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcReplayWriteSeq tcReplayWriteSeq(spParams, sequenceCount);
result = tcReplayWriteSeq.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcReplayWriteSeq.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcModeReplay() {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcModeReplay tcModeReplay(spParams, sequenceCount);
result = tcModeReplay.buildPacket();
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcModeReplay.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcModeIdle() {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcModeIdle tcModeIdle(spParams, sequenceCount);
result = tcModeIdle.buildPacket();
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcModeIdle.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcCamCmdSend(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcCamcmdSend tcCamCmdSend(spParams, sequenceCount);
result = tcCamCmdSend.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcCamCmdSend.getFullPacketLen());
nextReplyId = mpsoc::TM_CAM_CMD_RPT;
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcCamTakePic(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcCamTakePic tcCamTakePic(spParams, sequenceCount);
result = tcCamTakePic.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcCamTakePic.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcSimplexSendFile(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcSimplexSendFile tcSimplexSendFile(spParams, sequenceCount);
result = tcSimplexSendFile.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcSimplexSendFile.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcDownlinkDataModulate(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcDownlinkDataModulate tcDownlinkDataModulate(spParams, sequenceCount);
result = tcDownlinkDataModulate.buildPacket(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcDownlinkDataModulate.getFullPacketLen());
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::prepareTcModeSnapshot() {
ReturnValue_t result = returnvalue::OK;
mpsoc::TcModeSnapshot tcModeSnapshot(spParams, sequenceCount);
result = tcModeSnapshot.buildPacket();
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(tcModeSnapshot.getFullPacketLen());
return returnvalue::OK;
}
void PlocMPSoCHandler::finishTcPrep(size_t packetLen) {
nextReplyId = mpsoc::ACK_REPORT;
rawPacket = commandBuffer;
rawPacketLen = packetLen;
sequenceCount++;
}
ReturnValue_t PlocMPSoCHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
if (CRC::crc16ccitt(start, foundLen) != 0) {
return MPSoCReturnValuesIF::CRC_FAILURE;
}
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::handleAckReport(const uint8_t* data) {
ReturnValue_t result = returnvalue::OK;
result = verifyPacket(data, mpsoc::SIZE_ACK_REPORT);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleAckReport: CRC failure" << std::endl;
nextReplyId = mpsoc::NONE;
replyRawReplyIfnotWiretapped(data, mpsoc::SIZE_ACK_REPORT);
triggerEvent(MPSOC_HANDLER_CRC_FAILURE);
sendFailureReport(mpsoc::ACK_REPORT, MPSoCReturnValuesIF::CRC_FAILURE);
disableAllReplies();
return IGNORE_REPLY_DATA;
}
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
switch (apid) {
case mpsoc::apid::ACK_FAILURE: {
sif::debug << "PlocMPSoCHandler::handleAckReport: Received Ack failure report" << std::endl;
DeviceCommandId_t commandId = getPendingCommand();
uint16_t status = getStatus(data);
printStatus(data);
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
triggerEvent(ACK_FAILURE, commandId, status);
}
sendFailureReport(mpsoc::ACK_REPORT, status);
disableAllReplies();
nextReplyId = mpsoc::NONE;
result = IGNORE_REPLY_DATA;
break;
}
case mpsoc::apid::ACK_SUCCESS: {
setNextReplyId();
break;
}
default: {
sif::debug << "PlocMPSoCHandler::handleAckReport: Invalid APID in Ack report" << std::endl;
result = returnvalue::FAILED;
break;
}
}
return result;
}
ReturnValue_t PlocMPSoCHandler::handleExecutionReport(const uint8_t* data) {
ReturnValue_t result = returnvalue::OK;
result = verifyPacket(data, mpsoc::SIZE_EXE_REPORT);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleExecutionReport: CRC failure" << std::endl;
nextReplyId = mpsoc::NONE;
return result;
}
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
switch (apid) {
case (mpsoc::apid::EXE_SUCCESS): {
break;
}
case (mpsoc::apid::EXE_FAILURE): {
// TODO: Interpretation of status field in execution report
sif::warning << "PlocMPSoCHandler::handleExecutionReport: Received execution failure report"
<< std::endl;
DeviceCommandId_t commandId = getPendingCommand();
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
uint16_t status = getStatus(data);
triggerEvent(EXE_FAILURE, commandId, status);
} else {
sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl;
}
printStatus(data);
sendFailureReport(mpsoc::EXE_REPORT, MPSoCReturnValuesIF::RECEIVED_EXE_FAILURE);
disableExeReportReply();
result = IGNORE_REPLY_DATA;
break;
}
default: {
sif::warning << "PlocMPSoCHandler::handleExecutionReport: Unknown APID" << std::endl;
result = returnvalue::FAILED;
break;
}
}
nextReplyId = mpsoc::NONE;
return result;
}
ReturnValue_t PlocMPSoCHandler::handleMemoryReadReport(const uint8_t* data) {
ReturnValue_t result = returnvalue::OK;
result = verifyPacket(data, tmMemReadReport.rememberRequestedSize);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleMemoryReadReport: Memory read report has invalid crc"
<< std::endl;
}
uint16_t memLen =
*(data + mpsoc::MEM_READ_RPT_LEN_OFFSET) << 8 | *(data + mpsoc::MEM_READ_RPT_LEN_OFFSET + 1);
/** Send data to commanding queue */
handleDeviceTM(data + mpsoc::DATA_FIELD_OFFSET, mpsoc::SIZE_MEM_READ_RPT_FIX + memLen * 4,
mpsoc::TM_MEMORY_READ_REPORT);
nextReplyId = mpsoc::EXE_REPORT;
return result;
}
ReturnValue_t PlocMPSoCHandler::handleGetHkReport(const uint8_t* data) {
ReturnValue_t result = verifyPacket(data, foundPacketLen);
if (result != returnvalue::OK) {
return result;
}
SpacePacketReader packetReader(data, foundPacketLen);
const uint8_t* dataStart = data + 6;
PoolReadGuard pg(&hkReport);
size_t deserLen = mpsoc::SIZE_TM_HK_REPORT;
SerializeIF::Endianness endianness = SerializeIF::Endianness::NETWORK;
result = SerializeAdapter::deSerialize(&hkReport.status.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.mode.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkPwrOn.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkReplyActive.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkJesdSyncStatus.value, &dataStart,
&deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkDacStatus.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.camStatus.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.camSdiStatus.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.camFpgaTemp.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonTemp.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccInt.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccAux.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccBram.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccPaux.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccPint.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccPdro.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonMb12V.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonMb3V3.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonMb1V8.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc12V.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonVcc5V.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc3V3.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc3V3VA.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc2V5DDR.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc1V2DDR.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc0V9.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc0V6VTT.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonSafeCotsCur.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonNvm4XoCur.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.semUncorrectableErrs.value, &dataStart,
&deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.semCorrectableErrs.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.semStatus.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
// Skip the weird filename
dataStart += 256;
result = SerializeAdapter::deSerialize(&hkReport.rebootMpsocRequired, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
return returnvalue::OK;
}
ReturnValue_t PlocMPSoCHandler::handleCamCmdRpt(const uint8_t* data) {
ReturnValue_t result = verifyPacket(data, foundPacketLen);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleCamCmdRpt: CRC failure" << std::endl;
}
SpacePacketReader packetReader(data, foundPacketLen);
const uint8_t* dataFieldPtr = data + mpsoc::SPACE_PACKET_HEADER_SIZE + sizeof(uint16_t);
std::string camCmdRptMsg(reinterpret_cast<const char*>(dataFieldPtr),
foundPacketLen - mpsoc::SPACE_PACKET_HEADER_SIZE - sizeof(uint16_t) - 3);
#if OBSW_DEBUG_PLOC_MPSOC == 1
uint8_t ackValue = *(packetReader.getFullData() + packetReader.getFullPacketLen() - 2);
sif::info << "PlocMPSoCHandler: CamCmdRpt message: " << camCmdRptMsg << std::endl;
sif::info << "PlocMPSoCHandler: CamCmdRpt Ack value: 0x" << std::hex
<< static_cast<unsigned int>(ackValue) << std::endl;
#endif /* OBSW_DEBUG_PLOC_MPSOC == 1 */
handleDeviceTM(packetReader.getPacketData() + sizeof(uint16_t),
packetReader.getPacketDataLen() - 1, mpsoc::TM_CAM_CMD_RPT);
return result;
}
ReturnValue_t PlocMPSoCHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies, bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
ReturnValue_t result = returnvalue::OK;
uint8_t enabledReplies = 0;
auto enableThreeReplies = [&](DeviceCommandId_t replyId) {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, replyId);
if (result != returnvalue::OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id "
<< mpsoc::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl;
return result;
}
return returnvalue::OK;
};
switch (command->first) {
case mpsoc::TC_MEM_WRITE:
case mpsoc::TC_FLASHDELETE:
case mpsoc::TC_REPLAY_START:
case mpsoc::TC_REPLAY_STOP:
case mpsoc::TC_DOWNLINK_PWR_ON:
case mpsoc::TC_DOWNLINK_PWR_OFF:
case mpsoc::TC_REPLAY_WRITE_SEQUENCE:
case mpsoc::TC_MODE_REPLAY:
case mpsoc::TC_MODE_IDLE:
case mpsoc::TC_CAM_TAKE_PIC:
case mpsoc::TC_SIMPLEX_SEND_FILE:
case mpsoc::TC_DOWNLINK_DATA_MODULATE:
case mpsoc::TC_MODE_SNAPSHOT:
enabledReplies = 2;
break;
case mpsoc::TC_GET_HK_REPORT: {
result = enableThreeReplies(mpsoc::TM_GET_HK_REPORT);
if (result != returnvalue::OK) {
return result;
}
break;
}
case mpsoc::TC_MEM_READ: {
result = enableThreeReplies(mpsoc::TM_MEMORY_READ_REPORT);
if (result != returnvalue::OK) {
return result;
}
break;
}
case mpsoc::TC_CAM_CMD_SEND: {
result = enableThreeReplies(mpsoc::TM_CAM_CMD_RPT);
if (result != returnvalue::OK) {
return result;
}
break;
}
case mpsoc::OBSW_RESET_SEQ_COUNT:
break;
default:
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
break;
}
/**
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::ACK_REPORT);
if (result != returnvalue::OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::ACK_REPORT
<< " not in replyMap" << std::endl;
}
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::EXE_REPORT);
if (result != returnvalue::OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::EXE_REPORT
<< " not in replyMap" << std::endl;
}
switch (command->first) {
case mpsoc::TC_REPLAY_WRITE_SEQUENCE: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
// Overwrite delay cycles because replay write sequence command can required up to
// 30 seconds for execution
iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY;
break;
}
case mpsoc::TC_DOWNLINK_PWR_ON: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
iter->second.delayCycles = mpsoc::TC_DOWNLINK_PWR_ON_EXECUTION_DELAY;
break;
}
case mpsoc::TC_CAM_TAKE_PIC: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
iter->second.delayCycles = mpsoc::TC_CAM_TAKE_PIC_EXECUTION_DELAY;
break;
}
case mpsoc::TC_SIMPLEX_SEND_FILE: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
iter->second.delayCycles = mpsoc::TC_SIMPLEX_SEND_FILE_DELAY;
break;
}
default:
break;
}
return returnvalue::OK;
}
void PlocMPSoCHandler::setNextReplyId() {
switch (getPendingCommand()) {
case mpsoc::TC_MEM_READ:
nextReplyId = mpsoc::TM_MEMORY_READ_REPORT;
break;
default:
/* If no telemetry is expected the next reply is always the execution report */
nextReplyId = mpsoc::EXE_REPORT;
break;
}
}
size_t PlocMPSoCHandler::getNextReplyLength(DeviceCommandId_t commandId) {
size_t replyLen = 0;
if (nextReplyId == mpsoc::NONE) {
return replyLen;
}
DeviceReplyIter iter = deviceReplyMap.find(nextReplyId);
if (iter != deviceReplyMap.end()) {
if (iter->second.delayCycles == 0) {
/* Reply inactive */
return replyLen;
}
switch (nextReplyId) {
case mpsoc::TM_MEMORY_READ_REPORT: {
replyLen = tmMemReadReport.rememberRequestedSize;
break;
}
case mpsoc::TM_CAM_CMD_RPT:
// Read acknowledgment, camera and execution report in one go because length of camera
// report is not fixed
replyLen = mpsoc::SP_MAX_SIZE;
break;
default: {
replyLen = iter->second.replyLen;
break;
}
}
} else {
sif::debug << "PlocMPSoCHandler::getNextReplyLength: No entry for reply with reply id "
<< std::hex << nextReplyId << " in deviceReplyMap" << std::endl;
}
return replyLen;
}
ReturnValue_t PlocMPSoCHandler::doSendReadHook() {
// Prevent DHB from polling UART during commands executed by the mpsoc helper task
if (plocMPSoCHelperExecuting) {
return returnvalue::FAILED;
}
return returnvalue::OK;
}
MessageQueueIF* PlocMPSoCHandler::getCommandQueuePtr() { return commandActionHelperQueue; }
void PlocMPSoCHandler::stepSuccessfulReceived(ActionId_t actionId, uint8_t step) { return; }
void PlocMPSoCHandler::stepFailedReceived(ActionId_t actionId, uint8_t step,
ReturnValue_t returnCode) {
switch (actionId) {
case supv::START_MPSOC: {
sif::warning << "PlocMPSoCHandler::stepFailedReceived: Failed to start MPSoC" << std::endl;
// This usually happens when the supervisor handler is in off mode
powerState = PowerState::OFF;
setMode(MODE_OFF);
break;
}
case supv::SHUTDOWN_MPSOC: {
triggerEvent(MPSOC_SHUTDOWN_FAILED);
sif::warning << "PlocMPSoCHandler::stepFailedReceived: Failed to shutdown MPSoC" << std::endl;
powerState = PowerState::OFF;
break;
}
default:
sif::debug << "PlocMPSoCHandler::stepFailedReceived: Received unexpected action reply"
<< std::endl;
break;
}
}
void PlocMPSoCHandler::dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) {
return;
}
void PlocMPSoCHandler::completionSuccessfulReceived(ActionId_t actionId) {
if (actionId != supv::EXE_REPORT) {
sif::debug << "PlocMPSoCHandler::completionSuccessfulReceived: Did not expect this action "
<< "ID" << std::endl;
return;
}
switch (powerState) {
case PowerState::BOOTING: {
powerState = PowerState::ON;
break;
}
case PowerState::SHUTDOWN: {
powerState = PowerState::OFF;
break;
}
default: {
break;
}
}
}
void PlocMPSoCHandler::completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) {
handleActionCommandFailure(actionId);
}
void PlocMPSoCHandler::handleDeviceTM(const uint8_t* data, size_t dataSize,
DeviceCommandId_t replyId) {
ReturnValue_t result = returnvalue::OK;
if (wiretappingMode == RAW) {
/* Data already sent in doGetRead() */
return;
}
DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId);
if (iter == deviceReplyMap.end()) {
sif::debug << "PlocMPSoCHandler::handleDeviceTM: Unknown reply id" << std::endl;
return;
}
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
if (queueId == NO_COMMANDER) {
return;
}
result = actionHelper.reportData(queueId, replyId, data, dataSize);
if (result != returnvalue::OK) {
sif::debug << "PlocMPSoCHandler::handleDeviceTM: Failed to report data" << std::endl;
}
}
void PlocMPSoCHandler::disableAllReplies() {
using namespace mpsoc;
DeviceReplyMap::iterator iter;
/* Disable ack reply */
iter = deviceReplyMap.find(ACK_REPORT);
DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
DeviceCommandId_t commandId = getPendingCommand();
auto disableCommandWithReply = [&](DeviceCommandId_t replyId) {
iter = deviceReplyMap.find(replyId);
info = &(iter->second);
info->delayCycles = 0;
info->active = false;
info->command = deviceCommandMap.end();
};
/* If the command expects a telemetry packet the appropriate tm reply will be disabled here */
switch (commandId) {
case TC_MEM_WRITE:
case TC_FLASHDELETE:
case TC_REPLAY_START:
case TC_REPLAY_STOP:
case TC_DOWNLINK_PWR_ON:
case TC_DOWNLINK_PWR_OFF:
case TC_REPLAY_WRITE_SEQUENCE:
case TC_MODE_REPLAY:
case TC_MODE_IDLE:
case TC_CAM_TAKE_PIC:
case TC_SIMPLEX_SEND_FILE:
case TC_DOWNLINK_DATA_MODULATE:
case TC_MODE_SNAPSHOT:
break;
case TC_MEM_READ: {
disableCommandWithReply(TM_MEMORY_READ_REPORT);
break;
}
case TC_GET_HK_REPORT: {
disableCommandWithReply(TM_GET_HK_REPORT);
break;
}
case TC_CAM_CMD_SEND: {
disableCommandWithReply(TM_CAM_CMD_RPT);
break;
}
default: {
sif::debug << "PlocMPSoCHandler::disableAllReplies: Unknown command id: " << commandId
<< std::endl;
break;
}
}
/* We always need to disable the execution report reply here */
disableExeReportReply();
nextReplyId = mpsoc::NONE;
}
void PlocMPSoCHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) {
DeviceReplyIter iter = deviceReplyMap.find(replyId);
if (iter == deviceReplyMap.end()) {
sif::debug << "PlocMPSoCHandler::sendFailureReport: Reply not in reply map" << std::endl;
return;
}
DeviceCommandInfo* info = &(iter->second.command->second);
if (info == nullptr) {
sif::debug << "PlocMPSoCHandler::sendFailureReport: Reply has no active command" << std::endl;
return;
}
if (info->sendReplyTo != NO_COMMANDER) {
actionHelper.finish(false, info->sendReplyTo, iter->first, status);
}
info->isExecuting = false;
}
void PlocMPSoCHandler::disableExeReportReply() {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
/* Expected replies is set to one here. The value will be set to 0 in replyToReply() */
info->command->second.expectedReplies = 0;
}
void PlocMPSoCHandler::printStatus(const uint8_t* data) {
uint16_t status = *(data + STATUS_OFFSET) << 8 | *(data + STATUS_OFFSET + 1);
sif::info << "Verification report status: " << getStatusString(status) << std::endl;
}
uint16_t PlocMPSoCHandler::getStatus(const uint8_t* data) {
return *(data + STATUS_OFFSET) << 8 | *(data + STATUS_OFFSET + 1);
}
void PlocMPSoCHandler::handleActionCommandFailure(ActionId_t actionId) {
switch (actionId) {
case supv::ACK_REPORT:
case supv::EXE_REPORT:
break;
default:
sif::debug << "PlocMPSoCHandler::handleActionCommandFailure: Did not expect this action ID "
<< std::endl;
return;
}
switch (powerState) {
case PowerState::BOOTING: {
sif::info << "PlocMPSoCHandler::handleActionCommandFailure: MPSoC boot command failed"
<< std::endl;
// This is commonly the case when the MPSoC is already operational. Thus the power state is
// set to on here
powerState = PowerState::ON;
break;
}
case PowerState::SHUTDOWN: {
// FDIR will intercept event and switch PLOC power off
triggerEvent(MPSOC_SHUTDOWN_FAILED);
sif::warning << "PlocMPSoCHandler::handleActionCommandFailure: Failed to shutdown MPSoC"
<< std::endl;
powerState = PowerState::OFF;
break;
}
default:
break;
}
return;
}
LocalPoolDataSetBase* PlocMPSoCHandler::getDataSetHandle(sid_t sid) {
if (sid == hkReport.getSid()) {
return &hkReport;
}
return nullptr;
}
std::string PlocMPSoCHandler::getStatusString(uint16_t status) {
switch (status) {
case (mpsoc::status_code::UNKNOWN_APID): {
return "Unknown APID";
break;
}
case (mpsoc::status_code::INCORRECT_LENGTH): {
return "Incorrect length";
break;
}
case (mpsoc::status_code::INCORRECT_CRC): {
return "Incorrect crc";
break;
}
case (mpsoc::status_code::INCORRECT_PKT_SEQ_CNT): {
return "Incorrect packet sequence count";
break;
}
case (mpsoc::status_code::TC_NOT_ALLOWED_IN_MODE): {
return "TC not allowed in this mode";
break;
}
case (mpsoc::status_code::TC_EXEUTION_DISABLED): {
return "TC execution disabled";
break;
}
case (mpsoc::status_code::FLASH_MOUNT_FAILED): {
return "Flash mount failed";
break;
}
case (mpsoc::status_code::FLASH_FILE_ALREADY_CLOSED): {
return "Flash file already closed";
break;
}
case (mpsoc::status_code::FLASH_FILE_OPEN_FAILED): {
return "Flash file open failed";
break;
}
case (mpsoc::status_code::FLASH_FILE_NOT_OPEN): {
return "Flash file not open";
break;
}
case (mpsoc::status_code::FLASH_UNMOUNT_FAILED): {
return "Flash unmount failed";
break;
}
case (mpsoc::status_code::HEAP_ALLOCATION_FAILED): {
return "Heap allocation failed";
break;
}
case (mpsoc::status_code::INVALID_PARAMETER): {
return "Invalid parameter";
break;
}
case (mpsoc::status_code::NOT_INITIALIZED): {
return "Not initialized";
break;
}
case (mpsoc::status_code::REBOOT_IMMINENT): {
return "Reboot imminent";
break;
}
case (mpsoc::status_code::CORRUPT_DATA): {
return "Corrupt data";
break;
}
case (mpsoc::status_code::FLASH_CORRECTABLE_MISMATCH): {
return "Flash correctable mismatch";
break;
}
case (mpsoc::status_code::FLASH_UNCORRECTABLE_MISMATCH): {
return "Flash uncorrectable mismatch";
break;
}
case (mpsoc::status_code::DEFAULT_ERROR_CODE): {
return "Default error code";
break;
}
default:
std::stringstream ss;
ss << "0x" << std::hex << status;
return ss.str();
break;
}
return "";
}