Added reworked manager / statemachine tasks, thread implementation and new directory layout

This commit is contained in:
dario
2023-09-22 15:07:15 +02:00
parent adeec2f3f9
commit 503d874a6e
13 changed files with 652 additions and 26 deletions

View File

@@ -6,42 +6,70 @@
*/
#include <sta/debug/debug.hpp>
#include <sta/debug/assert.hpp>
#include <list>
#include <algorithm>
#include <cmsis_os2.h>
#include <FreeRTOS.h>
#include <sta/debug/debug.hpp>
#include <sta/debug/assert.hpp>
#include <sta/rtos/system/events.hpp>
#include <tasks/statemachine.hpp>
#define STATE_CHANGED_MSK 0x01
#define STATE_CHANGED_TIMOUT_MSK 0x02
// The state changed event defined somewhere else.
extern osEventFlagsId_t stateChangeEvent_id;
namespace tacos
{
// The data structure representing a TACOS task.
struct tacos_task_t
{
// The code to be executed for this task.
osThreadFunc_t func;
// The attributes for the task.
osThreadAttr_t attribs;
// A list of currently running instances of this task.
std::list<osThreadId_t> running;
// A list of states for which this task should be running.
std::list<tacos_states_t> states;
};
} // namespace tacos
// The current state defined somewhere else.
extern tacos_states_t currentState;
// The data structure representing a TACOS task.
struct tacos_task_t
extern "C"
{
// The code to be executed for this task.
osThreadFunc_t func;
void managerTask(void *)
{
STA_DEBUG_PRINTLN("INITIALIZED MANAGER TASK");
while (true)
{
// Wait until the state machine triggers an event signaling a state-change.
uint32_t flags = osEventFlagsWait(stateChangeEvent_id, STATE_CHANGED_MSK, osFlagsWaitAll, osWaitForever);
}
}
}
// The attributes for the task.
osThreadAttr_t attribs;
// A list of currently running instances of this task.
std::list<osThreadId_t> running;
// A list of states for which this task should be running.
std::list<tacos_states_t> states;
};
std::list<tacos_task_t> tasks;
@@ -111,12 +139,12 @@ extern "C" void startManagerTask(void *)
{
if (!task.running.empty())
{
osThreadCreate(thread_def, argument);
osThreadDef (task.attribs.name, task.attribs.priority, 1, 0);
osThreadCreate(osTh, argument);
}
}
}
STA_DEBUG_PRINTLN("STARTING NEW TASKS DUE TO STATE CHANGE!");
}
osThreadExit();

View File

@@ -46,8 +46,8 @@ void changeState(uint8_t flag)
osEventFlagsSet(stateChangeEvent_id, flag);
osEventFlagsClear(stateChangeEvent_id, TACOS_STATE_CHG_ALL);
uint8_t lockoutCycles = 0;
uint8_t failsafeCycles = 0;
uint32_t lockoutCycles = 0;
uint32_t failsafeCycles = 0;
switch (currentState) {
case tacos_states_t::init: