eive-obsw/linux/payload/PlocMpsocSpecialComHelper.h

201 lines
8.0 KiB
C
Raw Permalink Normal View History

2022-01-06 18:05:21 +01:00
#ifndef BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_
#define BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_
2023-05-15 15:15:58 +02:00
#include <linux/payload/plocMpsocHelpers.h>
2023-03-26 16:42:00 +02:00
#include <mission/utility/trace.h>
2022-01-06 18:05:21 +01:00
#include <string>
2022-03-26 20:47:25 +01:00
2023-05-03 19:49:45 +02:00
#include "OBSWConfig.h"
2022-03-26 20:47:25 +01:00
#include "fsfw/devicehandlers/CookieIF.h"
#include "fsfw/objectmanager/SystemObject.h"
2022-01-06 18:05:21 +01:00
#include "fsfw/osal/linux/BinarySemaphore.h"
2022-08-24 17:27:47 +02:00
#include "fsfw/returnvalues/returnvalue.h"
2022-01-06 18:05:21 +01:00
#include "fsfw/tasks/ExecutableObjectIF.h"
2022-01-11 12:56:02 +01:00
#include "fsfw/tmtcservices/SourceSequenceCounter.h"
2022-11-10 18:07:59 +01:00
#include "fsfw_hal/linux/serial/SerialComIF.h"
#ifdef XIPHOS_Q7S
2022-09-16 11:53:33 +02:00
#include "bsp_q7s/fs/SdCardManager.h"
#endif
2022-01-06 18:05:21 +01:00
/**
* @brief Helper class for MPSoC of PLOC intended to accelerate large data transfers between
* MPSoC and OBC.
* @author J. Meier
*/
2023-05-15 15:15:58 +02:00
class PlocMpsocSpecialComHelper : public SystemObject, public ExecutableObjectIF {
2022-03-26 20:47:25 +01:00
public:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HELPER;
//! [EXPORT] : [COMMENT] Flash write fails
static const Event MPSOC_FLASH_WRITE_FAILED = MAKE_EVENT(0, severity::LOW);
//! [EXPORT] : [COMMENT] Flash write successful
2023-05-03 19:37:10 +02:00
static const Event MPSOC_FLASH_WRITE_SUCCESSFUL = MAKE_EVENT(1, severity::INFO);
2022-03-26 20:47:25 +01:00
//! [EXPORT] : [COMMENT] Communication interface returned failure when trying to send the command
2022-04-10 18:46:39 +02:00
//! to the MPSoC
2022-03-26 20:47:25 +01:00
//! P1: Return value returned by the communication interface sendMessage function
//! P2: Internal state of MPSoC helper
2022-04-10 18:46:39 +02:00
static const Event MPSOC_SENDING_COMMAND_FAILED = MAKE_EVENT(2, severity::LOW);
2022-03-26 20:47:25 +01:00
//! [EXPORT] : [COMMENT] Request receive message of communication interface failed
//! P1: Return value returned by the communication interface requestReceiveMessage function
//! P2: Internal state of MPSoC helper
static const Event MPSOC_HELPER_REQUESTING_REPLY_FAILED = MAKE_EVENT(3, severity::LOW);
//! [EXPORT] : [COMMENT] Reading receive message of communication interface failed
//! P1: Return value returned by the communication interface readingReceivedMessage function
//! P2: Internal state of MPSoC helper
static const Event MPSOC_HELPER_READING_REPLY_FAILED = MAKE_EVENT(4, severity::LOW);
2022-04-10 18:46:39 +02:00
//! [EXPORT] : [COMMENT] Did not receive acknowledgment report
2022-03-26 20:47:25 +01:00
//! P1: Number of bytes missing
//! P2: Internal state of MPSoC helper
2022-04-10 18:46:39 +02:00
static const Event MPSOC_MISSING_ACK = MAKE_EVENT(5, severity::LOW);
2022-03-26 20:47:25 +01:00
//! [EXPORT] : [COMMENT] Did not receive execution report
//! P1: Number of bytes missing
//! P2: Internal state of MPSoC helper
2022-04-10 18:46:39 +02:00
static const Event MPSOC_MISSING_EXE = MAKE_EVENT(6, severity::LOW);
//! [EXPORT] : [COMMENT] Received acknowledgment failure report
2022-03-26 20:47:25 +01:00
//! P1: Internal state of MPSoC
2022-04-10 18:46:39 +02:00
static const Event MPSOC_ACK_FAILURE_REPORT = MAKE_EVENT(7, severity::LOW);
2022-03-26 20:47:25 +01:00
//! [EXPORT] : [COMMENT] Received execution failure report
//! P1: Internal state of MPSoC
2022-04-10 18:46:39 +02:00
static const Event MPSOC_EXE_FAILURE_REPORT = MAKE_EVENT(8, severity::LOW);
//! [EXPORT] : [COMMENT] Expected acknowledgment report but received space packet with other apid
2022-03-26 20:47:25 +01:00
//! P1: Apid of received space packet
//! P2: Internal state of MPSoC
2022-04-10 18:46:39 +02:00
static const Event MPSOC_ACK_INVALID_APID = MAKE_EVENT(9, severity::LOW);
2022-03-26 20:47:25 +01:00
//! [EXPORT] : [COMMENT] Expected execution report but received space packet with other apid
//! P1: Apid of received space packet
//! P2: Internal state of MPSoC
2022-04-10 18:46:39 +02:00
static const Event MPSOC_EXE_INVALID_APID = MAKE_EVENT(10, severity::LOW);
2022-03-26 20:47:25 +01:00
//! [EXPORT] : [COMMENT] Received sequence count does not match expected sequence count
//! P1: Expected sequence count
//! P2: Received sequence count
static const Event MPSOC_HELPER_SEQ_CNT_MISMATCH = MAKE_EVENT(11, severity::LOW);
2022-08-15 18:34:26 +02:00
static const Event MPSOC_TM_SIZE_ERROR = MAKE_EVENT(12, severity::LOW);
static const Event MPSOC_TM_CRC_MISSMATCH = MAKE_EVENT(13, severity::LOW);
2023-05-03 19:37:10 +02:00
static const Event MPSOC_FLASH_READ_PACKET_ERROR = MAKE_EVENT(14, severity::LOW);
static const Event MPSOC_FLASH_READ_FAILED = MAKE_EVENT(15, severity::LOW);
static const Event MPSOC_FLASH_READ_SUCCESSFUL = MAKE_EVENT(16, severity::INFO);
2023-05-16 18:41:04 +02:00
static const Event MPSOC_READ_TIMEOUT = MAKE_EVENT(17, severity::LOW);
2023-05-03 19:37:10 +02:00
enum FlashReadErrorType : uint32_t {
FLASH_READ_APID_ERROR = 0,
FLASH_READ_FILENAME_ERROR = 1,
FLASH_READ_READLEN_ERROR = 2
};
2022-03-26 20:47:25 +01:00
2023-05-15 15:15:58 +02:00
PlocMpsocSpecialComHelper(object_id_t objectId);
virtual ~PlocMpsocSpecialComHelper();
2022-03-26 20:47:25 +01:00
ReturnValue_t initialize() override;
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
ReturnValue_t setComIF(DeviceCommunicationIF* communicationInterface_);
void setComCookie(CookieIF* comCookie_);
/**
* @brief Starts flash write sequence
*
* @param obcFile File where to read from the data
* @param mpsocFile The file of the MPSoC where should be written to
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise error return value
2022-03-26 20:47:25 +01:00
*/
ReturnValue_t startFlashWrite(std::string obcFile, std::string mpsocFile);
2023-05-03 19:49:45 +02:00
/**
*
* @param obcFile Full target file name on OBC
* @param mpsocFile The file on the MPSoC which should be copied ot the OBC
* @param readFileSize The size of the file on the MPSoC.
* @return
*/
ReturnValue_t startFlashRead(std::string obcFile, std::string mpsocFile, size_t readFileSize);
2022-03-26 20:47:25 +01:00
/**
* @brief Can be used to interrupt a running data transfer.
*/
void stopProcess();
/**
* @brief Sets the sequence count object responsible for the sequence count handling
*/
void setSequenceCount(SourceSequenceCounter* sequenceCount_);
private:
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HELPER;
2023-05-03 19:37:10 +02:00
//! [EXPORT] : [COMMENT] File error occured for file transfers from OBC to the MPSoC.
static const ReturnValue_t FILE_WRITE_ERROR = MAKE_RETURN_CODE(0xA0);
//! [EXPORT] : [COMMENT] File error occured for file transfers from MPSoC to OBC.
static const ReturnValue_t FILE_READ_ERROR = MAKE_RETURN_CODE(0xA1);
2022-03-26 20:47:25 +01:00
// Maximum number of times the communication interface retries polling data from the reply
// buffer
static const int RETRIES = 10000;
2023-05-03 17:46:47 +02:00
struct FlashInfo {
2022-03-26 20:47:25 +01:00
std::string obcFile;
std::string mpsocFile;
};
2023-05-03 17:46:47 +02:00
struct FlashRead : public FlashInfo {
2023-05-03 19:37:10 +02:00
size_t totalReadSize = 0;
2023-05-03 17:46:47 +02:00
};
2022-03-26 20:47:25 +01:00
2023-05-03 17:46:47 +02:00
struct FlashRead flashReadAndWrite;
2023-02-14 11:10:18 +01:00
#if OBSW_THREAD_TRACING == 1
uint32_t opCounter = 0;
#endif
2022-03-26 20:47:25 +01:00
enum class InternalState { IDLE, FLASH_WRITE, FLASH_READ };
InternalState internalState = InternalState::IDLE;
BinarySemaphore semaphore;
#ifdef XIPHOS_Q7S
2022-03-26 20:47:25 +01:00
SdCardManager* sdcMan = nullptr;
#endif
2022-03-26 20:47:25 +01:00
uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE];
2022-08-15 18:34:26 +02:00
SpacePacketCreator creator;
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
2023-05-16 18:41:04 +02:00
Countdown tmCountdown = Countdown(5000);
2023-05-03 19:37:10 +02:00
std::array<uint8_t, mpsoc::SP_MAX_DATA_SIZE> fileBuf{};
2023-05-03 17:46:47 +02:00
std::array<uint8_t, mpsoc::MAX_REPLY_SIZE> tmBuf{};
2022-03-26 20:47:25 +01:00
bool terminate = false;
/**
* Communication interface of MPSoC responsible for low level access. Must be set by the
* MPSoC Handler.
*/
2022-11-10 18:07:59 +01:00
SerialComIF* uartComIF = nullptr;
2022-03-26 20:47:25 +01:00
// Communication cookie. Must be set by the MPSoC Handler
CookieIF* comCookie = nullptr;
// Sequence count, must be set by Ploc MPSoC Handler
2022-08-15 18:34:26 +02:00
SourceSequenceCounter* sequenceCount = nullptr;
2023-05-16 18:41:04 +02:00
ploc::SpTmReader spReader;
2022-03-26 20:47:25 +01:00
2023-05-15 14:40:14 +02:00
void resetHelper();
2022-03-26 20:47:25 +01:00
ReturnValue_t performFlashWrite();
2023-05-03 17:46:47 +02:00
ReturnValue_t performFlashRead();
2023-05-17 18:33:48 +02:00
ReturnValue_t flashfopen(uint8_t accessMode);
2022-03-26 20:47:25 +01:00
ReturnValue_t flashfclose();
2023-05-03 19:37:10 +02:00
ReturnValue_t handlePacketTransmissionNoReply(ploc::SpTcBase& tc);
2023-05-16 18:41:04 +02:00
ReturnValue_t handlePacketTransmissionFlashRead(mpsoc::TcFlashRead& tc, std::ofstream& ofile,
size_t expectedReadLen);
2023-05-03 19:37:10 +02:00
ReturnValue_t handleFlashReadReply(std::ofstream& ofile, size_t expectedReadLen);
2022-08-15 18:34:26 +02:00
ReturnValue_t sendCommand(ploc::SpTcBase& tc);
2023-05-16 18:41:04 +02:00
ReturnValue_t receive(uint8_t* data, size_t requestBytes, size_t* readBytes);
2022-03-26 20:47:25 +01:00
ReturnValue_t handleAck();
ReturnValue_t handleExe();
2023-05-03 19:49:45 +02:00
ReturnValue_t startFlashReadOrWriteBase(std::string obcFile, std::string mpsocFile);
ReturnValue_t fileCheck(std::string obcFile);
2023-05-15 15:15:58 +02:00
void handleAckApidFailure(const ploc::SpTmReader& reader);
2023-05-16 18:41:04 +02:00
void handleExeFailure();
ReturnValue_t handleTmReception();
ReturnValue_t checkReceivedTm();
2022-01-06 18:05:21 +01:00
};
#endif /* BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_ */