Added dummy task. Still a lot of compiler errors to be fixed

This commit is contained in:
dario
2023-09-22 15:50:26 +02:00
parent 326083e48a
commit 10bcad8203
13 changed files with 88 additions and 387 deletions

34
App/Src/tasks/dummy.cpp Normal file
View File

@@ -0,0 +1,34 @@
/*
* dummy.cpp
*
* Created on: 22 Sep 2023
* Author: Dario
*/
#include <tasks/dummy.hpp>
#include <sta/debug/debug.hpp>
#include <cmsis_os2.h>
namespace demo
{
DummyTask::DummyTask(const char* name)
: TacosThread(name, osPriorityNormal)
{
}
void DummyTask::init()
{
STA_DEBUG_PRINTLN("Initialized dummy task!");
}
void DummyTask::func()
{
STA_DEBUG_PRINT("Executing ");
STA_DEBUG_PRINTLN(this->getName());
}
} // namespace demo

View File

@@ -1,152 +0,0 @@
/*
* manager.cpp
*
* Created on: Aug 30, 2023
* Author: Dario
*/
#include <sta/debug/debug.hpp>
#include <sta/debug/assert.hpp>
#include <list>
#include <algorithm>
#include <cmsis_os2.h>
#include <FreeRTOS.h>
#include <sta/rtos/system/events.hpp>
#include <tasks/statemachine.hpp>
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;
extern "C"
{
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);
}
}
}
std::list<tacos_task_t> tasks;
void dummyInit(void *)
{
while (true)
{
STA_DEBUG_PRINTLN("INIT STATE");
}
osThreadExit();
}
void dummyStarted(void *)
{
while (true)
{
STA_DEBUG_PRINTLN("STARTED STATE");
}
osThreadExit();
}
void dummyFlying(void *)
{
while (true)
{
STA_DEBUG_PRINTLN("FLYING STATE");
}
osThreadExit();
}
void dummyLanded(void *)
{
while (true)
{
STA_DEBUG_PRINTLN("LANDED STATE");
}
osThreadExit();
}
extern "C" void startManagerTask(void *)
{
STA_DEBUG_PRINTLN("INITIALIZED MANAGER TASK");
while (true)
{
// Wait until the state machine triggers an event signaling a state-change.
osEventFlagsWait(stateChangeEvent_id, STATE_CHANGED_MSK, osFlagsWaitAll, osWaitForever);
for (tacos_task_t task : tasks)
{
// Check if this task is supposed to be running for this state. If not, kill all instances, else create the desired number of instances.
if (std::find(task.states.begin(), task.states.end(), currentState) == task.states.end())
{
for (osThreadId_t instance : task.running)
{
osThreadTerminate(instance);
}
}
else
{
if (!task.running.empty())
{
osThreadDef (task.attribs.name, task.attribs.priority, 1, 0);
osThreadCreate(osTh, argument);
}
}
}
}
osThreadExit();
}

View File

@@ -1,25 +0,0 @@
/*
* manager.cpp
*
* Created on: Aug 31, 2023
* Author: Carl
*/
#include <cmsis_os.h>
#include <string>
#include <usart.h>
#include <sta/debug/debug.hpp>
extern "C" void outputTask(void *)
{
while (true)
{
STA_DEBUG_PRINTLN("OUTPUT TASK RUNNING");
osThreadYield();
}
osThreadExit();
}

View File

@@ -1,107 +0,0 @@
/*
* state_machine.cpp
*
* Created on: Sep 4, 2023
* Author: Dario
*/
#include <cmsis_os2.h>
#include <tasks/statemachine.hpp>
#include <sta/debug/assert.hpp>
tacos_states_t currentState;
osTimerId_t lockout;
osTimerId_t failsafe;
void lockoutCallback(void* arg)
{
}
void failsafeCallback(void* arg)
{
changeState(TACOS_STATE_CHG_TIMEOUT);
}
bool checkStateChangeConditions()
{
// Only use the timers in this demo.
return false;
}
void changeState(uint8_t flag)
{
// Stop the old timers.
osTimerStop(lockout);
osTimerStop(failsafe);
// Set the event flags to signal other tasks that a state change has occured. Reset the flags immediately.
osEventFlagsSet(stateChangeEvent_id, flag);
osEventFlagsClear(stateChangeEvent_id, TACOS_STATE_CHG_ALL);
uint32_t lockoutCycles = 0;
uint32_t failsafeCycles = 0;
switch (currentState) {
case tacos_states_t::init:
currentState = tacos_states_t::started;
lockoutCycles = 5000;
failsafeCycles = 6000;
case tacos_states_t::started:
currentState = tacos_states_t::flying;
lockoutCycles = 1000;
failsafeCycles = 2000;
case tacos_states_t::flying:
currentState = tacos_states_t::landed;
lockoutCycles = 5000;
failsafeCycles = 6000;
break;
default:
break;
}
// Restart the timers.
osTimerStart(lockout, lockoutCycles);
osTimerStart(failsafe, failsafeCycles);
}
extern "C" void startStateMachine(void*)
{
// Initialize the stateChange event.
stateChangeEvent_id = osEventFlagsNew(NULL);
STA_ASSERT_MSG(stateChangeEvent_id != NULL, "Failed to initialize state change event!");
// The timers for catching errors.
lockout = osTimerNew(lockoutCallback, osTimerOnce, NULL, NULL);
failsafe = osTimerNew(failsafeCallback, osTimerOnce, NULL, NULL);
// Check if the initialization of the timers was successful.
STA_ASSERT_MSG(lockout != 0, "Failed to initialize lockout timer");
STA_ASSERT_MSG(failsafe != 0, "Failed to initialize failsafe timer");
while (true)
{
if (checkStateChangeConditions())
{
changeState(TACOS_STATE_CHG_NATURAL);
}
}
osThreadExit();
}

View File

@@ -1,24 +0,0 @@
/*
* watchdog.cpp
*
* Created on: Sep 1, 2023
* Author: Dario
*/
#include <sta/debug/debug.hpp>
#include <sta/rtos/system/watchdog.hpp>
namespace sta
{
namespace rtos
{
// Implementation of the watchdog event handler.
void watchdogEventHandler(void *, uint32_t flags)
{
if (flags & STA_WATCHDOG_FLAG_HEARTBEAT)
{
STA_DEBUG_PRINTLN("PING!");
}
}
}
} // namespace sta