From c3bca9bb5426607042631b7b40df17e395656ff2 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 7 Aug 2023 17:08:33 +0200 Subject: [PATCH] added event which is triggered when config of pdec is corrupted --- linux/ipcore/PdecConfig.cpp | 90 +++++++++++++++++++++--------------- linux/ipcore/PdecConfig.h | 32 ++++++++++++- linux/ipcore/PdecHandler.cpp | 10 ++++ linux/ipcore/PdecHandler.h | 5 ++ linux/ipcore/pdec.h | 4 ++ 5 files changed, 103 insertions(+), 38 deletions(-) diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index a41c5ba6..3bc478a8 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -22,11 +22,11 @@ ReturnValue_t PdecConfig::write() { if (result != returnvalue::OK) { return result; } - result = writeFrameHeaderFirstOctet(); + result = writeFrameHeaderFirstWord(); if (result != returnvalue::OK) { return result; } - result = writeFrameHeaderSecondOctet(); + result = writeFrameHeaderSecondWord(); if (result != returnvalue::OK) { return result; } @@ -77,7 +77,7 @@ ReturnValue_t PdecConfig::setPositiveWindow(uint8_t pw) { return result; } // Rewrite second config word which contains the positive window parameter - writeFrameHeaderSecondOctet(); + writeFrameHeaderSecondWord(); return returnvalue::OK; } @@ -92,7 +92,7 @@ ReturnValue_t PdecConfig::setNegativeWindow(uint8_t nw) { return result; } // Rewrite second config word which contains the negative window parameter - writeFrameHeaderSecondOctet(); + writeFrameHeaderSecondWord(); return returnvalue::OK; } @@ -114,42 +114,14 @@ ReturnValue_t PdecConfig::getNegativeWindow(uint8_t& negativeWindow) { return returnvalue::OK; } -ReturnValue_t PdecConfig::writeFrameHeaderFirstOctet() { - uint32_t word = 0; - word |= (VERSION_ID << 30); - - // Setting the bypass flag and the control command flag should not have any - // implication on the operation of the PDEC IP Core - word |= (BYPASS_FLAG << 29); - word |= (CONTROL_COMMAND_FLAG << 28); - - word |= (RESERVED_FIELD_A << 26); - word |= (SPACECRAFT_ID << 16); - word |= (VIRTUAL_CHANNEL << 10); - word |= (DUMMY_BITS << 8); - uint8_t positiveWindow = 0; - ReturnValue_t result = - localParameterHandler.getValue(pdecconfigdefs::paramkeys::POSITIVE_WINDOW, positiveWindow); - if (result != returnvalue::OK) { - return result; - } - word |= static_cast(positiveWindow); +ReturnValue_t PdecConfig::writeFrameHeaderFirstWord() { + uint32_t word = createFirstWord(); *(memoryBaseAddress + FRAME_HEADER_OFFSET) = word; return returnvalue::OK; } -ReturnValue_t PdecConfig::writeFrameHeaderSecondOctet() { - uint8_t negativeWindow = 0; - ReturnValue_t result = - localParameterHandler.getValue(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, negativeWindow); - if (result != returnvalue::OK) { - return result; - } - uint32_t word = 0; - word = 0; - word |= (static_cast(negativeWindow) << 24); - word |= (HIGH_AU_MAP_ID << 16); - word |= (ENABLE_DERANDOMIZER << 8); +ReturnValue_t PdecConfig::writeFrameHeaderSecondWord() { + uint32_t word = createSecondWord(); *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1) = word; return returnvalue::OK; } @@ -189,3 +161,49 @@ uint8_t PdecConfig::getOddParity(uint8_t number) { parityBit = ~(countBits & 0x1) & 0x1; return parityBit; } + +uint32_t PdecConfig::createFirstWord() { + uint32_t word = 0; + word |= (VERSION_ID << 30); + + // Setting the bypass flag and the control command flag should not have any + // implication on the operation of the PDEC IP Core + word |= (BYPASS_FLAG << 29); + word |= (CONTROL_COMMAND_FLAG << 28); + + word |= (RESERVED_FIELD_A << 26); + word |= (SPACECRAFT_ID << 16); + word |= (VIRTUAL_CHANNEL << 10); + word |= (DUMMY_BITS << 8); + uint8_t positiveWindow = 0; + ReturnValue_t result = + localParameterHandler.getValue(pdecconfigdefs::paramkeys::POSITIVE_WINDOW, positiveWindow); + if (result != returnvalue::OK) { + return result; + } + word |= static_cast(positiveWindow); + return word; +} + +uint32_t PdecConfig::createSecondWord() { + uint8_t negativeWindow = 0; + ReturnValue_t result = + localParameterHandler.getValue(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, negativeWindow); + if (result != returnvalue::OK) { + return result; + } + uint32_t word = 0; + word = 0; + word |= (static_cast(negativeWindow) << 24); + word |= (HIGH_AU_MAP_ID << 16); + word |= (ENABLE_DERANDOMIZER << 8); + return word; +} + +uint32_t PdecConfig::readbackFirstWord() { + return *(memoryBaseAddress + FRAME_HEADER_OFFSET); +} + +uint32_t PdecConfig::readbackSecondWord() { + return *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1); +} diff --git a/linux/ipcore/PdecConfig.h b/linux/ipcore/PdecConfig.h index f7203eec..3f17f08f 100644 --- a/linux/ipcore/PdecConfig.h +++ b/linux/ipcore/PdecConfig.h @@ -48,6 +48,34 @@ class PdecConfig { ReturnValue_t getPositiveWindow(uint8_t& positiveWindow); ReturnValue_t getNegativeWindow(uint8_t& negativeWindow); + /** + * @brief Creates the first word of the PDEC configuration + * + * @return The created config word + */ + uint32_t createFirstWord(); + + /** + * @brief Creates the second word of the PDEC configuration + * + * @return The created config word + */ + uint32_t createSecondWord(); + + /** + * @brief Reads first config word from the config memory + * + * @return The config word + */ + uint32_t readbackFirstWord(); + + /** + * @brief Reads the second config word from the config memory + * + * @return The config word + */ + uint32_t readbackSecondWord(); + private: // TC transfer frame configuration parameters static const uint8_t VERSION_ID = 0; @@ -102,8 +130,8 @@ class PdecConfig { */ ReturnValue_t createPersistentConfig(); - ReturnValue_t writeFrameHeaderFirstOctet(); - ReturnValue_t writeFrameHeaderSecondOctet(); + ReturnValue_t writeFrameHeaderFirstWord(); + ReturnValue_t writeFrameHeaderSecondWord(); void writeMapConfig(); /** diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index cc074ddd..86df3ad2 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -478,6 +478,7 @@ bool PdecHandler::checkFrameAna(uint32_t pdecFar) { } case (FrameAna_t::FRAME_DIRTY): { triggerEvent(INVALID_TC_FRAME, FRAME_DIRTY_RETVAL); + checkConfig(); sif::warning << "PdecHandler::checkFrameAna: Frame dirty" << std::endl; break; } @@ -577,6 +578,15 @@ void PdecHandler::handleIReason(uint32_t pdecFar, ReturnValue_t parameter1) { } } +void PdecHandler::checkConfig() { + uint32_t firstWord = pdecConfig.createFirstWord(); + uint32_t secondWord = pdecConfig.createSecondWord(); + if (firstWord != pdecConfig.readbackFirstWord() or + secondWord != pdecConfig.readbackSecondWord()) { + triggerEvent(PDEC_CONFIG_CORRUPTED, firstWord, secondWord); + } +} + void PdecHandler::handleNewTc() { ReturnValue_t result = returnvalue::OK; diff --git a/linux/ipcore/PdecHandler.h b/linux/ipcore/PdecHandler.h index 882dca50..11ae4de3 100644 --- a/linux/ipcore/PdecHandler.h +++ b/linux/ipcore/PdecHandler.h @@ -282,6 +282,11 @@ class PdecHandler : public SystemObject, */ void handleIReason(uint32_t pdecFar, ReturnValue_t parameter1); + /** + * @brief Checks if PDEC configuration is still correct + */ + void checkConfig(); + /** * @brief Handles the reception of new TCs. Reads the pointer to the storage location of the * new TC segment, extracts the PUS packet and forwards the data to the object diff --git a/linux/ipcore/pdec.h b/linux/ipcore/pdec.h index 0574ee73..de703c5a 100644 --- a/linux/ipcore/pdec.h +++ b/linux/ipcore/pdec.h @@ -71,6 +71,10 @@ static constexpr Event OPEN_IRQ_FILE_FAILED = event::makeEvent(SUBSYSTEM_ID, 13, //! [EXPORT] : [COMMENT] PDEC initialization failed. This might also be due to the persistent //! confiuration never becoming available, for example due to SD card issues. static constexpr Event PDEC_INIT_FAILED = event::makeEvent(SUBSYSTEM_ID, 14, severity::HIGH); +//! [EXPORT] : [COMMENT] The PDEC configuration area has been corrupted +//! P1: The first configuration word +//! P2: The second configuration word +static constexpr Event PDEC_CONFIG_CORRUPTED = event::makeEvent(SUBSYSTEM_ID, 15, severity::HIGH); // Action IDs static constexpr ActionId_t PRINT_CLCW = 0;