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
// 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<sd::SdState, sd::SdState> 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;
}