From 08c5c5ebebc400638c0c68743f52f2a4e623d094 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Jul 2021 12:09:31 +0200 Subject: [PATCH] added more sd card stubs --- bsp_q7s/CMakeLists.txt | 1 + bsp_q7s/boardconfig/q7sConfig.h.in | 8 ++++ bsp_q7s/boardtest/CMakeLists.txt | 1 + bsp_q7s/boardtest/FileSystemTest.cpp | 9 +++- bsp_q7s/boardtest/Q7STestTask.cpp | 42 ++++++++++++++++ bsp_q7s/boardtest/Q7STestTask.h | 16 +++++++ bsp_q7s/core/ObjectFactory.cpp | 7 +++ bsp_q7s/memory/CMakeLists.txt | 1 + bsp_q7s/memory/SdCardAccess.cpp | 20 +++++++- bsp_q7s/memory/SdCardAccess.h | 4 +- bsp_q7s/memory/SdCardAccessManager.cpp | 33 +++++++++++++ bsp_q7s/memory/SdCardAccessManager.h | 48 +++++++++++++++++++ bsp_q7s/memory/definitions.h | 15 ++++++ fsfw | 2 +- .../pollingSequenceFactory.cpp | 10 ++++ mission/core/GenericFactory.cpp | 5 -- 16 files changed, 213 insertions(+), 9 deletions(-) create mode 100644 bsp_q7s/boardtest/Q7STestTask.cpp create mode 100644 bsp_q7s/boardtest/Q7STestTask.h create mode 100644 bsp_q7s/memory/SdCardAccessManager.cpp create mode 100644 bsp_q7s/memory/SdCardAccessManager.h create mode 100644 bsp_q7s/memory/definitions.h diff --git a/bsp_q7s/CMakeLists.txt b/bsp_q7s/CMakeLists.txt index d0ee0800..d4f69217 100644 --- a/bsp_q7s/CMakeLists.txt +++ b/bsp_q7s/CMakeLists.txt @@ -11,4 +11,5 @@ else() add_subdirectory(comIF) add_subdirectory(gpio) add_subdirectory(core) + add_subdirectory(memory) endif() diff --git a/bsp_q7s/boardconfig/q7sConfig.h.in b/bsp_q7s/boardconfig/q7sConfig.h.in index bf509f0d..9bed2a4a 100644 --- a/bsp_q7s/boardconfig/q7sConfig.h.in +++ b/bsp_q7s/boardconfig/q7sConfig.h.in @@ -1,6 +1,8 @@ #ifndef BSP_Q7S_BOARDCONFIG_Q7S_CONFIG_H_ #define BSP_Q7S_BOARDCONFIG_Q7S_CONFIG_H_ +#include + #cmakedefine01 Q7S_SIMPLE_MODE #define Q7S_ADD_RTD_DEVICES 0 @@ -13,4 +15,10 @@ #define Q7S_SIMPLE_ADD_FILE_SYSTEM_TEST 0 +namespace config { + +static const uint32_t SD_CARD_ACCESS_MUTEX_TIMEOUT = 50; + +} + #endif /* BSP_Q7S_BOARDCONFIG_Q7S_CONFIG_H_ */ diff --git a/bsp_q7s/boardtest/CMakeLists.txt b/bsp_q7s/boardtest/CMakeLists.txt index 9a5c0a0a..1cda38ca 100644 --- a/bsp_q7s/boardtest/CMakeLists.txt +++ b/bsp_q7s/boardtest/CMakeLists.txt @@ -1,5 +1,6 @@ target_sources(${TARGET_NAME} PRIVATE FileSystemTest.cpp + Q7STestTask.cpp ) diff --git a/bsp_q7s/boardtest/FileSystemTest.cpp b/bsp_q7s/boardtest/FileSystemTest.cpp index fa504b0c..1de5bb7a 100644 --- a/bsp_q7s/boardtest/FileSystemTest.cpp +++ b/bsp_q7s/boardtest/FileSystemTest.cpp @@ -1,4 +1,5 @@ #include "FileSystemTest.h" +#include "fsfw/timemanager/Stopwatch.h" #include #include @@ -7,7 +8,13 @@ FileSystemTest::FileSystemTest() { using namespace std; SdCard sdCard = SdCard::SDC0; cout << "SD Card Test for SD card " << static_cast(sdCard) << std::endl; - //std::system("echo Hello World"); + //Stopwatch stopwatch; + std::system("q7hw sd info all > /tmp/sd_status.txt"); + //stopwatch.stop(true); + std::system("q7hw sd set 0 on > /tmp/sd_set.txt"); + //stopwatch.stop(true); + std::system("q7hw sd set 0 off > /tmp/sd_set.txt"); + //stopwatch.stop(true); } FileSystemTest::~FileSystemTest() { diff --git a/bsp_q7s/boardtest/Q7STestTask.cpp b/bsp_q7s/boardtest/Q7STestTask.cpp new file mode 100644 index 00000000..0166bfb8 --- /dev/null +++ b/bsp_q7s/boardtest/Q7STestTask.cpp @@ -0,0 +1,42 @@ +#include "Q7STestTask.h" +#include "fsfw/timemanager/Stopwatch.h" +#include "fsfw/tasks/TaskFactory.h" +#include +#include +#include + +Q7STestTask::Q7STestTask(object_id_t objectId): TestTask(objectId) { +} + +ReturnValue_t Q7STestTask::performOneShotAction() { + sdCardTests(); + return TestTask::performOneShotAction(); +} + +void Q7STestTask::sdCardTests() { + using namespace std; + Stopwatch stopwatch; + FILE* testFile = popen("q7hw sd info all > /tmp/sd_status.txt", "r"); + TaskFactory::delayTask(3000); + //int result = system(); + //std::fstream fs(testFile); + // Read contents from file + char* line = nullptr; + size_t len = 0; + ssize_t read = getline(&line, &len, testFile); + if(read != -1 and line != nullptr) { + cout << line << endl; + } +// c = fgetc(testFile); +// while (c != EOF) +// { +// printf ("%c", c); +// c = fgetc(testFile); +// } +// cout << "Info result " << result << endl; +// stopwatch.stop(true); +// system("q7hw sd set 0 on > /tmp/sd_set.txt"); +// stopwatch.stop(true); +// system("q7hw sd set 0 off > /tmp/sd_set.txt"); +// stopwatch.stop(true); +} diff --git a/bsp_q7s/boardtest/Q7STestTask.h b/bsp_q7s/boardtest/Q7STestTask.h new file mode 100644 index 00000000..4b1aea7e --- /dev/null +++ b/bsp_q7s/boardtest/Q7STestTask.h @@ -0,0 +1,16 @@ +#ifndef BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ +#define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ + +#include "test/testtasks/TestTask.h" + +class Q7STestTask: public TestTask { +public: + Q7STestTask(object_id_t objectId); +private: + ReturnValue_t performOneShotAction() override; + + void sdCardTests(); +}; + + +#endif /* BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ */ diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 99ec65c2..bb0edf82 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -1,3 +1,4 @@ +#include #include "ObjectFactory.h" #include "OBSWConfig.h" #include "tmtc/apid.h" @@ -556,6 +557,11 @@ void ObjectFactory::produce(void* args){ new UdpTmTcBridge(objects::UDP_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR); new UdpTcPollingTask(objects::UDP_POLLING_TASK, objects::UDP_BRIDGE); + /* Test Task */ +#if OBSW_ADD_TEST_CODE == 1 + new Q7STestTask(objects::TEST_TASK); +#endif + #if TE0720 == 1 && TEST_LIBGPIOD == 1 /* Configure MIO0 as input */ GpiodRegular gpioConfigMio0(std::string("gpiochip0"), 0, @@ -630,4 +636,5 @@ void ObjectFactory::produce(void* args){ #if Q7S_ADD_SPI_TEST == 1 new SpiTestClass(objects::SPI_TEST, gpioComIF); #endif + } diff --git a/bsp_q7s/memory/CMakeLists.txt b/bsp_q7s/memory/CMakeLists.txt index 2ccdc7e2..03b7f0b9 100644 --- a/bsp_q7s/memory/CMakeLists.txt +++ b/bsp_q7s/memory/CMakeLists.txt @@ -1,4 +1,5 @@ target_sources(${TARGET_NAME} PRIVATE FileSystemManager.cpp SdCardAccess.cpp + SdCardAccessManager.cpp ) \ No newline at end of file diff --git a/bsp_q7s/memory/SdCardAccess.cpp b/bsp_q7s/memory/SdCardAccess.cpp index 3d5f12b9..05e8bd3c 100644 --- a/bsp_q7s/memory/SdCardAccess.cpp +++ b/bsp_q7s/memory/SdCardAccess.cpp @@ -1,4 +1,22 @@ #include "SdCardAccess.h" +#include "q7sConfig.h" +#include "SdCardAccessManager.h" -SdCardAccess::SdCardAccess() { +#include "fsfw/ipc/MutexGuard.h" + +SdCardAccess::SdCardAccess(sd::SdCard sdCard) { + auto accessManager = SdCardAccessManager::instance(); + MutexGuard(accessManager->mutex, MutexIF::TimeoutType::WAITING, + config::SD_CARD_ACCESS_MUTEX_TIMEOUT); + if(accessManager->getSdCardAccessors(sdCard) == 0) { + if(sdCard == sd::SdCard::SLOT_0) { + std::system("q7hw sd set 0 on"); + accessManager->activeAccessesSdCard0++; + + } + else { + std::system("q7hw sd set 1 on"); + accessManager->activeAccessesSdCard1++; + } + } } diff --git a/bsp_q7s/memory/SdCardAccess.h b/bsp_q7s/memory/SdCardAccess.h index ba273d09..8128b122 100644 --- a/bsp_q7s/memory/SdCardAccess.h +++ b/bsp_q7s/memory/SdCardAccess.h @@ -1,9 +1,11 @@ #ifndef BSP_Q7S_MEMORY_SDCARDACCESS_H_ #define BSP_Q7S_MEMORY_SDCARDACCESS_H_ +#include "definitions.h" + class SdCardAccess { public: - SdCardAccess(); + SdCardAccess(sd::SdCard sdCard); private: }; diff --git a/bsp_q7s/memory/SdCardAccessManager.cpp b/bsp_q7s/memory/SdCardAccessManager.cpp new file mode 100644 index 00000000..8c204aae --- /dev/null +++ b/bsp_q7s/memory/SdCardAccessManager.cpp @@ -0,0 +1,33 @@ +#include "SdCardAccessManager.h" +#include "fsfw/ipc/MutexFactory.h" + +SdCardAccessManager* SdCardAccessManager::factoryInstance = nullptr; + +SdCardAccessManager::~SdCardAccessManager() { + MutexFactory::instance()->deleteMutex(mutex); +} + +void SdCardAccessManager::create() { + if(factoryInstance == nullptr) { + factoryInstance = new SdCardAccessManager(); + } +} + +SdCardAccessManager* SdCardAccessManager::instance() { + SdCardAccessManager::create(); + return SdCardAccessManager::factoryInstance; +} + +SdCardAccessManager::SdCardAccessManager() { + mutex = MutexFactory::instance()->createMutex(); + +} + +uint8_t SdCardAccessManager::getSdCardAccessors(sd::SdCard sdCard) const { + if(sdCard == sd::SdCard::SLOT_0) { + return activeAccessesSdCard0; + } + else { + return activeAccessesSdCard1; + } +} diff --git a/bsp_q7s/memory/SdCardAccessManager.h b/bsp_q7s/memory/SdCardAccessManager.h new file mode 100644 index 00000000..2c6337b7 --- /dev/null +++ b/bsp_q7s/memory/SdCardAccessManager.h @@ -0,0 +1,48 @@ +#ifndef BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_ +#define BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_ + +#include "definitions.h" + +#include + +class MutexIF; + +/** + * @brief This class manages selecting and switching the active SD card, therefore also + * managing the redundancy of the SD cards + * @details + * This class will track the currently active users for a SD card. It is always used by the + * SD card access token automatically to get the currently active SD card in a thread safe way- + */ +class SdCardAccessManager { + friend class SdCardAccess; +public: + virtual ~SdCardAccessManager(); + + static void create(); + + /** + * Returns the single instance of the SD card manager. + */ + static SdCardAccessManager* instance(); + + sd::SdCard getPreferedSdCard() const; + + /** + * Get current number of SD card users + * @param sdCard + * @return + */ + uint8_t getSdCardAccessors(sd::SdCard sdCard) const; + +private: + SdCardAccessManager(); + MutexIF* mutex; + + uint8_t activeAccessesSdCard0 = 0; + uint8_t activeAccessesSdCard1 = 0; + + static SdCardAccessManager* factoryInstance; +}; + +#endif /* BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_ */ diff --git a/bsp_q7s/memory/definitions.h b/bsp_q7s/memory/definitions.h new file mode 100644 index 00000000..460f294b --- /dev/null +++ b/bsp_q7s/memory/definitions.h @@ -0,0 +1,15 @@ +#ifndef BSP_Q7S_MEMORY_DEFINITIONS_H_ +#define BSP_Q7S_MEMORY_DEFINITIONS_H_ + +namespace sd { + +enum SdCard { + SLOT_0, + SLOT_1 +}; + +} + + + +#endif /* BSP_Q7S_MEMORY_DEFINITIONS_H_ */ diff --git a/fsfw b/fsfw index 38f2f69c..c2b8507d 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 38f2f69c784c74cd87a10dce6c968325cf1cb472 +Subproject commit c2b8507d2947c48e2a2cd19b71640471f436bc5c diff --git a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 3b64724a..4e9b2b7b 100644 --- a/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/linux/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -430,46 +430,56 @@ ReturnValue_t pst::pstUart(FixedTimeslotTaskIF *thisSequence) { DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::SYRLINKS_HK_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +#if OBSW_ADD_ACS_BOARD == 1 thisSequence->addSlot(objects::GPS0_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::GPS1_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +#endif thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::SYRLINKS_HK_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); +#if OBSW_ADD_ACS_BOARD == 1 thisSequence->addSlot(objects::GPS0_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::GPS1_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); +#endif thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::SYRLINKS_HK_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); +#if OBSW_ADD_ACS_BOARD == 1 thisSequence->addSlot(objects::GPS0_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::GPS1_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); +#endif thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SYRLINKS_HK_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); +#if OBSW_ADD_ACS_BOARD == 1 thisSequence->addSlot(objects::GPS0_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::GPS1_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); +#endif thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::SYRLINKS_HK_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); +#if OBSW_ADD_ACS_BOARD == 1 thisSequence->addSlot(objects::GPS0_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::GPS1_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); +#endif if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { sif::error << "UART PST initialization failed" << std::endl; diff --git a/mission/core/GenericFactory.cpp b/mission/core/GenericFactory.cpp index 2fcb4450..fae8b7d8 100644 --- a/mission/core/GenericFactory.cpp +++ b/mission/core/GenericFactory.cpp @@ -83,9 +83,4 @@ void ObjectFactory::produceGenericObjects() { pus::PUS_SERVICE_20); new CService200ModeCommanding(objects::PUS_SERVICE_200_MODE_MGMT, apid::EIVE_OBSW, pus::PUS_SERVICE_200); - - /* Test Device Handler */ -#if OBSW_ADD_TEST_CODE == 1 - new TestTask(objects::TEST_TASK); -#endif }