From 60c99fdbfb3f0d79033de583495a76cf356edc0c Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 13 Feb 2023 11:28:27 +0100 Subject: [PATCH 01/15] local parameter handler wip --- bsp_q7s/core/ObjectFactory.cpp | 6 + bsp_q7s/core/ObjectFactory.h | 2 + bsp_q7s/fmObjectFactory.cpp | 2 + bsp_q7s/memory/CMakeLists.txt | 2 +- bsp_q7s/memory/LocalParameterHandler.cpp | 22 +++ bsp_q7s/memory/LocalParameterHandler.h | 66 +++++++++ linux/ipcore/PdecConfig.cpp | 139 ++++++++++++++---- linux/ipcore/PdecConfig.h | 91 +++++++++++- linux/ipcore/PdecHandler.cpp | 107 +++++++------- linux/ipcore/PdecHandler.h | 58 ++++---- mission/config/configfile.h | 9 ++ mission/system/objects/ComSubsystem.h | 1 + mission/utility/GlobalConfigFileDefinitions.h | 2 + mission/utility/GlobalConfigHandler.cpp | 47 +++--- mission/utility/GlobalConfigHandler.h | 15 +- 15 files changed, 417 insertions(+), 152 deletions(-) create mode 100644 bsp_q7s/memory/LocalParameterHandler.cpp create mode 100644 bsp_q7s/memory/LocalParameterHandler.h create mode 100644 mission/config/configfile.h diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 1fb9efed..47ca4e18 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -51,6 +51,8 @@ #include "mission/system/tree/comModeTree.h" #include "mission/system/tree/payloadModeTree.h" #include "mission/system/tree/tcsModeTree.h" +#include "mission/utility/GlobalConfigHandler.h" +#include "mission/config/configfile.h" #include "tmtc/pusIds.h" #if OBSW_TEST_LIBGPIOD == 1 #include "linux/boardtest/LibgpiodTest.h" @@ -966,3 +968,7 @@ void ObjectFactory::testAcsBrdAss(AcsBoardAssembly* acsAss) { sif::warning << "Sending mode command failed" << std::endl; } } + +void ObjectFactory::createGlobalConfigHandler() { + new GlobalConfigHandler(objects::GLOBAL_JSON_CFG, configfile::sdrelative); +} diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index c55e8452..853fd9ce 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -48,6 +48,8 @@ void createTestComponents(LinuxLibgpioIF* gpioComIF); void testAcsBrdAss(AcsBoardAssembly* assAss); +void createGlobalConfigHandler(); + }; // namespace ObjectFactory #endif /* BSP_Q7S_OBJECTFACTORY_H_ */ diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index 44b53225..40d2454e 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -86,6 +86,8 @@ void ObjectFactory::produce(void* args) { createTestComponents(gpioComIF); #endif /* OBSW_ADD_TEST_CODE == 1 */ + createGlobalConfigHandler(); + createMiscComponents(); createThermalController(); createAcsController(true); diff --git a/bsp_q7s/memory/CMakeLists.txt b/bsp_q7s/memory/CMakeLists.txt index 06909a0a..4ff840c8 100644 --- a/bsp_q7s/memory/CMakeLists.txt +++ b/bsp_q7s/memory/CMakeLists.txt @@ -1 +1 @@ -target_sources(${OBSW_NAME} PRIVATE scratchApi.cpp) +target_sources(${OBSW_NAME} PRIVATE scratchApi.cpp LocalParameterHandler.cpp) diff --git a/bsp_q7s/memory/LocalParameterHandler.cpp b/bsp_q7s/memory/LocalParameterHandler.cpp new file mode 100644 index 00000000..03a5ba82 --- /dev/null +++ b/bsp_q7s/memory/LocalParameterHandler.cpp @@ -0,0 +1,22 @@ +#include "LocalParameterHandler.h" +#include + +LocalParameterHandler::LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan) + : sdRelativeName(sdRelativeName), sdcMan(sdcMan) {} + +LocalParameterHandler::~LocalParameterHandler() { +} + +ReturnValue_t LocalParameterHandler::initialize() { + std::string mountPrefix = sdcMan->getCurrentMountPrefix(); + std::string fullname = mountPrefix + "/" + sdRelativeName; + setFullName(fullname); + ReturnValue_t result = readJsonFile(); + if (result != returnvalue::OK) { + sif::warning << "LocalParameterHandler::initialize: Failed to read json file" + << getFullName() << std::endl; + return result; + } + return returnvalue::OK; +} + diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h new file mode 100644 index 00000000..57d646cb --- /dev/null +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -0,0 +1,66 @@ +#ifndef BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ +#define BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ + +#include + +#include +#include + +/** + * @brief Class to handle persistent parameters + * + * @details Use the insertValue function to add parameters + */ +class LocalParameterHandler : public NVMParameterBase { + public: + /** + * @brief Constructor + * + * @param sdRelativeName Absolute name of json file relative to mount + * directory of SD card. E.g. conf/example.json + * @param sdcMan Pointer to SD card manager + */ + LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan); + virtual ~LocalParameterHandler(); + + /** + * @brief Will initialize the local parameter handler + * + * @return OK if successful, otherwise error return value + */ + ReturnValue_t initialize(); + + /** + * @brief Function to add parameter to json file + * + * @param key The string to identify the parameter + * @param value The value to set for this parameter + * + * @return OK if successful, otherwise error return value + * + * @details The function will add the parameter only if it is not already + * present in the json file + */ + template ReturnValue_t addParameter(std::string key, T value); + + private: + + // Name relative to mount point of SD card where parameters will be stored + std::string sdRelativeName; + + SdCardMountedIF* sdcMan; +}; + +template inline ReturnValue_t LocalParameterHandler::addParameter(std::string key, T value) { + ReturnValue_t result = insertValue(key, value); + if (result != returnvalue::OK) { + return result; + } + result = writeJsonFile(); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; +} + +#endif /* BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ */ diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index 21de4610..152ea320 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -2,41 +2,126 @@ #include "fsfw/serviceinterface/ServiceInterface.h" -PdecConfig::PdecConfig() { initialize(); } +PdecConfig::PdecConfig() + : localParameterHandler("conf/pdecconfig", SdCardManager::instance()) { +} PdecConfig::~PdecConfig() {} -void PdecConfig::initialize() { - 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); - word |= POSITIVE_WINDOW; - configWords[0] = word; - word = 0; - word |= (NEGATIVE_WINDOW << 24); - word |= (HIGH_AU_MAP_ID << 16); - word |= (ENABLE_DERANDOMIZER << 8); - configWords[1] = word; +void PdecConfig::setMemoryBaseAddress(uint32_t* memoryBaseAddress_) { + memoryBaseAddress = memoryBaseAddress_; } -uint32_t PdecConfig::getConfigWord(uint8_t wordNo) { - if (wordNo >= CONFIG_WORDS_NUM) { - sif::error << "PdecConfig::getConfigWord: Invalid word number" << std::endl; - return 0; - } - return configWords[wordNo]; +ReturnValue_t PdecConfig::write() { + if (memoryBaseAddress == nullptr) { + sif::error << "PdecConfig::write: Memory base address not set" << std::endl; + return returnvalue::FAILED; + } + + writeFrameHeaderFirstOctet(); + writeFrameHeaderSecondOctet(); + writeMapConfig(); + return returnvalue::FAILED; } uint32_t PdecConfig::getImrReg() { return static_cast(enableNewFarIrq << 2) | static_cast(enableTcAbortIrq << 1) | static_cast(enableTcNewIrq); } + +ReturnValue_t PdecConfig::setPositiveWindow(uint8_t pw) { + if (memoryBaseAddress == nullptr) { + sif::error << "PdecConfig::setPositiveWindow: Memory base address not set" + << std::endl; + return returnvalue::FAILED; + } + positiveWindow = pw; + // Rewrite second config word which contains the positive window parameter + writeFrameHeaderSecondOctet(); + return returnvalue::OK; +} + +ReturnValue_t PdecConfig::setNegativeWindow(uint8_t nw) { + if (memoryBaseAddress == nullptr) { + sif::error << "PdecConfig::setPositiveWindow: Memory base address not set" + << std::endl; + return returnvalue::FAILED; + } + negativeWindow = nw; + // Rewrite second config word which contains the negative window parameter + writeFrameHeaderSecondOctet(); + return returnvalue::OK; +} + +uint8_t PdecConfig::getPositiveWindow() { + return positiveWindow; +} + +uint8_t PdecConfig::getNegativeWindow() { + return negativeWindow; +} + +void 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); + word |= positiveWindow; + *(memoryBaseAddress + FRAME_HEADER_OFFSET) = word; +} + +void PdecConfig::writeFrameHeaderSecondOctet() { + uint32_t word = 0; + word = 0; + word |= (negativeWindow << 24); + word |= (HIGH_AU_MAP_ID << 16); + word |= (ENABLE_DERANDOMIZER << 8); + *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1) = word; +} + +void PdecConfig::writeMapConfig() { + // Configure all MAP IDs as invalid + for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { + *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + idx / 4) = + NO_DESTINATION << 24 | NO_DESTINATION << 16 | NO_DESTINATION << 8 | NO_DESTINATION; + } + + // All TCs with MAP ID 7 will be routed to the PM module (can then be read from memory) + uint8_t routeToPm = calcMapAddrEntry(PM_BUFFER); + *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + 1) = + (NO_DESTINATION << 24) | (NO_DESTINATION << 16) | (NO_DESTINATION << 8) | routeToPm; + + // Write map id clock frequencies + for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { + *(memoryBaseAddress + MAP_CLK_FREQ_OFFSET + idx / 4) = + MAP_CLK_FREQ << 24 | MAP_CLK_FREQ << 16 | MAP_CLK_FREQ << 8 | MAP_CLK_FREQ; + } +} + +uint8_t PdecConfig::calcMapAddrEntry(uint8_t moduleId) { + uint8_t lutEntry = 0; + uint8_t parity = getOddParity(moduleId | (1 << VALID_POSITION)); + lutEntry = (parity << PARITY_POSITION) | (1 << VALID_POSITION) | moduleId; + return lutEntry; +} + +uint8_t PdecConfig::getOddParity(uint8_t number) { + uint8_t parityBit = 0; + uint8_t countBits = 0; + for (unsigned int idx = 0; idx < sizeof(number) * 8; idx++) { + countBits += (number >> idx) & 0x1; + } + parityBit = ~(countBits & 0x1) & 0x1; + return parityBit; +} + + + diff --git a/linux/ipcore/PdecConfig.h b/linux/ipcore/PdecConfig.h index 3d909581..0b665c6c 100644 --- a/linux/ipcore/PdecConfig.h +++ b/linux/ipcore/PdecConfig.h @@ -3,28 +3,51 @@ #include +#include "bsp_q7s/memory/LocalParameterHandler.h" +#include "bsp_q7s/fs/SdCardManager.h" #include "fsfw/returnvalues/returnvalue.h" +#include "pdec.h" /** * @brief This class generates the configuration words for the configuration memory of the PDEC * IP Cores. * - * @details Fields are initialized according to pecification in PDEC datasheet section 6.11.3.1 + * @details Fields are initialized according to specification in PDEC datasheet section 6.11.3.1 * PROM usage. * * @author J. Meier */ class PdecConfig { public: + /** + * @brief Constructor + */ PdecConfig(); virtual ~PdecConfig(); /** - * @brief Returns the configuration word by specifying the position. + * @brief Sets the memory base address pointer + */ + void setMemoryBaseAddress(uint32_t* memoryBaseAddress_); + + /** + * @brief Will write the config to the PDEC configuration memory. New config + * becomes active after resetting PDEC. + */ + ReturnValue_t write(); + + /** + * @brief Returns the value to write to the interrupt mask register. This + * value defines which interrupts should be enabled/disabled. */ - uint32_t getConfigWord(uint8_t wordNo); uint32_t getImrReg(); + ReturnValue_t setPositiveWindow(uint8_t pw); + ReturnValue_t setNegativeWindow(uint8_t nw); + + uint8_t getPositiveWindow(); + uint8_t getNegativeWindow(); + private: // TC transfer frame configuration parameters static const uint8_t VERSION_ID = 0; @@ -36,21 +59,73 @@ class PdecConfig { static const uint8_t RESERVED_FIELD_A = 0; static const uint16_t SPACECRAFT_ID = 0x3DC; static const uint16_t DUMMY_BITS = 0; - // Parameters to control the FARM for AD frames - // Set here for future use - static const uint8_t POSITIVE_WINDOW = 10; - static const uint8_t NEGATIVE_WINDOW = 151; static const uint8_t HIGH_AU_MAP_ID = 0xF; static const uint8_t ENABLE_DERANDOMIZER = 1; static const uint8_t CONFIG_WORDS_NUM = 2; + // 0x200 / 4 = 0x80 + static const uint32_t FRAME_HEADER_OFFSET = 0x80; + + static const uint32_t MAP_ADDR_LUT_OFFSET = 0xA0; + static const uint32_t MAP_CLK_FREQ_OFFSET = 0x90; + // MAP clock frequency. Must be a value between 1 and 13 otherwise the TC segment will be + // discarded + static const uint8_t MAP_CLK_FREQ = 2; + + static const uint8_t MAX_MAP_ADDR = 63; + // Writing this to the map address in the look up table will invalidate a MAP ID. + static const uint8_t NO_DESTINATION = 0; + static const uint8_t VALID_POSITION = 6; + static const uint8_t PARITY_POSITION = 7; + + /** + * TCs with map addresses (also know as Map IDs) assigned to this channel will be stored in + * the PDEC memory. + */ + static const uint8_t PM_BUFFER = 7; + + uint32_t* memoryBaseAddress = nullptr; + + // Pointer to object providing access to persistent configuration parameters + LocalParameterHandler localParameterHandler; + uint32_t configWords[CONFIG_WORDS_NUM]; bool enableTcNewIrq = true; bool enableTcAbortIrq = true; bool enableNewFarIrq = true; - void initialize(); + NVMParameterBase persistenParams; + + // Parameters to control the FARM for AD frames + // Set here for future use + uint8_t positiveWindow = 10; + uint8_t negativeWindow = 151; + + void writeFrameHeaderFirstOctet(); + void writeFrameHeaderSecondOctet(); + void writeMapConfig(); + + /** + * @brief This function calculates the entry for the configuration of the MAP ID routing. + * + * @param mapAddr The MAP ID to configure + * @param moduleId The destination module where all TCs with the map id mapAddr will be routed + * to. + * + * @details The PDEC has different modules where the TCs can be routed to. A lookup table is + * used which links the MAP ID field to the destination module. The entry for this + * lookup table is created by this function and must be stored in the configuration + * memory region of the PDEC. The entry has a specific format + */ + uint8_t calcMapAddrEntry(uint8_t moduleId); + + /** + * @brief This functions calculates the odd parity of the bits in number. + * + * @param number The number from which to calculate the odd parity. + */ + uint8_t getOddParity(uint8_t number); }; #endif /* LINUX_OBC_PDECCONFIG_H_ */ diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 57d59841..3d1b9d58 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -22,13 +22,15 @@ using namespace pdec; uint32_t PdecHandler::CURRENT_FAR = 0; PdecHandler::PdecHandler(object_id_t objectId, object_id_t tcDestinationId, - LinuxLibgpioIF* gpioComIF, gpioId_t pdecReset, UioNames names) + LinuxLibgpioIF* gpioComIF, gpioId_t pdecReset, UioNames names, + object_id_t globalConfigHandlerId) : SystemObject(objectId), tcDestinationId(tcDestinationId), gpioComIF(gpioComIF), pdecReset(pdecReset), actionHelper(this, nullptr), - uioNames(names) { + uioNames(names), + globalConfigHandlerId(globalConfigHandlerId) { auto mqArgs = MqArgs(objectId, static_cast(this)); commandQueue = QueueFactory::instance()->createMessageQueue( QUEUE_SIZE, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); @@ -61,6 +63,8 @@ ReturnValue_t PdecHandler::initialize() { result = configMemMapper.getMappedAdress(&memoryBaseAddress, UioMapper::Permissions::READ_WRITE); if (result != returnvalue::OK) { return ObjectManagerIF::CHILD_INIT_FAILED; + } else { + pdecConfig.setMemoryBaseAddress(memoryBaseAddress); } UioMapper ramMapper(uioNames.ramMemory); result = ramMapper.getMappedAdress(&ramBaseAddress, UioMapper::Permissions::READ_WRITE); @@ -72,8 +76,19 @@ ReturnValue_t PdecHandler::initialize() { sif::error << "Can not use IRQ mode if IRQ UIO name is invalid" << std::endl; return returnvalue::FAILED; } - PdecConfig pdecConfig; - writePdecConfigDuringReset(pdecConfig); + + globalConfigHandler = ObjectManager::instance()->get(objects::GLOBAL_JSON_CFG); + if (globalConfigHandler == nullptr) { + sif::error << "PdecHandler::initialize: Invalid global config handler" << std::endl; + return ObjectManagerIF::CHILD_INIT_FAILED; + } + + pdecConfig.setGlobalConfigHandler(globalConfigHandler); + result = pdecConfig.write(); + if (result != returnvalue::OK) { + sif::error << "PdecHandler::initialize: Failed to write PDEC config" << std::endl; + return ObjectManagerIF::CHILD_INIT_FAILED; + } result = releasePdec(); if (result != returnvalue::OK) { @@ -233,26 +248,45 @@ void PdecHandler::readCommandQueue(void) { MessageQueueId_t PdecHandler::getCommandQueue() const { return commandQueue->getId(); } -void PdecHandler::writePdecConfigDuringReset(PdecConfig& pdecConfig) { - *(memoryBaseAddress + FRAME_HEADER_OFFSET) = pdecConfig.getConfigWord(0); - *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1) = pdecConfig.getConfigWord(1); - - // Configure all MAP IDs as invalid - for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { - *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + idx / 4) = - NO_DESTINATION << 24 | NO_DESTINATION << 16 | NO_DESTINATION << 8 | NO_DESTINATION; +ReturnValue_t PdecHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, + const uint8_t* data, size_t size) { + switch (actionId) { + case PRINT_CLCW: + printClcw(); + return EXECUTION_FINISHED; + case PRINT_PDEC_MON: + printPdecMon(); + return EXECUTION_FINISHED; + default: + return COMMAND_NOT_IMPLEMENTED; } +} - // All TCs with MAP ID 7 will be routed to the PM module (can then be read from memory) - uint8_t routeToPm = calcMapAddrEntry(PM_BUFFER); - *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + 1) = - (NO_DESTINATION << 24) | (NO_DESTINATION << 16) | (NO_DESTINATION << 8) | routeToPm; - - // Write map id clock frequencies - for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { - *(memoryBaseAddress + MAP_CLK_FREQ_OFFSET + idx / 4) = - MAP_CLK_FREQ << 24 | MAP_CLK_FREQ << 16 | MAP_CLK_FREQ << 8 | MAP_CLK_FREQ; +ReturnValue_t PdecHandler::getParameter(uint8_t domainId, uint8_t uniqueIdentifier, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues, uint16_t startAtIndex) { + if ((domainId == 0) and (uniqueIdentifier == ParameterId::POSITIVE_WINDOW)) { + uint8_t newVal = 0; + ReturnValue_t result = newValues->getElement(&newVal); + if (result != returnvalue::OK) { + return result; + } + parameterWrapper->set(); + com::setCurrentDatarate(static_cast(newVal)); + return returnvalue::OK; + } else if ((domainId == 0) and + (uniqueIdentifier == static_cast(com::ParameterId::TRANSMITTER_TIMEOUT))) { + uint8_t newVal = 0; + ReturnValue_t result = newValues->getElement(&newVal); + if (result != returnvalue::OK) { + return result; + } + parameterWrapper->set(transmitterTimeout); + transmitterTimeout = newVal; + transmitterCountdown.setTimeout(transmitterTimeout); + return returnvalue::OK; } + return returnvalue::OK; } ReturnValue_t PdecHandler::resetFarStatFlag() { @@ -518,23 +552,6 @@ void PdecHandler::printTC(uint32_t tcLength) { sif::info << tcSegmentStream.str() << std::endl; } -uint8_t PdecHandler::calcMapAddrEntry(uint8_t moduleId) { - uint8_t lutEntry = 0; - uint8_t parity = getOddParity(moduleId | (1 << VALID_POSITION)); - lutEntry = (parity << PARITY_POSITION) | (1 << VALID_POSITION) | moduleId; - return lutEntry; -} - -uint8_t PdecHandler::getOddParity(uint8_t number) { - uint8_t parityBit = 0; - uint8_t countBits = 0; - for (unsigned int idx = 0; idx < sizeof(number) * 8; idx++) { - countBits += (number >> idx) & 0x1; - } - parityBit = ~(countBits & 0x1) & 0x1; - return parityBit; -} - uint32_t PdecHandler::getClcw() { return *(registerBaseAddress + PDEC_CLCW_OFFSET); } uint32_t PdecHandler::getPdecMon() { return *(registerBaseAddress + PDEC_MON_OFFSET); } @@ -620,17 +637,3 @@ std::string PdecHandler::getMonStatusString(uint32_t status) { break; } } - -ReturnValue_t PdecHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size) { - switch (actionId) { - case PRINT_CLCW: - printClcw(); - return EXECUTION_FINISHED; - case PRINT_PDEC_MON: - printPdecMon(); - return EXECUTION_FINISHED; - default: - return COMMAND_NOT_IMPLEMENTED; - } -} diff --git a/linux/ipcore/PdecHandler.h b/linux/ipcore/PdecHandler.h index 6ebd9ce6..8664e732 100644 --- a/linux/ipcore/PdecHandler.h +++ b/linux/ipcore/PdecHandler.h @@ -8,6 +8,8 @@ #include "eive/definitions.h" #include "fsfw/action/ActionHelper.h" #include "fsfw/action/HasActionsIF.h" +#include "fsfw/parameters/HasParametersIF.h" +#include "fsfw/parameters/ParameterHelper.h" #include "fsfw/objectmanager/SystemObject.h" #include "fsfw/returnvalues/returnvalue.h" #include "fsfw/storagemanager/StorageManagerIF.h" @@ -15,6 +17,7 @@ #include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" #include "fsfw_hal/common/gpio/gpioDefinitions.h" #include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h" +#include "mission/utility/GlobalConfigHandler.h" struct UioNames { const char* configMemory; @@ -41,7 +44,10 @@ struct UioNames { * * @author J. Meier */ -class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasActionsIF { +class PdecHandler : public SystemObject, + public ExecutableObjectIF, + public HasActionsIF, + public HasParametersIF { public: static constexpr dur_millis_t IRQ_TIMEOUT_MS = 500; @@ -55,9 +61,10 @@ class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasAc * @param pdecReset GPIO ID of GPIO connected to the reset signal of the PDEC. * @param uioConfigMemory String of uio device file same mapped to the PDEC memory space * @param uioregsiters String of uio device file same mapped to the PDEC register space + * @param globalConfigHandler Object ID of global config file handler */ PdecHandler(object_id_t objectId, object_id_t tcDestinationId, LinuxLibgpioIF* gpioComIF, - gpioId_t pdecReset, UioNames names); + gpioId_t pdecReset, UioNames names, object_id_t globalConfigHandlerId); virtual ~PdecHandler(); @@ -70,6 +77,10 @@ class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasAc ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t* data, size_t size) override; + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueIdentifier, + ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, + uint16_t startAtIndex) override; + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PDEC_HANDLER; //! [EXPORT] : [COMMENT] Frame acceptance report signals an invalid frame @@ -138,9 +149,6 @@ class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasAc static const int REGISTER_MAP_SIZE = 0x4000; #endif /* BOARD_TE0720 == 1 */ - // 0x200 / 4 = 0x80 - static const uint32_t FRAME_HEADER_OFFSET = 0x80; - static const size_t MAX_TC_SEGMENT_SIZE = 1017; static const uint8_t MAP_ID_MASK = 0x3F; @@ -150,15 +158,6 @@ class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasAc static const uint32_t PHYSICAL_RAM_BASE_ADDRESS = 0x26000000; #endif - static const uint32_t MAP_ADDR_LUT_OFFSET = 0xA0; - static const uint32_t MAP_CLK_FREQ_OFFSET = 0x90; - - static const uint8_t MAX_MAP_ADDR = 63; - // Writing this to the map address in the look up table will invalidate a MAP ID. - static const uint8_t NO_DESTINATION = 0; - static const uint8_t VALID_POSITION = 6; - static const uint8_t PARITY_POSITION = 7; - // Expected value stored in FAR register after reset static const uint32_t FAR_RESET = 0x7FE0; @@ -167,15 +166,13 @@ class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasAc static const uint32_t NO_RF_MASK = 0x8000; static const uint32_t NO_BITLOCK_MASK = 0x4000; - /** - * TCs with map addresses (also know as Map IDs) assigned to this channel will be stored in - * the PDEC memory. - */ - static const uint8_t PM_BUFFER = 7; - - // MAP clock frequency. Must be a value between 1 and 13 otherwise the TC segment will be - // discarded - static const uint8_t MAP_CLK_FREQ = 2; + class ParameterId { + public: + // ID of the parameter to update the positive window of AD frames + static const uint8_t POSITIVE_WINDOW = 0; + // ID of the parameter to update the negative window of AD frames + static const uint8_t NEGATIVE_WINDOW = 1; + }; enum class FrameAna_t : uint8_t { ABANDONED_CLTU, @@ -249,6 +246,15 @@ class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasAc UioNames uioNames; + // Object ID of global config file handler + object_id_t globalConfigHandlerId; + + ParameterHelper paramHelper; + + GlobalConfigHandler* globalConfigHandler = nullptr; + + PdecConfig pdecConfig; + /** * @brief Reads and handles messages stored in the commandQueue */ @@ -341,12 +347,6 @@ class PdecHandler : public SystemObject, public ExecutableObjectIF, public HasAc */ uint8_t calcMapAddrEntry(uint8_t moduleId); - /** - * @brief This functions calculates the odd parity of the bits in number. - * - * @param number The number from which to calculate the odd parity. - */ - uint8_t getOddParity(uint8_t number); /** * brief Returns the 32-bit wide communication link control word (CLCW) diff --git a/mission/config/configfile.h b/mission/config/configfile.h new file mode 100644 index 00000000..eb8fb0a5 --- /dev/null +++ b/mission/config/configfile.h @@ -0,0 +1,9 @@ +#ifndef MISSION_CONFIG_CONFIGFILE_H_ +#define MISSION_CONFIG_CONFIGFILE_H_ + +namespace configfile { + // Name of global config file relative to currently mounted SD card + static const char sdrelative[] = "config/global_config.json"; +} + +#endif /* MISSION_CONFIG_CONFIGFILE_H_ */ diff --git a/mission/system/objects/ComSubsystem.h b/mission/system/objects/ComSubsystem.h index ac8cc60f..b1bbeed9 100644 --- a/mission/system/objects/ComSubsystem.h +++ b/mission/system/objects/ComSubsystem.h @@ -50,6 +50,7 @@ class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { // Maximum time after which the transmitter will be turned of. This is a // protection mechanism due prevent the syrlinks from overheating uint32_t transmitterTimeout = 0; + ParameterHelper paramHelper; MessageQueueIF* eventQueue = nullptr; diff --git a/mission/utility/GlobalConfigFileDefinitions.h b/mission/utility/GlobalConfigFileDefinitions.h index 2e7d133a..2c9b6b66 100644 --- a/mission/utility/GlobalConfigFileDefinitions.h +++ b/mission/utility/GlobalConfigFileDefinitions.h @@ -15,6 +15,8 @@ enum ParamIds : uint8_t { PARAM0 = 0, PARAM1 = 1, PARAM2 = 2, + PDEC_PW = 3, + PDEC_NW = 4 }; #endif /* MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ */ diff --git a/mission/utility/GlobalConfigHandler.cpp b/mission/utility/GlobalConfigHandler.cpp index bb4b3d7d..ffd1963b 100644 --- a/mission/utility/GlobalConfigHandler.cpp +++ b/mission/utility/GlobalConfigHandler.cpp @@ -23,23 +23,24 @@ GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string confi CONFIG_LOCK = MutexFactory::instance()->createMutex(); } } + ReturnValue_t GlobalConfigHandler::initialize() { ReturnValue_t result = SystemObject::initialize(); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize() failed with " + sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize failed with " << result << std::endl; #endif return result; } - result = ReadConfigFile(); + result = readConfigFile(); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName() << std::endl; #endif - result = ResetConfigFile(); + result = resetConfigFile(); if (result != returnvalue::OK) { return result; } @@ -63,6 +64,7 @@ ReturnValue_t GlobalConfigHandler::lockConfigFile() { result = CONFIG_LOCK->lockMutex(MutexIF::TimeoutType::WAITING, 10); return result; } + ReturnValue_t GlobalConfigHandler::unlockConfigFile() { ReturnValue_t result = returnvalue::OK; result = CONFIG_LOCK->unlockMutex(); @@ -70,34 +72,21 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile() { } template -ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) { +ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string paramName, T data) { ReturnValue_t result = returnvalue::OK; ReturnValue_t resultSet = returnvalue::OK; result = lockConfigFile(); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result + sif::info << "GlobalConfigHandler::setConfigFileValue: Lock mutex failed with " << result << std::endl; #endif return result; } - std::string paramString; - paramString = PARAM_KEY_MAP[paramID]; - - // Check if key exists in map before setting value. No check is done in setValue! Somehow - // PARAM_KEY_MAP.count(paramID) == 0 does not work - if (paramString.empty() == true) { -#if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::setConfigFileValue ParamId " << PARAM_KEY_MAP[paramID] - << " not found!" << std::endl; -#endif - triggerEvent(SET_CONFIGFILEVALUE_FAILED, 1, 0); - return returnvalue::FAILED; - } - - resultSet = setValue(PARAM_KEY_MAP[paramID], data); + // If value exists it is updated otherwise a new entry will be created + resultSet = insertValue(paramName, data); if (resultSet != returnvalue::OK) { triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 @@ -117,6 +106,7 @@ ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) return resultSet; } + template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) { ReturnValue_t result = returnvalue::OK; @@ -161,8 +151,10 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { #endif return result; } - insertValue(PARAM_KEY_MAP[PARAM0], PARAM0_DEFAULT); - insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT); + + for(const auto& keyMap: PARAM_KEY_MAP) { + insertValue(keyMap.second, PARAM0_DEFAULT); + } result = unlockConfigFile(); if (result != returnvalue::OK) { @@ -174,7 +166,8 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { } return result; } -ReturnValue_t GlobalConfigHandler::WriteConfigFile() { + +ReturnValue_t GlobalConfigHandler::writeConfigFile() { ReturnValue_t result = returnvalue::OK; ReturnValue_t resultWrite = returnvalue::OK; result = lockConfigFile(); @@ -205,7 +198,8 @@ ReturnValue_t GlobalConfigHandler::WriteConfigFile() { } return resultWrite; } -ReturnValue_t GlobalConfigHandler::ReadConfigFile() { + +ReturnValue_t GlobalConfigHandler::readConfigFile() { ReturnValue_t result = returnvalue::OK; ReturnValue_t resultRead = returnvalue::OK; result = lockConfigFile(); @@ -237,7 +231,8 @@ ReturnValue_t GlobalConfigHandler::ReadConfigFile() { return resultRead; } -ReturnValue_t GlobalConfigHandler::ResetConfigFile() { + +ReturnValue_t GlobalConfigHandler::resetConfigFile() { ReturnValue_t result = returnvalue::OK; result = resetConfigFileValues(); if (result != returnvalue::OK) { @@ -253,7 +248,7 @@ ReturnValue_t GlobalConfigHandler::ResetConfigFile() { ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName) { ReturnValue_t result = returnvalue::OK; setFullName(configFileName); - result = ResetConfigFile(); + result = resetConfigFile(); return result; } std::string GlobalConfigHandler::getConfigFileName() { return getFullName(); } diff --git a/mission/utility/GlobalConfigHandler.h b/mission/utility/GlobalConfigHandler.h index 80e141c6..1a2fe07f 100644 --- a/mission/utility/GlobalConfigHandler.h +++ b/mission/utility/GlobalConfigHandler.h @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -24,10 +25,6 @@ #include "fsfw/parameters/ParameterHelper.h" #include "mission/memory/NVMParameterBase.h" -static std::map PARAM_KEY_MAP = { - {PARAM0, "Parameter0"}, - {PARAM1, "Parameter1"}, -}; /* * Idea: This class is intended to be used as a subclass for the Core Controller. * Its tasks is managing a configuration JSON file containing config values important for various @@ -54,12 +51,12 @@ class GlobalConfigHandler : public SystemObject, ReturnValue_t initialize(); template - ReturnValue_t setConfigFileValue(ParamIds paramID, T data); + ReturnValue_t setConfigFileValue(std::string paramName, T data); template - ReturnValue_t getConfigFileValue(ParamIds paramID, T& data); + ReturnValue_t getConfigFileValue(std::string paramName, T& data); - ReturnValue_t ResetConfigFile(); - ReturnValue_t WriteConfigFile(); + ReturnValue_t resetConfigFile(); + ReturnValue_t writeConfigFile(); std::string getConfigFileName(); private: @@ -71,7 +68,7 @@ class GlobalConfigHandler : public SystemObject, ReturnValue_t setConfigFileName(std::string configFileName); - ReturnValue_t ReadConfigFile(); + ReturnValue_t readConfigFile(); MessageQueueIF* commandQueue; }; From a13ae7abcc5666e60c6077d498ec6eb32aaed725 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 15 Feb 2023 10:21:35 +0100 Subject: [PATCH 02/15] pdec ad frame config, wip --- fsfw | 2 +- linux/ipcore/PdecConfig.cpp | 6 +++++- linux/ipcore/PdecConfig.h | 10 ++-------- linux/ipcore/pdecconfigdefs.h | 20 ++++++++++++++++++++ tmtc | 2 +- 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 linux/ipcore/pdecconfigdefs.h diff --git a/fsfw b/fsfw index 01cc619e..dac2d210 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 01cc619e67b84cef514b045377771ff1e11caf80 +Subproject commit dac2d210b597adfaf45bd5ae6a4c027599927601 diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index 152ea320..173ee477 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -1,4 +1,5 @@ #include "PdecConfig.h" +#include "pdecconfigdefs.h" #include "fsfw/serviceinterface/ServiceInterface.h" @@ -74,11 +75,14 @@ void PdecConfig::writeFrameHeaderFirstOctet() { word |= (SPACECRAFT_ID << 16); word |= (VIRTUAL_CHANNEL << 10); word |= (DUMMY_BITS << 8); - word |= positiveWindow; + word |= localParameterHandler.getValue(pdecconfigdefs::paramkeys::POSITIVE_WINDOW, + pdecconfigdefs::defaultvalue::positiveWindow); *(memoryBaseAddress + FRAME_HEADER_OFFSET) = word; } void PdecConfig::writeFrameHeaderSecondOctet() { + uint8_t negativeWindow = localParameterHandler.getValue(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, + pdecconfigdefs::defaultvalue::negativeWindow); uint32_t word = 0; word = 0; word |= (negativeWindow << 24); diff --git a/linux/ipcore/PdecConfig.h b/linux/ipcore/PdecConfig.h index 0b665c6c..fa471775 100644 --- a/linux/ipcore/PdecConfig.h +++ b/linux/ipcore/PdecConfig.h @@ -1,7 +1,7 @@ #ifndef LINUX_OBC_PDECCONFIG_H_ #define LINUX_OBC_PDECCONFIG_H_ -#include +#include #include "bsp_q7s/memory/LocalParameterHandler.h" #include "bsp_q7s/fs/SdCardManager.h" @@ -49,6 +49,7 @@ class PdecConfig { uint8_t getNegativeWindow(); private: + // TC transfer frame configuration parameters static const uint8_t VERSION_ID = 0; // BD Frames @@ -95,13 +96,6 @@ class PdecConfig { bool enableTcAbortIrq = true; bool enableNewFarIrq = true; - NVMParameterBase persistenParams; - - // Parameters to control the FARM for AD frames - // Set here for future use - uint8_t positiveWindow = 10; - uint8_t negativeWindow = 151; - void writeFrameHeaderFirstOctet(); void writeFrameHeaderSecondOctet(); void writeMapConfig(); diff --git a/linux/ipcore/pdecconfigdefs.h b/linux/ipcore/pdecconfigdefs.h new file mode 100644 index 00000000..bc2cfa8c --- /dev/null +++ b/linux/ipcore/pdecconfigdefs.h @@ -0,0 +1,20 @@ +#ifndef LINUX_IPCORE_PDECCONFIGDEFS_H_ +#define LINUX_IPCORE_PDECCONFIGDEFS_H_ + +#include + +namespace pdecconfigdefs { + +namespace paramkeys { + static const std::string POSITIVE_WINDOW = "positive_window"; + static const std::string NEGATIVE_WINDOW = "negattive_window"; +} + +namespace defaultvalue { + static const uint8_t positiveWindow = 10; + static const uint8_t negativeWindow = 151; +} + +} + +#endif /* LINUX_IPCORE_PDECCONFIGDEFS_H_ */ diff --git a/tmtc b/tmtc index a3a3aaa8..8d036bcd 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a3a3aaa8836b425c923eb97e49ed29b452377bf6 +Subproject commit 8d036bcd4fed1211ad5b15ddae7b42e61e22fcfd From 7dae81c1228fd6166f7d8a8a77004e92f2393436 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Tue, 21 Feb 2023 14:13:46 +0100 Subject: [PATCH 03/15] added local parameter handler --- bsp_q7s/memory/LocalParameterHandler.h | 26 ++- fsfw | 2 +- linux/ipcore/PdecConfig.cpp | 211 +++++++++++++++--------- linux/ipcore/PdecConfig.h | 15 +- linux/ipcore/PdecHandler.cpp | 43 +++-- mission/utility/GlobalConfigHandler.cpp | 47 +++--- mission/utility/GlobalConfigHandler.h | 15 +- thirdparty/lwgps | 2 +- tmtc | 2 +- 9 files changed, 241 insertions(+), 122 deletions(-) diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h index 57d646cb..4f872131 100644 --- a/bsp_q7s/memory/LocalParameterHandler.h +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -31,7 +31,8 @@ class LocalParameterHandler : public NVMParameterBase { ReturnValue_t initialize(); /** - * @brief Function to add parameter to json file + * @brief Function to add parameter to json file. If the json file does + * not yet exist it will be created here. * * @param key The string to identify the parameter * @param value The value to set for this parameter @@ -43,6 +44,17 @@ class LocalParameterHandler : public NVMParameterBase { */ template ReturnValue_t addParameter(std::string key, T value); + /** + * @brief Function will update a parameter which already exists in the json + * file + * + * @param key The unique string to identify the parameter to update + * @param value The new new value to set + * + * @return OK if successful, otherwise error return value + */ + template ReturnValue_t updateParameter(std::string key, T value); + private: // Name relative to mount point of SD card where parameters will be stored @@ -63,4 +75,16 @@ template inline ReturnValue_t LocalParameterHandler::addParameter(st return returnvalue::OK; } +template inline ReturnValue_t LocalParameterHandler::updateParameter(std::string key, T value) { + ReturnValue_t result = setValue(key, value); + if (result != returnvalue::OK) { + return result; + } + result = writeJsonFile(); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; +} + #endif /* BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ */ diff --git a/fsfw b/fsfw index dac2d210..c8469ca6 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit dac2d210b597adfaf45bd5ae6a4c027599927601 +Subproject commit c8469ca6473f64676e007e2e2f1c733fe6252053 diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index 173ee477..fb554063 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -1,28 +1,65 @@ #include "PdecConfig.h" + +#include "fsfw/filesystem/HasFileSystemIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" #include "pdecconfigdefs.h" -#include "fsfw/serviceinterface/ServiceInterface.h" - -PdecConfig::PdecConfig() - : localParameterHandler("conf/pdecconfig", SdCardManager::instance()) { -} +PdecConfig::PdecConfig() : localParameterHandler("conf/pdecconfig", SdCardManager::instance()) {} PdecConfig::~PdecConfig() {} void PdecConfig::setMemoryBaseAddress(uint32_t* memoryBaseAddress_) { - memoryBaseAddress = memoryBaseAddress_; + memoryBaseAddress = memoryBaseAddress_; } ReturnValue_t PdecConfig::write() { - if (memoryBaseAddress == nullptr) { - sif::error << "PdecConfig::write: Memory base address not set" << std::endl; - return returnvalue::FAILED; + if (memoryBaseAddress == nullptr) { + sif::error << "PdecConfig::write: Memory base address not set" << std::endl; + return returnvalue::FAILED; + } + ReturnValue_t result = initializePersistentParameters(); + if (result != returnvalue::OK) { + return result; + } + result = writeFrameHeaderFirstOctet(); + if (result != returnvalue::OK) { + return result; } + result = writeFrameHeaderSecondOctet(); + if (result != returnvalue::OK) { + return result; + } + writeMapConfig(); + return returnvalue::FAILED; +} - writeFrameHeaderFirstOctet(); - writeFrameHeaderSecondOctet(); - writeMapConfig(); - return returnvalue::FAILED; +ReturnValue_t PdecConfig::initializePersistentParameters() { + ReturnValue_t result = localParameterHandler.initialize(); + if (result != returnvalue::OK) { + if (result == HasFileSystemIF::FILE_DOES_NOT_EXIST) { + result = createPersistentConfig(); + if (result != returnvalue::OK) { + return result; + } + } + } + return returnvalue::OK; +} + +ReturnValue_t PdecConfig::createPersistentConfig() { + ReturnValue_t result = localParameterHandler.addParameter( + pdecconfigdefs::paramkeys::POSITIVE_WINDOW, pdecconfigdefs::defaultvalue::positiveWindow); + if (result != returnvalue::OK) { + sif::error << "PdecConfig::createPersistentConfig: Failed to set positive window" << std::endl; + return result; + } + ReturnValue_t result = localParameterHandler.addParameter( + pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, pdecconfigdefs::defaultvalue::negativeWindow); + if (result != returnvalue::OK) { + sif::error << "PdecConfig::createPersistentConfig: Failed to set negative window" << std::endl; + return result; + } + return returnvalue::OK; } uint32_t PdecConfig::getImrReg() { @@ -31,83 +68,110 @@ uint32_t PdecConfig::getImrReg() { } ReturnValue_t PdecConfig::setPositiveWindow(uint8_t pw) { - if (memoryBaseAddress == nullptr) { - sif::error << "PdecConfig::setPositiveWindow: Memory base address not set" - << std::endl; - return returnvalue::FAILED; - } - positiveWindow = pw; - // Rewrite second config word which contains the positive window parameter - writeFrameHeaderSecondOctet(); - return returnvalue::OK; + if (memoryBaseAddress == nullptr) { + sif::error << "PdecConfig::setPositiveWindow: Memory base address not set" << std::endl; + return returnvalue::FAILED; + } + ReturnValue_t result = + localParameterHandler.updateParameter(pdecconfigdefs::paramkeys::POSITIVE_WINDOW, pw); + if (result != returnvalue::OK) { + return result; + } + // Rewrite second config word which contains the positive window parameter + writeFrameHeaderSecondOctet(); + return returnvalue::OK; } ReturnValue_t PdecConfig::setNegativeWindow(uint8_t nw) { - if (memoryBaseAddress == nullptr) { - sif::error << "PdecConfig::setPositiveWindow: Memory base address not set" - << std::endl; - return returnvalue::FAILED; - } - negativeWindow = nw; - // Rewrite second config word which contains the negative window parameter - writeFrameHeaderSecondOctet(); - return returnvalue::OK; + if (memoryBaseAddress == nullptr) { + sif::error << "PdecConfig::setPositiveWindow: Memory base address not set" << std::endl; + return returnvalue::FAILED; + } + ReturnValue_t result = + localParameterHandler.updateParameter(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, nw); + if (result != returnvalue::OK) { + return result; + } + // Rewrite second config word which contains the negative window parameter + writeFrameHeaderSecondOctet(); + return returnvalue::OK; } -uint8_t PdecConfig::getPositiveWindow() { - return positiveWindow; +ReturnValue_t PdecConfig::getPositiveWindow(uint8_t& positiveWindow) { + ReturnValue_t result = + localParameterHandler.getValue(pdecconfigdefs::paramkeys::POSITIVE_WINDOW, positiveWindow); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; } -uint8_t PdecConfig::getNegativeWindow() { - return negativeWindow; +ReturnValue_t PdecConfig::getNegativeWindow(uint8_t& negativeWindow) { + ReturnValue_t result = + localParameterHandler.getValue(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, negativeWindow); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; } -void PdecConfig::writeFrameHeaderFirstOctet() { - uint32_t word = 0; - word |= (VERSION_ID << 30); +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); + // 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); - word |= localParameterHandler.getValue(pdecconfigdefs::paramkeys::POSITIVE_WINDOW, - pdecconfigdefs::defaultvalue::positiveWindow); - *(memoryBaseAddress + FRAME_HEADER_OFFSET) = word; + word |= (RESERVED_FIELD_A << 26); + word |= (SPACECRAFT_ID << 16); + word |= (VIRTUAL_CHANNEL << 10); + word |= (DUMMY_BITS << 8); + uint8_t negativeWindow = 0; + ReturnValue_t result = + localParameterHandler.getValue(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, negativeWindow); + if (result != returnvalue::OK) { + return result; + } + word |= negativeWindow; + *(memoryBaseAddress + FRAME_HEADER_OFFSET) = word; + return returnvalue::OK; } -void PdecConfig::writeFrameHeaderSecondOctet() { - uint8_t negativeWindow = localParameterHandler.getValue(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, - pdecconfigdefs::defaultvalue::negativeWindow); - uint32_t word = 0; - word = 0; - word |= (negativeWindow << 24); - word |= (HIGH_AU_MAP_ID << 16); - word |= (ENABLE_DERANDOMIZER << 8); - *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1) = word; +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 |= (negativeWindow << 24); + word |= (HIGH_AU_MAP_ID << 16); + word |= (ENABLE_DERANDOMIZER << 8); + *(memoryBaseAddress + FRAME_HEADER_OFFSET + 1) = word; + return returnvalue::OK; } void PdecConfig::writeMapConfig() { - // Configure all MAP IDs as invalid - for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { - *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + idx / 4) = - NO_DESTINATION << 24 | NO_DESTINATION << 16 | NO_DESTINATION << 8 | NO_DESTINATION; - } + // Configure all MAP IDs as invalid + for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { + *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + idx / 4) = + NO_DESTINATION << 24 | NO_DESTINATION << 16 | NO_DESTINATION << 8 | NO_DESTINATION; + } - // All TCs with MAP ID 7 will be routed to the PM module (can then be read from memory) - uint8_t routeToPm = calcMapAddrEntry(PM_BUFFER); - *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + 1) = - (NO_DESTINATION << 24) | (NO_DESTINATION << 16) | (NO_DESTINATION << 8) | routeToPm; + // All TCs with MAP ID 7 will be routed to the PM module (can then be read from memory) + uint8_t routeToPm = calcMapAddrEntry(PM_BUFFER); + *(memoryBaseAddress + MAP_ADDR_LUT_OFFSET + 1) = + (NO_DESTINATION << 24) | (NO_DESTINATION << 16) | (NO_DESTINATION << 8) | routeToPm; - // Write map id clock frequencies - for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { - *(memoryBaseAddress + MAP_CLK_FREQ_OFFSET + idx / 4) = - MAP_CLK_FREQ << 24 | MAP_CLK_FREQ << 16 | MAP_CLK_FREQ << 8 | MAP_CLK_FREQ; - } + // Write map id clock frequencies + for (int idx = 0; idx <= MAX_MAP_ADDR; idx += 4) { + *(memoryBaseAddress + MAP_CLK_FREQ_OFFSET + idx / 4) = + MAP_CLK_FREQ << 24 | MAP_CLK_FREQ << 16 | MAP_CLK_FREQ << 8 | MAP_CLK_FREQ; + } } uint8_t PdecConfig::calcMapAddrEntry(uint8_t moduleId) { @@ -126,6 +190,3 @@ uint8_t PdecConfig::getOddParity(uint8_t number) { parityBit = ~(countBits & 0x1) & 0x1; return parityBit; } - - - diff --git a/linux/ipcore/PdecConfig.h b/linux/ipcore/PdecConfig.h index fa471775..0cff9871 100644 --- a/linux/ipcore/PdecConfig.h +++ b/linux/ipcore/PdecConfig.h @@ -45,8 +45,8 @@ class PdecConfig { ReturnValue_t setPositiveWindow(uint8_t pw); ReturnValue_t setNegativeWindow(uint8_t nw); - uint8_t getPositiveWindow(); - uint8_t getNegativeWindow(); + ReturnValue_t getPositiveWindow(uint8_t& positiveWindow); + ReturnValue_t getNegativeWindow(uint8_t& negativeWindow); private: @@ -96,8 +96,15 @@ class PdecConfig { bool enableTcAbortIrq = true; bool enableNewFarIrq = true; - void writeFrameHeaderFirstOctet(); - void writeFrameHeaderSecondOctet(); + ReturnValue_t initializePersistentParameters(); + /** + * @brief If the json file containing the persistent config parameters does + * not exist it will be created here. + */ + ReturnValue_t createPersistentConfig(); + + ReturnValue_t writeFrameHeaderFirstOctet(); + ReturnValue_t writeFrameHeaderSecondOctet(); void writeMapConfig(); /** diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 3d1b9d58..69c99feb 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -78,12 +78,11 @@ ReturnValue_t PdecHandler::initialize() { } globalConfigHandler = ObjectManager::instance()->get(objects::GLOBAL_JSON_CFG); - if (globalConfigHandler == nullptr) { - sif::error << "PdecHandler::initialize: Invalid global config handler" << std::endl; - return ObjectManagerIF::CHILD_INIT_FAILED; - } + if (globalConfigHandler == nullptr) { + sif::error << "PdecHandler::initialize: Invalid global config handler" << std::endl; + return ObjectManagerIF::CHILD_INIT_FAILED; + } - pdecConfig.setGlobalConfigHandler(globalConfigHandler); result = pdecConfig.write(); if (result != returnvalue::OK) { sif::error << "PdecHandler::initialize: Failed to write PDEC config" << std::endl; @@ -271,19 +270,39 @@ ReturnValue_t PdecHandler::getParameter(uint8_t domainId, uint8_t uniqueIdentifi if (result != returnvalue::OK) { return result; } - parameterWrapper->set(); - com::setCurrentDatarate(static_cast(newVal)); + uint8_t positiveWindow = 0; + result = pdecConfig.getPositiveWindow(positiveWindow); + if (result != returnvalue::OK) { + sif::warning << "PdecHandler::getParameter: Failed to get positive window from pdec config" + << std::endl; + return returnvalue::FAILED; + } + parameterWrapper->set(positiveWindow); + result = pdecConfig.setPositiveWindow(newVal); + if (result != returnvalue::OK) { + sif::warning << "PdecHandler::getParameter: Failed to set positive window" << std::endl; + return returnvalue::FAILED; + } return returnvalue::OK; - } else if ((domainId == 0) and - (uniqueIdentifier == static_cast(com::ParameterId::TRANSMITTER_TIMEOUT))) { + } else if ((domainId == 0) and (uniqueIdentifier == ParameterId::NEGATIVE_WINDOW)) { uint8_t newVal = 0; ReturnValue_t result = newValues->getElement(&newVal); if (result != returnvalue::OK) { return result; } - parameterWrapper->set(transmitterTimeout); - transmitterTimeout = newVal; - transmitterCountdown.setTimeout(transmitterTimeout); + uint8_t negativeWindow = 0; + result = pdecConfig.getNegativeWindow(negativeWindow); + if (result != returnvalue::OK) { + sif::warning << "PdecHandler::getParameter: Failed to get negative window from pdec config" + << std::endl; + return returnvalue::FAILED; + } + parameterWrapper->set(negativeWindow); + result = pdecConfig.setNegativeWindow(negativeWindow); + if (result != returnvalue::OK) { + sif::warning << "PdecHandler::getParameter: Failed to set negative window" << std::endl; + return returnvalue::FAILED; + } return returnvalue::OK; } return returnvalue::OK; diff --git a/mission/utility/GlobalConfigHandler.cpp b/mission/utility/GlobalConfigHandler.cpp index ffd1963b..bb4b3d7d 100644 --- a/mission/utility/GlobalConfigHandler.cpp +++ b/mission/utility/GlobalConfigHandler.cpp @@ -23,24 +23,23 @@ GlobalConfigHandler::GlobalConfigHandler(object_id_t objectId, std::string confi CONFIG_LOCK = MutexFactory::instance()->createMutex(); } } - ReturnValue_t GlobalConfigHandler::initialize() { ReturnValue_t result = SystemObject::initialize(); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize failed with " + sif::info << "GlobalConfigHandler::initialize: SystemObject::initialize() failed with " << result << std::endl; #endif return result; } - result = readConfigFile(); + result = ReadConfigFile(); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 sif::info << "GlobalConfigHandler::initialize: Creating JSON file at " << getFullName() << std::endl; #endif - result = resetConfigFile(); + result = ResetConfigFile(); if (result != returnvalue::OK) { return result; } @@ -64,7 +63,6 @@ ReturnValue_t GlobalConfigHandler::lockConfigFile() { result = CONFIG_LOCK->lockMutex(MutexIF::TimeoutType::WAITING, 10); return result; } - ReturnValue_t GlobalConfigHandler::unlockConfigFile() { ReturnValue_t result = returnvalue::OK; result = CONFIG_LOCK->unlockMutex(); @@ -72,21 +70,34 @@ ReturnValue_t GlobalConfigHandler::unlockConfigFile() { } template -ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string paramName, T data) { +ReturnValue_t GlobalConfigHandler::setConfigFileValue(ParamIds paramID, T data) { ReturnValue_t result = returnvalue::OK; ReturnValue_t resultSet = returnvalue::OK; result = lockConfigFile(); if (result != returnvalue::OK) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "GlobalConfigHandler::setConfigFileValue: Lock mutex failed with " << result + sif::info << "GlobalConfigHandler::setConfigFileValue lock mutex failed with " << result << std::endl; #endif return result; } - // If value exists it is updated otherwise a new entry will be created - resultSet = insertValue(paramName, data); + std::string paramString; + paramString = PARAM_KEY_MAP[paramID]; + + // Check if key exists in map before setting value. No check is done in setValue! Somehow + // PARAM_KEY_MAP.count(paramID) == 0 does not work + if (paramString.empty() == true) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "GlobalConfigHandler::setConfigFileValue ParamId " << PARAM_KEY_MAP[paramID] + << " not found!" << std::endl; +#endif + triggerEvent(SET_CONFIGFILEVALUE_FAILED, 1, 0); + return returnvalue::FAILED; + } + + resultSet = setValue(PARAM_KEY_MAP[paramID], data); if (resultSet != returnvalue::OK) { triggerEvent(SET_CONFIGFILEVALUE_FAILED, 0, 0); #if OBSW_VERBOSE_LEVEL >= 1 @@ -106,7 +117,6 @@ ReturnValue_t GlobalConfigHandler::setConfigFileValue(std::string paramName, T d return resultSet; } - template ReturnValue_t GlobalConfigHandler::getConfigFileValue(ParamIds paramID, T& data) { ReturnValue_t result = returnvalue::OK; @@ -151,10 +161,8 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { #endif return result; } - - for(const auto& keyMap: PARAM_KEY_MAP) { - insertValue(keyMap.second, PARAM0_DEFAULT); - } + insertValue(PARAM_KEY_MAP[PARAM0], PARAM0_DEFAULT); + insertValue(PARAM_KEY_MAP[PARAM1], PARAM1_DEFAULT); result = unlockConfigFile(); if (result != returnvalue::OK) { @@ -166,8 +174,7 @@ ReturnValue_t GlobalConfigHandler::resetConfigFileValues() { } return result; } - -ReturnValue_t GlobalConfigHandler::writeConfigFile() { +ReturnValue_t GlobalConfigHandler::WriteConfigFile() { ReturnValue_t result = returnvalue::OK; ReturnValue_t resultWrite = returnvalue::OK; result = lockConfigFile(); @@ -198,8 +205,7 @@ ReturnValue_t GlobalConfigHandler::writeConfigFile() { } return resultWrite; } - -ReturnValue_t GlobalConfigHandler::readConfigFile() { +ReturnValue_t GlobalConfigHandler::ReadConfigFile() { ReturnValue_t result = returnvalue::OK; ReturnValue_t resultRead = returnvalue::OK; result = lockConfigFile(); @@ -231,8 +237,7 @@ ReturnValue_t GlobalConfigHandler::readConfigFile() { return resultRead; } - -ReturnValue_t GlobalConfigHandler::resetConfigFile() { +ReturnValue_t GlobalConfigHandler::ResetConfigFile() { ReturnValue_t result = returnvalue::OK; result = resetConfigFileValues(); if (result != returnvalue::OK) { @@ -248,7 +253,7 @@ ReturnValue_t GlobalConfigHandler::resetConfigFile() { ReturnValue_t GlobalConfigHandler::setConfigFileName(std::string configFileName) { ReturnValue_t result = returnvalue::OK; setFullName(configFileName); - result = resetConfigFile(); + result = ResetConfigFile(); return result; } std::string GlobalConfigHandler::getConfigFileName() { return getFullName(); } diff --git a/mission/utility/GlobalConfigHandler.h b/mission/utility/GlobalConfigHandler.h index 1a2fe07f..80e141c6 100644 --- a/mission/utility/GlobalConfigHandler.h +++ b/mission/utility/GlobalConfigHandler.h @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -25,6 +24,10 @@ #include "fsfw/parameters/ParameterHelper.h" #include "mission/memory/NVMParameterBase.h" +static std::map PARAM_KEY_MAP = { + {PARAM0, "Parameter0"}, + {PARAM1, "Parameter1"}, +}; /* * Idea: This class is intended to be used as a subclass for the Core Controller. * Its tasks is managing a configuration JSON file containing config values important for various @@ -51,12 +54,12 @@ class GlobalConfigHandler : public SystemObject, ReturnValue_t initialize(); template - ReturnValue_t setConfigFileValue(std::string paramName, T data); + ReturnValue_t setConfigFileValue(ParamIds paramID, T data); template - ReturnValue_t getConfigFileValue(std::string paramName, T& data); + ReturnValue_t getConfigFileValue(ParamIds paramID, T& data); - ReturnValue_t resetConfigFile(); - ReturnValue_t writeConfigFile(); + ReturnValue_t ResetConfigFile(); + ReturnValue_t WriteConfigFile(); std::string getConfigFileName(); private: @@ -68,7 +71,7 @@ class GlobalConfigHandler : public SystemObject, ReturnValue_t setConfigFileName(std::string configFileName); - ReturnValue_t readConfigFile(); + ReturnValue_t ReadConfigFile(); MessageQueueIF* commandQueue; }; diff --git a/thirdparty/lwgps b/thirdparty/lwgps index 52999ddf..18ce34fa 160000 --- a/thirdparty/lwgps +++ b/thirdparty/lwgps @@ -1 +1 @@ -Subproject commit 52999ddfe5177493b96b55871961a8a97131596d +Subproject commit 18ce34faf729ed63c94517b2ae6a3d3741e0a054 diff --git a/tmtc b/tmtc index 8d036bcd..a3a3aaa8 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 8d036bcd4fed1211ad5b15ddae7b42e61e22fcfd +Subproject commit a3a3aaa8836b425c923eb97e49ed29b452377bf6 From 62cadd16abacf354a94a3d0a23ae91762e05ee65 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 22 Feb 2023 07:15:19 +0100 Subject: [PATCH 04/15] missing constructor call in LocalParameterHandler --- bsp_q7s/memory/LocalParameterHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp_q7s/memory/LocalParameterHandler.cpp b/bsp_q7s/memory/LocalParameterHandler.cpp index 03a5ba82..9428837d 100644 --- a/bsp_q7s/memory/LocalParameterHandler.cpp +++ b/bsp_q7s/memory/LocalParameterHandler.cpp @@ -2,7 +2,7 @@ #include LocalParameterHandler::LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan) - : sdRelativeName(sdRelativeName), sdcMan(sdcMan) {} + : NVMParameterBase(), sdRelativeName(sdRelativeName), sdcMan(sdcMan) {} LocalParameterHandler::~LocalParameterHandler() { } From ce72e4308ebaa5d17c03b3356e5686e037f711f6 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 22 Feb 2023 14:50:24 +0100 Subject: [PATCH 05/15] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index a3a3aaa8..24e9c25b 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a3a3aaa8836b425c923eb97e49ed29b452377bf6 +Subproject commit 24e9c25ba4c677ae900b6ad477272ae32bd3bc0d From 28f3b07c5c4f334253cf058b9234ff0aeb4bc942 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 22 Feb 2023 15:57:24 +0100 Subject: [PATCH 06/15] removed global config handler --- bsp_hosted/ObjectFactory.cpp | 1 - bsp_q7s/core/ObjectFactory.cpp | 4 ---- bsp_q7s/core/ObjectFactory.h | 2 -- bsp_q7s/fmObjectFactory.cpp | 2 -- bsp_q7s/memory/LocalParameterHandler.cpp | 2 -- linux/ipcore/PdecConfig.cpp | 2 +- 6 files changed, 1 insertion(+), 12 deletions(-) diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index d2c3c3da..b0c4ad7f 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -29,7 +29,6 @@ #include #include "dummies/helpers.h" -#include "mission/utility/GlobalConfigHandler.h" #ifdef PLATFORM_UNIX #include diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 70ccd08c..b3378221 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -943,7 +943,3 @@ void ObjectFactory::testAcsBrdAss(AcsBoardAssembly* acsAss) { sif::warning << "Sending mode command failed" << std::endl; } } - -void ObjectFactory::createGlobalConfigHandler() { - new GlobalConfigHandler(objects::GLOBAL_JSON_CFG, configfile::sdrelative); -} diff --git a/bsp_q7s/core/ObjectFactory.h b/bsp_q7s/core/ObjectFactory.h index b835b032..2118e3d7 100644 --- a/bsp_q7s/core/ObjectFactory.h +++ b/bsp_q7s/core/ObjectFactory.h @@ -49,8 +49,6 @@ void createTestComponents(LinuxLibgpioIF* gpioComIF); void testAcsBrdAss(AcsBoardAssembly* assAss); -void createGlobalConfigHandler(); - }; // namespace ObjectFactory #endif /* BSP_Q7S_OBJECTFACTORY_H_ */ diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index f24feb5d..d640ac35 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -86,8 +86,6 @@ void ObjectFactory::produce(void* args) { createTestComponents(gpioComIF); #endif /* OBSW_ADD_TEST_CODE == 1 */ - createGlobalConfigHandler(); - createMiscComponents(); createThermalController(*heaterHandler); createAcsController(true); diff --git a/bsp_q7s/memory/LocalParameterHandler.cpp b/bsp_q7s/memory/LocalParameterHandler.cpp index 9428837d..953d79a2 100644 --- a/bsp_q7s/memory/LocalParameterHandler.cpp +++ b/bsp_q7s/memory/LocalParameterHandler.cpp @@ -13,8 +13,6 @@ ReturnValue_t LocalParameterHandler::initialize() { setFullName(fullname); ReturnValue_t result = readJsonFile(); if (result != returnvalue::OK) { - sif::warning << "LocalParameterHandler::initialize: Failed to read json file" - << getFullName() << std::endl; return result; } return returnvalue::OK; diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index f468c410..f299b060 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -30,7 +30,7 @@ ReturnValue_t PdecConfig::write() { return result; } writeMapConfig(); - return returnvalue::FAILED; + return returnvalue::OK; } ReturnValue_t PdecConfig::initializePersistentParameters() { From 3b17af9d07adb14d0114a8064ec29aeb6976eb56 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 23 Feb 2023 10:09:04 +0100 Subject: [PATCH 07/15] added local parameter handler to PdecConfig to store persistent parameters --- bsp_q7s/fs/FilesystemHelper.cpp | 2 +- bsp_q7s/memory/LocalParameterHandler.cpp | 9 ++- bsp_q7s/memory/LocalParameterHandler.h | 4 ++ linux/fsfwconfig/returnvalues/classIds.h | 1 + linux/ipcore/PdecConfig.cpp | 18 +++-- linux/ipcore/PdecHandler.cpp | 87 +++++++++++++++--------- linux/ipcore/PdecHandler.h | 13 ++++ mission/devices/PayloadPcduHandler.cpp | 2 +- 8 files changed, 89 insertions(+), 47 deletions(-) diff --git a/bsp_q7s/fs/FilesystemHelper.cpp b/bsp_q7s/fs/FilesystemHelper.cpp index bc435d1c..8f49d109 100644 --- a/bsp_q7s/fs/FilesystemHelper.cpp +++ b/bsp_q7s/fs/FilesystemHelper.cpp @@ -22,7 +22,7 @@ ReturnValue_t FilesystemHelper::checkPath(std::string path) { } } else if (path.substr(0, sizeof(config::SD_1_MOUNT_POINT)) == std::string(config::SD_1_MOUNT_POINT)) { - if (!sdcMan->isSdCardUsable(sd::SLOT_0)) { + if (!sdcMan->isSdCardUsable(sd::SLOT_1)) { sif::warning << "FilesystemHelper::checkPath: SD card 1 not mounted" << std::endl; return SD_NOT_MOUNTED; } diff --git a/bsp_q7s/memory/LocalParameterHandler.cpp b/bsp_q7s/memory/LocalParameterHandler.cpp index 953d79a2..b24a3e08 100644 --- a/bsp_q7s/memory/LocalParameterHandler.cpp +++ b/bsp_q7s/memory/LocalParameterHandler.cpp @@ -8,7 +8,14 @@ LocalParameterHandler::~LocalParameterHandler() { } ReturnValue_t LocalParameterHandler::initialize() { - std::string mountPrefix = sdcMan->getCurrentMountPrefix(); + std::string mountPrefix; + auto activeSd = sdcMan->getActiveSdCard(); + if (activeSd and sdcMan->isSdCardUsable(activeSd.value())) { + mountPrefix = sdcMan->getCurrentMountPrefix(); + } else { + return SD_NOT_READY; + } + mountPrefix = sdcMan->getCurrentMountPrefix(); std::string fullname = mountPrefix + "/" + sdRelativeName; setFullName(fullname); ReturnValue_t result = readJsonFile(); diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h index 4f872131..37fa7f2c 100644 --- a/bsp_q7s/memory/LocalParameterHandler.h +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -13,6 +13,10 @@ */ class LocalParameterHandler : public NVMParameterBase { public: + + static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_PARAM_HANDLER; + + static constexpr ReturnValue_t SD_NOT_READY = returnvalue::makeCode(INTERFACE_ID, 0); /** * @brief Constructor * diff --git a/linux/fsfwconfig/returnvalues/classIds.h b/linux/fsfwconfig/returnvalues/classIds.h index abd8f785..e42c3c3f 100644 --- a/linux/fsfwconfig/returnvalues/classIds.h +++ b/linux/fsfwconfig/returnvalues/classIds.h @@ -15,6 +15,7 @@ enum { CLASS_ID_START = COMMON_CLASS_ID_END, SD_CARD_MANAGER, // SDMA SCRATCH_BUFFER, // SCBU + LOCAL_PARAM_HANDLER, // LPH CLASS_ID_END // [EXPORT] : [END] }; } diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index f299b060..4051fe09 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -4,7 +4,7 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "pdecconfigdefs.h" -PdecConfig::PdecConfig() : localParameterHandler("conf/pdecconfig", SdCardManager::instance()) {} +PdecConfig::PdecConfig() : localParameterHandler("conf/pdecconfig.json", SdCardManager::instance()) {} PdecConfig::~PdecConfig() {} @@ -35,15 +35,13 @@ ReturnValue_t PdecConfig::write() { ReturnValue_t PdecConfig::initializePersistentParameters() { ReturnValue_t result = localParameterHandler.initialize(); - if (result != returnvalue::OK) { - if (result == HasFileSystemIF::FILE_DOES_NOT_EXIST) { - result = createPersistentConfig(); - if (result != returnvalue::OK) { - return result; - } - } - } - return returnvalue::OK; + if (result == HasFileSystemIF::FILE_DOES_NOT_EXIST) { + result = createPersistentConfig(); + if (result != returnvalue::OK) { + return result; + } + } + return result; } ReturnValue_t PdecConfig::createPersistentConfig() { diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 0f43c6f7..ebf9376a 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -77,22 +77,6 @@ ReturnValue_t PdecHandler::initialize() { return returnvalue::FAILED; } - result = pdecConfig.write(); - if (result != returnvalue::OK) { - sif::error << "PdecHandler::initialize: Failed to write PDEC config" << std::endl; - return ObjectManagerIF::CHILD_INIT_FAILED; - } - - result = releasePdec(); - if (result != returnvalue::OK) { - return ObjectManagerIF::CHILD_INIT_FAILED; - } - - // This configuration must be done while the PDEC is not held in reset. - if (OP_MODE == Modes::IRQ) { - // Configure interrupt mask register to enable interrupts - *(registerBaseAddress + PDEC_IMR_OFFSET) = pdecConfig.getImrReg(); - } result = actionHelper.initialize(commandQueue); if (result != returnvalue::OK) { return result; @@ -101,6 +85,36 @@ ReturnValue_t PdecHandler::initialize() { return returnvalue::OK; } +ReturnValue_t PdecHandler::firstLoop() { + ReturnValue_t result = pdecConfig.write(); + if (result != returnvalue::OK) { + if (result == LocalParameterHandler::SD_NOT_READY) { + return result; + } else { + sif::error << "PdecHandler::firstLoop: Failed to write PDEC config" << std::endl; + } + return returnvalue::FAILED; + } + + result = releasePdec(); + if (result != returnvalue::OK) { + return returnvalue::FAILED; + } + + // This configuration must be done while the PDEC is not held in reset. + if (OP_MODE == Modes::IRQ) { + // Configure interrupt mask register to enable interrupts + *(registerBaseAddress + PDEC_IMR_OFFSET) = pdecConfig.getImrReg(); + } + result = resetFarStatFlag(); + if (result != returnvalue::OK) { + // Requires reconfiguration and reinitialization of PDEC + triggerEvent(INVALID_FAR); + return result; + } + return returnvalue::OK; +} + ReturnValue_t PdecHandler::performOperation(uint8_t operationCode) { if (OP_MODE == Modes::POLLED) { return polledOperation(); @@ -111,19 +125,11 @@ ReturnValue_t PdecHandler::performOperation(uint8_t operationCode) { } ReturnValue_t PdecHandler::polledOperation() { - ReturnValue_t result = returnvalue::OK; readCommandQueue(); switch (state) { case State::INIT: - resetFarStatFlag(); - if (result != returnvalue::OK) { - // Requires reconfiguration and reinitialization of PDEC - triggerEvent(INVALID_FAR); - state = State::WAIT_FOR_RECOVERY; - break; - } - state = State::RUNNING; + handleInitState(); break; case State::RUNNING: if (newTcReceived()) { @@ -143,7 +149,6 @@ ReturnValue_t PdecHandler::polledOperation() { // See https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html for more information. ReturnValue_t PdecHandler::irqOperation() { - ReturnValue_t result = returnvalue::OK; int fd = open(uioNames.irq, O_RDWR); if (fd < 0) { sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" @@ -166,14 +171,7 @@ ReturnValue_t PdecHandler::irqOperation() { readCommandQueue(); switch (state) { case State::INIT: - result = resetFarStatFlag(); - if (result != returnvalue::OK) { - // Requires reconfiguration and reinitialization of PDEC - triggerEvent(INVALID_FAR); - state = State::WAIT_FOR_RECOVERY; - return result; - } - state = State::RUNNING; + handleInitState(); break; case State::RUNNING: { checkAndHandleIrqs(fd, info); @@ -194,6 +192,27 @@ ReturnValue_t PdecHandler::irqOperation() { return returnvalue::OK; } +void PdecHandler::handleInitState() { + ReturnValue_t result = firstLoop(); + if (result != returnvalue::OK) { + if (result == LocalParameterHandler::SD_NOT_READY) { + TaskFactory::delayTask(400); + if (initTries == MAX_INIT_TRIES) { + sif::error << "PdecHandler::handleInitState: SD card never " + "becomes ready" + << std::endl; + state = State::WAIT_FOR_RECOVERY; + return; + } else { + state = State::INIT; + return; + } + } + state = State::WAIT_FOR_RECOVERY; + } + state = State::RUNNING; +} + ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { ssize_t nb = write(fd, &info, sizeof(info)); if (nb != static_cast(sizeof(info))) { diff --git a/linux/ipcore/PdecHandler.h b/linux/ipcore/PdecHandler.h index 2c8da14c..d43c86e3 100644 --- a/linux/ipcore/PdecHandler.h +++ b/linux/ipcore/PdecHandler.h @@ -169,6 +169,8 @@ class PdecHandler : public SystemObject, static const uint32_t NO_RF_MASK = 0x8000; static const uint32_t NO_BITLOCK_MASK = 0x4000; + static const uint32_t MAX_INIT_TRIES = 20; + class ParameterId { public: // ID of the parameter to update the positive window of AD frames @@ -258,6 +260,16 @@ class PdecHandler : public SystemObject, PdecConfig pdecConfig; + uint32_t initTries = 0; + + /** + * @brief Performs initialization stuff which must be performed in first + * loop of running task + * + * @return OK if successful, otherwise FAILED + */ + ReturnValue_t firstLoop(); + /** * @brief Reads and handles messages stored in the commandQueue */ @@ -265,6 +277,7 @@ class PdecHandler : public SystemObject, ReturnValue_t polledOperation(); ReturnValue_t irqOperation(); + void handleInitState(); ReturnValue_t checkAndHandleIrqs(int fd, uint32_t& info); uint32_t readFar(); diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 44dd667c..efefb16b 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -664,7 +664,7 @@ ReturnValue_t PayloadPcduHandler::getParameter(uint8_t domainId, uint8_t uniqueI } void PayloadPcduHandler::handleFailureInjection(std::string output, Event event) { - sif::info << "PayloadPcduHandler::checkAdcValues: " << output + sif::info << "PayloadPcduHandler::handleFailureInjection: " << output << " failure injection. " "Transitioning back to off" << std::endl; From 1e45bff0cc888e228fa5cd570e547b4d41d75304 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 23 Feb 2023 15:23:35 +0100 Subject: [PATCH 08/15] tmtc update --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 24e9c25b..e47eb577 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 24e9c25ba4c677ae900b6ad477272ae32bd3bc0d +Subproject commit e47eb577fada9e1d84abc4d5fdd13862f5f4e7bf From 5db1f7185455b814eb9458bd7a755cb9d8fd3963 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 23 Feb 2023 15:27:24 +0100 Subject: [PATCH 09/15] run clang formatting script --- bsp_q7s/core/ObjectFactory.cpp | 2 +- bsp_q7s/memory/LocalParameterHandler.cpp | 53 ++++---- bsp_q7s/memory/LocalParameterHandler.h | 73 +++++------ linux/fsfwconfig/returnvalues/classIds.h | 8 +- linux/ipcore/PdecConfig.cpp | 29 ++--- linux/ipcore/PdecConfig.h | 85 +++++++------ linux/ipcore/PdecHandler.cpp | 119 +++++++++--------- linux/ipcore/PdecHandler.h | 18 ++- linux/ipcore/pdecconfigdefs.h | 14 +-- mission/config/configfile.h | 6 +- mission/controller/acs/Guidance.cpp | 3 +- .../acs/MultiplicativeKalmanFilter.cpp | 7 +- mission/memory/NVMParameterBase.h | 2 +- mission/system/objects/ComSubsystem.h | 4 +- mission/utility/GlobalConfigFileDefinitions.h | 8 +- 15 files changed, 212 insertions(+), 219 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 30fecf60..41098175 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -40,6 +40,7 @@ #include "linux/ipcore/PdecHandler.h" #include "linux/ipcore/Ptme.h" #include "linux/ipcore/PtmeConfig.h" +#include "mission/config/configfile.h" #include "mission/csp/CspCookie.h" #include "mission/system/fdir/AcsBoardFdir.h" #include "mission/system/fdir/GomspacePowerFdir.h" @@ -54,7 +55,6 @@ #include "mission/system/tree/payloadModeTree.h" #include "mission/system/tree/tcsModeTree.h" #include "mission/utility/GlobalConfigHandler.h" -#include "mission/config/configfile.h" #include "tmtc/pusIds.h" #if OBSW_TEST_LIBGPIOD == 1 #include "linux/boardtest/LibgpiodTest.h" diff --git a/bsp_q7s/memory/LocalParameterHandler.cpp b/bsp_q7s/memory/LocalParameterHandler.cpp index 90c15f39..d1fb6353 100644 --- a/bsp_q7s/memory/LocalParameterHandler.cpp +++ b/bsp_q7s/memory/LocalParameterHandler.cpp @@ -1,42 +1,41 @@ #include "LocalParameterHandler.h" + #include LocalParameterHandler::LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan) : NVMParameterBase(), sdRelativeName(sdRelativeName), sdcMan(sdcMan) {} -LocalParameterHandler::~LocalParameterHandler() { -} +LocalParameterHandler::~LocalParameterHandler() {} ReturnValue_t LocalParameterHandler::initialize() { - ReturnValue_t result = updateFullName(); - if (result != returnvalue::OK) { - return result; - } - result = readJsonFile(); - if (result != returnvalue::OK) { - return result; - } - return returnvalue::OK; + ReturnValue_t result = updateFullName(); + if (result != returnvalue::OK) { + return result; + } + result = readJsonFile(); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; } ReturnValue_t LocalParameterHandler::writeJsonFile() { - ReturnValue_t result = updateFullName(); - if (result != returnvalue::OK) { - return result; - } - return NVMParameterBase::writeJsonFile(); + ReturnValue_t result = updateFullName(); + if (result != returnvalue::OK) { + return result; + } + return NVMParameterBase::writeJsonFile(); } ReturnValue_t LocalParameterHandler::updateFullName() { - std::string mountPrefix; - auto activeSd = sdcMan->getActiveSdCard(); - if (activeSd and sdcMan->isSdCardUsable(activeSd.value())) { - mountPrefix = sdcMan->getCurrentMountPrefix(); - } else { - return SD_NOT_READY; - } - std::string fullname = mountPrefix + "/" + sdRelativeName; - NVMParameterBase::setFullName(fullname); - return returnvalue::OK; + std::string mountPrefix; + auto activeSd = sdcMan->getActiveSdCard(); + if (activeSd and sdcMan->isSdCardUsable(activeSd.value())) { + mountPrefix = sdcMan->getCurrentMountPrefix(); + } else { + return SD_NOT_READY; + } + std::string fullname = mountPrefix + "/" + sdRelativeName; + NVMParameterBase::setFullName(fullname); + return returnvalue::OK; } - diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h index bb5eae55..b32761ef 100644 --- a/bsp_q7s/memory/LocalParameterHandler.h +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -1,11 +1,11 @@ #ifndef BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ #define BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ -#include - #include #include +#include + /** * @brief Class to handle persistent parameters * @@ -13,17 +13,17 @@ */ class LocalParameterHandler : public NVMParameterBase { public: + static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_PARAM_HANDLER; - static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_PARAM_HANDLER; - - static constexpr ReturnValue_t SD_NOT_READY = returnvalue::makeCode(INTERFACE_ID, 0); - /** - * @brief Constructor - * - * @param sdRelativeName Absolute name of json file relative to mount - * directory of SD card. E.g. conf/example.json - * @param sdcMan Pointer to SD card manager - */ + static constexpr ReturnValue_t SD_NOT_READY = returnvalue::makeCode(INTERFACE_ID, 0); + /** + * @brief Constructor + * + * @param sdRelativeName Absolute name of json file relative to mount + * directory of SD card. + * E.g. conf/example.json + * @param sdcMan Pointer to SD card manager + */ LocalParameterHandler(std::string sdRelativeName, SdCardMountedIF* sdcMan); virtual ~LocalParameterHandler(); @@ -46,7 +46,8 @@ class LocalParameterHandler : public NVMParameterBase { * @details The function will add the parameter only if it is not already * present in the json file */ - template ReturnValue_t addParameter(std::string key, T value); + template + ReturnValue_t addParameter(std::string key, T value); /** * @brief Function will update a parameter which already exists in the json @@ -57,10 +58,10 @@ class LocalParameterHandler : public NVMParameterBase { * * @return OK if successful, otherwise error return value */ - template ReturnValue_t updateParameter(std::string key, T value); + template + ReturnValue_t updateParameter(std::string key, T value); private: - // Name relative to mount point of SD card where parameters will be stored std::string sdRelativeName; @@ -77,28 +78,30 @@ class LocalParameterHandler : public NVMParameterBase { ReturnValue_t updateFullName(); }; -template inline ReturnValue_t LocalParameterHandler::addParameter(std::string key, T value) { - ReturnValue_t result = insertValue(key, value); - if (result != returnvalue::OK) { - return result; - } - result = writeJsonFile(); - if (result != returnvalue::OK) { - return result; - } - return returnvalue::OK; +template +inline ReturnValue_t LocalParameterHandler::addParameter(std::string key, T value) { + ReturnValue_t result = insertValue(key, value); + if (result != returnvalue::OK) { + return result; + } + result = writeJsonFile(); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; } -template inline ReturnValue_t LocalParameterHandler::updateParameter(std::string key, T value) { - ReturnValue_t result = setValue(key, value); - if (result != returnvalue::OK) { - return result; - } - result = writeJsonFile(); - if (result != returnvalue::OK) { - return result; - } - return returnvalue::OK; +template +inline ReturnValue_t LocalParameterHandler::updateParameter(std::string key, T value) { + ReturnValue_t result = setValue(key, value); + if (result != returnvalue::OK) { + return result; + } + result = writeJsonFile(); + if (result != returnvalue::OK) { + return result; + } + return returnvalue::OK; } #endif /* BSP_Q7S_MEMORY_LOCALPARAMETERHANDLER_H_ */ diff --git a/linux/fsfwconfig/returnvalues/classIds.h b/linux/fsfwconfig/returnvalues/classIds.h index e42c3c3f..0e1b2c7c 100644 --- a/linux/fsfwconfig/returnvalues/classIds.h +++ b/linux/fsfwconfig/returnvalues/classIds.h @@ -13,10 +13,10 @@ namespace CLASS_ID { enum { CLASS_ID_START = COMMON_CLASS_ID_END, - SD_CARD_MANAGER, // SDMA - SCRATCH_BUFFER, // SCBU - LOCAL_PARAM_HANDLER, // LPH - CLASS_ID_END // [EXPORT] : [END] + SD_CARD_MANAGER, // SDMA + SCRATCH_BUFFER, // SCBU + LOCAL_PARAM_HANDLER, // LPH + CLASS_ID_END // [EXPORT] : [END] }; } diff --git a/linux/ipcore/PdecConfig.cpp b/linux/ipcore/PdecConfig.cpp index 4051fe09..a41c5ba6 100644 --- a/linux/ipcore/PdecConfig.cpp +++ b/linux/ipcore/PdecConfig.cpp @@ -4,7 +4,8 @@ #include "fsfw/serviceinterface/ServiceInterface.h" #include "pdecconfigdefs.h" -PdecConfig::PdecConfig() : localParameterHandler("conf/pdecconfig.json", SdCardManager::instance()) {} +PdecConfig::PdecConfig() + : localParameterHandler("conf/pdecconfig.json", SdCardManager::instance()) {} PdecConfig::~PdecConfig() {} @@ -19,28 +20,28 @@ ReturnValue_t PdecConfig::write() { } ReturnValue_t result = initializePersistentParameters(); if (result != returnvalue::OK) { - return result; + return result; } result = writeFrameHeaderFirstOctet(); if (result != returnvalue::OK) { - return result; - } + return result; + } result = writeFrameHeaderSecondOctet(); if (result != returnvalue::OK) { - return result; - } + return result; + } writeMapConfig(); return returnvalue::OK; } ReturnValue_t PdecConfig::initializePersistentParameters() { ReturnValue_t result = localParameterHandler.initialize(); - if (result == HasFileSystemIF::FILE_DOES_NOT_EXIST) { - result = createPersistentConfig(); - if (result != returnvalue::OK) { - return result; - } - } + if (result == HasFileSystemIF::FILE_DOES_NOT_EXIST) { + result = createPersistentConfig(); + if (result != returnvalue::OK) { + return result; + } + } return result; } @@ -51,8 +52,8 @@ ReturnValue_t PdecConfig::createPersistentConfig() { sif::error << "PdecConfig::createPersistentConfig: Failed to set positive window" << std::endl; return result; } - result = localParameterHandler.addParameter( - pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, pdecconfigdefs::defaultvalue::negativeWindow); + result = localParameterHandler.addParameter(pdecconfigdefs::paramkeys::NEGATIVE_WINDOW, + pdecconfigdefs::defaultvalue::negativeWindow); if (result != returnvalue::OK) { sif::error << "PdecConfig::createPersistentConfig: Failed to set negative window" << std::endl; return result; diff --git a/linux/ipcore/PdecConfig.h b/linux/ipcore/PdecConfig.h index 0cff9871..f7203eec 100644 --- a/linux/ipcore/PdecConfig.h +++ b/linux/ipcore/PdecConfig.h @@ -3,8 +3,8 @@ #include -#include "bsp_q7s/memory/LocalParameterHandler.h" #include "bsp_q7s/fs/SdCardManager.h" +#include "bsp_q7s/memory/LocalParameterHandler.h" #include "fsfw/returnvalues/returnvalue.h" #include "pdec.h" @@ -19,9 +19,9 @@ */ class PdecConfig { public: - /** - * @brief Constructor - */ + /** + * @brief Constructor + */ PdecConfig(); virtual ~PdecConfig(); @@ -49,7 +49,6 @@ class PdecConfig { ReturnValue_t getNegativeWindow(uint8_t& negativeWindow); private: - // TC transfer frame configuration parameters static const uint8_t VERSION_ID = 0; // BD Frames @@ -66,25 +65,25 @@ class PdecConfig { static const uint8_t CONFIG_WORDS_NUM = 2; // 0x200 / 4 = 0x80 - static const uint32_t FRAME_HEADER_OFFSET = 0x80; + static const uint32_t FRAME_HEADER_OFFSET = 0x80; - static const uint32_t MAP_ADDR_LUT_OFFSET = 0xA0; - static const uint32_t MAP_CLK_FREQ_OFFSET = 0x90; - // MAP clock frequency. Must be a value between 1 and 13 otherwise the TC segment will be - // discarded - static const uint8_t MAP_CLK_FREQ = 2; + static const uint32_t MAP_ADDR_LUT_OFFSET = 0xA0; + static const uint32_t MAP_CLK_FREQ_OFFSET = 0x90; + // MAP clock frequency. Must be a value between 1 and 13 otherwise the TC segment will be + // discarded + static const uint8_t MAP_CLK_FREQ = 2; - static const uint8_t MAX_MAP_ADDR = 63; - // Writing this to the map address in the look up table will invalidate a MAP ID. - static const uint8_t NO_DESTINATION = 0; - static const uint8_t VALID_POSITION = 6; - static const uint8_t PARITY_POSITION = 7; + static const uint8_t MAX_MAP_ADDR = 63; + // Writing this to the map address in the look up table will invalidate a MAP ID. + static const uint8_t NO_DESTINATION = 0; + static const uint8_t VALID_POSITION = 6; + static const uint8_t PARITY_POSITION = 7; - /** - * TCs with map addresses (also know as Map IDs) assigned to this channel will be stored in - * the PDEC memory. - */ - static const uint8_t PM_BUFFER = 7; + /** + * TCs with map addresses (also know as Map IDs) assigned to this channel will be stored in + * the PDEC memory. + */ + static const uint8_t PM_BUFFER = 7; uint32_t* memoryBaseAddress = nullptr; @@ -103,30 +102,30 @@ class PdecConfig { */ ReturnValue_t createPersistentConfig(); - ReturnValue_t writeFrameHeaderFirstOctet(); - ReturnValue_t writeFrameHeaderSecondOctet(); - void writeMapConfig(); + ReturnValue_t writeFrameHeaderFirstOctet(); + ReturnValue_t writeFrameHeaderSecondOctet(); + void writeMapConfig(); - /** - * @brief This function calculates the entry for the configuration of the MAP ID routing. - * - * @param mapAddr The MAP ID to configure - * @param moduleId The destination module where all TCs with the map id mapAddr will be routed - * to. - * - * @details The PDEC has different modules where the TCs can be routed to. A lookup table is - * used which links the MAP ID field to the destination module. The entry for this - * lookup table is created by this function and must be stored in the configuration - * memory region of the PDEC. The entry has a specific format - */ - uint8_t calcMapAddrEntry(uint8_t moduleId); + /** + * @brief This function calculates the entry for the configuration of the MAP ID routing. + * + * @param mapAddr The MAP ID to configure + * @param moduleId The destination module where all TCs with the map id mapAddr will be routed + * to. + * + * @details The PDEC has different modules where the TCs can be routed to. A lookup table is + * used which links the MAP ID field to the destination module. The entry for this + * lookup table is created by this function and must be stored in the configuration + * memory region of the PDEC. The entry has a specific format + */ + uint8_t calcMapAddrEntry(uint8_t moduleId); - /** - * @brief This functions calculates the odd parity of the bits in number. - * - * @param number The number from which to calculate the odd parity. - */ - uint8_t getOddParity(uint8_t number); + /** + * @brief This functions calculates the odd parity of the bits in number. + * + * @param number The number from which to calculate the odd parity. + */ + uint8_t getOddParity(uint8_t number); }; #endif /* LINUX_OBC_PDECCONFIG_H_ */ diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 3ac9a465..3c901b42 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -30,7 +30,7 @@ PdecHandler::PdecHandler(object_id_t objectId, object_id_t tcDestinationId, pdecReset(pdecReset), actionHelper(this, nullptr), uioNames(names), - paramHelper(this) { + paramHelper(this) { auto mqArgs = MqArgs(objectId, static_cast(this)); commandQueue = QueueFactory::instance()->createMessageQueue( QUEUE_SIZE, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); @@ -91,33 +91,33 @@ ReturnValue_t PdecHandler::initialize() { } ReturnValue_t PdecHandler::firstLoop() { - ReturnValue_t result = pdecConfig.write(); - if (result != returnvalue::OK) { - if (result == LocalParameterHandler::SD_NOT_READY) { - return result; - } else { - sif::error << "PdecHandler::firstLoop: Failed to write PDEC config" << std::endl; - } - return returnvalue::FAILED; - } + ReturnValue_t result = pdecConfig.write(); + if (result != returnvalue::OK) { + if (result == LocalParameterHandler::SD_NOT_READY) { + return result; + } else { + sif::error << "PdecHandler::firstLoop: Failed to write PDEC config" << std::endl; + } + return returnvalue::FAILED; + } - result = releasePdec(); - if (result != returnvalue::OK) { - return returnvalue::FAILED; - } + result = releasePdec(); + if (result != returnvalue::OK) { + return returnvalue::FAILED; + } - // This configuration must be done while the PDEC is not held in reset. - if (OP_MODE == Modes::IRQ) { - // Configure interrupt mask register to enable interrupts - *(registerBaseAddress + PDEC_IMR_OFFSET) = pdecConfig.getImrReg(); - } - result = resetFarStatFlag(); - if (result != returnvalue::OK) { - // Requires reconfiguration and reinitialization of PDEC - triggerEvent(INVALID_FAR); - return result; - } - return returnvalue::OK; + // This configuration must be done while the PDEC is not held in reset. + if (OP_MODE == Modes::IRQ) { + // Configure interrupt mask register to enable interrupts + *(registerBaseAddress + PDEC_IMR_OFFSET) = pdecConfig.getImrReg(); + } + result = resetFarStatFlag(); + if (result != returnvalue::OK) { + // Requires reconfiguration and reinitialization of PDEC + triggerEvent(INVALID_FAR); + return result; + } + return returnvalue::OK; } ReturnValue_t PdecHandler::performOperation(uint8_t operationCode) { @@ -134,7 +134,7 @@ ReturnValue_t PdecHandler::polledOperation() { switch (state) { case State::INIT: { - handleInitState(); + handleInitState(); break; } case State::RUNNING: { @@ -145,13 +145,13 @@ ReturnValue_t PdecHandler::polledOperation() { break; } case State::PDEC_RESET: { - ReturnValue_t result = pdecToReset(); - if (result != returnvalue::OK) { - triggerEvent(PDEC_RESET_FAILED); - } - state = State::INIT; - break; - } + ReturnValue_t result = pdecToReset(); + if (result != returnvalue::OK) { + triggerEvent(PDEC_RESET_FAILED); + } + state = State::INIT; + break; + } case State::WAIT_FOR_RECOVERY: break; default: @@ -191,12 +191,12 @@ ReturnValue_t PdecHandler::irqOperation() { break; } case State::PDEC_RESET: { - ReturnValue_t result = pdecToReset(); - if (result != returnvalue::OK) { - triggerEvent(PDEC_RESET_FAILED); - } - state = State::INIT; - break; + ReturnValue_t result = pdecToReset(); + if (result != returnvalue::OK) { + triggerEvent(PDEC_RESET_FAILED); + } + state = State::INIT; + break; } case State::RUNNING: { checkAndHandleIrqs(fd, info); @@ -218,24 +218,24 @@ ReturnValue_t PdecHandler::irqOperation() { } void PdecHandler::handleInitState() { - ReturnValue_t result = firstLoop(); - if (result != returnvalue::OK) { - if (result == LocalParameterHandler::SD_NOT_READY) { - TaskFactory::delayTask(400); - if (initTries == MAX_INIT_TRIES) { - sif::error << "PdecHandler::handleInitState: SD card never " - "becomes ready" - << std::endl; - state = State::WAIT_FOR_RECOVERY; - return; - } else { - state = State::INIT; - return; - } - } - state = State::WAIT_FOR_RECOVERY; - } - state = State::RUNNING; + ReturnValue_t result = firstLoop(); + if (result != returnvalue::OK) { + if (result == LocalParameterHandler::SD_NOT_READY) { + TaskFactory::delayTask(400); + if (initTries == MAX_INIT_TRIES) { + sif::error << "PdecHandler::handleInitState: SD card never " + "becomes ready" + << std::endl; + state = State::WAIT_FOR_RECOVERY; + return; + } else { + state = State::INIT; + return; + } + } + state = State::WAIT_FOR_RECOVERY; + } + state = State::RUNNING; } ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { @@ -422,7 +422,8 @@ ReturnValue_t PdecHandler::pdecToReset() { result = gpioComIF->pullLow(pdecReset); if (result != returnvalue::OK) { sif::error << "PdecHandler::pdecToReset: Failed to pull PDEC reset line" - " to low" << std::endl; + " to low" + << std::endl; } return result; } diff --git a/linux/ipcore/PdecHandler.h b/linux/ipcore/PdecHandler.h index b15736c1..d3507211 100644 --- a/linux/ipcore/PdecHandler.h +++ b/linux/ipcore/PdecHandler.h @@ -8,9 +8,9 @@ #include "eive/definitions.h" #include "fsfw/action/ActionHelper.h" #include "fsfw/action/HasActionsIF.h" -#include "fsfw/parameters/ReceivesParameterMessagesIF.h" -#include "fsfw/parameters/ParameterHelper.h" #include "fsfw/objectmanager/SystemObject.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/parameters/ReceivesParameterMessagesIF.h" #include "fsfw/returnvalues/returnvalue.h" #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" @@ -103,8 +103,7 @@ class PdecHandler : public SystemObject, static constexpr Event WRITE_SYSCALL_ERROR_PDEC = event::makeEvent(SUBSYSTEM_ID, 9, severity::MEDIUM); //! [EXPORT] : [COMMENT] Failed to pull PDEC reset to low - static constexpr Event PDEC_RESET_FAILED = - event::makeEvent(SUBSYSTEM_ID, 10, severity::HIGH); + static constexpr Event PDEC_RESET_FAILED = event::makeEvent(SUBSYSTEM_ID, 10, severity::HIGH); private: static const uint8_t INTERFACE_ID = CLASS_ID::PDEC_HANDLER; @@ -175,11 +174,11 @@ class PdecHandler : public SystemObject, static const uint32_t MAX_INIT_TRIES = 20; class ParameterId { - public: - // ID of the parameter to update the positive window of AD frames - static const uint8_t POSITIVE_WINDOW = 0; - // ID of the parameter to update the negative window of AD frames - static const uint8_t NEGATIVE_WINDOW = 1; + public: + // ID of the parameter to update the positive window of AD frames + static const uint8_t POSITIVE_WINDOW = 0; + // ID of the parameter to update the negative window of AD frames + static const uint8_t NEGATIVE_WINDOW = 1; }; static constexpr uint32_t MAX_ALLOWED_IRQS_PER_WINDOW = 800; @@ -377,7 +376,6 @@ class PdecHandler : public SystemObject, */ uint8_t calcMapAddrEntry(uint8_t moduleId); - /** * brief Returns the 32-bit wide communication link control word (CLCW) */ diff --git a/linux/ipcore/pdecconfigdefs.h b/linux/ipcore/pdecconfigdefs.h index bc2cfa8c..0b7f392c 100644 --- a/linux/ipcore/pdecconfigdefs.h +++ b/linux/ipcore/pdecconfigdefs.h @@ -6,15 +6,15 @@ namespace pdecconfigdefs { namespace paramkeys { - static const std::string POSITIVE_WINDOW = "positive_window"; - static const std::string NEGATIVE_WINDOW = "negattive_window"; -} +static const std::string POSITIVE_WINDOW = "positive_window"; +static const std::string NEGATIVE_WINDOW = "negattive_window"; +} // namespace paramkeys namespace defaultvalue { - static const uint8_t positiveWindow = 10; - static const uint8_t negativeWindow = 151; -} +static const uint8_t positiveWindow = 10; +static const uint8_t negativeWindow = 151; +} // namespace defaultvalue -} +} // namespace pdecconfigdefs #endif /* LINUX_IPCORE_PDECCONFIGDEFS_H_ */ diff --git a/mission/config/configfile.h b/mission/config/configfile.h index eb8fb0a5..3fa9f070 100644 --- a/mission/config/configfile.h +++ b/mission/config/configfile.h @@ -2,8 +2,8 @@ #define MISSION_CONFIG_CONFIGFILE_H_ namespace configfile { - // Name of global config file relative to currently mounted SD card - static const char sdrelative[] = "config/global_config.json"; -} +// Name of global config file relative to currently mounted SD card +static const char sdrelative[] = "config/global_config.json"; +} // namespace configfile #endif /* MISSION_CONFIG_CONFIGFILE_H_ */ diff --git a/mission/controller/acs/Guidance.cpp b/mission/controller/acs/Guidance.cpp index 2346d18f..031cd384 100644 --- a/mission/controller/acs/Guidance.cpp +++ b/mission/controller/acs/Guidance.cpp @@ -111,8 +111,7 @@ void Guidance::targetQuatPtgSingleAxis(timeval now, double posSatE[3], double ve if (sightAngleSun < critSightAngle) { strBlindAvoidFlag = true; } - } - else { + } else { if (sightAngleSun < blindEnd * exclAngle) { double normBlindRefRate = acsParameters.targetModeControllerParameters.blindRotRate; double blindRefRate[3] = {0, 0, 0}; diff --git a/mission/controller/acs/MultiplicativeKalmanFilter.cpp b/mission/controller/acs/MultiplicativeKalmanFilter.cpp index d90f3f51..5bae4624 100644 --- a/mission/controller/acs/MultiplicativeKalmanFilter.cpp +++ b/mission/controller/acs/MultiplicativeKalmanFilter.cpp @@ -1098,7 +1098,7 @@ void MultiplicativeKalmanFilter::reset(acsctrl::MekfData *mekfData) { } void MultiplicativeKalmanFilter::updateDataSetWithoutData(acsctrl::MekfData *mekfData, - MekfStatus mekfStatus) { + MekfStatus mekfStatus) { { PoolReadGuard pg(mekfData); if (pg.getReadResult() == returnvalue::OK) { @@ -1114,9 +1114,8 @@ void MultiplicativeKalmanFilter::updateDataSetWithoutData(acsctrl::MekfData *mek } } -void MultiplicativeKalmanFilter::updateDataSet(acsctrl::MekfData *mekfData, - MekfStatus mekfStatus, double quat[4], - double satRotRate[3]) { +void MultiplicativeKalmanFilter::updateDataSet(acsctrl::MekfData *mekfData, MekfStatus mekfStatus, + double quat[4], double satRotRate[3]) { { PoolReadGuard pg(mekfData); if (pg.getReadResult() == returnvalue::OK) { diff --git a/mission/memory/NVMParameterBase.h b/mission/memory/NVMParameterBase.h index ba5c57da..8487c990 100644 --- a/mission/memory/NVMParameterBase.h +++ b/mission/memory/NVMParameterBase.h @@ -69,7 +69,7 @@ inline ReturnValue_t NVMParameterBase::insertValue(std::string key, T value) { template inline ReturnValue_t NVMParameterBase::setValue(std::string key, T value) { - json[key] = value; + json[key] = value; return returnvalue::OK; } diff --git a/mission/system/objects/ComSubsystem.h b/mission/system/objects/ComSubsystem.h index 85bb4273..fb97f226 100644 --- a/mission/system/objects/ComSubsystem.h +++ b/mission/system/objects/ComSubsystem.h @@ -17,8 +17,8 @@ class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { * @param maxNumberOfSequences * @param maxNumberOfTables * @param transmitterTimeout Maximum time the transmitter of the syrlinks - * will be - * enabled + * will + * be enabled */ ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequences, uint32_t maxNumberOfTables, uint32_t transmitterTimeout); diff --git a/mission/utility/GlobalConfigFileDefinitions.h b/mission/utility/GlobalConfigFileDefinitions.h index 2c9b6b66..13d8cdfa 100644 --- a/mission/utility/GlobalConfigFileDefinitions.h +++ b/mission/utility/GlobalConfigFileDefinitions.h @@ -11,12 +11,6 @@ static constexpr double PARAM0_DEFAULT = 5.0; static constexpr int PARAM1_DEFAULT = 905; -enum ParamIds : uint8_t { - PARAM0 = 0, - PARAM1 = 1, - PARAM2 = 2, - PDEC_PW = 3, - PDEC_NW = 4 -}; +enum ParamIds : uint8_t { PARAM0 = 0, PARAM1 = 1, PARAM2 = 2, PDEC_PW = 3, PDEC_NW = 4 }; #endif /* MISSION_UTILITY_GLOBALCONFIGFILEDEFINITIONS_H_ */ From ee4db78a9595efb4a045cb88428e976e4b8ca7c0 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 23 Feb 2023 15:37:20 +0100 Subject: [PATCH 10/15] removed wrong comment --- bsp_q7s/memory/LocalParameterHandler.h | 1 - 1 file changed, 1 deletion(-) diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h index b32761ef..a8b96950 100644 --- a/bsp_q7s/memory/LocalParameterHandler.h +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -9,7 +9,6 @@ /** * @brief Class to handle persistent parameters * - * @details Use the insertValue function to add parameters */ class LocalParameterHandler : public NVMParameterBase { public: From 316971c6bc9e754339f87b743b3587c6814eca5d Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 27 Feb 2023 07:49:09 +0100 Subject: [PATCH 11/15] * added event when transmitter is turned on due to bitlock detection * added event when tx timer has expired --- common/config/eive/eventSubsystemIds.h | 1 + linux/ipcore/PdecHandler.cpp | 4 +--- mission/system/objects/ComSubsystem.cpp | 2 ++ mission/system/objects/ComSubsystem.h | 13 +++++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/common/config/eive/eventSubsystemIds.h b/common/config/eive/eventSubsystemIds.h index 32397f9f..923a06ad 100644 --- a/common/config/eive/eventSubsystemIds.h +++ b/common/config/eive/eventSubsystemIds.h @@ -37,6 +37,7 @@ enum : uint8_t { CONFIGHANDLER = 139, CORE = 140, TCS_CONTROLLER = 141, + COM_SUBSYSTEM = 142, COMMON_SUBSYSTEM_ID_END }; diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index 3c901b42..db93bd6e 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -187,7 +187,6 @@ ReturnValue_t PdecHandler::irqOperation() { switch (state) { case State::INIT: { handleInitState(); - checkLocks(); break; } case State::PDEC_RESET: { @@ -199,6 +198,7 @@ ReturnValue_t PdecHandler::irqOperation() { break; } case State::RUNNING: { + checkLocks(); checkAndHandleIrqs(fd, info); break; } @@ -251,7 +251,6 @@ ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { int ret = poll(&fds, 1, IRQ_TIMEOUT_MS); if (ret == 0) { // No TCs for timeout period - checkLocks(); genericCheckCd.resetTimer(); resetIrqLimiters(); } else if (ret >= 1) { @@ -278,7 +277,6 @@ ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { static_cast(dummy); if (genericCheckCd.hasTimedOut()) { - checkLocks(); genericCheckCd.resetTimer(); if (interruptWindowCd.hasTimedOut()) { if (interruptCounter >= MAX_ALLOWED_IRQS_PER_WINDOW) { diff --git a/mission/system/objects/ComSubsystem.cpp b/mission/system/objects/ComSubsystem.cpp index a30f441b..9df7e72b 100644 --- a/mission/system/objects/ComSubsystem.cpp +++ b/mission/system/objects/ComSubsystem.cpp @@ -166,6 +166,7 @@ void ComSubsystem::handleBitLockEvent() { rememberBitLock = true; return; } + triggerEvent(BIT_LOCK_TX_ON); startRxAndTxLowRateSeq(); } @@ -183,6 +184,7 @@ void ComSubsystem::startRxAndTxLowRateSeq() { void ComSubsystem::checkTransmitterCountdown() { if (transmitterCountdown.hasTimedOut()) { + triggerEvent(TX_TIMER_EXPIRED, transmitterTimeout); startTransition(com::Submode::RX_ONLY, SUBMODE_NONE); countdownActive = false; } diff --git a/mission/system/objects/ComSubsystem.h b/mission/system/objects/ComSubsystem.h index fb97f226..831b4cec 100644 --- a/mission/system/objects/ComSubsystem.h +++ b/mission/system/objects/ComSubsystem.h @@ -5,11 +5,21 @@ #include #include #include +#include #include "mission/comDefs.h" class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { public: + + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::COM_SUBSYSTEM; + + //! [EXPORT] : [COMMENT] The transmit timer to protect the Syrlinks expired + //! P1: The current timer value + static const Event TX_TIMER_EXPIRED = MAKE_EVENT(1, severity::INFO); + //! [EXPORT] : [COMMENT] Transmitter will be turned on due to detection of bitlock + static const Event BIT_LOCK_TX_ON = MAKE_EVENT(2, severity::INFO); + /** * @brief Constructor * @@ -17,8 +27,7 @@ class ComSubsystem : public Subsystem, public ReceivesParameterMessagesIF { * @param maxNumberOfSequences * @param maxNumberOfTables * @param transmitterTimeout Maximum time the transmitter of the syrlinks - * will - * be enabled + * will be enabled */ ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequences, uint32_t maxNumberOfTables, uint32_t transmitterTimeout); From 20edbf6213a47c281e4ee7691803d0d97ab96568 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 27 Feb 2023 08:50:47 +0100 Subject: [PATCH 12/15] included classIds in ComSubsystem --- bsp_q7s/memory/LocalParameterHandler.h | 1 + 1 file changed, 1 insertion(+) diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h index a8b96950..77822d49 100644 --- a/bsp_q7s/memory/LocalParameterHandler.h +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -3,6 +3,7 @@ #include #include +#include #include From 0df5070fa675a6f8f3033bd547561e9df551c607 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 27 Feb 2023 09:03:06 +0100 Subject: [PATCH 13/15] moved sd card manager and local param handler class ids to commonClassIds --- common/config/eive/resultClassIds.h | 2 ++ linux/fsfwconfig/returnvalues/classIds.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/config/eive/resultClassIds.h b/common/config/eive/resultClassIds.h index 310d9e0b..f7bf26c1 100644 --- a/common/config/eive/resultClassIds.h +++ b/common/config/eive/resultClassIds.h @@ -40,6 +40,8 @@ enum commonClassIds : uint8_t { ACS_SAFE, // ACSSAF ACS_PTG, // ACSPTG ACS_DETUMBLE, // ACSDTB + SD_CARD_MANAGER, // SDMA + LOCAL_PARAM_HANDLER, // LPH COMMON_CLASS_ID_END // [EXPORT] : [END] }; } diff --git a/linux/fsfwconfig/returnvalues/classIds.h b/linux/fsfwconfig/returnvalues/classIds.h index 0e1b2c7c..0a71a8b6 100644 --- a/linux/fsfwconfig/returnvalues/classIds.h +++ b/linux/fsfwconfig/returnvalues/classIds.h @@ -13,9 +13,7 @@ namespace CLASS_ID { enum { CLASS_ID_START = COMMON_CLASS_ID_END, - SD_CARD_MANAGER, // SDMA SCRATCH_BUFFER, // SCBU - LOCAL_PARAM_HANDLER, // LPH CLASS_ID_END // [EXPORT] : [END] }; } From 89ba9f7009bc72e2463b1d472e75c01948ea11bf Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 27 Feb 2023 09:12:50 +0100 Subject: [PATCH 14/15] removed class id header --- bsp_q7s/memory/LocalParameterHandler.h | 1 - 1 file changed, 1 deletion(-) diff --git a/bsp_q7s/memory/LocalParameterHandler.h b/bsp_q7s/memory/LocalParameterHandler.h index 77822d49..a8b96950 100644 --- a/bsp_q7s/memory/LocalParameterHandler.h +++ b/bsp_q7s/memory/LocalParameterHandler.h @@ -3,7 +3,6 @@ #include #include -#include #include From c06dd15303331429b781843a65cb8a4d8f427f9e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Mon, 27 Feb 2023 11:35:43 +0100 Subject: [PATCH 15/15] minor bugfix in PDEC Handler --- linux/ipcore/PdecHandler.cpp | 33 +++++++++++++++++++++------------ linux/ipcore/PdecHandler.h | 8 ++++++-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/linux/ipcore/PdecHandler.cpp b/linux/ipcore/PdecHandler.cpp index db93bd6e..80327c94 100644 --- a/linux/ipcore/PdecHandler.cpp +++ b/linux/ipcore/PdecHandler.cpp @@ -164,13 +164,8 @@ ReturnValue_t PdecHandler::polledOperation() { // See https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt.html for more information. ReturnValue_t PdecHandler::irqOperation() { - int fd = open(uioNames.irq, O_RDWR); - if (fd < 0) { - sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" - << std::endl; - return returnvalue::FAILED; - } - + ReturnValue_t result = returnvalue::OK; + int fd = -1; // Used to unmask IRQ uint32_t info = 1; @@ -186,11 +181,14 @@ ReturnValue_t PdecHandler::irqOperation() { readCommandQueue(); switch (state) { case State::INIT: { - handleInitState(); + result = handleInitState(); + if (result == returnvalue::OK) { + openIrqFile(&fd); + } break; } case State::PDEC_RESET: { - ReturnValue_t result = pdecToReset(); + result = pdecToReset(); if (result != returnvalue::OK) { triggerEvent(PDEC_RESET_FAILED); } @@ -217,7 +215,7 @@ ReturnValue_t PdecHandler::irqOperation() { return returnvalue::OK; } -void PdecHandler::handleInitState() { +ReturnValue_t PdecHandler::handleInitState() { ReturnValue_t result = firstLoop(); if (result != returnvalue::OK) { if (result == LocalParameterHandler::SD_NOT_READY) { @@ -227,15 +225,26 @@ void PdecHandler::handleInitState() { "becomes ready" << std::endl; state = State::WAIT_FOR_RECOVERY; - return; } else { state = State::INIT; - return; } + return result; } state = State::WAIT_FOR_RECOVERY; + return result; } state = State::RUNNING; + return returnvalue::OK; +} + +void PdecHandler::openIrqFile(int* fd) { + *fd = open(uioNames.irq, O_RDWR); + if (*fd < 0) { + sif::error << "PdecHandler::irqOperation: Opening UIO IRQ file" << uioNames.irq << " failed" + << std::endl; + triggerEvent(OPEN_IRQ_FILE_FAILED); + state = State::WAIT_FOR_RECOVERY; + } } ReturnValue_t PdecHandler::checkAndHandleIrqs(int fd, uint32_t& info) { diff --git a/linux/ipcore/PdecHandler.h b/linux/ipcore/PdecHandler.h index d3507211..e98e939c 100644 --- a/linux/ipcore/PdecHandler.h +++ b/linux/ipcore/PdecHandler.h @@ -101,9 +101,12 @@ class PdecHandler : public SystemObject, static constexpr Event POLL_SYSCALL_ERROR_PDEC = event::makeEvent(SUBSYSTEM_ID, 8, severity::MEDIUM); static constexpr Event WRITE_SYSCALL_ERROR_PDEC = - event::makeEvent(SUBSYSTEM_ID, 9, severity::MEDIUM); + event::makeEvent(SUBSYSTEM_ID, 9, severity::HIGH); //! [EXPORT] : [COMMENT] Failed to pull PDEC reset to low static constexpr Event PDEC_RESET_FAILED = event::makeEvent(SUBSYSTEM_ID, 10, severity::HIGH); + //! [EXPORT] : [COMMENT] Failed to open the IRQ uio file + static constexpr Event OPEN_IRQ_FILE_FAILED = + event::makeEvent(SUBSYSTEM_ID, 11, severity::HIGH); private: static const uint8_t INTERFACE_ID = CLASS_ID::PDEC_HANDLER; @@ -279,7 +282,8 @@ class PdecHandler : public SystemObject, ReturnValue_t polledOperation(); ReturnValue_t irqOperation(); - void handleInitState(); + ReturnValue_t handleInitState(); + void openIrqFile(int* fd); ReturnValue_t checkAndHandleIrqs(int fd, uint32_t& info); uint32_t readFar();