safety mechanism on reboots #308

Merged
meierj merged 5 commits from mueller/sdc-safety-mechanism-on-reboot into develop 2022-10-25 14:34:00 +02:00
3 changed files with 19 additions and 0 deletions
Showing only changes of commit a9096a46c0 - Show all commits

View File

@ -3,6 +3,7 @@
#include <fsfw/events/EventManager.h> #include <fsfw/events/EventManager.h>
#include <fsfw/filesystem/HasFileSystemIF.h> #include <fsfw/filesystem/HasFileSystemIF.h>
#include <fsfw/ipc/QueueFactory.h> #include <fsfw/ipc/QueueFactory.h>
#include <fsfw/tasks/TaskFactory.h>
#include "OBSWVersion.h" #include "OBSWVersion.h"
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/ServiceInterface.h"
@ -932,6 +933,9 @@ ReturnValue_t CoreController::actionReboot(const uint8_t *data, size_t size) {
ReturnValue_t CoreController::gracefulShutdownTasks(xsc::Chip chip, xsc::Copy copy, ReturnValue_t CoreController::gracefulShutdownTasks(xsc::Chip chip, xsc::Copy copy,
bool &protOpPerformed) { bool &protOpPerformed) {
sdcMan->setBlocking(true); sdcMan->setBlocking(true);
sdcMan->markUnusable();
// Wait two seconds to ensure no one uses the SD cards
TaskFactory::delayTask(2000);
// Attempt graceful shutdown by unmounting and switching off SD cards // Attempt graceful shutdown by unmounting and switching off SD cards
sdcMan->switchOffSdCard(sd::SdCard::SLOT_0); sdcMan->switchOffSdCard(sd::SdCard::SLOT_0);
sdcMan->switchOffSdCard(sd::SdCard::SLOT_1); sdcMan->switchOffSdCard(sd::SdCard::SLOT_1);

View File

@ -460,6 +460,13 @@ void SdCardManager::setBlocking(bool blocking) { this->blocking = blocking; }
void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; } void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; }
bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) { bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) {
{
MutexGuard mg(mutex);
if (markedUnusable) {
return false;
}
}
SdCardManager::SdStatePair active; SdCardManager::SdStatePair active;
ReturnValue_t result = this->getSdCardsStatus(active); ReturnValue_t result = this->getSdCardsStatus(active);
@ -562,3 +569,8 @@ std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const {
MutexGuard mg(mutex); MutexGuard mg(mutex);
return sdInfo.active; return sdInfo.active;
} }
void SdCardManager::markUnusable() {
MutexGuard mg(mutex);
markedUnusable = true;
}

View File

@ -214,12 +214,15 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
ReturnValue_t performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError); ReturnValue_t performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError);
void markUnusable();
private: private:
CommandExecutor cmdExecutor; CommandExecutor cmdExecutor;
Operations currentOp = Operations::IDLE; Operations currentOp = Operations::IDLE;
bool blocking = false; bool blocking = false;
bool sdCardActive = true; bool sdCardActive = true;
bool printCmdOutput = true; bool printCmdOutput = true;
bool markedUnusable = false;
MutexIF* mutex = nullptr; MutexIF* mutex = nullptr;
SdCardManager(); SdCardManager();