2022-02-28 14:13:31 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
2022-03-01 15:06:59 +01:00
|
|
|
#include <cstdint>
|
2022-02-28 14:13:31 +01:00
|
|
|
#include <string>
|
|
|
|
|
2022-03-01 15:06:59 +01:00
|
|
|
#include "SdCardManager.h"
|
|
|
|
#include "definitions.h"
|
|
|
|
|
2022-02-28 14:13:31 +01:00
|
|
|
namespace xsc {
|
|
|
|
|
2022-02-28 19:52:43 +01:00
|
|
|
enum Chip : int { CHIP_0, CHIP_1, NO_CHIP, SELF_CHIP, ALL_CHIP };
|
|
|
|
enum Copy : int { COPY_0, COPY_1, NO_COPY, SELF_COPY, ALL_COPY };
|
2022-02-28 14:13:31 +01:00
|
|
|
|
|
|
|
} // namespace xsc
|
|
|
|
|
2023-06-24 17:29:23 +02:00
|
|
|
struct RebootWatchdogFile {
|
2022-02-28 14:13:31 +01:00
|
|
|
static constexpr uint8_t DEFAULT_MAX_BOOT_CNT = 10;
|
|
|
|
|
2022-03-01 14:51:12 +01:00
|
|
|
bool enabled = true;
|
2022-02-28 14:13:31 +01:00
|
|
|
size_t maxCount = DEFAULT_MAX_BOOT_CNT;
|
2022-02-28 16:47:36 +01:00
|
|
|
uint32_t img00Cnt = 0;
|
|
|
|
uint32_t img01Cnt = 0;
|
|
|
|
uint32_t img10Cnt = 0;
|
|
|
|
uint32_t img11Cnt = 0;
|
2022-03-01 11:57:48 +01:00
|
|
|
bool img00Lock = false;
|
|
|
|
bool img01Lock = false;
|
|
|
|
bool img10Lock = false;
|
|
|
|
bool img11Lock = false;
|
2022-02-28 19:52:43 +01:00
|
|
|
uint32_t* relevantBootCnt = &img00Cnt;
|
2022-02-28 14:13:31 +01:00
|
|
|
bool bootFlag = false;
|
|
|
|
xsc::Chip lastChip = xsc::Chip::CHIP_0;
|
|
|
|
xsc::Copy lastCopy = xsc::Copy::COPY_0;
|
2022-03-01 11:57:48 +01:00
|
|
|
xsc::Chip mechanismNextChip = xsc::Chip::NO_CHIP;
|
|
|
|
xsc::Copy mechanismNextCopy = xsc::Copy::NO_COPY;
|
2022-02-28 14:13:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class SdCardManager;
|
|
|
|
|
|
|
|
class CoreController {
|
2022-03-01 15:06:59 +01:00
|
|
|
public:
|
2023-06-24 17:14:56 +02:00
|
|
|
static constexpr char REBOOT_WATCHDOG_FILE[] = "/conf/reboot.txt";
|
2022-02-28 19:52:43 +01:00
|
|
|
//! [EXPORT] : [COMMENT] The reboot mechanism was triggered.
|
|
|
|
//! P1: First 16 bits: Last Chip, Last 16 bits: Last Copy,
|
|
|
|
//! P2: Each byte is the respective reboot count for the slots
|
|
|
|
static constexpr Event REBOOT_MECHANISM_TRIGGERED = 1;
|
2022-02-28 14:13:31 +01:00
|
|
|
static xsc::Chip CURRENT_CHIP;
|
|
|
|
static xsc::Copy CURRENT_COPY;
|
|
|
|
|
2022-02-28 16:55:49 +01:00
|
|
|
static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5;
|
2022-03-01 14:44:50 +01:00
|
|
|
static constexpr ActionId_t RESET_REBOOT_COUNTERS = 6;
|
|
|
|
static constexpr ActionId_t SWITCH_IMG_LOCK = 7;
|
|
|
|
static constexpr ActionId_t SET_MAX_REBOOT_CNT = 8;
|
2022-02-28 16:55:49 +01:00
|
|
|
|
2022-02-28 14:13:31 +01:00
|
|
|
CoreController();
|
2022-02-28 16:55:49 +01:00
|
|
|
|
2022-02-28 19:52:43 +01:00
|
|
|
static void setCurrentBootCopy(xsc::Chip chip, xsc::Copy copy);
|
2022-02-28 16:55:49 +01:00
|
|
|
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
2022-03-01 15:06:59 +01:00
|
|
|
const uint8_t* data, size_t size);
|
2023-06-24 17:29:23 +02:00
|
|
|
void performRebootWatchdogHandling(bool recreateFile);
|
|
|
|
void determineAndExecuteReboot(RebootWatchdogFile& rf, bool& needsReboot, xsc::Chip& tgtChip,
|
2022-03-01 15:06:59 +01:00
|
|
|
xsc::Copy& tgtCopy);
|
2022-03-01 14:44:50 +01:00
|
|
|
void setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::Copy tgtCopy);
|
2022-02-28 14:13:31 +01:00
|
|
|
void resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy);
|
2023-06-24 17:29:23 +02:00
|
|
|
bool parseRebootWatchdogFile(std::string path, RebootWatchdogFile& file);
|
|
|
|
void rewriteRebootWatchdogFile(RebootWatchdogFile file);
|
2022-03-01 15:06:59 +01:00
|
|
|
|
|
|
|
private:
|
2022-09-27 10:51:07 +02:00
|
|
|
struct SdFsmParams {
|
|
|
|
sd::SdCard active = sd::SdCard::NONE;
|
|
|
|
sd::SdState activeState = sd::SdState::OFF;
|
2022-02-28 14:13:31 +01:00
|
|
|
sd::SdCard other = sd::SdCard::NONE;
|
|
|
|
sd::SdState otherState = sd::SdState::OFF;
|
|
|
|
} sdInfo;
|
|
|
|
|
|
|
|
SdCardManager* sdcMan = nullptr;
|
2023-06-24 17:29:23 +02:00
|
|
|
RebootWatchdogFile rebootWatchdogFile = {};
|
2022-02-28 14:13:31 +01:00
|
|
|
bool doPerformRebootFileHandling = true;
|
|
|
|
};
|