eive-obsw/mission/system/EiveSystem.h

98 lines
3.3 KiB
C
Raw Normal View History

2023-04-06 16:50:33 +02:00
#ifndef MISSION_SYSTEM_EIVESYSTEM_H_
#define MISSION_SYSTEM_EIVESYSTEM_H_
#include <fsfw/action/HasActionsIF.h>
#include <fsfw/power/PowerSwitchIF.h>
#include <fsfw/subsystem/Subsystem.h>
2023-04-06 17:49:34 +02:00
#include <atomic>
2023-04-06 16:50:33 +02:00
class EiveSystem : public Subsystem, public HasActionsIF {
public:
2023-04-14 13:11:11 +02:00
static constexpr uint8_t FRAME_DIRTY_COM_REBOOT_LIMIT = 4;
2023-08-04 14:23:10 +02:00
static constexpr uint32_t PDEC_RESET_MAX_COUNT_BEFORE_REBOOT = 10;
2023-04-14 13:11:11 +02:00
2023-04-06 16:50:33 +02:00
static constexpr ActionId_t EXECUTE_I2C_REBOOT = 10;
2023-04-06 17:49:34 +02:00
EiveSystem(object_id_t setObjectId, uint32_t maxNumberOfSequences, uint32_t maxNumberOfTables,
std::atomic_uint16_t& i2cErrors);
2023-04-06 16:50:33 +02:00
2023-04-06 17:49:34 +02:00
void setI2cRecoveryParams(PowerSwitchIF* pwrSwitcher);
2023-04-06 16:50:33 +02:00
[[nodiscard]] MessageQueueId_t getCommandQueue() const override;
private:
enum class ForcePlOffState {
NONE,
FORCE_ALL_EXCEPT_SUPV_OFF,
WAITING,
FORCE_SUPV_OFF
} forcePlOffState = ForcePlOffState::NONE;
2023-04-06 16:50:33 +02:00
enum class I2cRebootState {
NONE,
SYSTEM_MODE_BOOT,
SWITCH_3V3_STACK_OFF_AND_BATT_REBOOT,
2023-04-06 22:35:23 +02:00
WAIT_CYCLE,
2023-04-06 16:50:33 +02:00
SWITCH_3V3_STACK_ON,
SYSTEM_MODE_SAFE
} i2cRebootState = I2cRebootState::NONE;
MessageQueueIF* eventQueue = nullptr;
bool performSafeRecovery = false;
bool performI2cReboot = false;
2023-04-06 17:01:28 +02:00
bool alreadyTriedI2cRecovery = false;
2023-04-14 13:11:11 +02:00
uint8_t frameDirtyErrorCounter = 0;
Countdown supvOffDelay = Countdown(3000);
2023-04-14 13:11:11 +02:00
Countdown frameDirtyCheckCd = Countdown(10000);
// If the PDEC reset was already attempted in the last 2 minutes, there is a high chance that
// only a full reboot will fix the issue.
2023-08-04 14:23:10 +02:00
Countdown pdecResetCounterResetCd = Countdown(120000);
2023-08-02 09:19:43 +02:00
bool waitingForI2cReboot = false;
bool waitingForPdecReboot = false;
2023-04-14 13:11:11 +02:00
2023-08-04 14:23:10 +02:00
uint32_t pdecResetCounter = 0;
2023-04-06 16:50:33 +02:00
ActionHelper actionHelper;
PowerSwitchIF* powerSwitcher = nullptr;
2023-04-06 17:49:34 +02:00
std::atomic_uint16_t& i2cErrors;
2023-09-29 14:18:42 +02:00
MessageQueueId_t plSsQueueId = MessageQueueIF::NO_QUEUE;
MessageQueueId_t plPcduQueueId = MessageQueueIF::NO_QUEUE;
MessageQueueId_t plocMpsocQueueId = MessageQueueIF::NO_QUEUE;
MessageQueueId_t plocSupervisorQueueId = MessageQueueIF::NO_QUEUE;
MessageQueueId_t cameraQueueId = MessageQueueIF::NO_QUEUE;
MessageQueueId_t scexQueueId = MessageQueueIF::NO_QUEUE;
MessageQueueId_t radSensorQueueId = MessageQueueIF::NO_QUEUE;
MessageQueueId_t strQueueId = MessageQueueIF::NO_QUEUE;
2023-04-14 13:26:44 +02:00
MessageQueueId_t pdecHandlerQueueId = MessageQueueIF::NO_QUEUE;
2023-04-06 16:50:33 +02:00
MessageQueueId_t bpxBattQueueId = MessageQueueIF::NO_QUEUE;
2023-04-06 17:49:34 +02:00
MessageQueueId_t coreCtrlQueueId = MessageQueueIF::NO_QUEUE;
2023-04-06 16:50:33 +02:00
MessageQueueId_t actionCommandedBy = MessageQueueIF::NO_QUEUE;
2023-04-06 17:49:34 +02:00
Countdown i2cRebootHandlingCountdown = Countdown(10000);
// After 1 minute, clear the flag to avoid full reboots on I2C issues.
2023-04-06 17:01:28 +02:00
Countdown i2cRecoveryClearCountdown = Countdown(60000);
2023-04-06 16:50:33 +02:00
ReturnValue_t initialize() override;
void performChildOperation() override;
void announceMode(bool recursive) override;
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override;
2023-04-06 22:35:23 +02:00
ReturnValue_t handleCommandMessage(CommandMessage* message) override;
2023-04-14 13:26:44 +02:00
ReturnValue_t sendFullRebootCommand();
2023-08-01 09:26:06 +02:00
ReturnValue_t sendSelfRebootCommand();
2023-04-14 13:26:44 +02:00
2023-09-29 14:18:42 +02:00
void forceOffPayload();
2023-04-14 13:26:44 +02:00
void pdecRecoveryLogic();
2023-04-06 17:01:28 +02:00
void i2cRecoveryLogic();
2023-04-06 16:50:33 +02:00
void handleEventMessages();
void commandSelfToSafe();
2023-04-06 17:49:34 +02:00
void commonI2cRecoverySequenceFinish();
2023-04-06 16:50:33 +02:00
};
#endif /* MISSION_SYSTEM_EIVESYSTEM_H_ */