mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 18:15:59 +00:00
Merge pull request 'Moved startup to TACOS' (#31) from refactor/startup into main
Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils/pulls/31 Reviewed-by: dario <dario@noreply.git.intern.spaceteamaachen.de>
This commit is contained in:
commit
a718324f8a
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,3 +12,6 @@
|
|||||||
# Doxygen
|
# Doxygen
|
||||||
docs/html
|
docs/html
|
||||||
docs/latex
|
docs/latex
|
||||||
|
|
||||||
|
# Mac OS X
|
||||||
|
.DS_Store
|
||||||
|
10
README.md
10
README.md
@ -25,16 +25,6 @@ Mainly defers to the TACOS CAN module, but provides a simple interface for sendi
|
|||||||
Expandable for isotp.
|
Expandable for isotp.
|
||||||
|
|
||||||
|
|
||||||
## Watchdog
|
|
||||||
|
|
||||||
The watchdog task waits for signals sent either from its heartbeat timer or manually via `sta::notifyWatchdog`
|
|
||||||
and passes the event flags to the `sta::watchdogEventHandler` function. This function must be implemented by the application.
|
|
||||||
|
|
||||||
Configuration:
|
|
||||||
* `#define STA_RTOS_WATCHDOG_ENABLE`: Enable module
|
|
||||||
* `#define STA_RTOS_WATCHDOG_TIMER_PERIOD <period_ticks>`: Set period in ticks of heartbeat timer (default: 1000)
|
|
||||||
|
|
||||||
|
|
||||||
# STA-Core Interfaces
|
# STA-Core Interfaces
|
||||||
|
|
||||||
The library provides implementations for the following interfaces using CMSIS-RTOS2 functionality:
|
The library provides implementations for the following interfaces using CMSIS-RTOS2 functionality:
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
#ifndef STA_RTOS_C_API_STARTUP_H
|
|
||||||
#define STA_RTOS_C_API_STARTUP_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief
|
|
||||||
*
|
|
||||||
* @param arg Default task argument
|
|
||||||
*/
|
|
||||||
void startALPAKA(void * arg);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS_C_API_STARTUP_H
|
|
@ -5,30 +5,24 @@
|
|||||||
#ifndef STA_RTOS_SYSTEM_STARTUP_HPP
|
#ifndef STA_RTOS_SYSTEM_STARTUP_HPP
|
||||||
#define STA_RTOS_SYSTEM_STARTUP_HPP
|
#define STA_RTOS_SYSTEM_STARTUP_HPP
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup STA_RTOS_Startup Startup task
|
* @defgroup STA_RTOS_Startup RTOS Startup
|
||||||
* @ingroup STA_RTOS_API
|
* @ingroup STA_RTOS_API
|
||||||
* @brief Startup system task.
|
* @brief Initializes rtos functions.
|
||||||
*
|
|
||||||
* Check @ref STA_RTOS_BuildConfig for configuration options.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
namespace rtos
|
namespace rtos
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @brief Extra initialization run at start of startup task.
|
* @brief Initializes rtos functions.
|
||||||
*
|
*
|
||||||
* May be overridden by application if required.
|
* @ingroup STA_RTOS_Startup
|
||||||
*
|
*/
|
||||||
* @ingroup STA_RTOS_Startup
|
void initSystem();
|
||||||
*/
|
} // namespace rtos
|
||||||
void startupExtras(void * argument);
|
} // namespace sta
|
||||||
} // namespace rtos
|
|
||||||
} // namespace sta
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS_SYSTEM_STARTUP_HPP
|
#endif // STA_RTOS_SYSTEM_STARTUP_HPP
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief Implementation of watchdog system task.
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS_SYSTEM_WATCHDOG_HPP
|
|
||||||
#define STA_RTOS_SYSTEM_WATCHDOG_HPP
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup STA_RTOS_Watchdog Watchdog task
|
|
||||||
* @ingroup STA_RTOS_API
|
|
||||||
* @brief Watchdog system task.
|
|
||||||
*
|
|
||||||
* Check @ref STA_RTOS_BuildConfig for configuration options.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
/**
|
|
||||||
* @brief Enable module.
|
|
||||||
*
|
|
||||||
* @ingroup STA_RTOS_BuildConfig
|
|
||||||
*/
|
|
||||||
# define STA_RTOS_WATCHDOG_ENABLE
|
|
||||||
#endif // DOXYGEN
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def STA_RTOS_SYSTEM_WATCHDOG_TIMER_PERIOD
|
|
||||||
* @brief Set period in ticks of heartbeat timer.
|
|
||||||
*
|
|
||||||
* @ingroup STA_RTOS_BuildConfig
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS_SYSTEM_WATCHDOG_TIMER_PERIOD
|
|
||||||
# define STA_RTOS_SYSTEM_WATCHDOG_TIMER_PERIOD 1000
|
|
||||||
#endif // !STA_RTOS_SYSTEM_WATCHDOG_TIMER_PERIOD
|
|
||||||
|
|
||||||
|
|
||||||
#include <sta/config.hpp>
|
|
||||||
#ifdef STA_RTOS_WATCHDOG_ENABLE
|
|
||||||
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
|
|
||||||
// Watchdog task flags
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Watchdog heartbeat flag.
|
|
||||||
*
|
|
||||||
* @ingroup STA_RTOS_Watchdog
|
|
||||||
*/
|
|
||||||
#define STA_WATCHDOG_FLAG_HEARTBEAT 0x00001000U
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
|
||||||
{
|
|
||||||
namespace rtos
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief Initialize system watchdog.
|
|
||||||
*
|
|
||||||
* @ingroup STA_RTOS_Watchdog
|
|
||||||
*/
|
|
||||||
void initWatchdog();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Send notification to watchdog task.
|
|
||||||
*
|
|
||||||
* @ingroup STA_RTOS_Watchdog
|
|
||||||
*/
|
|
||||||
void notifyWatchdog(uint32_t flags);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Handler for watchdog events.
|
|
||||||
*
|
|
||||||
* Must be implemented by application.
|
|
||||||
*
|
|
||||||
* @param arg Watchdog task argument
|
|
||||||
* @param flags Event flags
|
|
||||||
*
|
|
||||||
* @ingroup STA_RTOS_Watchdog
|
|
||||||
*/
|
|
||||||
void watchdogEventHandler(void * arg, uint32_t flags);
|
|
||||||
} // namespace rtos
|
|
||||||
} // namespace sta
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS_WATCHDOG_ENABLE
|
|
||||||
|
|
||||||
#endif // STA_RTOS_SYSTEM_WATCHDOG_HPP
|
|
@ -1,64 +1,16 @@
|
|||||||
#include <sta/rtos/system/startup.hpp>
|
|
||||||
|
|
||||||
#include <sta/rtos/c_api/startup.h>
|
|
||||||
|
|
||||||
#include <sta/debug/assert.hpp>
|
|
||||||
#include <sta/lang.hpp>
|
|
||||||
#include <sta/rtos/system/can_bus.hpp>
|
|
||||||
#include <sta/rtos/system/events.hpp>
|
#include <sta/rtos/system/events.hpp>
|
||||||
#include <sta/rtos/system/watchdog.hpp>
|
|
||||||
#include <sta/devices/stm32/init.hpp>
|
|
||||||
|
|
||||||
#include <cmsis_os2.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
namespace rtos
|
namespace rtos
|
||||||
{
|
{
|
||||||
// Provide weak implementation to allow overriding
|
|
||||||
STA_WEAK
|
|
||||||
void startupExtras(void *)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void initSystem()
|
void initSystem()
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef STA_RTOS_SYSTEM_EVENTS_ENABLE
|
#ifdef STA_RTOS_SYSTEM_EVENTS_ENABLE
|
||||||
initSystemEvents();
|
initSystemEvents();
|
||||||
#endif // STA_RTOS_SYSTEM_EVENTS_ENABLE
|
#endif // STA_RTOS_SYSTEM_EVENTS_ENABLE
|
||||||
|
|
||||||
#ifdef STA_RTOS_WATCHDOG_ENABLE
|
|
||||||
initWatchdog();
|
|
||||||
#endif // STA_RTOS_WATCHDOG_ENABLE
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} // namespace rtos
|
} // namespace rtos
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
void startALPAKA(void * arg)
|
|
||||||
{
|
|
||||||
STA_ASSERT_MSG(osKernelGetState() != osKernelInactive, "Cannot call startALPAKA() before osKernelInitialize()");
|
|
||||||
|
|
||||||
// Initialize HAL
|
|
||||||
sta::initHAL();
|
|
||||||
|
|
||||||
// Initialize RTOS system resources
|
|
||||||
sta::rtos::initSystem();
|
|
||||||
|
|
||||||
// Call further initialization code
|
|
||||||
sta::rtos::startupExtras(arg);
|
|
||||||
|
|
||||||
// Wake threads
|
|
||||||
#ifdef STA_RTOS_SYSTEM_EVENTS_ENABLE
|
|
||||||
sta::rtos::signalStartupEvent();
|
|
||||||
#endif // STA_RTOS_SYSTEM_EVENTS_ENABLE
|
|
||||||
|
|
||||||
// Check if called from thread
|
|
||||||
if (osThreadGetId() != nullptr)
|
|
||||||
{
|
|
||||||
// Terminate current thread
|
|
||||||
osThreadExit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
#include <sta/rtos/system/watchdog.hpp>
|
|
||||||
#ifdef STA_RTOS_WATCHDOG_ENABLE
|
|
||||||
|
|
||||||
#include <sta/debug/assert.hpp>
|
|
||||||
#include <sta/debug/debug.hpp>
|
|
||||||
#include <sta/lang.hpp>
|
|
||||||
#include <sta/rtos/defs.hpp>
|
|
||||||
#include <sta/rtos/system/events.hpp>
|
|
||||||
|
|
||||||
#include <cmsis_os2.h>
|
|
||||||
#include <FreeRTOS.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
StaticTask_t watchdogCB;
|
|
||||||
StaticTimer_t watchdogTimerCB;
|
|
||||||
|
|
||||||
osThreadId_t watchdogTaskHandle = nullptr;
|
|
||||||
osTimerId_t watchdogTimerHandle = nullptr;
|
|
||||||
|
|
||||||
// Static stack memory
|
|
||||||
uint32_t stackBuffer[256];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
void watchdogTask(void * arg);
|
|
||||||
void watchdogTimerCallback(void *);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
|
||||||
{
|
|
||||||
namespace rtos
|
|
||||||
{
|
|
||||||
void initWatchdog()
|
|
||||||
{
|
|
||||||
// Create thread using static allocation
|
|
||||||
const osThreadAttr_t taskAttributes = {
|
|
||||||
.name = "sysWatchdog",
|
|
||||||
.cb_mem = &watchdogCB,
|
|
||||||
.cb_size = sizeof(watchdogCB),
|
|
||||||
.stack_mem = &stackBuffer[0],
|
|
||||||
.stack_size = sizeof(stackBuffer),
|
|
||||||
.priority = (osPriority_t) osPriorityLow,
|
|
||||||
};
|
|
||||||
|
|
||||||
watchdogTaskHandle = osThreadNew(watchdogTask, NULL, &taskAttributes);
|
|
||||||
STA_ASSERT_MSG(watchdogTaskHandle != nullptr, "System watchdog task initialization failed");
|
|
||||||
|
|
||||||
|
|
||||||
// Create timer using static allocation
|
|
||||||
const osTimerAttr_t timerAttributes = {
|
|
||||||
.name = "sysWatchdogTimer",
|
|
||||||
.attr_bits = 0, // Reserved, must be set to 0
|
|
||||||
.cb_mem = &watchdogTimerCB,
|
|
||||||
.cb_size = sizeof(watchdogTimerCB)
|
|
||||||
};
|
|
||||||
|
|
||||||
watchdogTimerHandle = osTimerNew(watchdogTimerCallback, osTimerPeriodic, nullptr, &timerAttributes);
|
|
||||||
STA_ASSERT_MSG(watchdogTimerHandle != nullptr, "System watchdog timer initialization failed");
|
|
||||||
osTimerStart(watchdogTimerHandle, STA_RTOS_SYSTEM_WATCHDOG_TIMER_PERIOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void notifyWatchdog(uint32_t flags)
|
|
||||||
{
|
|
||||||
STA_ASSERT_MSG(watchdogTaskHandle != nullptr, "System watchdog not initialized");
|
|
||||||
osThreadFlagsSet(watchdogTaskHandle, flags);
|
|
||||||
}
|
|
||||||
} // namespace rtos
|
|
||||||
} // namespace sta
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void watchdogTask(void * arg)
|
|
||||||
{
|
|
||||||
sta::rtos::waitForStartupEvent();
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// Wait for any flag to be set
|
|
||||||
uint32_t flags = osThreadFlagsWait(STA_RTOS_THREAD_FLAGS_VALID_BITS, osFlagsWaitAny, osWaitForever);
|
|
||||||
|
|
||||||
// Call event handler
|
|
||||||
sta::rtos::watchdogEventHandler(arg, flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void watchdogTimerCallback(void *)
|
|
||||||
{
|
|
||||||
// Notify watchdog task to send heartbeat message
|
|
||||||
// Required because blocking in a timer callback is not allowed
|
|
||||||
osThreadFlagsSet(watchdogTaskHandle, STA_WATCHDOG_FLAG_HEARTBEAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS_WATCHDOG_ENABLE
|
|
Loading…
x
Reference in New Issue
Block a user