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,
|
|
|
|
NO_CHIP
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Copy: uint8_t {
|
|
|
|
COPY_0,
|
|
|
|
COPY_1,
|
|
|
|
NO_COPY
|
|
|
|
};
|
|
|
|
|
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-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
|
|
|
|
|
|
|
static ReturnValue_t incrementAllocationFailureCount();
|
2021-07-28 16:37:08 +02:00
|
|
|
static void getCurrentBootCopy(Chip& chip, Copy& copy);
|
|
|
|
|
2021-05-26 14:16:16 +02:00
|
|
|
private:
|
2021-07-28 16:37:08 +02:00
|
|
|
static Chip currentChip;
|
|
|
|
static Copy currentCopy;
|
|
|
|
|
2021-05-26 14:16:16 +02:00
|
|
|
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);
|
2021-07-12 14:32:20 +02:00
|
|
|
|
2021-08-05 18:13:32 +02:00
|
|
|
// States for non-blocking setup
|
|
|
|
enum class SdStates {
|
|
|
|
NONE,
|
|
|
|
START,
|
|
|
|
GET_INFO,
|
2021-08-05 18:37:14 +02:00
|
|
|
SET_STATE_SELF,
|
|
|
|
SET_STATE_OTHER,
|
2021-08-05 18:13:32 +02:00
|
|
|
MOUNT,
|
|
|
|
UPDATE_INFO,
|
|
|
|
DONE
|
|
|
|
};
|
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;
|
|
|
|
uint16_t sdcInitCycleCount = 0;
|
|
|
|
ReturnValue_t initSdCardBlocking();
|
|
|
|
ReturnValue_t initSdCardNonBlocking();
|
|
|
|
sd::SdCard preferredSdCard = sd::SdCard::NONE;
|
|
|
|
SdStates state = SdStates::START;
|
|
|
|
SdCardManager::SdStatusPair statusPair;
|
|
|
|
bool commandExecuted = true;
|
|
|
|
bool sdInitFinished = false;
|
|
|
|
ReturnValue_t sdCardSetup(SdCardManager::SdStatusPair& statusPair,
|
|
|
|
sd::SdCard sdCard, std::string sdString);
|
2021-07-16 20:32:13 +02:00
|
|
|
ReturnValue_t sdCardColdRedundantInit(SdCardManager* sdcMan,
|
2021-08-05 18:13:32 +02:00
|
|
|
SdCardManager::SdStatusPair& statusPair, SdStates step = SdStates::NONE);
|
|
|
|
void determinePreferredSdCard();
|
2021-07-24 15:00:07 +02:00
|
|
|
|
2021-07-28 16:37:08 +02:00
|
|
|
ReturnValue_t initVersionFile();
|
2021-07-28 19:46:19 +02:00
|
|
|
ReturnValue_t initBootCopy();
|
2021-07-29 16:31:04 +02:00
|
|
|
ReturnValue_t initWatchdogFifo();
|
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-26 11:47:45 +02:00
|
|
|
void initPrint();
|
2021-07-24 15:00:07 +02:00
|
|
|
|
2021-07-29 18:09:54 +02:00
|
|
|
// Designated value for rechecking FIFO open
|
|
|
|
static constexpr int RETRY_FIFO_OPEN = -2;
|
2021-07-29 16:31:04 +02:00
|
|
|
int watchdogFifoFd = 0;
|
2021-07-29 18:09:54 +02:00
|
|
|
|
|
|
|
PeriodicOperationDivider opDivider;
|
|
|
|
void performWatchdogControlOperation();
|
2021-05-26 14:16:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */
|