improve MPSoC boot and shutdown process
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-09-25 16:36:35 +02:00
parent 35fd2c72d8
commit 0d0a98220a
4 changed files with 120 additions and 72 deletions

View File

@ -188,72 +188,27 @@ void PlocMpsocHandler::doStartUp() {
startupState = StartupState::HW_INIT;
}
if (startupState == StartupState::HW_INIT) {
#ifdef XIPHOS_Q7S
#if not OBSW_MPSOC_JTAG_BOOT == 1
switch (powerState) {
case PowerState::OFF:
commandActionHelper.commandAction(supervisorHandler, supv::START_MPSOC);
powerState = PowerState::BOOTING;
return;
case PowerState::ON:
uartIsolatorSwitch.pullHigh();
startupState = StartupState::WAIT_CYCLES;
break;
default:
return;
}
#else
uartIsolatorSwitch.pullHigh();
startupState = StartupState::WAIT_CYCLES;
#endif /* not MSPOC_JTAG_BOOT == 1 */
#else
startupState = StartupState::WAIT_CYCLES;
powerState = PowerState::ON;
#endif /* XIPHOS_Q7S */
}
// Need to wait, MPSoC still not booted properly, requesting HK without these wait cycles does
// not work, no replies..
if (startupState == StartupState::WAIT_CYCLES) {
waitCycles++;
if (waitCycles >= 8) {
if (handleHwStartup()) {
startupState = StartupState::DONE;
waitCycles = 0;
}
}
if (startupState == StartupState::DONE) {
setMode(_MODE_TO_ON);
hkReport.setReportingEnabled(true);
powerState = PowerState::IDLE;
startupState = StartupState::IDLE;
}
}
void PlocMpsocHandler::doShutDown() {
#ifdef XIPHOS_Q7S
#if not OBSW_MPSOC_JTAG_BOOT == 1
if (powerState == PowerState::ON) {
uartIsolatorSwitch.pullLow();
commandActionHelper.commandAction(supervisorHandler, supv::SHUTDOWN_MPSOC);
powerState = PowerState::SHUTDOWN;
return;
} else if (powerState == PowerState::SHUTDOWN) {
// Wait till power state is OFF.
return;
if (handleHwShutdown()) {
hkReport.setReportingEnabled(false);
setMode(_MODE_POWER_DOWN);
commandIsPending = false;
sequenceCount = 0;
powerState = PowerState::IDLE;
startupState = StartupState::IDLE;
}
#else
uartIsolatorSwitch.pullLow();
powerState = PowerState::OFF;
#endif
#endif
if (specialComHelper != nullptr) {
specialComHelper->stopProcess();
}
hkReport.setReportingEnabled(false);
setMode(_MODE_POWER_DOWN);
commandIsPending = false;
sequenceCount = 0;
specialComHelperExecuting = false;
startupState = StartupState::IDLE;
}
ReturnValue_t PlocMpsocHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
@ -1247,15 +1202,11 @@ void PlocMpsocHandler::stepFailedReceived(ActionId_t actionId, uint8_t step,
switch (actionId) {
case supv::START_MPSOC: {
sif::warning << "PlocMPSoCHandler::stepFailedReceived: Failed to start MPSoC" << std::endl;
// This usually happens when the supervisor handler is in off mode
powerState = PowerState::OFF;
setMode(MODE_OFF);
break;
}
case supv::SHUTDOWN_MPSOC: {
triggerEvent(MPSOC_SHUTDOWN_FAILED);
sif::warning << "PlocMPSoCHandler::stepFailedReceived: Failed to shutdown MPSoC" << std::endl;
powerState = PowerState::OFF;
break;
}
default:
@ -1263,6 +1214,7 @@ void PlocMpsocHandler::stepFailedReceived(ActionId_t actionId, uint8_t step,
<< std::endl;
break;
}
powerState = PowerState::SUPV_FAILED;
}
void PlocMpsocHandler::dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) {
@ -1272,16 +1224,14 @@ void PlocMpsocHandler::dataReceived(ActionId_t actionId, const uint8_t* data, ui
void PlocMpsocHandler::completionSuccessfulReceived(ActionId_t actionId) {
if (actionId != supv::EXE_REPORT) {
sif::warning << "PlocMPSoCHandler::completionSuccessfulReceived: Did not expect this action "
<< "ID " << actionId << std::endl;
<< "ID " << actionId << std::endl;
return;
}
switch (powerState) {
case PowerState::BOOTING: {
powerState = PowerState::ON;
break;
}
case PowerState::SHUTDOWN: {
powerState = PowerState::OFF;
case PowerState::PENDING_STARTUP:
case PowerState::PENDING_SHUTDOWN: {
// sif::debug << "power switching done" << std::endl;
powerState = PowerState::DONE;
break;
}
default: {
@ -1409,6 +1359,88 @@ void PlocMpsocHandler::disableExeReportReply() {
info->command->second.expectedReplies = 0;
}
void PlocMpsocHandler::stopSpecialComHelper() {
if (specialComHelper != nullptr) {
specialComHelper->stopProcess();
}
specialComHelperExecuting = false;
}
bool PlocMpsocHandler::handleHwStartup() {
#if OBSW_MPSOC_JTAG_BOOT == 1
uartIsolatorSwitch.pullHigh();
startupState = StartupState::WAIT_CYCLES;
return true;
#endif
if (powerState == PowerState::IDLE) {
if (supv::SUPV_ON) {
commandActionHelper.commandAction(supervisorHandler, supv::START_MPSOC);
supvTransitionCd.resetTimer();
powerState = PowerState::PENDING_STARTUP;
} else {
triggerEvent(SUPV_NOT_ON, 1);
// Set back to OFF for now, failing the transition.
setMode(MODE_OFF);
}
}
if (powerState == PowerState::SUPV_FAILED) {
setMode(MODE_OFF);
powerState = PowerState::IDLE;
return false;
}
if (powerState == PowerState::PENDING_STARTUP) {
if (supvTransitionCd.hasTimedOut()) {
// Process with transition nonetheless..
triggerEvent(SUPV_REPLY_TIMEOUT);
powerState = PowerState::DONE;
} else {
return false;
}
}
if (powerState == PowerState::DONE) {
if (not !supvTransitionCd.hasTimedOut()) {
// Wait a bit for the MPSoC to fully boot. We re-use the SUPV transition countdown
// for this.
return false;
}
uartIsolatorSwitch.pullHigh();
powerState = PowerState::IDLE;
}
return true;
}
bool PlocMpsocHandler::handleHwShutdown() {
stopSpecialComHelper();
uartIsolatorSwitch.pullLow();
#if OBSW_MPSOC_JTAG_BOOT == 1
powerState = PowerState::DONE;
return true;
#endif
if (powerState == PowerState::IDLE) {
if (supv::SUPV_ON) {
commandActionHelper.commandAction(supervisorHandler, supv::SHUTDOWN_MPSOC);
supvTransitionCd.resetTimer();
powerState = PowerState::PENDING_SHUTDOWN;
} else {
triggerEvent(SUPV_NOT_ON, 0);
powerState = PowerState::DONE;
}
}
if (powerState == PowerState::PENDING_SHUTDOWN) {
if (supvTransitionCd.hasTimedOut()) {
powerState = PowerState::DONE;
// Process with transition nonetheless..
triggerEvent(SUPV_REPLY_TIMEOUT);
return true;
} else {
// Wait till power state is OFF.
return false;
}
}
return true;
}
void PlocMpsocHandler::handleActionCommandFailure(ActionId_t actionId) {
switch (actionId) {
case supv::ACK_REPORT:
@ -1420,25 +1452,24 @@ void PlocMpsocHandler::handleActionCommandFailure(ActionId_t actionId) {
return;
}
switch (powerState) {
case PowerState::BOOTING: {
case PowerState::PENDING_STARTUP: {
sif::info << "PlocMPSoCHandler::handleActionCommandFailure: MPSoC boot command failed"
<< std::endl;
// This is commonly the case when the MPSoC is already operational. Thus the power state is
// set to on here
powerState = PowerState::ON;
break;
}
case PowerState::SHUTDOWN: {
case PowerState::PENDING_SHUTDOWN: {
// FDIR will intercept event and switch PLOC power off
triggerEvent(MPSOC_SHUTDOWN_FAILED);
sif::warning << "PlocMPSoCHandler::handleActionCommandFailure: Failed to shutdown MPSoC"
<< std::endl;
powerState = PowerState::OFF;
break;
}
default:
break;
}
powerState = PowerState::SUPV_FAILED;
return;
}

View File

@ -103,11 +103,16 @@ class PlocMpsocHandler : public DeviceHandlerBase, public CommandsActionsIF {
//! [EXPORT] : [COMMENT] Supervisor fails to shutdown MPSoC. Requires to power off the PLOC and
//! thus also to shutdown the supervisor.
static const Event MPSOC_SHUTDOWN_FAILED = MAKE_EVENT(6, severity::HIGH);
//! [EXPORT] : [COMMENT] SUPV not on for boot or shutdown process. P1: 0 for OFF transition, 1 for
//! ON transition.
static constexpr Event SUPV_NOT_ON = event::makeEvent(SUBSYSTEM_ID, 6, severity::LOW);
static constexpr Event SUPV_REPLY_TIMEOUT = event::makeEvent(SUBSYSTEM_ID, 7, severity::LOW);
static const uint16_t APID_MASK = 0x7FF;
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
mpsoc::HkReport hkReport;
Countdown supvTransitionCd = Countdown(3000);
MessageQueueIF* eventQueue = nullptr;
MessageQueueIF* commandActionHelperQueue = nullptr;
@ -188,10 +193,10 @@ class PlocMpsocHandler : public DeviceHandlerBase, public CommandsActionsIF {
TelemetryBuffer tmBuffer;
uint32_t waitCycles = 0;
enum class StartupState { IDLE, HW_INIT, WAIT_CYCLES, DONE } startupState = StartupState::IDLE;
enum class PowerState { OFF, BOOTING, SHUTDOWN, ON };
enum class StartupState { IDLE, HW_INIT, DONE } startupState = StartupState::IDLE;
enum class PowerState { IDLE, PENDING_STARTUP, PENDING_SHUTDOWN, SUPV_FAILED, DONE };
PowerState powerState = PowerState::OFF;
PowerState powerState = PowerState::IDLE;
/**
* @brief Handles events received from the PLOC MPSoC helper
@ -299,6 +304,9 @@ class PlocMpsocHandler : public DeviceHandlerBase, public CommandsActionsIF {
ReturnValue_t prepareTcModeReplay();
void cmdDoneHandler(bool success, ReturnValue_t result);
bool handleHwStartup();
bool handleHwShutdown();
void stopSpecialComHelper();
void handleActionCommandFailure(ActionId_t actionId);
};

View File

@ -19,6 +19,8 @@
using namespace supv;
using namespace returnvalue;
std::atomic_bool supv::SUPV_ON = false;
PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, CookieIF* comCookie,
Gpio uartIsolatorSwitch, power::Switch_t powerSwitch,
PlocSupvUartManager& supvHelper)
@ -156,6 +158,7 @@ void PlocSupervisorHandler::doStartUp() {
}
if (startupState == StartupState::ON) {
hkset.setReportingEnabled(true);
supv::SUPV_ON = true;
setMode(_MODE_TO_ON);
}
}
@ -169,6 +172,7 @@ void PlocSupervisorHandler::doShutDown() {
nextReplyId = supv::NONE;
uartManager.stop();
uartIsolatorSwitch.pullLow();
supv::SUPV_ON = false;
startupState = StartupState::OFF;
}
@ -202,11 +206,13 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d
break;
}
case START_MPSOC: {
sif::info << "PLOC SUPV: Starting MPSoC" << std::endl;
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::START_MPSOC));
result = returnvalue::OK;
break;
}
case SHUTDOWN_MPSOC: {
sif::info << "PLOC SUPV: Shutting down MPSoC" << std::endl;
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::SHUTDOWN_MPSOC));
result = returnvalue::OK;
break;

View File

@ -10,12 +10,15 @@
#include <fsfw/tmtcpacket/ccsds/SpacePacketReader.h>
#include <mission/payload/plocSpBase.h>
#include <atomic>
#include <optional>
#include "eive/resultClassIds.h"
namespace supv {
extern std::atomic_bool SUPV_ON;
namespace result {
static const uint8_t INTERFACE_ID = CLASS_ID::SUPV_RETURN_VALUES_IF;