From d28ec2c31a872dd7c56d9f798cc7e545a3b949e8 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 11 Aug 2023 16:15:56 +0200 Subject: [PATCH] config word functions pass value now by reference and return returnvalue --- linux/ipcore/PdecConfig.cpp | 56 ++++++++++++++++++++---------------- linux/ipcore/PdecConfig.h | 15 +++++++--- linux/ipcore/PdecHandler.cpp | 20 +++++++++++-- 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index 3bc478a8..8399f6d3 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -115,14 +115,22 @@ ReturnValue_t PdecConfig::getNegativeWindow(uint8_t& negativeWindow) { } ReturnValue_t PdecConfig::writeFrameHeaderFirstWord() { - uint32_t word = createFirstWord(); - *(memoryBaseAddress + FRAME_HEADER_OFFSET) = word; + uint32_t word = 0; + ReturnValue_t result = createFirstWord(&word); + if (result != returnvalue::OK) { + return result; + } + *(memoryBaseAddress + FRAME_HEADER_OFFSET + OFFSET_FIRST_CONFIG_WORD) = word; return returnvalue::OK; } ReturnValue_t PdecConfig::writeFrameHeaderSecondWord() { - uint32_t word = createSecondWord(); - *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1) = word; + uint32_t word = 0; + ReturnValue_t result = createSecondWord(&word); + if (result != returnvalue::OK) { + return result; + } + *(memoryBaseAddress + FRAME_HEADER_OFFSET + OFFSET_SECOND_CONFIG_WORD) = word; return returnvalue::OK; } @@ -162,48 +170,48 @@ uint8_t PdecConfig::getOddParity(uint8_t number) { return parityBit; } -uint32_t PdecConfig::createFirstWord() { - uint32_t word = 0; - word |= (VERSION_ID << 30); +ReturnValue_t PdecConfig::createFirstWord(uint32_t* word) { + *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 |= (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); + *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; + *word |= static_cast(positiveWindow); + return returnvalue::OK; } -uint32_t PdecConfig::createSecondWord() { +ReturnValue_t PdecConfig::createSecondWord(uint32_t* word) { 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; + *word = 0; + *word = 0; + *word |= (static_cast(negativeWindow) << 24); + *word |= (HIGH_AU_MAP_ID << 16); + *word |= (ENABLE_DERANDOMIZER << 8); + return returnvalue::OK; } uint32_t PdecConfig::readbackFirstWord() { - return *(memoryBaseAddress + FRAME_HEADER_OFFSET); + return *(memoryBaseAddress + FRAME_HEADER_OFFSET + OFFSET_FIRST_CONFIG_WORD); } uint32_t PdecConfig::readbackSecondWord() { - return *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1); + return *(memoryBaseAddress + FRAME_HEADER_OFFSET + OFFSET_SECOND_CONFIG_WORD); } diff --git a/linux/ipcore/PdecConfig.h b/linux/ipcore/PdecConfig.h index 3f17f08f..e3faee4d 100644 --- a/linux/ipcore/PdecConfig.h +++ b/linux/ipcore/PdecConfig.h @@ -51,16 +51,21 @@ class PdecConfig { /** * @brief Creates the first word of the PDEC configuration * - * @return The created config word + * @param word The created word will be written to this pointer + * + * @return OK if successful, otherwise error return value + * */ - uint32_t createFirstWord(); + ReturnValue_t createFirstWord(uint32_t* word); /** * @brief Creates the second word of the PDEC configuration * - * @return The created config word + * @param word The created word will be written to this pointer + * + * @return OK if successful, otherwise error return value */ - uint32_t createSecondWord(); + ReturnValue_t createSecondWord(uint32_t* word); /** * @brief Reads first config word from the config memory @@ -94,6 +99,8 @@ class PdecConfig { // 0x200 / 4 = 0x80 static const uint32_t FRAME_HEADER_OFFSET = 0x80; + static const uint32_t OFFSET_FIRST_CONFIG_WORD = 0; + static const uint32_t OFFSET_SECOND_CONFIG_WORD = 1; static const uint32_t MAP_ADDR_LUT_OFFSET = 0xA0; static const uint32_t MAP_CLK_FREQ_OFFSET = 0x90; diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 86df3ad2..91aec623 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -579,8 +579,24 @@ void PdecHandler::handleIReason(uint32_t pdecFar, ReturnValue_t parameter1) { } void PdecHandler::checkConfig() { - uint32_t firstWord = pdecConfig.createFirstWord(); - uint32_t secondWord = pdecConfig.createSecondWord(); + uint32_t firstWord = 0; + ReturnValue_t result = pdecConfig.createFirstWord(&firstWord); + if (result != returnvalue::OK) { + // This should normally never happen during runtime. So here is just + // output a warning + sif::warning << "PdecHandler::checkConfig: Failed to create first word" + << std::endl; + return; + } + uint32_t secondWord = 0; + result = pdecConfig.createSecondWord(&secondWord); + if (result != returnvalue::OK) { + // This should normally never happen during runtime. So here is just + // output a warning + sif::warning << "PdecHandler::checkConfig: Failed to create second word" + << std::endl; + return; + } if (firstWord != pdecConfig.readbackFirstWord() or secondWord != pdecConfig.readbackSecondWord()) { triggerEvent(PDEC_CONFIG_CORRUPTED, firstWord, secondWord);