Skip to content

Commit 6d65b30

Browse files
committed
More reliable (?) task handling
Came up with the idea while chatting w/ GitHub Copilot. It should be less likely to lead to configuration errors, but is probably harder to program right.
1 parent e912c9b commit 6d65b30

4 files changed

Lines changed: 604 additions & 78 deletions

File tree

include/LoadContainer.hpp

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,29 @@ class LoadContainer {
1414
// constexpr uint_fast8_t NUM_MAIN_TASKS = 1;
1515
// Arduino Loop has priority 1
1616
// TODO: Note: Task priority must be < 25
17-
etl::array<TaskInfo, NUM_MAIN_TASKS> mainTaskDescriptions = {
18-
TaskInfo{vTaskUpdateFSM, "FSM", 1024, nullptr, 24, nullptr, 0,
19-
false}, // 0
20-
TaskInfo{vTaskPollSensors, "Poll", 2048, nullptr, 20, nullptr, 0,
21-
false}, // 1
22-
TaskInfo{vTaskAdjustLoad, "AdLd", 2048, nullptr, 20, nullptr, 0,
23-
false}, // 2
24-
TaskInfo{vTaskRecvData, "Recv", 2048, nullptr, 15, nullptr, 0,
25-
false}, // 3
2617

27-
TaskInfo{vTaskSendData, "Send", 2048, nullptr, 15, nullptr, 0,
28-
false}, // 4
29-
TaskInfo{vTaskConfigure, "Cfg", 1024, nullptr, 10, nullptr, 0,
30-
false}, // 5
31-
TaskInfo{vTaskStatusLED, "LED", 2048, nullptr, 2, nullptr, 0,
32-
false}, // 6
33-
TaskInfo{vTLog, "Log", 4096, nullptr, 1, nullptr, 0, false} // 7
34-
};
18+
TaskInfo tFSM{vTaskUpdateFSM, "FSM", 1024, nullptr, 24, nullptr, 0, false};
19+
TaskInfo tPoll{vTaskPollSensors, "Poll", 2048, nullptr, 20,
20+
nullptr, 0, false};
21+
TaskInfo tAdjustLoad{vTaskAdjustLoad, "AdLd", 2048, nullptr, 20,
22+
nullptr, 0, false};
23+
TaskInfo tRecv{vTaskRecvData, "Recv", 2048, nullptr, 15, nullptr, 0, false};
3524

36-
etl::array<TaskInfo, NUM_OPTIONAL_TASKS> optionalTaskDescriptions = {
37-
TaskInfo{vTaskTelnet, "Telnet", 4096, nullptr, 1, nullptr, 0,
38-
false}, // 0
39-
TaskInfo{vTaskOTA, "OTA", 4096, nullptr, 1, nullptr, 0, false}, // 1
40-
};
25+
TaskInfo tSend{vTaskSendData, "Send", 2048, nullptr, 15, nullptr, 0, false};
26+
TaskInfo tCfg{vTaskConfigure, "Cfg", 1024, nullptr, 10, nullptr, 0, false};
27+
TaskInfo tLED{vTaskStatusLED, "LED", 2048, nullptr, 2, nullptr, 0, false};
28+
TaskInfo tLog{vTLog, "Log", 4096, nullptr, 1, nullptr, 0, false};
29+
// namespace TaskInfo
4130

42-
/**
43-
* @SupressWarnings("cpp:S3642") // Does not work
44-
*/
45-
enum TASK_IDS : uint_fast8_t { // NOSONAR
46-
TID_FSM = 0,
47-
TID_POLL,
48-
TID_ADJUST_LOAD,
49-
TID_RECV,
50-
TID_SEND,
51-
TID_CFG,
52-
TID_LED,
53-
TID_LOG
54-
};
31+
etl::array<TaskInfo *, NUM_MAIN_TASKS> mainTaskDescriptions = {
32+
&tFSM, &tPoll, &tAdjustLoad, &tRecv, &tSend, &tCfg, &tLED, &tLog};
5533

56-
enum OPT_TASK_IDS : uint_fast8_t { // NOSONAR
57-
TID_TELNET = 0,
58-
TID_OTA
59-
};
34+
TaskInfo tTelnet{vTaskTelnet, "Telnet", 4096, nullptr,
35+
1, nullptr, 0, false};
36+
TaskInfo tOTA{vTaskOTA, "OTA", 4096, nullptr, 1, nullptr, 0, false};
37+
38+
etl::array<TaskInfo *, NUM_OPTIONAL_TASKS> optionalTaskDescriptions = {
39+
&tTelnet, &tOTA};
6040

6141
LoadContainer(MCP23008T &loadDevice) : loadDevice(loadDevice) {}
6242
~LoadContainer() = default;

include/LoadFSM.hpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ class LoadFSM {
6464
currentState = FSMCommon::States::sESTOP;
6565

6666
// TODO: Signal nacelle to ESTOP (setSafetyFlag)
67-
vTaskSuspend(load.mainTaskDescriptions
68-
[LoadContainer::TASK_IDS::TID_ADJUST_LOAD]
69-
.pxHandle);
67+
vTaskSuspend(load.tAdjustLoad.pxHandle);
7068
load.setLoadGPIO(0b0000'0000); // todo: one inverted?
7169

7270
return UPDATE_RESULT::STATE_CHANGED;
@@ -83,9 +81,7 @@ class LoadFSM {
8381
currentState = FSMCommon::States::sRST;
8482

8583
// Signal Nacelle (unset safetyFlag)
86-
vTaskSuspend(load.mainTaskDescriptions
87-
[LoadContainer::TASK_IDS::TID_ADJUST_LOAD]
88-
.pxHandle);
84+
vTaskSuspend(load.tAdjustLoad.pxHandle);
8985
load.setLoadGPIO(0b0000'0000); // todo: one inverted?
9086

9187
return UPDATE_RESULT::STATE_CHANGED;
@@ -112,10 +108,9 @@ class LoadFSM {
112108
currentState = FSMCommon::States::sRunLoad;
113109

114110
// Nacelle can detect this on it's own
115-
vTaskResume( // todo: check load logic
116-
load.mainTaskDescriptions
117-
[LoadContainer::TASK_IDS::TID_ADJUST_LOAD]
118-
.pxHandle); // todo: better way to signal load task?
111+
// todo: check load logic
112+
// todo: better way to signal load task?
113+
vTaskResume(load.tAdjustLoad.pxHandle);
119114

120115
return UPDATE_RESULT::STATE_CHANGED;
121116
} else if ((currentState == FSMCommon::States::sRunLoad) &&

0 commit comments

Comments
 (0)