SD shutdown handling non-blocking #753

Merged
muellerr merged 7 commits from sd-shutdown-non-blocking into main 2023-07-26 11:09:48 +02:00
Showing only changes of commit abbf170ce2 - Show all commits

View File

@ -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 // 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. // the more graceful way to reboot the system.
ReturnValue_t result = handleSwitchingSdCardsOffNonBlocking(); ReturnValue_t result = handleSwitchingSdCardsOffNonBlocking();
if(result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::error << "CoreController::gracefulShutdownTasks: Issues unmounting or switching SD cards off" sif::error
<< "CoreController::gracefulShutdownTasks: Issues unmounting or switching SD cards off"
<< std::endl; << std::endl;
} }
// If any boot copies are unprotected. // If any boot copies are unprotected.
// Actually this function only ensures that reboots to the own image are protected.. // Actually this function only ensures that reboots to the own image are protected..
result = setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, result = setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, protOpPerformed,
protOpPerformed, false); false);
if (result == returnvalue::OK and protOpPerformed) { if (result == returnvalue::OK and protOpPerformed) {
// TODO: Would be nice to notify operator. But we can't use the filesystem anymore // TODO: Would be nice to notify operator. But we can't use the filesystem anymore
// and a reboot is imminent. Use scratch buffer? // and a reboot is imminent. Use scratch buffer?
@ -2589,11 +2590,16 @@ void CoreController::announceSdInfo(SdCardManager::SdStatePair sdStates) {
} }
ReturnValue_t CoreController::handleSwitchingSdCardsOffNonBlocking() { ReturnValue_t CoreController::handleSwitchingSdCardsOffNonBlocking() {
Countdown maxWaitTimeCd(6000); Countdown maxWaitTimeCd(10000);
Stopwatch watch; Stopwatch watch;
sdcMan->setBlocking(false); sdcMan->setBlocking(false);
SdCardManager::Operations op; SdCardManager::Operations op;
std::pair<sd::SdState, sd::SdState> sdStatus;
ReturnValue_t result = sdcMan->getSdCardsStatus(sdStatus);
if (result != returnvalue::OK) {
return result;
}
auto waitingForFinish = [&]() { auto waitingForFinish = [&]() {
while (sdcMan->checkCurrentOp(op) == SdCardManager::OpStatus::ONGOING) { while (sdcMan->checkCurrentOp(op) == SdCardManager::OpStatus::ONGOING) {
TaskFactory::delayTask(50); TaskFactory::delayTask(50);
@ -2603,28 +2609,33 @@ ReturnValue_t CoreController::handleSwitchingSdCardsOffNonBlocking() {
} }
return returnvalue::OK; return returnvalue::OK;
}; };
sif::debug << "hello 0" << std::endl;
if (sdStatus.first != sd::SdState::OFF) {
sdcMan->unmountSdCard(sd::SdCard::SLOT_0); sdcMan->unmountSdCard(sd::SdCard::SLOT_0);
ReturnValue_t result = waitingForFinish();
if (result != returnvalue::OK) {
return result;
}
sdcMan->unmountSdCard(sd::SdCard::SLOT_1);
result = waitingForFinish(); result = waitingForFinish();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
sdcMan->switchOffSdCard(sd::SdCard::SLOT_0, false); sdcMan->switchOffSdCard(sd::SdCard::SLOT_0, false);
result = waitingForFinish(); result = waitingForFinish();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; 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); sdcMan->switchOffSdCard(sd::SdCard::SLOT_1, false);
result = waitingForFinish(); result = waitingForFinish();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
}
sif::debug << "hello 2" << std::endl;
return result; return result;
} }