From abbf170ce2bfedd8b7eac47810da347d5f116441 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 25 Jul 2023 16:54:40 +0200 Subject: [PATCH] core controller doing weird things --- bsp_q7s/core/CoreController.cpp | 61 +++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 60ef389e..8865c158 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -1232,15 +1232,16 @@ ReturnValue_t CoreController::gracefulShutdownTasks(xsc::Chip chip, xsc::Copy co // Unmount and switch off SD cards. This could possibly fix issues with the SD card and is // the more graceful way to reboot the system. ReturnValue_t result = handleSwitchingSdCardsOffNonBlocking(); - if(result != returnvalue::OK) { - sif::error << "CoreController::gracefulShutdownTasks: Issues unmounting or switching SD cards off" + if (result != returnvalue::OK) { + sif::error + << "CoreController::gracefulShutdownTasks: Issues unmounting or switching SD cards off" << std::endl; } // If any boot copies are unprotected. // Actually this function only ensures that reboots to the own image are protected.. - result = setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, - protOpPerformed, false); + result = setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, protOpPerformed, + false); if (result == returnvalue::OK and protOpPerformed) { // TODO: Would be nice to notify operator. But we can't use the filesystem anymore // and a reboot is imminent. Use scratch buffer? @@ -2589,11 +2590,16 @@ void CoreController::announceSdInfo(SdCardManager::SdStatePair sdStates) { } ReturnValue_t CoreController::handleSwitchingSdCardsOffNonBlocking() { - Countdown maxWaitTimeCd(6000); + Countdown maxWaitTimeCd(10000); Stopwatch watch; sdcMan->setBlocking(false); SdCardManager::Operations op; + std::pair sdStatus; + ReturnValue_t result = sdcMan->getSdCardsStatus(sdStatus); + if (result != returnvalue::OK) { + return result; + } auto waitingForFinish = [&]() { while (sdcMan->checkCurrentOp(op) == SdCardManager::OpStatus::ONGOING) { TaskFactory::delayTask(50); @@ -2603,28 +2609,33 @@ ReturnValue_t CoreController::handleSwitchingSdCardsOffNonBlocking() { } return returnvalue::OK; }; - - sdcMan->unmountSdCard(sd::SdCard::SLOT_0); - ReturnValue_t result = waitingForFinish(); - if (result != returnvalue::OK) { - return result; + sif::debug << "hello 0" << std::endl; + if (sdStatus.first != sd::SdState::OFF) { + sdcMan->unmountSdCard(sd::SdCard::SLOT_0); + result = waitingForFinish(); + if (result != returnvalue::OK) { + return result; + } + sdcMan->switchOffSdCard(sd::SdCard::SLOT_0, false); + result = waitingForFinish(); + if (result != returnvalue::OK) { + return result; + } } - sdcMan->unmountSdCard(sd::SdCard::SLOT_1); - result = waitingForFinish(); - if (result != returnvalue::OK) { - return result; - } - - sdcMan->switchOffSdCard(sd::SdCard::SLOT_0, false); - result = waitingForFinish(); - if (result != returnvalue::OK) { - return result; - } - sdcMan->switchOffSdCard(sd::SdCard::SLOT_1, false); - result = waitingForFinish(); - if (result != returnvalue::OK) { - return result; + sif::debug << "hello 1" << std::endl; + if (sdStatus.second != sd::SdState::OFF) { + sdcMan->unmountSdCard(sd::SdCard::SLOT_1); + result = waitingForFinish(); + if (result != returnvalue::OK) { + return result; + } + sdcMan->switchOffSdCard(sd::SdCard::SLOT_1, false); + result = waitingForFinish(); + if (result != returnvalue::OK) { + return result; + } } + sif::debug << "hello 2" << std::endl; return result; }