SD Card, Scratch Buffer and README updates #52
@ -1,5 +1,5 @@
|
|||||||
target_sources(${TARGET_NAME} PRIVATE
|
target_sources(${TARGET_NAME} PRIVATE
|
||||||
FileSystemManager.cpp
|
FileSystemManager.cpp
|
||||||
SdCardAccess.cpp
|
SdCardAccess.cpp
|
||||||
SdCardAccessManager.cpp
|
SdCardManager.cpp
|
||||||
)
|
)
|
@ -1,22 +1,7 @@
|
|||||||
#include "SdCardAccess.h"
|
#include "SdCardAccess.h"
|
||||||
#include "q7sConfig.h"
|
|
||||||
#include "SdCardAccessManager.h"
|
|
||||||
|
|
||||||
#include "fsfw/ipc/MutexGuard.h"
|
#include "fsfw/ipc/MutexGuard.h"
|
||||||
|
|
||||||
SdCardAccess::SdCardAccess(sd::SdCard sdCard) {
|
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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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_ */
|
|
55
bsp_q7s/memory/SdCardManager.cpp
Normal file
55
bsp_q7s/memory/SdCardManager.cpp
Normal 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() {
|
||||||
|
}
|
56
bsp_q7s/memory/SdCardManager.h
Normal file
56
bsp_q7s/memory/SdCardManager.h
Normal 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_ */
|
@ -13,6 +13,7 @@ namespace CLASS_ID {
|
|||||||
enum {
|
enum {
|
||||||
CLASS_ID_START = COMMON_CLASS_ID_END,
|
CLASS_ID_START = COMMON_CLASS_ID_END,
|
||||||
SA_DEPL_HANDLER, //SADPL
|
SA_DEPL_HANDLER, //SADPL
|
||||||
|
SD_CARD_MANAGER, //SDMA
|
||||||
CLASS_ID_END // [EXPORT] : [END]
|
CLASS_ID_END // [EXPORT] : [END]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -707,6 +707,7 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||||
|
<storageModule moduleId="ilg.gnumcueclipse.managedbuild.packs"/>
|
||||||
</cconfiguration>
|
</cconfiguration>
|
||||||
<cconfiguration id="cdt.managedbuild.toolchain.gnu.mingw.base.1455833186.1840876443.2117915473.688890851.1707795689.1939781894">
|
<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">
|
<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">
|
||||||
|
Loading…
Reference in New Issue
Block a user