eive-obsw/linux/payload/PlocMpsocHandler.h

315 lines
14 KiB
C
Raw Normal View History

2022-01-05 11:26:01 +01:00
#ifndef BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
#define BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
2021-03-29 14:37:52 +02:00
2023-05-15 15:15:58 +02:00
#include <linux/payload/PlocMpsocSpecialComHelper.h>
2023-03-26 16:42:00 +02:00
#include <linux/payload/mpsocRetvals.h>
2023-05-15 15:15:58 +02:00
#include <linux/payload/plocMpsocHelpers.h>
2023-03-26 16:42:00 +02:00
#include <linux/payload/plocSupvDefs.h>
2022-01-10 16:18:18 +01:00
#include <string>
2022-03-27 13:07:18 +02:00
2022-03-30 09:19:30 +02:00
#include "fsfw/action/CommandActionHelper.h"
#include "fsfw/action/CommandsActionsIF.h"
2022-01-06 18:05:21 +01:00
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
2022-01-10 16:18:18 +01:00
#include "fsfw/ipc/QueueFactory.h"
2022-01-11 12:56:02 +01:00
#include "fsfw/tmtcservices/SourceSequenceCounter.h"
2022-03-28 09:08:11 +02:00
#include "fsfw_hal/linux/gpio/Gpio.h"
2022-11-10 18:07:59 +01:00
#include "fsfw_hal/linux/serial/SerialComIF.h"
2021-03-29 14:37:52 +02:00
/**
2022-01-06 18:05:21 +01:00
* @brief This is the device handler for the MPSoC of the payload computer.
*
2022-03-27 14:42:20 +02:00
* @details The PLOC uses the space packet protocol for communication. Each command will be
* answered with at least one acknowledgment and one execution report.
2022-03-27 13:07:18 +02:00
* Flight manual:
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/PLOC_MPSoC ICD:
* https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_TAS-ILH-IRS/ICD-PLOC/ILH&fileid=1030263
2022-01-06 18:05:21 +01:00
*
* @note The sequence count in the space packets must be incremented with each received and sent
2022-03-27 14:42:20 +02:00
* packet otherwise the MPSoC will reply with an acknowledgment failure report.
*
2023-05-15 13:25:53 +02:00
* NOTE: This is not an example for a good device handler, DO NOT USE THIS AS A REFERENCE HANDLER.
* @author J. Meier, R. Mueller
2021-03-29 14:37:52 +02:00
*/
2023-05-15 15:15:58 +02:00
class PlocMpsocHandler : public DeviceHandlerBase, public CommandsActionsIF {
2022-03-27 13:07:18 +02:00
public:
2022-03-30 09:19:30 +02:00
/**
* @brief Constructor
*
* @param ojectId Object ID of the MPSoC handler
* @param uartcomIFid Object ID of the UART communication interface
* @param comCookie UART communication cookie
* @param plocMPSoCHelper Pointer to MPSoC helper object
* @param uartIsolatorSwitch Gpio object representing the GPIO connected to the UART isolator
* module in the programmable logic
* @param supervisorHandler Object ID of the supervisor handler
*/
2023-05-15 15:15:58 +02:00
PlocMpsocHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF* comCookie,
PlocMpsocSpecialComHelper* plocMPSoCHelper, Gpio uartIsolatorSwitch,
2022-03-30 09:19:30 +02:00
object_id_t supervisorHandler);
2023-05-15 15:15:58 +02:00
virtual ~PlocMpsocHandler();
2022-03-27 13:07:18 +02:00
virtual ReturnValue_t initialize() override;
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override;
void performOperationHook() override;
2022-03-30 09:19:30 +02:00
MessageQueueIF* getCommandQueuePtr() override;
void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) override;
void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) override;
void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) override;
void completionSuccessfulReceived(ActionId_t actionId) override;
void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) override;
2022-03-27 13:07:18 +02:00
protected:
void doStartUp() override;
void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override;
void fillCommandAndReplyMap() override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId,
size_t* foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) override;
void setNormalDatapoolEntriesInvalid() override;
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies = 1, bool useAlternateId = false,
DeviceCommandId_t alternateReplyID = 0) override;
size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
2023-05-02 15:04:14 +02:00
ReturnValue_t doSendReadHook() override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
2023-05-15 13:25:53 +02:00
bool dontCheckQueue() override;
2022-03-27 13:07:18 +02:00
private:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HANDLER;
//! [EXPORT] : [COMMENT] PLOC crc failure in telemetry packet
static const Event MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT(1, severity::LOW);
//! [EXPORT] : [COMMENT] PLOC receive acknowledgment failure report
//! P1: Command Id which leads the acknowledgment failure report
//! P2: The status field inserted by the MPSoC into the data field
static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW);
//! [EXPORT] : [COMMENT] PLOC receive execution failure report
//! P1: Command Id which leads the execution failure report
//! P2: The status field inserted by the MPSoC into the data field
static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW);
//! [EXPORT] : [COMMENT] PLOC reply has invalid crc
static const Event MPSOC_HANDLER_CRC_FAILURE = MAKE_EVENT(4, severity::LOW);
//! [EXPORT] : [COMMENT] Packet sequence count in received space packet does not match expected
//! count P1: Expected sequence count P2: Received sequence count
2022-05-03 14:59:23 +02:00
static const Event MPSOC_HANDLER_SEQUENCE_COUNT_MISMATCH = MAKE_EVENT(5, severity::LOW);
2022-03-30 09:19:30 +02:00
//! [EXPORT] : [COMMENT] Supervisor fails to shutdown MPSoC. Requires to power off the PLOC and
//! thus also to shutdown the supervisor.
static const Event MPSOC_SHUTDOWN_FAILED = MAKE_EVENT(6, severity::HIGH);
//! [EXPORT] : [COMMENT] SUPV not on for boot or shutdown process. P1: 0 for OFF transition, 1 for
//! ON transition.
2023-09-25 17:50:13 +02:00
static constexpr Event SUPV_NOT_ON = event::makeEvent(SUBSYSTEM_ID, 7, severity::LOW);
static constexpr Event SUPV_REPLY_TIMEOUT = event::makeEvent(SUBSYSTEM_ID, 8, severity::LOW);
2022-03-27 13:07:18 +02:00
static const uint16_t APID_MASK = 0x7FF;
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
2023-05-02 15:04:14 +02:00
mpsoc::HkReport hkReport;
2023-09-25 18:07:54 +02:00
Countdown mpsocBootTransitionCd = Countdown(6500);
Countdown supvTransitionCd = Countdown(3000);
2023-05-02 15:04:14 +02:00
2022-03-27 13:07:18 +02:00
MessageQueueIF* eventQueue = nullptr;
2022-03-30 09:19:30 +02:00
MessageQueueIF* commandActionHelperQueue = nullptr;
2022-03-27 13:07:18 +02:00
2022-12-22 17:17:23 +01:00
SourceSequenceCounter sequenceCount = SourceSequenceCounter(0);
2022-03-27 13:07:18 +02:00
uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE];
2022-08-15 18:34:26 +02:00
SpacePacketCreator creator;
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
2022-03-27 13:07:18 +02:00
2023-05-12 12:14:37 +02:00
PoolEntry<uint32_t> peStatus = PoolEntry<uint32_t>();
2023-05-02 15:04:14 +02:00
PoolEntry<uint8_t> peMode = PoolEntry<uint8_t>();
PoolEntry<uint8_t> peDownlinkPwrOn = PoolEntry<uint8_t>();
PoolEntry<uint8_t> peDownlinkReplyActive = PoolEntry<uint8_t>();
PoolEntry<uint8_t> peDownlinkJesdSyncStatus = PoolEntry<uint8_t>();
PoolEntry<uint8_t> peDownlinkDacStatus = PoolEntry<uint8_t>();
PoolEntry<uint8_t> peCameraStatus = PoolEntry<uint8_t>();
PoolEntry<uint8_t> peCameraSdiStatus = PoolEntry<uint8_t>();
PoolEntry<float> peCameraFpgaTemp = PoolEntry<float>();
PoolEntry<float> peCameraSocTemp = PoolEntry<float>();
PoolEntry<float> peSysmonTemp = PoolEntry<float>();
PoolEntry<float> peSysmonVccInt = PoolEntry<float>();
PoolEntry<float> peSysmonVccAux = PoolEntry<float>();
PoolEntry<float> peSysmonVccBram = PoolEntry<float>();
PoolEntry<float> peSysmonVccPaux = PoolEntry<float>();
PoolEntry<float> peSysmonVccPint = PoolEntry<float>();
PoolEntry<float> peSysmonVccPdro = PoolEntry<float>();
PoolEntry<float> peSysmonMb12V = PoolEntry<float>();
PoolEntry<float> peSysmonMb3V3 = PoolEntry<float>();
PoolEntry<float> peSysmonMb1V8 = PoolEntry<float>();
PoolEntry<float> peSysmonVcc12V = PoolEntry<float>();
PoolEntry<float> peSysmonVcc5V = PoolEntry<float>();
PoolEntry<float> peSysmonVcc3V3 = PoolEntry<float>();
PoolEntry<float> peSysmonVcc3V3VA = PoolEntry<float>();
PoolEntry<float> peSysmonVcc2V5DDR = PoolEntry<float>();
PoolEntry<float> peSysmonVcc1V2DDR = PoolEntry<float>();
PoolEntry<float> peSysmonVcc0V9 = PoolEntry<float>();
PoolEntry<float> peSysmonVcc0V6VTT = PoolEntry<float>();
PoolEntry<float> peSysmonSafeCotsCur = PoolEntry<float>();
PoolEntry<float> peSysmonNvm4XoCur = PoolEntry<float>();
PoolEntry<uint16_t> peSemUncorrectableErrs = PoolEntry<uint16_t>();
PoolEntry<uint16_t> peSemCorrectableErrs = PoolEntry<uint16_t>();
PoolEntry<uint8_t> peSemStatus = PoolEntry<uint8_t>();
PoolEntry<uint8_t> peRebootMpsocRequired = PoolEntry<uint8_t>();
2022-03-27 13:07:18 +02:00
/**
* This variable is used to store the id of the next reply to receive. This is necessary
* because the PLOC sends as reply to each command at least one acknowledgment and execution
* report.
*/
DeviceCommandId_t nextReplyId = mpsoc::NONE;
2022-11-10 18:07:59 +01:00
SerialComIF* uartComIf = nullptr;
2022-03-27 13:07:18 +02:00
2023-05-15 15:19:12 +02:00
PlocMpsocSpecialComHelper* specialComHelper = nullptr;
2022-03-28 09:08:11 +02:00
Gpio uartIsolatorSwitch;
2022-03-30 09:19:30 +02:00
object_id_t supervisorHandler = 0;
CommandActionHelper commandActionHelper;
2022-03-27 13:07:18 +02:00
// Used to block incoming commands when MPSoC helper class is currently executing a command
2023-05-17 17:33:14 +02:00
bool specialComHelperExecuting = false;
2023-05-12 17:39:15 +02:00
bool commandIsPending = false;
2022-03-27 13:07:18 +02:00
2022-04-20 21:33:39 +02:00
struct TmMemReadReport {
2022-03-27 13:07:18 +02:00
static const uint8_t FIX_SIZE = 14;
size_t rememberRequestedSize = 0;
};
TmMemReadReport tmMemReadReport;
2023-05-15 13:25:53 +02:00
Countdown cmdCountdown = Countdown(10000);
2022-03-27 13:07:18 +02:00
2022-04-20 21:33:39 +02:00
struct TelemetryBuffer {
uint16_t length = 0;
uint8_t buffer[mpsoc::SP_MAX_SIZE];
2022-04-20 21:33:39 +02:00
};
2023-05-02 13:42:20 +02:00
size_t foundPacketLen = 0;
2022-04-20 21:33:39 +02:00
TelemetryBuffer tmBuffer;
enum class StartupState { IDLE, HW_INIT, DONE } startupState = StartupState::IDLE;
enum class PowerState { IDLE, PENDING_STARTUP, PENDING_SHUTDOWN, SUPV_FAILED, DONE };
2022-03-30 09:19:30 +02:00
PowerState powerState = PowerState::IDLE;
2022-03-30 09:19:30 +02:00
2022-03-27 13:07:18 +02:00
/**
* @brief Handles events received from the PLOC MPSoC helper
*/
void handleEvent(EventMessage* eventMessage);
ReturnValue_t prepareTcMemWrite(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcMemRead(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcFlashDelete(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcReplayStart(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcReplayStop();
ReturnValue_t prepareTcDownlinkPwrOn(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcDownlinkPwrOff();
2023-05-02 13:42:20 +02:00
ReturnValue_t prepareTcGetHkReport();
2023-05-03 15:24:47 +02:00
ReturnValue_t prepareTcGetDirContent(const uint8_t* commandData, size_t commandDataLen);
2022-03-27 13:07:18 +02:00
ReturnValue_t prepareTcReplayWriteSequence(const uint8_t* commandData, size_t commandDataLen);
2022-04-20 21:33:39 +02:00
ReturnValue_t prepareTcCamCmdSend(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcModeIdle();
ReturnValue_t prepareTcCamTakePic(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcSimplexSendFile(const uint8_t* commandData, size_t commandDataLen);
ReturnValue_t prepareTcDownlinkDataModulate(const uint8_t* commandData, size_t commandDataLen);
2023-02-14 14:00:53 +01:00
ReturnValue_t prepareTcModeSnapshot();
2023-05-16 13:34:06 +02:00
ReturnValue_t finishTcPrep(mpsoc::TcBase& tcBase);
2022-03-27 13:07:18 +02:00
/**
* @brief This function checks the crc of the received PLOC reply.
*
* @param start Pointer to the first byte of the reply.
* @param foundLen Pointer to the length of the whole packet.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if CRC is ok, otherwise CRC_FAILURE.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen);
/**
* @brief This function handles the acknowledgment report.
*
* @param data Pointer to the data holding the acknowledgment report.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise an error code.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t handleAckReport(const uint8_t* data);
/**
* @brief This function handles the data of a execution report.
*
* @param data Pointer to the received data packet.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise an error code.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t handleExecutionReport(const uint8_t* data);
/**
* @brief This function handles the memory read report.
*
* @param data Pointer to the data buffer holding the memory read report.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise an error code.
2022-03-27 13:07:18 +02:00
*/
ReturnValue_t handleMemoryReadReport(const uint8_t* data);
2023-05-02 13:42:20 +02:00
ReturnValue_t handleGetHkReport(const uint8_t* data);
2022-04-20 21:33:39 +02:00
ReturnValue_t handleCamCmdRpt(const uint8_t* data);
2022-03-27 13:07:18 +02:00
/**
* @brief Depending on the current active command, this function sets the reply id of the
* next reply after a successful acknowledgment report has been received. This is
* required by the function getNextReplyLength() to identify the length of the next
* reply to read.
*/
void setNextReplyId();
/**
* @brief This function handles action message replies in case the telemetry has been
* requested by another object.
*
* @param data Pointer to the telemetry data.
* @param dataSize Size of telemetry in bytes.
* @param replyId Id of the reply. This will be added to the ActionMessage.
*/
2023-05-03 15:24:47 +02:00
void handleDeviceTm(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId);
2022-03-27 13:07:18 +02:00
/**
* @brief In case an acknowledgment failure reply has been received this function disables
* all previously enabled commands and resets the exepected replies variable of an
* active command.
*/
void disableAllReplies();
/**
* @brief This function sends a failure report if the active action was commanded by an other
* object.
*
* @param replyId The id of the reply which signals a failure.
* @param status A status byte which gives information about the failure type.
*/
void sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status);
/**
* @brief This function disables the execution report reply. Within this function also the
* the variable expectedReplies of an active command will be set to 0.
*/
void disableExeReportReply();
ReturnValue_t prepareTcModeReplay();
2023-05-15 13:25:53 +02:00
void cmdDoneHandler(bool success, ReturnValue_t result);
bool handleHwStartup();
bool handleHwShutdown();
void stopSpecialComHelper();
2023-05-15 13:25:53 +02:00
2022-03-30 09:19:30 +02:00
void handleActionCommandFailure(ActionId_t actionId);
2021-03-29 14:37:52 +02:00
};
2022-01-05 11:26:01 +01:00
#endif /* BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_ */