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

View File

@ -101,12 +101,12 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="App"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Libs"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Tacos"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="App"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Libs"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
</sourceEntries>
</configuration>
</storageModule>
@ -200,10 +200,10 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="App"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Libs"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
</sourceEntries>
</configuration>
</storageModule>

View File

@ -1,5 +1,5 @@
635E684B79701B039C64EA45C3F84D30=C96BA6CC9F20E1205A6EBDFF40205165
66BE74F758C12D739921AEA421D593D3=4
8DF89ED150041C4CBC7CB9A9CAA90856=D6E44E0C9E8538D2672E3627575EB9A7
DC22A860405A8BF2F2C095E5B6529F12=B7A8998BB86F8064A3F4829332693759
DC22A860405A8BF2F2C095E5B6529F12=D6E44E0C9E8538D2672E3627575EB9A7
eclipse.preferences.version=1

25
App/Inc/tasks/dummy.hpp Normal file
View File

@ -0,0 +1,25 @@
/*
* dummy.hpp
*
* Created on: 22 Sep 2023
* Author: Dario
*/
#ifndef INC_TASKS_DUMMY_HPP_
#define INC_TASKS_DUMMY_HPP_
#include <sta/tacos/thread.hpp>
namespace demo
{
class DummyTask : public sta::tacos::TacosThread {
public:
DummyTask(const char* name);
void init() override;
void func() override;
};
} // namespace demo
#endif /* INC_TASKS_DUMMY_HPP_ */

View File

@ -1,45 +0,0 @@
/*
* statemachine.hpp
*
* Created on: Sep 6, 2023
* Author: Dario
*/
#ifndef INC_TASKS_STATEMACHINE_HPP_
#define INC_TASKS_STATEMACHINE_HPP_
// Two flags for the state change event. TODO: HOW TO SET THE VALUES?
#define TACOS_STATE_CHG_FORCED 0x01
#define TACOS_STATE_CHG_TIMEOUT 0x02
#define TACOS_STATE_CHG_NATURAL 0x03
#define TACOS_STATE_CHG_ALL TACOS_STATE_CHG_FORCED | TACOS_STATE_CHG_TIMEOUT | TACOS_STATE_CHG_NATURAL
// The event for signaling state changes to other tasks
osEventFlagsId_t stateChangeEvent_id;
// The states used for this demo
enum tacos_states_t
{
init,
started,
flying,
landed
};
namespace tacos
{
class StateMachine
{
public:
private:
};
}
#endif /* INC_TASKS_STATEMACHINE_HPP_ */

View File

@ -5,38 +5,31 @@
* Author: Dario
*/
#include <cmsis_os2.h>
#include <usart.h>
#include <sta/rtos/mutex.hpp>
#include <sta/devices/stm32/bus/uart.hpp>
#include <sta/debug/printing/printable_uart.hpp>
#include <sta/tacos/startup.hpp>
#include <sta/debug/debug.hpp>
// The UART mutex defined in freertos.c
extern osMutexId_t uartMutexHandle;
#include <sta/tacos/manager.hpp>
#include <tasks/dummy.hpp>
namespace sta
{
// Here the printable used for debugging is defined.
Printable * Debug;
namespace rtos
namespace tacos
{
// Override the weak implementation of startupExtras provided in rtos2-utils.
void startupExtras(void * argument)
void onStatemachineInit()
{
// Initialize the mutex for UART communication.
RtosMutex * mutex = new RtosMutex(&uartMutexHandle);
// Initialize the UART interface and printable object.
UARTSettings settings = { .mode = UARTMode::RX_TX };
STM32UART * intf_ptr = new STM32UART(&huart2, settings, mutex);
Debug = new PrintableUART(intf_ptr);
STA_DEBUG_PRINTLN("UART SUCCESSFULLY INITIALIZED");
STA_DEBUG_PRINTLN("Starting statemachine task!");
}
} // namespace rtos
void onManagerInit()
{
STA_DEBUG_PRINTLN("Starting manager task!");
Manager::instance()->registerThread(demo::DummyTask("A"), {0, 1});
Manager::instance()->registerThread(demo::DummyTask("B"), {1, 2});
Manager::instance()->registerThread(demo::DummyTask("C"), {2, 3});
}
} // namespace tacos
} // namespace sta

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

@ -12,13 +12,9 @@ namespace sta
{
namespace rtos
{
// Implementation of the watchdog event handler.
void watchdogEventHandler(void *, uint32_t flags)
void watchdogEventHandler(void * arg, uint32_t flags)
{
if (flags & STA_WATCHDOG_FLAG_HEARTBEAT)
{
STA_DEBUG_PRINTLN("PING!");
}
STA_DEBUG_PRINTLN("Watchdog is doing stuff?");
}
}
} // namespace sta

View File

@ -29,7 +29,6 @@
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
typedef StaticTask_t osStaticThreadDef_t;
typedef StaticSemaphore_t osStaticMutexDef_t;
/* USER CODE BEGIN PTD */
@ -56,19 +55,6 @@ const osThreadAttr_t defaultTask_attributes = {
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for managerTask */
osThreadId_t managerTaskHandle;
uint32_t managerTaskBuffer[ 128 ];
osStaticThreadDef_t managerTaskControlBlock;
const osThreadAttr_t managerTask_attributes = {
.name = "managerTask",
.cb_mem = &managerTaskControlBlock,
.cb_size = sizeof(managerTaskControlBlock),
.stack_mem = &managerTaskBuffer[0],
.stack_size = sizeof(managerTaskBuffer),
.priority = (osPriority_t) osPriorityLow,
};
/* Definitions for uartMutex */
osMutexId_t uartMutexHandle;
osStaticMutexDef_t uartMutex_cb;
@ -84,7 +70,6 @@ const osMutexAttr_t uartMutex_attributes = {
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void *argument);
extern void startManagerTask(void *argument);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
@ -133,9 +118,6 @@ void MX_FREERTOS_Init(void) {
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of managerTask */
managerTaskHandle = osThreadNew(startManagerTask, NULL, &managerTask_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */

View File

@ -5,7 +5,7 @@ CAD.provider=
FREERTOS.FootprintOK=true
FREERTOS.IPParameters=Tasks01,configUSE_NEWLIB_REENTRANT,configRECORD_STACK_HIGH_ADDRESS,configCHECK_FOR_STACK_OVERFLOW,Mutexes01,FootprintOK
FREERTOS.Mutexes01=uartMutex,Static,uartMutex_cb
FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;managerTask,8,128,startManagerTask,As external,NULL,Static,managerTaskBuffer,managerTaskControlBlock
FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL
FREERTOS.configCHECK_FOR_STACK_OVERFLOW=1
FREERTOS.configRECORD_STACK_HIGH_ADDRESS=1
FREERTOS.configUSE_NEWLIB_REENTRANT=1

View File

@ -42,6 +42,8 @@ namespace sta
uint16_t getCurrentState();
private:
static Statemachine * _instance;
class CGuard
{
public:
@ -61,8 +63,6 @@ namespace sta
~Statemachine() {}
static Statemachine * _instance;
uint16_t currentState_;
};
} // namespace tacos