Resolved merge conflict with main

This commit is contained in:
dario
2024-12-01 11:43:40 +01:00
8 changed files with 149 additions and 25 deletions

View File

@@ -7,9 +7,9 @@ extern "C" {
/** /**
* @brief * @brief Entry point for TACOS. Initializes all activated features and starts associated tasks.
* *
* @param arg Default task argument * @param arg Passed on default task argument
*/ */
void startTACOS(void * arg); void startTACOS(void * arg);

View File

@@ -20,7 +20,4 @@
// State transition message define with highest CAN priority // State transition message define with highest CAN priority
#define STA_TACOS_CAN_BUS_SYS_MSG_ID 0x0 #define STA_TACOS_CAN_BUS_SYS_MSG_ID 0x0
// TACOS requires system events to start threads
#define STA_RTOS_SYSTEM_EVENTS_ENABLE
#endif // STA_TACOS_CONFIGS_DEFAULT_HPP #endif // STA_TACOS_CONFIGS_DEFAULT_HPP

View File

@@ -303,7 +303,7 @@ namespace sta
* @ingroup tacos_statemachine * @ingroup tacos_statemachine
*/ */
STA_WEAK STA_WEAK
void onStateTransition(uint16_t from, uint16_t to, uint32_t lockout){} void onStateTransition(uint16_t from, uint16_t to, uint32_t lockout) {}
} // namespace tacos } // namespace tacos
} // namespace sta } // namespace sta

View File

@@ -0,0 +1,82 @@
/**
* @file
* @brief Implementation of system events.
*/
#ifndef STA_TACOS_SYSTEM_EVENTS_HPP
#define STA_TACOS_SYSTEM_EVENTS_HPP
/**
* @defgroup STA_RTOS_SysEvent System Events
* @ingroup STA_RTOS_API
* @brief System events.
*
* Check @ref STA_RTOS_BuildConfig for configuration options.
*/
#include <cstdint>
// System event flags
//
/**
* @brief Startup system event flag.
*
* @ingroup STA_RTOS_SysEvent
*/
#define STA_TACOS_SYSTEM_EVENTS_STARTUP 0x100000U
namespace sta
{
namespace tacos
{
/**
* @brief Initialize system events.
*/
void initSystemEvents();
/**
* @brief Signal system events.
*
* @param flags System event flags
*
* @ingroup STA_RTOS_SysEvent
*/
void signalSystemEvents(uint32_t flags);
/**
* @brief Wait for system events.
*
* @param flags System event flags
* @param options osFlagsWaitAll or osFlagsWaitAny (osFlagsNoClear always set)
* @param timeout Wait timeout (0 = instant, osWaitForever = infinite)
*
* @ingroup STA_RTOS_SysEvent
*/
void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout);
/**
* @brief Signal startup system event.
*
* @ingroup STA_RTOS_SysEvent
*/
void signalStartupEvent();
/**
* @brief Wait for startup system event.
*
* Blocking while waiting
*
* @ingroup STA_RTOS_SysEvent
*/
void waitForStartupEvent();
} // namespace tacos
} // namespace sta
#endif // STA_RTOS_SYSTEM_EVENTS_HPP

51
src/events.cpp Normal file
View File

@@ -0,0 +1,51 @@
#include <sta/tacos/system/events.hpp>
#include <sta/rtos/event.hpp>
#include <sta/debug/assert.hpp>
#include <cmsis_os2.h>
#include <FreeRTOS.h>
namespace
{
// Event handle
sta::RtosEvent * systemEvents = nullptr;
}
namespace sta
{
namespace tacos
{
void initSystemEvents()
{
if (systemEvents == nullptr)
{
systemEvents = new sta::RtosEvent();
}
}
void signalSystemEvents(uint32_t flags)
{
STA_ASSERT_MSG(systemEvents != nullptr, "System events not initialized");
systemEvents->set(flags);
}
void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout)
{
STA_ASSERT_MSG(systemEvents != nullptr, "System events not initialized");
systemEvents->peek(flags, timeout);
}
void signalStartupEvent()
{
signalSystemEvents(STA_TACOS_SYSTEM_EVENTS_STARTUP);
}
void waitForStartupEvent()
{
waitForSystemEvents(STA_TACOS_SYSTEM_EVENTS_STARTUP, osFlagsWaitAll, osWaitForever);
}
} // namespace tacos
} // namespace sta

View File

@@ -28,8 +28,7 @@
#include <sta/lang.hpp> #include <sta/lang.hpp>
// rtos2-utils-specific includes. // rtos2-utils-specific includes.
#include <sta/rtos/system/startup.hpp> #include <sta/tacos/system/events.hpp>
#include <sta/rtos/system/events.hpp>
// Tacos-specific includes. // Tacos-specific includes.
#include <sta/tacos/c_api/startup.h> #include <sta/tacos/c_api/startup.h>
@@ -84,18 +83,18 @@ namespace sta
namespace tacos namespace tacos
{ {
/** /**
* @brief Function that is called before the statemachine task is started. Override it to * @brief Function that is called before the statemachine task is started. It serves as an entry point for the user to
* adjust the statemachine to your specifications. * define the threads the statemachine should run.
* *
* @ingroup tacos_startup * @ingroup tacos_startup
*/ */
STA_WEAK STA_WEAK
void onStatemachineInit() void startup()
{} {}
void initStatemachine() void initStatemachine()
{ {
onStatemachineInit(); startup();
Statemachine::instance()->start(); Statemachine::instance()->start();
} }
@@ -158,16 +157,14 @@ void startTACOS(void * arg)
// Initialize HAL // Initialize HAL
sta::initHAL(); sta::initHAL();
// Initialize RTOS system resources // Initialize RTOS system events
sta::rtos::initSystem(); sta::tacos::initSystemEvents();
// Call further initialization code // Call further initialization code
sta::tacos::startupExtras(arg); sta::tacos::startupExtras(arg);
// Wake threads // Wake threads
#ifdef STA_RTOS_SYSTEM_EVENTS_ENABLE sta::tacos::signalStartupEvent();
sta::rtos::signalStartupEvent();
#endif // STA_RTOS_SYSTEM_EVENTS_ENABLE
// Check if called from thread // Check if called from thread
if (osThreadGetId() != nullptr) if (osThreadGetId() != nullptr)

View File

@@ -131,12 +131,8 @@ namespace sta
setLockoutTimer(lockout); setLockoutTimer(lockout);
} }
// get heap stats at the end of the state transition
HeapStats_t stats;
vPortGetHeapStats(&stats);
// Execute the user-defined callback. // Execute the user-defined callback.
sta::tacos::onStateTransition(transition.from, transition.to, transition.lockout); sta::tacos::onStateTransition(from, to, lockout);
// Start all new tasks and stop all the tasks that aren't supposed to be running. // Start all new tasks and stop all the tasks that aren't supposed to be running.
updateThreads(); updateThreads();

View File

@@ -7,9 +7,10 @@
#include <sta/tacos/thread.hpp> #include <sta/tacos/thread.hpp>
#include <sta/tacos/system/events.hpp>
#include <sta/debug/assert.hpp> #include <sta/debug/assert.hpp>
#include <sta/debug/debug.hpp> #include <sta/debug/debug.hpp>
#include <sta/rtos/system/events.hpp>
#include <functional> #include <functional>
#include <cstring> #include <cstring>
@@ -63,7 +64,7 @@ namespace sta
while (true) while (true)
{ {
// The thread has to wait until the system startup has been completed. // The thread has to wait until the system startup has been completed.
rtos::waitForStartupEvent(); sta::tacos::waitForStartupEvent();
// Wait for a thread start flag. // Wait for a thread start flag.
wait(STA_RTOS_THREAD_FLAG_START); wait(STA_RTOS_THREAD_FLAG_START);