From f0e282c6e1079048ce3e2527bca1b019a0d78126 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 5 Aug 2021 18:37:14 +0200 Subject: [PATCH] continued a bit --- bsp_q7s/core/CoreController.cpp | 50 ++++++++++++++++++-------------- bsp_q7s/core/CoreController.h | 5 ++-- bsp_q7s/memory/SdCardManager.cpp | 7 ++++- fsfw | 2 +- linux/fsfwconfig/OBSWConfig.h.in | 4 +++ 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 0516e26f..4a01ca50 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -159,18 +159,18 @@ ReturnValue_t CoreController::initSdCardNonBlocking() { SdCardManager::Operations operation; SdCardManager::OpStatus status = sdcMan->checkCurrentOp(operation); if(status == SdCardManager::OpStatus::SUCCESS) { - state = SdStates::SET_STATE; + state = SdStates::SET_STATE_SELF; commandExecuted = false; sdcInitCycleCount = 0; } - else if(sdcInitCycleCount > 2) { + else if(sdcInitCycleCount > 4) { sif::warning << "CoreController::initSdCardNonBlocking: " "Updating SDC file takes too long" << std::endl; } } } - if(state == SdStates::SET_STATE) { + if(state == SdStates::SET_STATE_SELF) { if(not commandExecuted) { determinePreferredSdCard(); statusPair = SdCardManager::SdStatusPair(sd::SdState::OFF, sd::SdState::OFF); @@ -250,6 +250,7 @@ ReturnValue_t CoreController::initSdCardNonBlocking() { } } + sdcInitCycleCount++; return HasReturnvaluesIF::RETURN_OK; #endif /* Q7S_SD_CARD_CONFIG != Q7S_SD_NONE */ } @@ -290,7 +291,7 @@ ReturnValue_t CoreController::sdCardSetup(SdCardManager::SdStatusPair& statusPai return sdcMan->switchOnSdCard(sdCard, true, &statusPair); } else { - if(state == SdStates::SET_STATE) { + if(state == SdStates::SET_STATE_SELF) { sif::info << "Switching on SD card" << std::endl; return sdcMan->switchOnSdCard(sdCard, false, &statusPair); } @@ -303,7 +304,7 @@ ReturnValue_t CoreController::sdCardSetup(SdCardManager::SdStatusPair& statusPai return sdcMan->mountSdCard(sdCard); } else { - if(state == SdStates::SET_STATE) { + if(state == SdStates::SET_STATE_SELF) { return SdCardManager::ALREADY_ON; } if(state == SdStates::MOUNT) { @@ -379,25 +380,32 @@ ReturnValue_t CoreController::sdCardColdRedundantInit(SdCardManager* sdcMan, otherString = "0"; } - result = sdCardSetup(statusPair, preferredSdCard, preferredString); - if(result != SdCardManager::ALREADY_MOUNTED and result != HasReturnvaluesIF::RETURN_OK) { - sif::warning << "Setting up preferred card " << otherString << - " in cold redundant mode failed" << std::endl; - // Try other SD card and mark set up operation as failed - sdCardSetup(statusPair, preferredSdCard, preferredString); - result = HasReturnvaluesIF::RETURN_FAILED; - } - - if(result != HasReturnvaluesIF::RETURN_FAILED and otherStatus != sd::SdState::OFF) { - sif::info << "Switching off secondary SD card " << otherString << std::endl; - // Switch off other SD card in cold redundant mode if setting up preferred one walked - // without issues - result = sdcMan->switchOffSdCard(otherSdc, otherStatus, &statusPair); - if(result != HasReturnvaluesIF::RETURN_OK and result != SdCardManager::ALREADY_OFF) { - sif::warning << "Switching off secondary SD card " << otherString << + if(step != SdStates::SET_STATE_OTHER) { + result = sdCardSetup(statusPair, preferredSdCard, preferredString); + if(result != SdCardManager::ALREADY_MOUNTED and result != HasReturnvaluesIF::RETURN_OK) { + sif::warning << "Setting up preferred card " << otherString << " in cold redundant mode failed" << std::endl; + // Try other SD card and mark set up operation as failed + sdCardSetup(statusPair, preferredSdCard, preferredString); + result = HasReturnvaluesIF::RETURN_FAILED; } } + + if(BLOCKING_SD_INIT or (not BLOCKING_SD_INIT and state == SdStates::SET_STATE_OTHER)) { + // Don't disable other card if enabling the first one already failed + // Otherwise, try to turn off the other SD card + if(result != HasReturnvaluesIF::RETURN_FAILED and otherStatus != sd::SdState::OFF) { + sif::info << "Switching off secondary SD card " << otherString << std::endl; + // Switch off other SD card in cold redundant mode if setting up preferred one worked + // without issues + ReturnValue_t result2 = sdcMan->switchOffSdCard(otherSdc, otherStatus, &statusPair); + if(result2 != HasReturnvaluesIF::RETURN_OK and result2 != SdCardManager::ALREADY_OFF) { + sif::warning << "Switching off secondary SD card " << otherString << + " in cold redundant mode failed" << std::endl; + } + } + } + return result; } diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index a424a615..a4f2868e 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -64,12 +64,13 @@ private: NONE, START, GET_INFO, - SET_STATE, + SET_STATE_SELF, + SET_STATE_OTHER, MOUNT, UPDATE_INFO, DONE }; - static constexpr bool BLOCKING_SD_INIT = true; + static constexpr bool BLOCKING_SD_INIT = false; SdCardManager* sdcMan = nullptr; uint16_t sdcInitCycleCount = 0; diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index 89cdf85f..d9442a8c 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -386,16 +386,21 @@ SdCardManager::OpStatus SdCardManager::checkCurrentOp(Operations ¤tOp) { currentOp = this->currentOp; bool bytesRead = false; +#if OBSW_ENABLE_TIMERS == 1 Timer timer; - timer.setTimer(200); + timer.setTimer(100); uint32_t remainingTimeMs = 0; +#endif while(true) { ReturnValue_t result = cmdExecutor.check(bytesRead); + // This timer can prevent deadlocks due to missconfigurations +#if OBSW_ENABLE_TIMERS == 1 timer.getTimer(&remainingTimeMs); if(remainingTimeMs == 0) { sif::error << "SdCardManager::checkCurrentOp: Timeout!" << std::endl; return OpStatus::FAIL; } +#endif switch(result) { case(CommandExecutor::BYTES_READ): { continue; diff --git a/fsfw b/fsfw index 6073abb1..3704d2b8 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 6073abb12db23decbc9d69f4b6342f4f6f1247bd +Subproject commit 3704d2b8295152652a4c7836b595223d8fa3767d diff --git a/linux/fsfwconfig/OBSWConfig.h.in b/linux/fsfwconfig/OBSWConfig.h.in index 778a1611..0246ff82 100644 --- a/linux/fsfwconfig/OBSWConfig.h.in +++ b/linux/fsfwconfig/OBSWConfig.h.in @@ -22,6 +22,10 @@ debugging. */ #define OBSW_VERBOSE_LEVEL 1 +//! Timers can mess up the code when debugging +//! TODO: Enable for mission code, disable for debug code +#define OBSW_ENABLE_TIMERS 0 + #define OBSW_PRINT_MISSED_DEADLINES 1 #define OBSW_ADD_TEST_CODE 1 #define OBSW_ADD_TEST_PST 1