From d60bf5e037e47b3800b05e17a9af53f789159333 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 27 May 2021 13:07:57 +0200 Subject: [PATCH] ptme bridge wip --- fsfw_hal | 2 +- fsfwconfig/OBSWConfig.h | 1 + mission/obc/CCSDSIPCoreBridge.cpp | 156 ++++++++++++++++-------------- mission/obc/CCSDSIPCoreBridge.h | 21 ++-- thirdparty/etl | 2 +- tmtc | 2 +- 6 files changed, 100 insertions(+), 84 deletions(-) diff --git a/fsfw_hal b/fsfw_hal index 6341da22..7724fdc3 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit 6341da22123166ac5fafdbc09e823d7464f769e5 +Subproject commit 7724fdc389c48fc3c52ba94c7c7d9fe4530f1996 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index efc8bcc2..1aa08764 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,6 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 #define TEST_CCSDS_BRIDGE 1 +#define PERFORM_PTME_TEST 1 #define TE0720 1 #define TE0720_HEATER_TEST 0 diff --git a/mission/obc/CCSDSIPCoreBridge.cpp b/mission/obc/CCSDSIPCoreBridge.cpp index 61b9b85b..0dc5ffa2 100644 --- a/mission/obc/CCSDSIPCoreBridge.cpp +++ b/mission/obc/CCSDSIPCoreBridge.cpp @@ -26,7 +26,8 @@ ReturnValue_t CCSDSIPCoreBridge::initialize() { * Map uio device in virtual address space * PROT_WRITE: Map uio device in writable only mode */ - ptmeBaseAddress = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + ptmeBaseAddress = static_cast(mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0)); if (ptmeBaseAddress == MAP_FAILED) { sif::error << "CCSDSIPCoreBridge::initialize: Failed to map uio address" << std::endl; @@ -38,6 +39,86 @@ ReturnValue_t CCSDSIPCoreBridge::initialize() { ReturnValue_t CCSDSIPCoreBridge::handleTm() { +#if PERFORM_PTME_TEST == 1 + return sendTestFrame(); +#else + return TmTcBridge::handleTm(); +#endif + +} + +ReturnValue_t CCSDSIPCoreBridge::sendTm(const uint8_t * data, size_t dataLen) { + + if(pollPapbBusySignal() == RETURN_OK) { + startPacketTransfer(); + } + + for(size_t idx = 0; idx < dataLen; idx++) { + if(pollPapbBusySignal() == RETURN_OK) { + *(ptmeBaseAddress + PTME_DATA_REG_OFFSET) = static_cast(*(data + idx)); + } + else { + sif::debug << "CCSDSIPCoreBridge::sendTm: Only written " << idx - 1 << " of " << dataLen + << " data" << std::endl; + return RETURN_FAILED; + } + } + + if(pollPapbBusySignal() == RETURN_OK) { + endPacketTransfer(); + } + return RETURN_OK; +} + +void CCSDSIPCoreBridge::startPacketTransfer() { + *ptmeBaseAddress = PTME_CONFIG_START; +} + +void CCSDSIPCoreBridge::endPacketTransfer() { + *ptmeBaseAddress = PTME_CONFIG_END; +} + +ReturnValue_t CCSDSIPCoreBridge::pollPapbBusySignal() { + int papbBusyState = 0; + ReturnValue_t result = RETURN_OK; + + /** Check if PAPB interface is ready to receive data */ + result = gpioComIF->readGpio(papbBusyId, &papbBusyState); + if (result != RETURN_OK) { + sif::debug << "CCSDSIPCoreBridge::pollPapbBusySignal: Failed to read papb busy signal" + << std::endl; + return RETURN_FAILED; + } + if (!papbBusyState) { + sif::debug << "CCSDSIPCoreBridge::pollPapbBusySignal: PAPB busy" << std::endl; + return PAPB_BUSY; + } + + return RETURN_OK; +} + +void CCSDSIPCoreBridge::isPtmeBufferEmpty() { + ReturnValue_t result = RETURN_OK; + int papbEmptyState = 1; + + result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState); + + if (result != RETURN_OK) { + sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Failed to read papb empty signal" + << std::endl; + return; + } + + if (papbEmptyState == 1) { + sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Buffer is empty" << std::endl; + } + else { + sif::debug << "CCSDSIPCoreBridge::isPtmeBufferEmpty: Buffer is not empty" << std::endl; + } + return; +} + +ReturnValue_t CCSDSIPCoreBridge::sendTestFrame() { /** Size of one complete transfer frame data field amounts to 1105 bytes */ uint8_t testPacket[1105]; @@ -50,79 +131,6 @@ ReturnValue_t CCSDSIPCoreBridge::handleTm() { if(result != RETURN_OK) { return result; } - return RETURN_OK; -} - -ReturnValue_t CCSDSIPCoreBridge::sendTm(const uint8_t * data, size_t dataLen) { - - if(pollPapbSignal() == RETURN_OK) { - ptmeBufferEmpty(); - startPacketTransfer(); - } - - for(size_t idx = 0; idx < dataLen; idx++) { - if(pollPapbSignal() == RETURN_OK) { - *(static_cast(ptmeBaseAddress) + PTME_DATA_REG_OFFSET) = - static_cast(*(data + idx)); - } - else { - sif::debug << "CCSDSIPCoreBridge::sendTm: Only written " << idx - 1 << " of " << dataLen - << " data" << std::endl; - return RETURN_FAILED; - } - } - - if(pollPapbSignal() == RETURN_OK) { - ptmeBufferEmpty(); - endPacketTransfer(); - } - return RETURN_OK; -} - -void CCSDSIPCoreBridge::startPacketTransfer() { - *(static_cast(ptmeBaseAddress)) = PTME_CONFIG_START; -} - -void CCSDSIPCoreBridge::endPacketTransfer() { - *(static_cast(ptmeBaseAddress)) = PTME_CONFIG_END; -} - -ReturnValue_t CCSDSIPCoreBridge::pollPapbSignal() { - int papbBusyState = 0; - ReturnValue_t result = RETURN_OK; - - /** Check if PAPB interface is ready to receive data */ - result = gpioComIF->readGpio(papbBusyId, &papbBusyState); - if (result != RETURN_OK) { - sif::debug << "CCSDSIPCoreBridge::pollPapbSignal: Failed to read papb busy signal" - << std::endl; - return RETURN_FAILED; - } - if (!papbBusyState) { - sif::debug << "CCSDSIPCoreBridge::pollPapbSignal: PAPB busy" << std::endl; - return PAPB_BUSY; - } return RETURN_OK; } - -void CCSDSIPCoreBridge::ptmeBufferEmpty() { - ReturnValue_t result = RETURN_OK; - int papbEmptyState = 1; - - result = gpioComIF->readGpio(papbEmptyId, &papbEmptyState); - - if (result != RETURN_OK) { - sif::debug << "CCSDSIPCoreBridge::ptmeBufferEmpty: Failed to read papb empty signal" - << std::endl; - return; - } - - if (papbEmptyState == 1) { - sif::debug << "CCSDSIPCoreBridge::ptmeBufferEmpty: Buffer is empty" << std::endl; - } - else { - sif::debug << "CCSDSIPCoreBridge::ptmeBufferEmpty: Buffer is not empty" << std::endl; - } - return; -} diff --git a/mission/obc/CCSDSIPCoreBridge.h b/mission/obc/CCSDSIPCoreBridge.h index e54875e0..5b7674e9 100644 --- a/mission/obc/CCSDSIPCoreBridge.h +++ b/mission/obc/CCSDSIPCoreBridge.h @@ -5,6 +5,7 @@ #include #include #include +#include "OBSWConfig.h" /** * @brief This class handles the interfacing to the telemetry (PTME) and telecommand (PDEC) IP @@ -38,8 +39,8 @@ public: protected: /** - * Overwriting this function for testing purpose. Function is periodically called in - * performOperation. + * Overwriting this function to provide the capability of testing the PTME IP Core + * implementation. */ virtual ReturnValue_t handleTm() override; @@ -73,8 +74,9 @@ private: /** * Writing to this offset within the PTME memory space will insert data for encoding to the * PTME IP core. + * The address offset is 0x400 (= 4 * 256) */ - static const int PTME_DATA_REG_OFFSET = 0x400; + static const int PTME_DATA_REG_OFFSET = 256; LinuxLibgpioIF* gpioComIF = nullptr; @@ -90,8 +92,7 @@ private: /** The file descriptor of the UIO driver */ int fd; - /** PTME base address */ - void* ptmeBaseAddress = nullptr; + uint32_t* ptmeBaseAddress = nullptr; /** * @brief This function sends the config byte to the PTME IP Core to initiate a packet @@ -111,13 +112,19 @@ private: * * @return RETURN_OK when ready to receive data else PAPB_BUSY. */ - ReturnValue_t pollPapbSignal(); + ReturnValue_t pollPapbBusySignal(); /** * @brief This function can be used for debugging to check wheter there are packets in * the packet buffer of the PTME or not. */ - void ptmeBufferEmpty(); + void isPtmeBufferEmpty(); + + /** + * @brief This function sends a complete telemetry transfer frame data field (1105 bytes) + * to the input of the PTME IP Core. Can be used to test the implementation. + */ + ReturnValue_t sendTestFrame(); }; #endif /* MISSION_OBC_CCSDSIPCOREBRIDGE_H_ */ diff --git a/thirdparty/etl b/thirdparty/etl index c308dc42..0efecca7 160000 --- a/thirdparty/etl +++ b/thirdparty/etl @@ -1 +1 @@ -Subproject commit c308dc427b7a34e54f33860fb2e244564b2740b4 +Subproject commit 0efecca700c6d0847f91b5540638571ba298c793 diff --git a/tmtc b/tmtc index 06750809..574a3e92 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 06750809cb52044392e0683896538a652f11a512 +Subproject commit 574a3e92074d9d4d0335dad3ddc5962e1369f5d5