From 711732ccd6a635ec698fbce3962a9a208d9cce37 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 1 Mar 2022 17:41:58 +0100 Subject: [PATCH 1/3] Udated for memory management --- bsp_q7s/memory/SdCardManager.cpp | 8 +++++++- bsp_q7s/memory/SdCardManager.h | 16 ++++++++++------ mission/memory/SdCardMountedIF.h | 18 ++++++++++++++++++ {bsp_q7s => mission}/memory/definitions.h | 0 tmtc | 2 +- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 mission/memory/SdCardMountedIF.h rename {bsp_q7s => mission}/memory/definitions.h (100%) diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index b9b89bb9..769a7dd7 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -1,5 +1,6 @@ #include "SdCardManager.h" +#include #include #include @@ -15,7 +16,9 @@ SdCardManager* SdCardManager::factoryInstance = nullptr; -SdCardManager::SdCardManager() : SystemObject(objects::SDC_MANAGER), cmdExecutor(256) {} +SdCardManager::SdCardManager() : SystemObject(objects::SDC_MANAGER), cmdExecutor(256) { + mutex = MutexFactory::instance()->createMutex(); +} SdCardManager::~SdCardManager() {} @@ -162,6 +165,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) { ReturnValue_t SdCardManager::getSdCardActiveStatus(SdStatePair& active) { using namespace std; + MutexGuard mg(mutex); if (not filesystem::exists(SD_STATE_FILE)) { return STATUS_FILE_NEXISTS; } @@ -366,6 +370,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) { return CommandExecutor::COMMAND_PENDING; } + MutexGuard mg(mutex); // Use q7hw utility and pipe the command output into the state file std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE); cmdExecutor.load(updateCmd, blocking, printCmdOutput); @@ -440,6 +445,7 @@ void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = p bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) { SdCardManager::SdStatePair active; ReturnValue_t result = this->getSdCardActiveStatus(active); + if (result != HasReturnvaluesIF::RETURN_OK) { sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state"; return false; diff --git a/bsp_q7s/memory/SdCardManager.h b/bsp_q7s/memory/SdCardManager.h index 51ea3425..37660f75 100644 --- a/bsp_q7s/memory/SdCardManager.h +++ b/bsp_q7s/memory/SdCardManager.h @@ -10,11 +10,12 @@ #include #include -#include "definitions.h" #include "events/subsystemIdRanges.h" #include "fsfw/events/Event.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw_hal/linux/CommandExecutor.h" +#include "mission/memory/SdCardMountedIF.h" +#include "mission/memory/definitions.h" #include "returnvalues/classIds.h" class MutexIF; @@ -23,10 +24,12 @@ class MutexIF; * @brief Manages handling of SD cards like switching them on or off or getting the current * state */ -class SdCardManager : public SystemObject { +class SdCardManager : public SystemObject, public SdCardMountedIF { friend class SdCardAccess; public: + using mountInitCb = ReturnValue_t (*)(void* args); + enum class Operations { SWITCHING_ON, SWITCHING_OFF, MOUNTING, UNMOUNTING, IDLE }; enum class OpStatus { IDLE, TIMEOUT, ONGOING, SUCCESS, FAIL }; @@ -88,7 +91,7 @@ class SdCardManager : public SystemObject { * @param sdCard * @return */ - ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const; + ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const override; /** * Switch on the specified SD card. @@ -170,7 +173,7 @@ class SdCardManager : public SystemObject { * @param prefSdCardPtr * @return */ - std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE); + std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE) override; OpStatus checkCurrentOp(Operations& currentOp); @@ -183,19 +186,20 @@ class SdCardManager : public SystemObject { void setPrintCommandOutput(bool print); /** - * @brief Checks if an SD card is mounted + * @brief Checks if an SD card is mounted. * * @param sdCard The SD card to check * * @return true if mounted, otherwise false */ - bool isSdCardMounted(sd::SdCard sdCard); + bool isSdCardMounted(sd::SdCard sdCard) override; private: CommandExecutor cmdExecutor; Operations currentOp = Operations::IDLE; bool blocking = false; bool printCmdOutput = true; + MutexIF* mutex = nullptr; SdCardManager(); diff --git a/mission/memory/SdCardMountedIF.h b/mission/memory/SdCardMountedIF.h new file mode 100644 index 00000000..ff6aace3 --- /dev/null +++ b/mission/memory/SdCardMountedIF.h @@ -0,0 +1,18 @@ +#ifndef MISSION_MEMORY_SDCARDMOUNTERIF_H_ +#define MISSION_MEMORY_SDCARDMOUNTERIF_H_ + +#include + +#include "definitions.h" + +class SdCardMountedIF { + public: + virtual ~SdCardMountedIF(){}; + virtual std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE) = 0; + virtual bool isSdCardMounted(sd::SdCard sdCard) = 0; + virtual ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const = 0; + + private: +}; + +#endif /* MISSION_MEMORY_SDCARDMOUNTERIF_H_ */ diff --git a/bsp_q7s/memory/definitions.h b/mission/memory/definitions.h similarity index 100% rename from bsp_q7s/memory/definitions.h rename to mission/memory/definitions.h diff --git a/tmtc b/tmtc index 56d414d9..2c96b9ed 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 56d414d9fc0d6b05f967c47a0bd124fc06de2ad3 +Subproject commit 2c96b9ed4c3392e83251809190b2049ff685f5cc From db75f6d3bf11d81829147907499baddddcbb1047 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 1 Mar 2022 17:45:41 +0100 Subject: [PATCH 2/3] repoint fsfw --- fsfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw b/fsfw index 6e0b9069..e05e203c 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 6e0b90696da2dfd2ec4749dfdb73950be2283c25 +Subproject commit e05e203c83825b4069bb1391005d46f041b08455 From fd368343c47347956e867afd8fd9c6fc80d7deb0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Mar 2022 10:36:53 +0100 Subject: [PATCH 3/3] submodule updates --- fsfw | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fsfw b/fsfw index e05e203c..75c56280 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit e05e203c83825b4069bb1391005d46f041b08455 +Subproject commit 75c56280ad139640d2c12ac4ab78ce66c25fb495 diff --git a/tmtc b/tmtc index 2c96b9ed..37c1a68d 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 2c96b9ed4c3392e83251809190b2049ff685f5cc +Subproject commit 37c1a68da1b465514e84403b06ce40d035e4ad88