2021-05-26 14:16:16 +02:00
|
|
|
#ifndef BSP_Q7S_CORE_CORECONTROLLER_H_
|
|
|
|
#define BSP_Q7S_CORE_CORECONTROLLER_H_
|
|
|
|
|
2021-07-29 18:09:54 +02:00
|
|
|
#include <fsfw/globalfunctions/PeriodicOperationDivider.h>
|
2021-05-26 14:16:16 +02:00
|
|
|
#include "fsfw/controller/ExtendedControllerBase.h"
|
2021-07-16 20:32:13 +02:00
|
|
|
#include "bsp_q7s/memory/SdCardManager.h"
|
2021-05-26 14:16:16 +02:00
|
|
|
|
2021-07-19 12:44:43 +02:00
|
|
|
#include "events/subsystemIdRanges.h"
|
|
|
|
|
2021-07-28 16:37:08 +02:00
|
|
|
|
2021-08-05 18:13:32 +02:00
|
|
|
class Timer;
|
|
|
|
class SdCardManager;
|
2021-07-28 16:37:08 +02:00
|
|
|
|
2021-05-26 14:16:16 +02:00
|
|
|
class CoreController: public ExtendedControllerBase {
|
|
|
|
public:
|
2021-07-28 16:37:08 +02:00
|
|
|
enum Chip: uint8_t {
|
|
|
|
CHIP_0,
|
|
|
|
CHIP_1,
|
2021-08-19 13:34:44 +02:00
|
|
|
NO_CHIP,
|
|
|
|
SELF_CHIP,
|
|
|
|
ALL_CHIP
|
2021-07-28 16:37:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Copy: uint8_t {
|
|
|
|
COPY_0,
|
|
|
|
COPY_1,
|
2021-08-19 13:34:44 +02:00
|
|
|
NO_COPY,
|
|
|
|
SELF_COPY,
|
|
|
|
ALL_COPY
|
2021-07-28 16:37:08 +02:00
|
|
|
};
|
|
|
|
|
2021-08-19 13:34:44 +02:00
|
|
|
static constexpr char CHIP_PROT_SCRIPT[] = "/home/root/scripts/get-chip-prot-status.sh";
|
|
|
|
static constexpr char CHIP_STATE_FILE[] = "/tmp/chip_prot_status.txt";
|
|
|
|
static constexpr char CURR_COPY_FILE[] = "/tmp/curr_copy.txt";
|
|
|
|
static constexpr char VERSION_FILE[] = "/conf/sd_status";
|
|
|
|
|
2021-07-19 20:06:28 +02:00
|
|
|
static constexpr ActionId_t LIST_DIRECTORY_INTO_FILE = 0;
|
2021-08-03 11:18:24 +02:00
|
|
|
static constexpr ActionId_t REBOOT_OBC = 32;
|
2021-08-19 13:34:44 +02:00
|
|
|
static constexpr ActionId_t MOUNT_OTHER_COPY = 33;
|
|
|
|
|
2021-07-19 20:06:28 +02:00
|
|
|
|
2021-07-19 12:44:43 +02:00
|
|
|
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CORE;
|
|
|
|
|
|
|
|
static constexpr Event ALLOC_FAILURE = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM);
|
|
|
|
|
2021-07-28 16:37:08 +02:00
|
|
|
|
2021-05-26 14:16:16 +02:00
|
|
|
CoreController(object_id_t objectId);
|
2021-08-05 18:13:32 +02:00
|
|
|
virtual~ CoreController();
|
2021-05-26 14:16:16 +02:00
|
|
|
|
2021-07-08 12:07:39 +02:00
|
|
|
ReturnValue_t initialize() override;
|
|
|
|
|
2021-07-24 15:00:07 +02:00
|
|
|
ReturnValue_t initializeAfterTaskCreation() override;
|
|
|
|
|
2021-07-19 20:06:28 +02:00
|
|
|
ReturnValue_t executeAction(ActionId_t actionId,
|
|
|
|
MessageQueueId_t commandedBy, const uint8_t *data, size_t size) override;
|
|
|
|
|
2021-05-26 14:16:16 +02:00
|
|
|
ReturnValue_t handleCommandMessage(CommandMessage *message) override;
|
|
|
|
void performControlOperation() override;
|
2021-07-19 12:44:43 +02:00
|
|
|
|
2021-08-19 13:34:44 +02:00
|
|
|
/**
|
|
|
|
* Generate a file containing the chip lock/unlock states inside /tmp/chip_status.txt
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
static ReturnValue_t generateChipStateFile();
|
2021-07-19 12:44:43 +02:00
|
|
|
static ReturnValue_t incrementAllocationFailureCount();
|
2021-07-28 16:37:08 +02:00
|
|
|
static void getCurrentBootCopy(Chip& chip, Copy& copy);
|
2021-08-19 13:34:44 +02:00
|
|
|
|
|
|
|
ReturnValue_t updateProtInfo(bool regenerateChipStateFile = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the target chip and copy are writeprotected and protect them if they are
|
|
|
|
* not
|
|
|
|
* @param targetChip
|
|
|
|
* @param targetCopy
|
|
|
|
* @param protect
|
|
|
|
* @param protOperationPerformed [out] Can be used to determine whether any operation
|
|
|
|
* was performed
|
|
|
|
* @param updateProtFile Specify whether the protection info file is updated
|
|
|
|
* @return
|
|
|
|
*/
|
2021-08-19 14:45:25 +02:00
|
|
|
ReturnValue_t setBootCopyProtection(Chip targetChip, Copy targetCopy,
|
2021-08-19 13:34:44 +02:00
|
|
|
bool protect, bool& protOperationPerformed, bool updateProtFile = true);
|
|
|
|
|
2021-08-06 01:25:36 +02:00
|
|
|
bool sdInitFinished() const;
|
2021-07-28 16:37:08 +02:00
|
|
|
|
2021-05-26 14:16:16 +02:00
|
|
|
private:
|
2021-08-19 13:34:44 +02:00
|
|
|
static Chip CURRENT_CHIP;
|
|
|
|
static Copy CURRENT_COPY;
|
2021-07-28 16:37:08 +02:00
|
|
|
|
2021-08-19 13:34:44 +02:00
|
|
|
// Designated value for rechecking FIFO open
|
|
|
|
static constexpr int RETRY_FIFO_OPEN = -2;
|
|
|
|
int watchdogFifoFd = 0;
|
2021-07-12 14:32:20 +02:00
|
|
|
|
2021-08-08 00:37:07 +02:00
|
|
|
// States for SD state machine, which is used in non-blocking mode
|
2021-08-05 18:13:32 +02:00
|
|
|
enum class SdStates {
|
|
|
|
NONE,
|
|
|
|
START,
|
|
|
|
GET_INFO,
|
2021-08-05 18:37:14 +02:00
|
|
|
SET_STATE_SELF,
|
2021-08-06 01:25:36 +02:00
|
|
|
MOUNT_SELF,
|
2021-08-08 00:37:07 +02:00
|
|
|
// Determine operations for other SD card, depending on redundancy configuration
|
2021-08-06 01:25:36 +02:00
|
|
|
DETERMINE_OTHER,
|
2021-08-05 18:37:14 +02:00
|
|
|
SET_STATE_OTHER,
|
2021-08-06 01:25:36 +02:00
|
|
|
// Mount or unmount other
|
|
|
|
MOUNT_UNMOUNT_OTHER,
|
2021-08-08 00:37:07 +02:00
|
|
|
// Skip period because the shell command used to generate the info file sometimes is
|
|
|
|
// missing the last performed operation if executed too early
|
|
|
|
SKIP_CYCLE_BEFORE_INFO_UPDATE,
|
2021-08-05 18:13:32 +02:00
|
|
|
UPDATE_INFO,
|
2021-08-08 00:37:07 +02:00
|
|
|
// SD initialization done
|
2021-08-08 01:24:18 +02:00
|
|
|
IDLE,
|
2021-08-08 00:37:07 +02:00
|
|
|
// Used if SD switches or mount commands are issued via telecommand
|
|
|
|
SET_STATE_FROM_COMMAND,
|
2021-08-05 18:13:32 +02:00
|
|
|
};
|
2021-08-05 18:37:14 +02:00
|
|
|
static constexpr bool BLOCKING_SD_INIT = false;
|
2021-08-05 18:13:32 +02:00
|
|
|
|
|
|
|
SdCardManager* sdcMan = nullptr;
|
2021-08-06 01:25:36 +02:00
|
|
|
|
|
|
|
struct SdInfo {
|
|
|
|
sd::SdCard pref = sd::SdCard::NONE;
|
|
|
|
sd::SdState prefState = sd::SdState::OFF;
|
|
|
|
sd::SdCard other = sd::SdCard::NONE;
|
|
|
|
sd::SdState otherState = sd::SdState::OFF;
|
|
|
|
std::string prefChar = "0";
|
|
|
|
std::string otherChar = "1";
|
|
|
|
SdStates state = SdStates::START;
|
2021-08-08 01:24:18 +02:00
|
|
|
// Used to track whether a command was executed
|
2021-08-06 01:25:36 +02:00
|
|
|
bool commandExecuted = true;
|
|
|
|
bool initFinished = false;
|
|
|
|
SdCardManager::SdStatePair currentState;
|
|
|
|
uint16_t cycleCount = 0;
|
2021-08-08 01:24:18 +02:00
|
|
|
// These two flags are related to external commanding
|
|
|
|
bool commandIssued = false;
|
|
|
|
bool commandFinished = false;
|
|
|
|
sd::SdState currentlyCommandedState = sd::SdState::OFF;
|
2021-08-08 00:37:07 +02:00
|
|
|
sd::SdCard commandedCard = sd::SdCard::NONE;
|
|
|
|
sd::SdState commandedState = sd::SdState::OFF;
|
2021-08-06 01:25:36 +02:00
|
|
|
};
|
|
|
|
SdInfo sdInfo;
|
|
|
|
|
2021-08-19 13:34:44 +02:00
|
|
|
/**
|
|
|
|
* Index 0: Chip 0 Copy 0
|
|
|
|
* Index 1: Chip 0 Copy 1
|
|
|
|
* Index 2: Chip 1 Copy 0
|
|
|
|
* Index 3: Chip 1 Copy 1
|
|
|
|
*/
|
|
|
|
std::array<bool, 4> protArray;
|
|
|
|
|
|
|
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
|
|
|
LocalDataPoolManager& poolManager) override;
|
|
|
|
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
|
|
|
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
|
|
|
uint32_t *msToReachTheMode);
|
|
|
|
|
|
|
|
ReturnValue_t initVersionFile();
|
|
|
|
ReturnValue_t initBootCopy();
|
|
|
|
ReturnValue_t initWatchdogFifo();
|
|
|
|
ReturnValue_t initSdCardBlocking();
|
|
|
|
void initPrint();
|
|
|
|
|
|
|
|
ReturnValue_t sdStateMachine();
|
2021-08-06 01:25:36 +02:00
|
|
|
void updateSdInfoOther();
|
2021-08-08 00:11:21 +02:00
|
|
|
ReturnValue_t sdCardSetup(sd::SdCard sdCard, sd::SdState targetState, std::string sdChar,
|
|
|
|
bool printOutput = true);
|
2021-08-06 01:25:36 +02:00
|
|
|
ReturnValue_t sdColdRedundantBlockingInit();
|
2021-08-08 01:24:18 +02:00
|
|
|
void currentStateSetter(sd::SdCard sdCard, sd::SdState newState);
|
2021-08-05 18:13:32 +02:00
|
|
|
void determinePreferredSdCard();
|
2021-08-08 01:24:18 +02:00
|
|
|
void executeNextExternalSdCommand();
|
|
|
|
void checkExternalSdCommandStatus();
|
2021-07-24 15:00:07 +02:00
|
|
|
|
2021-07-28 16:37:08 +02:00
|
|
|
ReturnValue_t actionListDirectoryIntoFile(ActionId_t actionId, MessageQueueId_t commandedBy,
|
|
|
|
const uint8_t *data, size_t size);
|
2021-08-03 11:18:24 +02:00
|
|
|
ReturnValue_t actionPerformReboot(const uint8_t *data, size_t size);
|
2021-07-28 16:37:08 +02:00
|
|
|
|
2021-07-29 18:09:54 +02:00
|
|
|
PeriodicOperationDivider opDivider;
|
|
|
|
void performWatchdogControlOperation();
|
2021-05-26 14:16:16 +02:00
|
|
|
|
2021-08-19 13:34:44 +02:00
|
|
|
ReturnValue_t handleProtInfoUpdateLine(std::string nextLine);
|
2021-08-19 18:10:19 +02:00
|
|
|
int handleBootCopyProtAtIndex(Chip targetChip, Copy targetCopy, bool protect,
|
|
|
|
bool &protOperationPerformed, bool selfChip, bool selfCopy, bool allChips,
|
|
|
|
bool allCopies, uint8_t arrIdx);
|
2021-08-19 13:34:44 +02:00
|
|
|
};
|
2021-05-26 14:16:16 +02:00
|
|
|
|
|
|
|
#endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */
|