SD Card, Scratch Buffer and README updates #52

Merged
meierj merged 41 commits from mueller/first-sd-tests into develop 2021-07-09 22:02:31 +02:00
8 changed files with 114 additions and 97 deletions
Showing only changes of commit 2526a45f6b - Show all commits

View File

@ -1,5 +1,5 @@
target_sources(${TARGET_NAME} PRIVATE
FileSystemManager.cpp
SdCardAccess.cpp
SdCardAccessManager.cpp
SdCardManager.cpp
)

View File

@ -1,22 +1,7 @@
#include "SdCardAccess.h"
#include "q7sConfig.h"
#include "SdCardAccessManager.h"
#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++;
}
}
}

View File

@ -1,33 +0,0 @@
#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;
}
}

View File

@ -1,48 +0,0 @@
#ifndef BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_
#define BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_
#include "definitions.h"
#include <cstdint>
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_ */

View File

@ -0,0 +1,55 @@
#include "SdCardManager.h"
#include "fsfw/ipc/MutexFactory.h"
#include <fstream>
#include <filesystem>
SdCardManager* SdCardManager::factoryInstance = nullptr;
SdCardManager::SdCardManager() {
}
SdCardManager::~SdCardManager() {
}
void SdCardManager::create() {
if(factoryInstance == nullptr) {
factoryInstance = new SdCardManager();
}
}
SdCardManager* SdCardManager::instance() {
SdCardManager::create();
return SdCardManager::factoryInstance;
}
ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard) {
if(sdCardActive(sdCard)) {
return ALREADY_ON;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard) {
return HasReturnvaluesIF::RETURN_OK;
}
bool SdCardManager::sdCardActive(sd::SdCard sdCard) {
if(std::filesystem::exists("/tmp/sd_status.txt")) {
std::ifstream sdStatus("/tmp/sd_status.txt");
return HasReturnvaluesIF::RETURN_OK;
}
return false;
}
sd::SdCard SdCardManager::getPreferredSdCard() const {
return preferredSdCard;
}
void SdCardManager::setPreferredSdCard(sd::SdCard sdCard) {
preferredSdCard = sdCard;
}
void SdCardManager::updateSdCardStateFile() {
}

View File

@ -0,0 +1,56 @@
#ifndef BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_
#define BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_
#include "definitions.h"
#include "returnvalues/classIds.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <cstdint>
class MutexIF;
/**
* @brief Manages handling of SD cards like switching them on or off or getting the current
* state
*/
class SdCardManager {
friend class SdCardAccess;
public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SD_CARD_MANAGER;
static constexpr ReturnValue_t ALREADY_ON = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0);
static constexpr ReturnValue_t ALREADY_OFF = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 1);
virtual ~SdCardManager();
static void create();
/**
* Returns the single instance of the SD card manager.
*/
static SdCardManager* instance();
void setPreferredSdCard(sd::SdCard sdCard);
sd::SdCard getPreferredSdCard() const;
ReturnValue_t switchOnSdCard(sd::SdCard sdCard);
ReturnValue_t switchOffSdCard(sd::SdCard sdCard);
bool sdCardActive(sd::SdCard sdCard);
sd::SdCard getPreferedSdCard() const;
private:
SdCardManager();
void updateSdCardStateFile();
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
static SdCardManager* factoryInstance;
};
#endif /* BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_ */

View File

@ -13,6 +13,7 @@ namespace CLASS_ID {
enum {
CLASS_ID_START = COMMON_CLASS_ID_END,
SA_DEPL_HANDLER, //SADPL
SD_CARD_MANAGER, //SDMA
CLASS_ID_END // [EXPORT] : [END]
};
}

View File

@ -707,6 +707,7 @@
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="ilg.gnumcueclipse.managedbuild.packs"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.toolchain.gnu.mingw.base.1455833186.1840876443.2117915473.688890851.1707795689.1939781894">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.mingw.base.1455833186.1840876443.2117915473.688890851.1707795689.1939781894" moduleId="org.eclipse.cdt.core.settings" name="eive-q7s-release">