mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-12 02:36:00 +00:00
Rename to STA RTOS
This commit is contained in:
parent
802999f2f6
commit
5e2296a028
28
README.md
28
README.md
@ -1,4 +1,4 @@
|
|||||||
# RTOS2 Utilities
|
# STA RTOS Utilities
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
@ -22,8 +22,8 @@ The library provides implementations for the following interfaces using CMSIS-RT
|
|||||||
Provides an interface for common system events.
|
Provides an interface for common system events.
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
* `#define STA_RTOS2_SYSTEM_EVENT_ENABLE`: Enable module
|
* `#define STA_RTOS_SYSTEM_EVENT_ENABLE`: Enable module
|
||||||
* `#define STA_RTOS2_SYSTEM_EVENT_HANDLE <var_name>`: Override variable name of flag handle (default: systemEventHandle)
|
* `#define STA_RTOS_SYSTEM_EVENT_HANDLE <var_name>`: Override variable name of flag handle (default: systemEventHandle)
|
||||||
|
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
@ -36,12 +36,12 @@ The watchdog task waits for signals sent either from the heartbeat timer or manu
|
|||||||
and forwards the event flags to the `sta::watchdogEventHandler` function implemented by the application.
|
and forwards the event flags to the `sta::watchdogEventHandler` function implemented by the application.
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
* `#define STA_RTOS2_WATCHDOG_ENABLE`: Enable module
|
* `#define STA_RTOS_WATCHDOG_ENABLE`: Enable module
|
||||||
* `#define STA_RTOS2_WATCHDOG_TIMER_PERIOD <period_ticks>`: Set period in ticks of heartbeat timer (default: 1000)
|
* `#define STA_RTOS_WATCHDOG_TIMER_PERIOD <period_ticks>`: Set period in ticks of heartbeat timer (default: 1000)
|
||||||
* `#define STA_RTOS2_WATCHDOG_TIMER_HANDLE <var_name>`: Override variable name of heartbeat timer handle (default: heartbeatHandle)
|
* `#define STA_RTOS_WATCHDOG_TIMER_HANDLE <var_name>`: Override variable name of heartbeat timer handle (default: heartbeatHandle)
|
||||||
* `#define STA_RTOS2_WATCHDOG_TIMER_CALLBACK <func_name>`: Override name of heartbeat timer callback function (default: heartbeatCallback)
|
* `#define STA_RTOS_WATCHDOG_TIMER_CALLBACK <func_name>`: Override name of heartbeat timer callback function (default: heartbeatCallback)
|
||||||
* `#define STA_RTOS2_WATCHDOG_HANDLE <var_name>`: Override variable name of watchdog task handle (default: watchdogHandle)
|
* `#define STA_RTOS_WATCHDOG_HANDLE <var_name>`: Override variable name of watchdog task handle (default: watchdogHandle)
|
||||||
* `#define STA_RTOS2_WATCHDOG_ENTRY_FUNCTION <func_name>`: Override name of watchdog task entry function (default: watchdogTask)
|
* `#define STA_RTOS_WATCHDOG_ENTRY_FUNCTION <func_name>`: Override name of watchdog task entry function (default: watchdogTask)
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
* Uses the `System Event` module
|
* Uses the `System Event` module
|
||||||
@ -56,8 +56,8 @@ It provides all setup required by the enabled system tasks. If additional initia
|
|||||||
application the function `void sta::startupExtras(void *)` declared in `<sta/rtos2/startup.hpp>` can be implemented.
|
application the function `void sta::startupExtras(void *)` declared in `<sta/rtos2/startup.hpp>` can be implemented.
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
* `#define STA_RTOS2_STARTUP_ENABLE`: Enable module
|
* `#define STA_RTOS_STARTUP_ENABLE`: Enable module
|
||||||
* `#define STA_RTOS2_STARTUP_ENTRY_FUNCTION <func_name>`: Override name of startup task entry function (default: startupTask)
|
* `#define STA_RTOS_STARTUP_ENTRY_FUNCTION <func_name>`: Override name of startup task entry function (default: startupTask)
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
* Uses the `System Event` module
|
* Uses the `System Event` module
|
||||||
@ -69,6 +69,6 @@ Requirements:
|
|||||||
Simplify configuration of modules. Intended for use in `<sta/config.hpp>`.
|
Simplify configuration of modules. Intended for use in `<sta/config.hpp>`.
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
* `#define STA_RTOS2_SYSTEM_TASKS_ENABLE`: Enable all modules required for system tasks
|
* `#define STA_RTOS_SYSTEM_TASKS_ENABLE`: Enable all modules required for system tasks
|
||||||
* `#define STA_RTOS2_WATCHDOG_TIMER_NAME <name>`: Override handle and callback name for watchdog timer
|
* `#define STA_RTOS_WATCHDOG_TIMER_NAME <name>`: Override handle and callback name for watchdog timer
|
||||||
* `#define STA_RTOS2_WATCHDOG_NAME <name>`: Override handle and entry function name for watchdog task
|
* `#define STA_RTOS_WATCHDOG_NAME <name>`: Override handle and entry function name for watchdog task
|
||||||
|
53
include/sta/rtos/defs.hpp
Normal file
53
include/sta/rtos/defs.hpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Constants and macros for use with CMSIS RTOS2.
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_DEFS_HPP
|
||||||
|
#define STA_RTOS_DEFS_HPP
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup STA_RTOS RTOS
|
||||||
|
* @brief STA RTOS library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup STA_RTOS_API API
|
||||||
|
* @ingroup STA_RTOS
|
||||||
|
* @brief Public interface.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup STA_RTOS_BuildConfig Build config
|
||||||
|
* @ingroup STA_RTOS
|
||||||
|
* @brief Build configuration options.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup STA_RTOS_API
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
// See limits defined in cmsis_os2.c
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Number of usable bits in task notification flags.
|
||||||
|
*/
|
||||||
|
#define STA_RTOS_MAX_BITS_TASK_NOTIFY 31U
|
||||||
|
/**
|
||||||
|
* @brief Number of usable bits in event group flags.
|
||||||
|
*/
|
||||||
|
#define STA_RTOS_MAX_BITS_EVENT_GROUPS 24U
|
||||||
|
/**
|
||||||
|
* @brief Mask for valid task notification flag bits.
|
||||||
|
*/
|
||||||
|
#define STA_RTOS_THREAD_FLAGS_VALID_BITS ( ( 1UL << STA_RTOS_MAX_BITS_TASK_NOTIFY ) - 1U )
|
||||||
|
/**
|
||||||
|
* @brief Mask for valid event group flag bits.
|
||||||
|
*/
|
||||||
|
#define STA_RTOS_EVENT_FLAGS_VALID_BITS ( ( 1UL << STA_RTOS_MAX_BITS_EVENT_GROUPS ) - 1U )
|
||||||
|
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#endif // STA_RTOS_DEFS_HPP
|
85
include/sta/rtos/easy_config.hpp
Normal file
85
include/sta/rtos/easy_config.hpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Helper for easy system task setup in `<sta/config.hpp>`.
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_EASY_CONFIG_HPP
|
||||||
|
#define STA_RTOS_EASY_CONFIG_HPP
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup STA_RTOS_EasyConfig Easy Config
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
* @brief Helpers for easy RTOS module setup.
|
||||||
|
*
|
||||||
|
* Use this header only inside the <sta/config.hpp> header of your application.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
/**
|
||||||
|
* @brief Don't warn about use of <rtos2/easy_config.hpp> outside of <sta/config.hpp>.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_EasyConfig
|
||||||
|
*/
|
||||||
|
# define STA_RTOS_EASY_CONFIG_NO_WARNING
|
||||||
|
#endif // DOXYGEN
|
||||||
|
|
||||||
|
#if !defined(STA_CONFIG_HPP) && !defined(STA_RTOS_EASY_CONFIG_NO_WARNING)
|
||||||
|
#warning "Intended for use in <sta/config.hpp>"
|
||||||
|
#endif // !STA_CONFIG_HPP && !STA_RTOS_EASY_CONFIG_NO_WARNING
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
/**
|
||||||
|
* @brief Enable all system tasks and required features.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_EasyConfig
|
||||||
|
*/
|
||||||
|
# define STA_RTOS_EASY_CONFIG_SYSTEM_TASKS_ENABLE
|
||||||
|
#endif // DOXYGEN
|
||||||
|
|
||||||
|
#ifdef STA_RTOS_EASY_CONFIG_SYSTEM_TASKS_ENABLE
|
||||||
|
// Enable system events used by system tasks
|
||||||
|
# define STA_RTOS_SYSTEM_EVENT_ENABLE
|
||||||
|
// Enable system tasks
|
||||||
|
# define STA_RTOS_WATCHDOG_ENABLE
|
||||||
|
# define STA_RTOS_STARTUP_ENABLE
|
||||||
|
#endif // STA_RTOS_EASY_CONFIG_SYSTEM_TASKS_ENABLE
|
||||||
|
|
||||||
|
|
||||||
|
#define _STA_RTOS_CONCAT(a, b) a ## b
|
||||||
|
|
||||||
|
#define STA_RTOS_MAKE_HANDLE_NAME(name) _STA_RTOS_CONCAT(name, Handle)
|
||||||
|
#define STA_RTOS_MAKE_CALLBACK_NAME(name) _STA_RTOS_CONCAT(name, Callback)
|
||||||
|
#define STA_RTOS_MAKE_TASK_NAME(name) _STA_RTOS_CONCAT(name, Task)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
/**
|
||||||
|
* @brief Common base name used for watchdog timer handle and callback names.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_EasyConfig
|
||||||
|
*/
|
||||||
|
# define STA_RTOS_EASY_CONFIG_WATCHDOG_TIMER_NAME
|
||||||
|
#endif // DOXYGEN
|
||||||
|
|
||||||
|
#ifdef STA_RTOS_EASY_CONFIG_WATCHDOG_TIMER_NAME
|
||||||
|
# define STA_RTOS_WATCHDOG_TIMER_HANDLE STA_RTOS_MAKE_HANDLE_NAME(STA_RTOS_EASY_CONFIG_WATCHDOG_TIMER_NAME)
|
||||||
|
# define STA_RTOS_WATCHDOG_TIMER_CALLBACK STA_RTOS_MAKE_CALLBACK_NAME(STA_RTOS_EASY_CONFIG_WATCHDOG_TIMER_NAME)
|
||||||
|
#endif // STA_RTOS_EASY_CONFIG_WATCHDOG_TIMER_NAME
|
||||||
|
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
/**
|
||||||
|
* @brief Common base name used for watchdog task handle and entry function names.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_EasyConfig
|
||||||
|
*/
|
||||||
|
# define STA_RTOS_EASY_CONFIG_WATCHDOG_NAME
|
||||||
|
#endif // DOXYGEN
|
||||||
|
|
||||||
|
#ifdef STA_RTOS_EASY_CONFIG_WATCHDOG_NAME
|
||||||
|
# define STA_RTOS_WATCHDOG_HANDLE STA_RTOS_MAKE_HANDLE_NAME(STA_RTOS_EASY_CONFIG_WATCHDOG_NAME)
|
||||||
|
# define STA_RTOS_WATCHDOG_ENTRY_FUNCTION STA_RTOS_MAKE_TASK_NAME(STA_RTOS_EASY_CONFIG_WATCHDOG_NAME)
|
||||||
|
#endif // STA_RTOS_EASY_CONFIG_WATCHDOG_NAME
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STA_RTOS_EASY_CONFIG_HPP
|
@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief CMSIS RTOS2 mutex implementation.
|
* @brief RTOS mutex implementation.
|
||||||
*/
|
*/
|
||||||
#ifndef STA_RTOS2_MUTEX_HPP
|
#ifndef STA_RTOS_MUTEX_HPP
|
||||||
#define STA_RTOS2_MUTEX_HPP
|
#define STA_RTOS_MUTEX_HPP
|
||||||
|
|
||||||
#include <sta/intf/mutex.hpp>
|
#include <sta/intf/mutex.hpp>
|
||||||
|
|
||||||
@ -15,15 +15,15 @@ namespace sta
|
|||||||
/**
|
/**
|
||||||
* @brief Implementation of Mutex interface using CMSIS RTOS2.
|
* @brief Implementation of Mutex interface using CMSIS RTOS2.
|
||||||
*
|
*
|
||||||
* @ingroup rtos2API
|
* @ingroup STA_RTOS_API
|
||||||
*/
|
*/
|
||||||
class Rtos2Mutex : public Mutex
|
class RTOSMutex : public Mutex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @param handle CMSIS RTOS2 mutex
|
* @param handle CMSIS RTOS2 mutex
|
||||||
*/
|
*/
|
||||||
Rtos2Mutex(osMutexId_t * handle);
|
RTOSMutex(osMutexId_t * handle);
|
||||||
|
|
||||||
void acquire() override;
|
void acquire() override;
|
||||||
void release() override;
|
void release() override;
|
||||||
@ -34,4 +34,4 @@ namespace sta
|
|||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_OS2_MUTEX_HPP
|
#endif // STA_RTOS_MUTEX_HPP
|
@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief CMSIS RTOS2 queue implementation.
|
* @brief RTOS queue implementation.
|
||||||
*/
|
*/
|
||||||
#ifndef STA_RTOS2_QUEUE_HPP
|
#ifndef STA_RTOS_QUEUE_HPP
|
||||||
#define STA_RTOS2_QUEUE_HPP
|
#define STA_RTOS_QUEUE_HPP
|
||||||
|
|
||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
|
|
||||||
@ -17,10 +17,10 @@ namespace sta
|
|||||||
*
|
*
|
||||||
* @tparam Message type
|
* @tparam Message type
|
||||||
*
|
*
|
||||||
* @ingroup rtos2API
|
* @ingroup STA_RTOS_API
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Rtos2Queue
|
class RTOSQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Message = T; /**< Queue message type */
|
using Message = T; /**< Queue message type */
|
||||||
@ -29,7 +29,7 @@ namespace sta
|
|||||||
/**
|
/**
|
||||||
* @param handle CMSIS RTOS2 queue handle
|
* @param handle CMSIS RTOS2 queue handle
|
||||||
*/
|
*/
|
||||||
Rtos2Queue(osMessageQueueId_t * handle);
|
RTOSQueue(osMessageQueueId_t * handle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Place message in queue.
|
* @brief Place message in queue.
|
||||||
@ -61,7 +61,7 @@ namespace sta
|
|||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
#include <sta/rtos2/queue.tpp>
|
#include <sta/rtos/queue.tpp>
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_QUEUE_HPP
|
#endif // STA_RTOS_QUEUE_HPP
|
41
include/sta/rtos/queue.tpp
Normal file
41
include/sta/rtos/queue.tpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#ifndef STA_RTOS_QUEUE_TPP
|
||||||
|
#define STA_RTOS_QUEUE_TPP
|
||||||
|
|
||||||
|
#ifndef STA_RTOS_QUEUE_HPP
|
||||||
|
# error "Internal header. Use <sta/rtos/queue.hpp> instead."
|
||||||
|
#endif // !STA_RTOS_QUEUE_HPP
|
||||||
|
|
||||||
|
#include <sta/assert.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace sta
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
RTOSQueue<T>::RTOSQueue(osMessageQueueId_t * handle)
|
||||||
|
: handle_{handle}
|
||||||
|
{
|
||||||
|
STA_ASSERT(handle != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool RTOSQueue<T>::put(const Message & msg, uint32_t timeout /* = osWaitForever */)
|
||||||
|
{
|
||||||
|
return (osOK == osMessageQueuePut(*handle_, &msg, 0, timeout));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool RTOSQueue<T>::get(Message * outMsg, uint32_t timeout /* = osWaitForever */)
|
||||||
|
{
|
||||||
|
uint8_t prio;
|
||||||
|
return (osOK == osMessageQueueGet(*handle_, outMsg, &prio, timeout));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
uint32 RTOSQueue<T>::available() const
|
||||||
|
{
|
||||||
|
return osMessageQueueGetCount(*handle_);
|
||||||
|
}
|
||||||
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STA_RTOS_QUEUE_TPP
|
@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief CMSIS RTOS2 signal implementation.
|
* @brief RTOS signal implementation.
|
||||||
*/
|
*/
|
||||||
#ifndef STA_RTOS2_SIGNAL_HPP
|
#ifndef STA_RTOS_SIGNAL_HPP
|
||||||
#define STA_RTOS2_SIGNAL_HPP
|
#define STA_RTOS_SIGNAL_HPP
|
||||||
|
|
||||||
#include <sta/intf/signal.hpp>
|
#include <sta/intf/signal.hpp>
|
||||||
|
|
||||||
@ -15,15 +15,15 @@ namespace sta
|
|||||||
/**
|
/**
|
||||||
* @brief Implementation of Signal interface using CMSIS RTOS2.
|
* @brief Implementation of Signal interface using CMSIS RTOS2.
|
||||||
*
|
*
|
||||||
* @ingroup rtos2API
|
* @ingroup STA_RTOS_API
|
||||||
*/
|
*/
|
||||||
class Rtos2Signal : public Signal
|
class RTOSSignal : public Signal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @param semaphore CMSIS RTOS2 semaphore
|
* @param semaphore CMSIS RTOS2 semaphore
|
||||||
*/
|
*/
|
||||||
Rtos2Signal(osSemaphoreId_t * semaphore);
|
RTOSSignal(osSemaphoreId_t * semaphore);
|
||||||
|
|
||||||
void notify() override;
|
void notify() override;
|
||||||
bool peek() override;
|
bool peek() override;
|
||||||
@ -36,4 +36,4 @@ namespace sta
|
|||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_SIGNAL_HPP
|
#endif // STA_RTOS_SIGNAL_HPP
|
57
include/sta/rtos/startup.hpp
Normal file
57
include/sta/rtos/startup.hpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Implementation of startup system task.
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_STARTUP_HPP
|
||||||
|
#define STA_RTOS_STARTUP_HPP
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup STA_RTOS_Startup Startup task
|
||||||
|
* @ingroup STA_RTOS_API
|
||||||
|
* @brief Startup system task.
|
||||||
|
*
|
||||||
|
* Check @ref STA_RTOS_BuildConfig for configuration options.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
/**
|
||||||
|
* @brief Enable module.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
*/
|
||||||
|
# define STA_RTOS_STARTUP_ENABLE
|
||||||
|
#endif // DOXYGEN
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def STA_RTOS_STARTUP_ENTRY_FUNCTION
|
||||||
|
* @brief Set name of startup task entry function.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_STARTUP_ENTRY_FUNCTION
|
||||||
|
# define STA_RTOS_STARTUP_ENTRY_FUNCTION startupTask
|
||||||
|
#endif // !STA_RTOS_STARTUP_ENTRY_FUNCTION
|
||||||
|
|
||||||
|
|
||||||
|
#include <sta/config.hpp>
|
||||||
|
#ifdef STA_RTOS_STARTUP_ENABLE
|
||||||
|
|
||||||
|
|
||||||
|
namespace sta
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief Extra initialization run at start of startup task.
|
||||||
|
*
|
||||||
|
* May be overridden by application if required.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_Startup
|
||||||
|
*/
|
||||||
|
void startupExtras(void * argument);
|
||||||
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STA_RTOS_STARTUP_ENABLE
|
||||||
|
|
||||||
|
#endif // STA_RTOS_STARTUP_HPP
|
@ -2,39 +2,39 @@
|
|||||||
* @file
|
* @file
|
||||||
* @brief Implementation of system events.
|
* @brief Implementation of system events.
|
||||||
*/
|
*/
|
||||||
#ifndef STA_OS2_SYSTEM_EVENT_HPP
|
#ifndef STA_RTOS_SYSTEM_EVENT_HPP
|
||||||
#define STA_OS2_SYSTEM_EVENT_HPP
|
#define STA_RTOS_SYSTEM_EVENT_HPP
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup rtos2SysEvent System Events
|
* @defgroup STA_RTOS_SysEvent System Events
|
||||||
* @ingroup rtos2API
|
* @ingroup STA_RTOS_API
|
||||||
* @brief System events.
|
* @brief System events.
|
||||||
*
|
*
|
||||||
* Check @ref rtos2BuildConfig for configuration options.
|
* Check @ref STA_RTOS_BuildConfig for configuration options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
#ifdef DOXYGEN
|
||||||
/**
|
/**
|
||||||
* @brief Enable module.
|
* @brief Enable module.
|
||||||
*
|
*
|
||||||
* @ingroup rtos2BuildConfig
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
*/
|
*/
|
||||||
# define STA_RTOS2_SYSTEM_EVENT_ENABLE
|
# define STA_RTOS2_SYSTEM_EVENT_ENABLE
|
||||||
#endif // DOXYGEN
|
#endif // DOXYGEN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def STA_RTOS2_SYSTEM_EVENT_HANDLE
|
* @def STA_RTOS_SYSTEM_EVENT_HANDLE
|
||||||
* @brief Set variable name of event flags handle.
|
* @brief Set variable name of event flags handle.
|
||||||
*
|
*
|
||||||
* @ingroup rtos2BuildConfig
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
*/
|
*/
|
||||||
#ifndef STA_RTOS2_SYSTEM_EVENT_HANDLE
|
#ifndef STA_RTOS_SYSTEM_EVENT_HANDLE
|
||||||
# define STA_RTOS2_SYSTEM_EVENT_HANDLE systemEventHandle
|
# define STA_RTOS_SYSTEM_EVENT_HANDLE systemEventHandle
|
||||||
#endif // !STA_RTOS2_SYSTEM_EVENT_HANDLE
|
#endif // !STA_RTOS_SYSTEM_EVENT_HANDLE
|
||||||
|
|
||||||
|
|
||||||
#include <sta/config.hpp>
|
#include <sta/config.hpp>
|
||||||
#ifdef STA_RTOS2_SYSTEM_EVENT_ENABLE
|
#ifdef STA_RTOS_SYSTEM_EVENT_ENABLE
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@ -45,7 +45,7 @@
|
|||||||
/**
|
/**
|
||||||
* @brief Startup system event flag.
|
* @brief Startup system event flag.
|
||||||
*
|
*
|
||||||
* @ingroup rtos2SysEvent
|
* @ingroup STA_RTOS_SysEvent
|
||||||
*/
|
*/
|
||||||
#define STA_SYSTEM_EVENT_STARTUP 0x100000U
|
#define STA_SYSTEM_EVENT_STARTUP 0x100000U
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ namespace sta
|
|||||||
*
|
*
|
||||||
* @param flags System event flags
|
* @param flags System event flags
|
||||||
*
|
*
|
||||||
* @ingroup rtos2SysEvent
|
* @ingroup STA_RTOS_SysEvent
|
||||||
*/
|
*/
|
||||||
void signalSystemEvents(uint32_t flags);
|
void signalSystemEvents(uint32_t flags);
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ namespace sta
|
|||||||
* @param options osFlagsWaitAll or osFlagsWaitAny (osFlagsNoClear always set)
|
* @param options osFlagsWaitAll or osFlagsWaitAny (osFlagsNoClear always set)
|
||||||
* @param timeout Wait timeout (0 = instant, osWaitForever = infinite)
|
* @param timeout Wait timeout (0 = instant, osWaitForever = infinite)
|
||||||
*
|
*
|
||||||
* @ingroup rtos2SysEvent
|
* @ingroup STA_RTOS_SysEvent
|
||||||
*/
|
*/
|
||||||
void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout);
|
void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ namespace sta
|
|||||||
/**
|
/**
|
||||||
* @brief Signal startup system event.
|
* @brief Signal startup system event.
|
||||||
*
|
*
|
||||||
* @ingroup rtos2SysEvent
|
* @ingroup STA_RTOS_SysEvent
|
||||||
*/
|
*/
|
||||||
void signalStartupEvent();
|
void signalStartupEvent();
|
||||||
|
|
||||||
@ -85,12 +85,12 @@ namespace sta
|
|||||||
*
|
*
|
||||||
* Blocking while waiting
|
* Blocking while waiting
|
||||||
*
|
*
|
||||||
* @ingroup rtos2SysEvent
|
* @ingroup STA_RTOS_SysEvent
|
||||||
*/
|
*/
|
||||||
void waitForStartupEvent();
|
void waitForStartupEvent();
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_SYSTEM_EVENT_ENABLE
|
#endif // STA_RTOS_SYSTEM_EVENT_ENABLE
|
||||||
|
|
||||||
#endif // STA_RTOS2_SYSTEM_EVENT_HPP
|
#endif // STA_RTOS_SYSTEM_EVENT_HPP
|
126
include/sta/rtos/watchdog.hpp
Normal file
126
include/sta/rtos/watchdog.hpp
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Implementation of watchdog system task.
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_WATCHDOG_HPP
|
||||||
|
#define STA_RTOS_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_WATCHDOG_TIMER_PERIOD
|
||||||
|
* @brief Set period in ticks of heartbeat timer.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_WATCHDOG_TIMER_PERIOD
|
||||||
|
# define STA_RTOS_WATCHDOG_TIMER_PERIOD 1000
|
||||||
|
#endif // !STA_RTOS_WATCHDOG_TIMER_PERIOD
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def STA_RTOS_WATCHDOG_TIMER_HANDLE
|
||||||
|
* @brief Set variable name of heartbeat timer handle.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_WATCHDOG_TIMER_HANDLE
|
||||||
|
# define STA_RTOS_WATCHDOG_TIMER_HANDLE heartbeatHandle
|
||||||
|
#endif // !STA_RTOS_WATCHDOG_TIMER_HANDLE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def STA_RTOS_WATCHDOG_TIMER_CALLBACK
|
||||||
|
* @brief Set name of heartbeat timer callback function.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_WATCHDOG_TIMER_CALLBACK
|
||||||
|
# define STA_RTOS_WATCHDOG_TIMER_CALLBACK heartbeatCallback
|
||||||
|
#endif // !STA_RTOS_WATCHDOG_TIMER_CALLBACK
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def STA_RTOS_WATCHDOG_HANDLE
|
||||||
|
* @brief Set variable name of watchdog task handle.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_WATCHDOG_HANDLE
|
||||||
|
# define STA_RTOS_WATCHDOG_HANDLE watchdogHandle
|
||||||
|
#endif // !STA_RTOS_WATCHDOG_HANDLE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def STA_RTOS_WATCHDOG_ENTRY_FUNCTION
|
||||||
|
* @brief Set name of watchdog task entry function.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_BuildConfig
|
||||||
|
*/
|
||||||
|
#ifndef STA_RTOS_WATCHDOG_ENTRY_FUNCTION
|
||||||
|
# define STA_RTOS_WATCHDOG_ENTRY_FUNCTION watchdogTask
|
||||||
|
#endif // !STA_RTOS_WATCHDOG_ENTRY_FUNCTION
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief Start heartbeat timer for watchdog.
|
||||||
|
*
|
||||||
|
* @ingroup STA_RTOS_Watchdog
|
||||||
|
*/
|
||||||
|
void startWatchdogTimer();
|
||||||
|
/**
|
||||||
|
* @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 sta
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STA_RTOS_WATCHDOG_ENABLE
|
||||||
|
|
||||||
|
#endif // STA_RTOS2_WATCHDOG_HPP
|
@ -1,53 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief Constants and macros for use with CMSIS RTOS2.
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_DEFS_HPP
|
|
||||||
#define STA_RTOS2_DEFS_HPP
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup rtos2 RTOS2
|
|
||||||
* @brief CMSIS RTOS2 library.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup rtos2API API
|
|
||||||
* @ingroup rtos2
|
|
||||||
* @brief Public interface.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup rtos2BuildConfig Build config
|
|
||||||
* @ingroup rtos2
|
|
||||||
* @brief Build configuration options.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup rtos2API
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
// See limits defined in cmsis_os2.c
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Number of usable bits in task notification flags.
|
|
||||||
*/
|
|
||||||
#define STA_RTOS2_MAX_BITS_TASK_NOTIFY 31U
|
|
||||||
/**
|
|
||||||
* @brief Number of usable bits in event group flags.
|
|
||||||
*/
|
|
||||||
#define STA_RTOS2_MAX_BITS_EVENT_GROUPS 24U
|
|
||||||
/**
|
|
||||||
* @brief Mask for valid task notification flag bits.
|
|
||||||
*/
|
|
||||||
#define STA_RTOS2_THREAD_FLAGS_VALID_BITS ((1UL << STA_RTOS2_MAX_BITS_TASK_NOTIFY) - 1U)
|
|
||||||
/**
|
|
||||||
* @brief Mask for valid event group flag bits.
|
|
||||||
*/
|
|
||||||
#define STA_RTOS2_EVENT_FLAGS_VALID_BITS ((1UL << STA_RTOS2_MAX_BITS_EVENT_GROUPS) - 1U)
|
|
||||||
|
|
||||||
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_DEFS_HPP
|
|
@ -1,85 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief Helper for easy system task setup in `<sta/config.hpp>`.
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_EASY_CONFIG_HPP
|
|
||||||
#define STA_RTOS2_EASY_CONFIG_HPP
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup rtos2EasyConfig Easy Config
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
* @brief Helpers for easy RTOS2 module setup.
|
|
||||||
*
|
|
||||||
* Use this header only inside the <sta/config.hpp> header of your application.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
/**
|
|
||||||
* @brief Don't warn about use of <rtos2/easy_config.hpp> outside of <sta/config.hpp>.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2EasyConfig
|
|
||||||
*/
|
|
||||||
# define STA_RTOS2_EASY_CONFIG_NO_WARNING
|
|
||||||
#endif // DOXYGEN
|
|
||||||
|
|
||||||
#if !defined(STA_CONFIG_HPP) && !defined(STA_RTOS2_EASY_CONFIG_NO_WARNING)
|
|
||||||
#warning "Intended for use in <sta/config.hpp>"
|
|
||||||
#endif // !STA_CONFIG_HPP && !STA_RTOS2_EASY_CONFIG_NO_WARNING
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
/**
|
|
||||||
* @brief Enable all system tasks and required features.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2EasyConfig
|
|
||||||
*/
|
|
||||||
# define STA_RTOS2_EASY_CONFIG_SYSTEM_TASKS_ENABLE
|
|
||||||
#endif // DOXYGEN
|
|
||||||
|
|
||||||
#ifdef STA_RTOS2_EASY_CONFIG_SYSTEM_TASKS_ENABLE
|
|
||||||
// Enable system events used by system tasks
|
|
||||||
# define STA_RTOS2_SYSTEM_EVENT_ENABLE
|
|
||||||
// Enable system tasks
|
|
||||||
# define STA_RTOS2_WATCHDOG_ENABLE
|
|
||||||
# define STA_RTOS2_STARTUP_ENABLE
|
|
||||||
#endif // STA_RTOS2_EASY_CONFIG_SYSTEM_TASKS_ENABLE
|
|
||||||
|
|
||||||
|
|
||||||
#define _STA_RTOS2_CONCAT(a, b) a ## b
|
|
||||||
|
|
||||||
#define STA_RTOS2_MAKE_HANDLE_NAME(name) _STA_RTOS2_CONCAT(name, Handle)
|
|
||||||
#define STA_RTOS2_MAKE_CALLBACK_NAME(name) _STA_RTOS2_CONCAT(name, Callback)
|
|
||||||
#define STA_RTOS2_MAKE_TASK_NAME(name) _STA_RTOS2_CONCAT(name, Task)
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
/**
|
|
||||||
* @brief Common base name used for watchdog timer handle and callback names.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2EasyConfig
|
|
||||||
*/
|
|
||||||
# define STA_RTOS2_EASY_CONFIG_WATCHDOG_TIMER_NAME
|
|
||||||
#endif // DOXYGEN
|
|
||||||
|
|
||||||
#ifdef STA_RTOS2_EASY_CONFIG_WATCHDOG_TIMER_NAME
|
|
||||||
# define STA_RTOS2_WATCHDOG_TIMER_HANDLE STA_RTOS2_MAKE_HANDLE_NAME(STA_RTOS2_EASY_CONFIG_WATCHDOG_TIMER_NAME)
|
|
||||||
# define STA_RTOS2_WATCHDOG_TIMER_CALLBACK STA_RTOS2_MAKE_CALLBACK_NAME(STA_RTOS2_EASY_CONFIG_WATCHDOG_TIMER_NAME)
|
|
||||||
#endif // STA_RTOS2_EASY_CONFIG_WATCHDOG_TIMER_NAME
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
/**
|
|
||||||
* @brief Common base name used for watchdog task handle and entry function names.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2EasyConfig
|
|
||||||
*/
|
|
||||||
# define STA_RTOS2_EASY_CONFIG_WATCHDOG_NAME
|
|
||||||
#endif // DOXYGEN
|
|
||||||
|
|
||||||
#ifdef STA_RTOS2_EASY_CONFIG_WATCHDOG_NAME
|
|
||||||
# define STA_RTOS2_WATCHDOG_HANDLE STA_RTOS2_MAKE_HANDLE_NAME(STA_RTOS2_EASY_CONFIG_WATCHDOG_NAME)
|
|
||||||
# define STA_RTOS2_WATCHDOG_ENTRY_FUNCTION STA_RTOS2_MAKE_TASK_NAME(STA_RTOS2_EASY_CONFIG_WATCHDOG_NAME)
|
|
||||||
#endif // STA_RTOS2_EASY_CONFIG_WATCHDOG_NAME
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_EASY_CONFIG_HPP
|
|
@ -1,41 +0,0 @@
|
|||||||
#ifndef STA_RTOS2_QUEUE_TPP
|
|
||||||
#define STA_RTOS2_QUEUE_TPP
|
|
||||||
|
|
||||||
#ifndef STA_RTOS2_QUEUE_HPP
|
|
||||||
# error "Internal header. Use <sta/rtos2/queue.hpp> instead."
|
|
||||||
#endif // !STA_RTOS2_QUEUE_HPP
|
|
||||||
|
|
||||||
#include <sta/assert.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
Rtos2Queue<T>::Rtos2Queue(osMessageQueueId_t * handle)
|
|
||||||
: handle_{handle}
|
|
||||||
{
|
|
||||||
STA_ASSERT(handle != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool Rtos2Queue<T>::put(const Message & msg, uint32_t timeout /* = osWaitForever */)
|
|
||||||
{
|
|
||||||
return (osOK == osMessageQueuePut(*handle_, &msg, 0, timeout));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool Rtos2Queue<T>::get(Message * outMsg, uint32_t timeout /* = osWaitForever */)
|
|
||||||
{
|
|
||||||
uint8_t prio;
|
|
||||||
return (osOK == osMessageQueueGet(*handle_, outMsg, &prio, timeout));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
uint32 Rtos2Queue<T>::available() const
|
|
||||||
{
|
|
||||||
return osMessageQueueGetCount(*handle_);
|
|
||||||
}
|
|
||||||
} // namespace sta
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_QUEUE_TPP
|
|
@ -1,57 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief Implementation of startup system task.
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_STARTUP_HPP
|
|
||||||
#define STA_RTOS2_STARTUP_HPP
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup rtos2Startup Startup task
|
|
||||||
* @ingroup rtos2API
|
|
||||||
* @brief Startup system task.
|
|
||||||
*
|
|
||||||
* Check @ref rtos2BuildConfig for configuration options.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
/**
|
|
||||||
* @brief Enable module.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
# define STA_RTOS2_STARTUP_ENABLE
|
|
||||||
#endif // DOXYGEN
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def STA_RTOS2_STARTUP_ENTRY_FUNCTION
|
|
||||||
* @brief Set name of startup task entry function.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_STARTUP_ENTRY_FUNCTION
|
|
||||||
# define STA_RTOS2_STARTUP_ENTRY_FUNCTION startupTask
|
|
||||||
#endif // !STA_RTOS2_STARTUP_ENTRY_FUNCTION
|
|
||||||
|
|
||||||
|
|
||||||
#include <sta/config.hpp>
|
|
||||||
#ifdef STA_RTOS2_STARTUP_ENABLE
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief Extra initialization run at start of startup task.
|
|
||||||
*
|
|
||||||
* May be overridden by application if required.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2Startup
|
|
||||||
*/
|
|
||||||
void startupExtras(void * argument);
|
|
||||||
} // namespace sta
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_STARTUP_ENABLE
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_STARTUP_HPP
|
|
@ -1,124 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief Implementation of watchdog system task.
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_WATCHDOG_HPP
|
|
||||||
#define STA_RTOS2_WATCHDOG_HPP
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup rtos2Watchdog Watchdog task
|
|
||||||
* @ingroup rtos2API
|
|
||||||
* @brief Watchdog system task.
|
|
||||||
*
|
|
||||||
* Check @ref rtos2BuildConfig for configuration options.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
|
||||||
/**
|
|
||||||
* @brief Enable module.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
# define STA_RTOS2_WATCHDOG_ENABLE
|
|
||||||
#endif // DOXYGEN
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def STA_RTOS2_WATCHDOG_TIMER_PERIOD
|
|
||||||
* @brief Set period in ticks of heartbeat timer.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_WATCHDOG_TIMER_PERIOD
|
|
||||||
# define STA_RTOS2_WATCHDOG_TIMER_PERIOD 1000
|
|
||||||
#endif // !STA_RTOS2_WATCHDOG_TIMER_PERIOD
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def STA_RTOS2_WATCHDOG_TIMER_HANDLE
|
|
||||||
* @brief Set variable name of heartbeat timer handle.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_WATCHDOG_TIMER_HANDLE
|
|
||||||
# define STA_RTOS2_WATCHDOG_TIMER_HANDLE heartbeatHandle
|
|
||||||
#endif // !STA_RTOS2_WATCHDOG_TIMER_HANDLE
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def STA_RTOS2_WATCHDOG_TIMER_CALLBACK
|
|
||||||
* @brief Set name of heartbeat timer callback function.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_WATCHDOG_TIMER_CALLBACK
|
|
||||||
# define STA_RTOS2_WATCHDOG_TIMER_CALLBACK heartbeatCallback
|
|
||||||
#endif // !STA_RTOS2_WATCHDOG_TIMER_CALLBACK
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def STA_RTOS2_WATCHDOG_HANDLE
|
|
||||||
* @brief Set variable name of watchdog task handle.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_WATCHDOG_HANDLE
|
|
||||||
# define STA_RTOS2_WATCHDOG_HANDLE watchdogHandle
|
|
||||||
#endif // !STA_RTOS2_WATCHDOG_HANDLE
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def STA_RTOS2_WATCHDOG_ENTRY_FUNCTION
|
|
||||||
* @brief Set name of watchdog task entry function.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2BuildConfig
|
|
||||||
*/
|
|
||||||
#ifndef STA_RTOS2_WATCHDOG_ENTRY_FUNCTION
|
|
||||||
# define STA_RTOS2_WATCHDOG_ENTRY_FUNCTION watchdogTask
|
|
||||||
#endif // !STA_RTOS2_WATCHDOG_ENTRY_FUNCTION
|
|
||||||
|
|
||||||
|
|
||||||
#include <sta/config.hpp>
|
|
||||||
#ifdef STA_RTOS2_WATCHDOG_ENABLE
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
|
|
||||||
// Watchdog task flags
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Watchdog heartbeat flag.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2Watchdog
|
|
||||||
*/
|
|
||||||
#define STA_WATCHDOG_FLAG_HEARTBEAT 0x00001000U
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @brief Start heartbeat timer for watchdog.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2Watchdog
|
|
||||||
*/
|
|
||||||
void startWatchdogTimer();
|
|
||||||
/**
|
|
||||||
* @brief Send notification to watchdog task.
|
|
||||||
*
|
|
||||||
* @ingroup rtos2Watchdog
|
|
||||||
*/
|
|
||||||
void notifyWatchdog(uint32_t flags);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Handler for watchdog events.
|
|
||||||
*
|
|
||||||
* Must be implemented by application.
|
|
||||||
*
|
|
||||||
* @param arg Watchdog task argument
|
|
||||||
* @param flags Event flags
|
|
||||||
*/
|
|
||||||
void watchdogEventHandler(void * arg, uint32_t flags);
|
|
||||||
} // namespace sta
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_WATCHDOG_ENABLE
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_WATCHDOG_HPP
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"owner" : "sta",
|
"owner" : "sta",
|
||||||
"name": "rtos2",
|
"name": "sta-rtos",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
{
|
{
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
#include <sta/rtos2/mutex.hpp>
|
#include <sta/rtos/mutex.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
Rtos2Mutex::Rtos2Mutex(osMutexId_t * handle)
|
RTOSMutex::RTOSMutex(osMutexId_t * handle)
|
||||||
: handle_{handle}
|
: handle_{handle}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void Rtos2Mutex::acquire()
|
void RTOSMutex::acquire()
|
||||||
{
|
{
|
||||||
osMutexAcquire(*handle_, osWaitForever);
|
osMutexAcquire(*handle_, osWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rtos2Mutex::release()
|
void RTOSMutex::release()
|
||||||
{
|
{
|
||||||
osMutexRelease(*handle_);
|
osMutexRelease(*handle_);
|
||||||
}
|
}
|
@ -1,28 +1,28 @@
|
|||||||
#include <sta/rtos2/signal.hpp>
|
#include <sta/rtos/signal.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
Rtos2Signal::Rtos2Signal(osSemaphoreId_t * semaphore)
|
RTOSSignal::RTOSSignal(osSemaphoreId_t * semaphore)
|
||||||
: semaphore_{semaphore}
|
: semaphore_{semaphore}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void Rtos2Signal::notify()
|
void RTOSSignal::notify()
|
||||||
{
|
{
|
||||||
osSemaphoreRelease(*semaphore_);
|
osSemaphoreRelease(*semaphore_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Rtos2Signal::peek()
|
bool RTOSSignal::peek()
|
||||||
{
|
{
|
||||||
return (osSemaphoreGetCount(*semaphore_) != 0);
|
return (osSemaphoreGetCount(*semaphore_) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Rtos2Signal::test()
|
bool RTOSSignal::test()
|
||||||
{
|
{
|
||||||
return (osSemaphoreAcquire(*semaphore_, 0) == osOK);
|
return (osSemaphoreAcquire(*semaphore_, 0) == osOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rtos2Signal::wait()
|
void RTOSSignal::wait()
|
||||||
{
|
{
|
||||||
osSemaphoreAcquire(*semaphore_, osWaitForever);
|
osSemaphoreAcquire(*semaphore_, osWaitForever);
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
#include <sta/rtos2/startup.hpp>
|
#include <sta/rtos/startup.hpp>
|
||||||
#ifdef STA_RTOS2_STARTUP_ENABLE
|
#ifdef STA_RTOS_STARTUP_ENABLE
|
||||||
|
|
||||||
#include <sta/lang.hpp>
|
#include <sta/lang.hpp>
|
||||||
#include <sta/rtos2/system_event.hpp>
|
#include <sta/rtos/system_event.hpp>
|
||||||
#include <sta/rtos2/watchdog.hpp>
|
#include <sta/rtos/watchdog.hpp>
|
||||||
#include <sta/stm32/init.hpp>
|
#include <sta/stm32/init.hpp>
|
||||||
|
|
||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
@ -21,7 +21,7 @@ namespace sta
|
|||||||
// Declare with C linkage
|
// Declare with C linkage
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
void STA_RTOS2_STARTUP_ENTRY_FUNCTION(void * arg)
|
void STA_RTOS_STARTUP_ENTRY_FUNCTION(void * arg)
|
||||||
{
|
{
|
||||||
// Call further initialization code
|
// Call further initialization code
|
||||||
sta::startupExtras(arg);
|
sta::startupExtras(arg);
|
||||||
@ -29,10 +29,10 @@ extern "C"
|
|||||||
// Initialize HAL
|
// Initialize HAL
|
||||||
sta::initHAL();
|
sta::initHAL();
|
||||||
|
|
||||||
#ifdef STA_RTOS2_WATCHDOG_ENABLE
|
#ifdef STA_RTOS_WATCHDOG_ENABLE
|
||||||
// Start timers
|
// Start timers
|
||||||
sta::startWatchdogTimer();
|
sta::startWatchdogTimer();
|
||||||
#endif // STA_RTOS2_WATCHDOG_ENABLE
|
#endif // STA_RTOS_WATCHDOG_ENABLE
|
||||||
|
|
||||||
// Wake tasks
|
// Wake tasks
|
||||||
sta::signalStartupEvent();
|
sta::signalStartupEvent();
|
||||||
@ -43,4 +43,4 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_STARTUP_ENABLE
|
#endif // STA_RTOS_STARTUP_ENABLE
|
@ -1,24 +1,24 @@
|
|||||||
#include <sta/rtos2/system_event.hpp>
|
#include <sta/rtos/system_event.hpp>
|
||||||
|
|
||||||
#ifdef STA_RTOS2_SYSTEM_EVENT_ENABLE
|
#ifdef STA_RTOS_SYSTEM_EVENT_ENABLE
|
||||||
|
|
||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
|
|
||||||
|
|
||||||
// Access handle from freertos.c
|
// Access handle from freertos.c
|
||||||
extern osEventFlagsId_t STA_RTOS2_SYSTEM_EVENT_HANDLE;
|
extern osEventFlagsId_t STA_RTOS_SYSTEM_EVENT_HANDLE;
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
void signalSystemEvents(uint32_t flags)
|
void signalSystemEvents(uint32_t flags)
|
||||||
{
|
{
|
||||||
osEventFlagsSet(STA_RTOS2_SYSTEM_EVENT_HANDLE, flags);
|
osEventFlagsSet(STA_RTOS_SYSTEM_EVENT_HANDLE, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout)
|
void waitForSystemEvents(uint32_t flags, uint32_t options, uint32_t timeout)
|
||||||
{
|
{
|
||||||
osEventFlagsWait(STA_RTOS2_SYSTEM_EVENT_HANDLE, flags, options | osFlagsNoClear, timeout);
|
osEventFlagsWait(STA_RTOS_SYSTEM_EVENT_HANDLE, flags, options | osFlagsNoClear, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -34,4 +34,4 @@ namespace sta
|
|||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_SYSTEM_EVENT_ENABLE
|
#endif // STA_RTOS_SYSTEM_EVENT_ENABLE
|
@ -1,19 +1,19 @@
|
|||||||
#include <sta/rtos2/watchdog.hpp>
|
#include <sta/rtos/watchdog.hpp>
|
||||||
|
|
||||||
#ifdef STA_RTOS2_WATCHDOG_ENABLE
|
#ifdef STA_RTOS_WATCHDOG_ENABLE
|
||||||
|
|
||||||
#include <cmsis_os2.h>
|
#include <cmsis_os2.h>
|
||||||
|
|
||||||
|
|
||||||
// Access handles from freertos.c
|
// Access handles from freertos.c
|
||||||
extern osTimerId_t STA_RTOS2_WATCHDOG_TIMER_HANDLE;
|
extern osTimerId_t STA_RTOS_WATCHDOG_TIMER_HANDLE;
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
void startWatchdogTimer()
|
void startWatchdogTimer()
|
||||||
{
|
{
|
||||||
osTimerStart(STA_RTOS2_WATCHDOG_TIMER_HANDLE, STA_RTOS2_WATCHDOG_TIMER_PERIOD);
|
osTimerStart(STA_RTOS_WATCHDOG_TIMER_HANDLE, STA_RTOS_WATCHDOG_TIMER_PERIOD);
|
||||||
}
|
}
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ namespace sta
|
|||||||
// Declare with C linkage
|
// Declare with C linkage
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
void STA_RTOS2_WATCHDOG_TIMER_CALLBACK(void *)
|
void STA_RTOS_WATCHDOG_TIMER_CALLBACK(void *)
|
||||||
{
|
{
|
||||||
// Notify watchdog task to send heartbeat message
|
// Notify watchdog task to send heartbeat message
|
||||||
// Required because blocking in a timer callback is not allowed
|
// Required because blocking in a timer callback is not allowed
|
||||||
@ -30,4 +30,4 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_WATCHDOG_ENABLE
|
#endif // STA_RTOS_WATCHDOG_ENABLE
|
45
src/rtos/watchdog/watchdog.cpp
Normal file
45
src/rtos/watchdog/watchdog.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include <sta/rtos/watchdog.hpp>
|
||||||
|
|
||||||
|
#ifdef STA_RTOS_WATCHDOG_ENABLE
|
||||||
|
|
||||||
|
#include <sta/rtos/defs.hpp>
|
||||||
|
#include <sta/rtos/system_event.hpp>
|
||||||
|
|
||||||
|
#include <main.h>
|
||||||
|
|
||||||
|
#include <cmsis_os2.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Access handle from freertos.c
|
||||||
|
extern osThreadId_t STA_RTOS_WATCHDOG_HANDLE;
|
||||||
|
|
||||||
|
|
||||||
|
namespace sta
|
||||||
|
{
|
||||||
|
void notifyWatchdog(uint32_t flags)
|
||||||
|
{
|
||||||
|
osThreadFlagsSet(STA_RTOS_WATCHDOG_HANDLE, flags);
|
||||||
|
}
|
||||||
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
|
// Declare with C linkage
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
void STA_RTOS_WATCHDOG_ENTRY_FUNCTION(void * arg)
|
||||||
|
{
|
||||||
|
sta::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::watchdogEventHandler(arg, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STA_RTOS_WATCHDOG_ENABLE
|
@ -1,45 +0,0 @@
|
|||||||
#include <sta/rtos2/watchdog.hpp>
|
|
||||||
|
|
||||||
#ifdef STA_RTOS2_WATCHDOG_ENABLE
|
|
||||||
|
|
||||||
#include <sta/rtos2/defs.hpp>
|
|
||||||
#include <sta/rtos2/system_event.hpp>
|
|
||||||
|
|
||||||
#include <main.h>
|
|
||||||
|
|
||||||
#include <cmsis_os2.h>
|
|
||||||
|
|
||||||
|
|
||||||
// Access handle from freertos.c
|
|
||||||
extern osThreadId_t STA_RTOS2_WATCHDOG_HANDLE;
|
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
|
||||||
{
|
|
||||||
void notifyWatchdog(uint32_t flags)
|
|
||||||
{
|
|
||||||
osThreadFlagsSet(STA_RTOS2_WATCHDOG_HANDLE, flags);
|
|
||||||
}
|
|
||||||
} // namespace sta
|
|
||||||
|
|
||||||
|
|
||||||
// Declare with C linkage
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
void STA_RTOS2_WATCHDOG_ENTRY_FUNCTION(void * arg)
|
|
||||||
{
|
|
||||||
sta::waitForStartupEvent();
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
// Wait for any flag to be set
|
|
||||||
uint32_t flags = osThreadFlagsWait(STA_RTOS2_THREAD_FLAGS_VALID_BITS, osFlagsWaitAny, osWaitForever);
|
|
||||||
|
|
||||||
// Call event handler
|
|
||||||
sta::watchdogEventHandler(arg, flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STA_RTOS2_WATCHDOG_ENABLE
|
|
Loading…
x
Reference in New Issue
Block a user