eive-obsw/linux/ipcore/PapbVcInterface.h

143 lines
4.8 KiB
C
Raw Normal View History

2021-09-19 12:27:48 +02:00
#ifndef LINUX_OBC_PAPBVCINTERFACE_H_
#define LINUX_OBC_PAPBVCINTERFACE_H_
#include <fsfw_hal/common/gpio/gpioDefinitions.h>
#include <fsfw_hal/linux/gpio/LinuxLibgpioIF.h>
2023-03-09 17:44:05 +01:00
#include <linux/ipcore/VirtualChannelIF.h>
2022-01-26 17:59:31 +01:00
2023-03-31 01:14:59 +02:00
#include <atomic>
2023-10-13 15:10:52 +02:00
#include <vector>
2023-03-31 01:14:59 +02:00
2022-01-17 15:58:27 +01:00
#include "OBSWConfig.h"
2022-08-24 17:27:47 +02:00
#include "fsfw/returnvalues/returnvalue.h"
2021-09-19 12:27:48 +02:00
/**
* @brief This class handles the transmission of data to a virtual channel of the PTME IP Core
* via the PAPB interface.
*
* @author J. Meier
*/
2023-03-09 17:44:05 +01:00
class PapbVcInterface : public VirtualChannelIF {
2022-01-17 15:58:27 +01:00
public:
/**
* @brief Constructor
*
* @param papbBusyId The ID of the GPIO which is connected to the PAPBBusy_N signal of the
* VcInterface IP Core. A low logic level indicates the VcInterface is not
* ready to receive more data.
* @param papbEmptyId The ID of the GPIO which is connected to the PAPBEmpty signal of the
* VcInterface IP Core. The signal is high when there are no packets in the
* external buffer memory (BRAM).
2022-01-24 16:33:22 +01:00
* @param uioFile UIO file providing access to the PAPB bus
* @param mapNum Map number of UIO map associated with this virtual channel
2022-01-17 15:58:27 +01:00
*/
2023-10-13 15:10:52 +02:00
PapbVcInterface(LinuxLibgpioIF* gpioComIF, gpioId_t papbEmptyId, std::string uioFile, int mapNum,
size_t maxPacketSize);
2022-01-17 15:58:27 +01:00
virtual ~PapbVcInterface();
2023-03-10 18:04:04 +01:00
bool isBusy() const override;
/**
*
* @param data
* @param size
* @return returnvalue::OK on successfull write, PAPB_BUSY if PAPB is busy.
*/
2023-10-13 09:20:51 +02:00
ReturnValue_t write(const uint8_t* data, size_t size, size_t& writtenSize) override;
2023-10-13 15:10:52 +02:00
ReturnValue_t advanceWrite(size_t& remainingSize) override;
// ReturnValue_t finishWriteInternal(const uint8_t* data, size_t start, size_t remainingSize,
// size_t& writtenSize, bool abortOnPartialWrite);
2022-01-17 15:58:27 +01:00
2023-03-23 18:31:47 +01:00
void cancelTransfer() override;
2023-10-13 15:24:06 +02:00
bool writeActive() const override;
2022-01-24 16:33:22 +01:00
ReturnValue_t initialize() override;
2022-01-17 15:58:27 +01:00
private:
static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_IP_CORE_BRIDGE;
static const ReturnValue_t PAPB_BUSY = MAKE_RETURN_CODE(0xA0);
enum ByteWidthCfg : uint32_t { ONE = 0b00, TWO = 0b01, THREE = 0b10, FOUR = 0b11 };
2022-01-17 15:58:27 +01:00
/**
* Configuration bits:
* bit[1:0]: Size of data (1,2,3 or 4 bytes). 1 Byte <=> b00
2023-03-23 15:43:14 +01:00
* bit[2]: Set this bit to 1 to abort a transferred packet
2022-01-17 15:58:27 +01:00
* bit[3]: Signals to VcInterface the start of a new telemetry packet
*/
static constexpr uint32_t CONFIG_DATA_INPUT = 0b00001000;
2023-03-23 15:43:14 +01:00
/**
* Abort a transferred packet.
*/
static constexpr uint32_t CONFIG_ABORT = 0b00000100;
2022-01-17 15:58:27 +01:00
/**
* Writing this word to the VcInterface base address signals to the virtual channel interface
* that a complete tm packet has been transferred.
*/
2023-03-23 15:43:14 +01:00
static constexpr uint32_t CONFIG_END = 0x0;
2022-01-17 15:58:27 +01:00
/**
* Writing to this offset within the memory space of a virtual channel will insert data for
* encoding to the external buffer memory of the PTME IP Core.
* The address offset is 0x400 (= 4 * 256)
*/
static const int DATA_REG_OFFSET = 256;
2023-03-29 17:38:38 +02:00
static constexpr long int FIRST_DELAY_PAPB_POLLING_NS = 10;
2023-03-28 21:45:04 +02:00
static constexpr long int MAX_DELAY_PAPB_POLLING_NS = 40;
2023-06-29 00:35:06 +02:00
static constexpr uint32_t MAX_BUSY_POLLS = 1000;
2023-03-27 17:02:02 +02:00
2022-01-17 15:58:27 +01:00
LinuxLibgpioIF* gpioComIF = nullptr;
/** High when external buffer memory of virtual channel is empty */
gpioId_t papbEmptyId = gpio::NO_GPIO;
2023-10-13 15:10:52 +02:00
std::vector<uint8_t> packetBuf;
2022-01-24 16:33:22 +01:00
std::string uioFile;
int mapNum = 0;
2023-10-13 15:24:06 +02:00
bool writeActiveStatus = false;
2023-10-13 15:10:52 +02:00
size_t currentPacketIndex = 0;
size_t currentPacketSize = 0;
mutable struct timespec nextDelay = {.tv_sec = 0, .tv_nsec = 0};
2023-03-31 15:12:05 +02:00
const struct timespec BETWEEN_POLL_DELAY = {.tv_sec = 0, .tv_nsec = 10};
2022-01-24 16:33:22 +01:00
2023-03-31 17:36:49 +02:00
volatile uint32_t* vcBaseReg = nullptr;
2022-01-17 15:58:27 +01:00
uint32_t vcOffset = 0;
/**
* @brief This function sends the config byte to the virtual channel of the PTME IP Core
* to initiate a packet transfer.
*/
void startPacketTransfer(ByteWidthCfg initWidth);
2022-01-17 15:58:27 +01:00
2023-03-23 15:43:14 +01:00
void abortPacketTransfer();
2022-01-17 15:58:27 +01:00
/**
* @brief This function sends the config byte to the virtual channel interface of the PTME
* IP Core to signal the end of a packet transfer.
*/
2023-03-23 15:43:14 +01:00
void completePacketTransfer();
2022-01-17 15:58:27 +01:00
/**
* @brief This function reads the papb busy signal indicating whether the virtual channel
* interface is ready to receive more data or not. PAPB is ready when
* PAPB_Busy_N == '1'.
*
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK when ready to receive data else PAPB_BUSY.
2022-01-17 15:58:27 +01:00
*/
2023-06-26 17:08:39 +02:00
inline bool pollReadyForPacket() const;
2022-01-17 15:58:27 +01:00
2023-06-29 00:33:58 +02:00
inline bool pollReadyForOctet(uint32_t maxCycles) const;
2022-01-17 15:58:27 +01:00
/**
* @brief This function can be used for debugging to check whether there are packets in
* the packet buffer of the virtual channel or not.
*/
2023-06-26 17:08:39 +02:00
bool isVcInterfaceBufferEmpty();
2021-09-19 12:27:48 +02:00
};
#endif /* LINUX_OBC_PAPBVCINTERFACE_H_ */