diff --git a/README.md b/README.md index ebcdd4a..53d8390 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# RTOS2 Utilities +# STA RTOS Utilities ![pre-release v0.1.0](https://img.shields.io/static/v1?label=pre-release&message=v0.1.0&color=orange&logo=git) ![Standard: C++11](https://img.shields.io/static/v1?label=standard&message=C%2B%2B11&color=blue&logo=cplusplus) @@ -22,8 +22,8 @@ The library provides implementations for the following interfaces using CMSIS-RT Provides an interface for common system events. Configuration: -* `#define STA_RTOS2_SYSTEM_EVENT_ENABLE`: Enable module -* `#define STA_RTOS2_SYSTEM_EVENT_HANDLE `: Override variable name of flag handle (default: systemEventHandle) +* `#define STA_RTOS_SYSTEM_EVENT_ENABLE`: Enable module +* `#define STA_RTOS_SYSTEM_EVENT_HANDLE `: Override variable name of flag handle (default: systemEventHandle) 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. Configuration: -* `#define STA_RTOS2_WATCHDOG_ENABLE`: Enable module -* `#define STA_RTOS2_WATCHDOG_TIMER_PERIOD `: Set period in ticks of heartbeat timer (default: 1000) -* `#define STA_RTOS2_WATCHDOG_TIMER_HANDLE `: Override variable name of heartbeat timer handle (default: heartbeatHandle) -* `#define STA_RTOS2_WATCHDOG_TIMER_CALLBACK `: Override name of heartbeat timer callback function (default: heartbeatCallback) -* `#define STA_RTOS2_WATCHDOG_HANDLE `: Override variable name of watchdog task handle (default: watchdogHandle) -* `#define STA_RTOS2_WATCHDOG_ENTRY_FUNCTION `: Override name of watchdog task entry function (default: watchdogTask) +* `#define STA_RTOS_WATCHDOG_ENABLE`: Enable module +* `#define STA_RTOS_WATCHDOG_TIMER_PERIOD `: Set period in ticks of heartbeat timer (default: 1000) +* `#define STA_RTOS_WATCHDOG_TIMER_HANDLE `: Override variable name of heartbeat timer handle (default: heartbeatHandle) +* `#define STA_RTOS_WATCHDOG_TIMER_CALLBACK `: Override name of heartbeat timer callback function (default: heartbeatCallback) +* `#define STA_RTOS_WATCHDOG_HANDLE `: Override variable name of watchdog task handle (default: watchdogHandle) +* `#define STA_RTOS_WATCHDOG_ENTRY_FUNCTION `: Override name of watchdog task entry function (default: watchdogTask) Requirements: * 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 `` can be implemented. Configuration: -* `#define STA_RTOS2_STARTUP_ENABLE`: Enable module -* `#define STA_RTOS2_STARTUP_ENTRY_FUNCTION `: Override name of startup task entry function (default: startupTask) +* `#define STA_RTOS_STARTUP_ENABLE`: Enable module +* `#define STA_RTOS_STARTUP_ENTRY_FUNCTION `: Override name of startup task entry function (default: startupTask) Requirements: * Uses the `System Event` module @@ -69,6 +69,6 @@ Requirements: Simplify configuration of modules. Intended for use in ``. Configuration: -* `#define STA_RTOS2_SYSTEM_TASKS_ENABLE`: Enable all modules required for system tasks -* `#define STA_RTOS2_WATCHDOG_TIMER_NAME `: Override handle and callback name for watchdog timer -* `#define STA_RTOS2_WATCHDOG_NAME `: Override handle and entry function name for watchdog task +* `#define STA_RTOS_SYSTEM_TASKS_ENABLE`: Enable all modules required for system tasks +* `#define STA_RTOS_WATCHDOG_TIMER_NAME `: Override handle and callback name for watchdog timer +* `#define STA_RTOS_WATCHDOG_NAME `: Override handle and entry function name for watchdog task diff --git a/include/sta/rtos/defs.hpp b/include/sta/rtos/defs.hpp new file mode 100644 index 0000000..a0a8f4f --- /dev/null +++ b/include/sta/rtos/defs.hpp @@ -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 diff --git a/include/sta/rtos/easy_config.hpp b/include/sta/rtos/easy_config.hpp new file mode 100644 index 0000000..6459e6f --- /dev/null +++ b/include/sta/rtos/easy_config.hpp @@ -0,0 +1,85 @@ +/** + * @file + * @brief Helper for easy system task setup in ``. + */ +#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 header of your application. + */ + + +#ifdef DOXYGEN +/** + * @brief Don't warn about use of outside of . + * + * @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 " +#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 diff --git a/include/sta/rtos2/mutex.hpp b/include/sta/rtos/mutex.hpp similarity index 63% rename from include/sta/rtos2/mutex.hpp rename to include/sta/rtos/mutex.hpp index 564e65d..211a0b8 100644 --- a/include/sta/rtos2/mutex.hpp +++ b/include/sta/rtos/mutex.hpp @@ -1,9 +1,9 @@ /** * @file - * @brief CMSIS RTOS2 mutex implementation. + * @brief RTOS mutex implementation. */ -#ifndef STA_RTOS2_MUTEX_HPP -#define STA_RTOS2_MUTEX_HPP +#ifndef STA_RTOS_MUTEX_HPP +#define STA_RTOS_MUTEX_HPP #include @@ -15,15 +15,15 @@ namespace sta /** * @brief Implementation of Mutex interface using CMSIS RTOS2. * - * @ingroup rtos2API + * @ingroup STA_RTOS_API */ - class Rtos2Mutex : public Mutex + class RTOSMutex : public Mutex { public: /** * @param handle CMSIS RTOS2 mutex */ - Rtos2Mutex(osMutexId_t * handle); + RTOSMutex(osMutexId_t * handle); void acquire() override; void release() override; @@ -34,4 +34,4 @@ namespace sta } // namespace sta -#endif // STA_OS2_MUTEX_HPP +#endif // STA_RTOS_MUTEX_HPP diff --git a/include/sta/rtos2/queue.hpp b/include/sta/rtos/queue.hpp similarity index 81% rename from include/sta/rtos2/queue.hpp rename to include/sta/rtos/queue.hpp index eb745b2..933f998 100644 --- a/include/sta/rtos2/queue.hpp +++ b/include/sta/rtos/queue.hpp @@ -1,9 +1,9 @@ /** * @file - * @brief CMSIS RTOS2 queue implementation. + * @brief RTOS queue implementation. */ -#ifndef STA_RTOS2_QUEUE_HPP -#define STA_RTOS2_QUEUE_HPP +#ifndef STA_RTOS_QUEUE_HPP +#define STA_RTOS_QUEUE_HPP #include @@ -17,10 +17,10 @@ namespace sta * * @tparam Message type * - * @ingroup rtos2API + * @ingroup STA_RTOS_API */ template - class Rtos2Queue + class RTOSQueue { public: using Message = T; /**< Queue message type */ @@ -29,7 +29,7 @@ namespace sta /** * @param handle CMSIS RTOS2 queue handle */ - Rtos2Queue(osMessageQueueId_t * handle); + RTOSQueue(osMessageQueueId_t * handle); /** * @brief Place message in queue. @@ -61,7 +61,7 @@ namespace sta } // namespace sta -#include +#include -#endif // STA_RTOS2_QUEUE_HPP +#endif // STA_RTOS_QUEUE_HPP diff --git a/include/sta/rtos/queue.tpp b/include/sta/rtos/queue.tpp new file mode 100644 index 0000000..b5bfb10 --- /dev/null +++ b/include/sta/rtos/queue.tpp @@ -0,0 +1,41 @@ +#ifndef STA_RTOS_QUEUE_TPP +#define STA_RTOS_QUEUE_TPP + +#ifndef STA_RTOS_QUEUE_HPP +# error "Internal header. Use instead." +#endif // !STA_RTOS_QUEUE_HPP + +#include + + +namespace sta +{ + template + RTOSQueue::RTOSQueue(osMessageQueueId_t * handle) + : handle_{handle} + { + STA_ASSERT(handle != nullptr); + } + + template + bool RTOSQueue::put(const Message & msg, uint32_t timeout /* = osWaitForever */) + { + return (osOK == osMessageQueuePut(*handle_, &msg, 0, timeout)); + } + + template + bool RTOSQueue::get(Message * outMsg, uint32_t timeout /* = osWaitForever */) + { + uint8_t prio; + return (osOK == osMessageQueueGet(*handle_, outMsg, &prio, timeout)); + } + + template + uint32 RTOSQueue::available() const + { + return osMessageQueueGetCount(*handle_); + } +} // namespace sta + + +#endif // STA_RTOS_QUEUE_TPP diff --git a/include/sta/rtos2/signal.hpp b/include/sta/rtos/signal.hpp similarity index 65% rename from include/sta/rtos2/signal.hpp rename to include/sta/rtos/signal.hpp index 69539ab..059d87f 100644 --- a/include/sta/rtos2/signal.hpp +++ b/include/sta/rtos/signal.hpp @@ -1,9 +1,9 @@ /** * @file - * @brief CMSIS RTOS2 signal implementation. + * @brief RTOS signal implementation. */ -#ifndef STA_RTOS2_SIGNAL_HPP -#define STA_RTOS2_SIGNAL_HPP +#ifndef STA_RTOS_SIGNAL_HPP +#define STA_RTOS_SIGNAL_HPP #include @@ -15,15 +15,15 @@ namespace sta /** * @brief Implementation of Signal interface using CMSIS RTOS2. * - * @ingroup rtos2API + * @ingroup STA_RTOS_API */ - class Rtos2Signal : public Signal + class RTOSSignal : public Signal { public: /** * @param semaphore CMSIS RTOS2 semaphore */ - Rtos2Signal(osSemaphoreId_t * semaphore); + RTOSSignal(osSemaphoreId_t * semaphore); void notify() override; bool peek() override; @@ -36,4 +36,4 @@ namespace sta } // namespace sta -#endif // STA_RTOS2_SIGNAL_HPP +#endif // STA_RTOS_SIGNAL_HPP diff --git a/include/sta/rtos/startup.hpp b/include/sta/rtos/startup.hpp new file mode 100644 index 0000000..1b69045 --- /dev/null +++ b/include/sta/rtos/startup.hpp @@ -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 +#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 diff --git a/include/sta/rtos2/system_event.hpp b/include/sta/rtos/system_event.hpp similarity index 61% rename from include/sta/rtos2/system_event.hpp rename to include/sta/rtos/system_event.hpp index f2f4c30..a51367f 100644 --- a/include/sta/rtos2/system_event.hpp +++ b/include/sta/rtos/system_event.hpp @@ -2,39 +2,39 @@ * @file * @brief Implementation of system events. */ -#ifndef STA_OS2_SYSTEM_EVENT_HPP -#define STA_OS2_SYSTEM_EVENT_HPP +#ifndef STA_RTOS_SYSTEM_EVENT_HPP +#define STA_RTOS_SYSTEM_EVENT_HPP /** - * @defgroup rtos2SysEvent System Events - * @ingroup rtos2API + * @defgroup STA_RTOS_SysEvent System Events + * @ingroup STA_RTOS_API * @brief System events. * - * Check @ref rtos2BuildConfig for configuration options. + * Check @ref STA_RTOS_BuildConfig for configuration options. */ #ifdef DOXYGEN /** * @brief Enable module. * - * @ingroup rtos2BuildConfig + * @ingroup STA_RTOS_BuildConfig */ # define STA_RTOS2_SYSTEM_EVENT_ENABLE #endif // DOXYGEN /** - * @def STA_RTOS2_SYSTEM_EVENT_HANDLE + * @def STA_RTOS_SYSTEM_EVENT_HANDLE * @brief Set variable name of event flags handle. * - * @ingroup rtos2BuildConfig + * @ingroup STA_RTOS_BuildConfig */ -#ifndef STA_RTOS2_SYSTEM_EVENT_HANDLE -# define STA_RTOS2_SYSTEM_EVENT_HANDLE systemEventHandle -#endif // !STA_RTOS2_SYSTEM_EVENT_HANDLE +#ifndef STA_RTOS_SYSTEM_EVENT_HANDLE +# define STA_RTOS_SYSTEM_EVENT_HANDLE systemEventHandle +#endif // !STA_RTOS_SYSTEM_EVENT_HANDLE #include -#ifdef STA_RTOS2_SYSTEM_EVENT_ENABLE +#ifdef STA_RTOS_SYSTEM_EVENT_ENABLE #include @@ -45,7 +45,7 @@ /** * @brief Startup system event flag. * - * @ingroup rtos2SysEvent + * @ingroup STA_RTOS_SysEvent */ #define STA_SYSTEM_EVENT_STARTUP 0x100000U @@ -57,7 +57,7 @@ namespace sta * * @param flags System event flags * - * @ingroup rtos2SysEvent + * @ingroup STA_RTOS_SysEvent */ void signalSystemEvents(uint32_t flags); @@ -68,7 +68,7 @@ namespace sta * @param options osFlagsWaitAll or osFlagsWaitAny (osFlagsNoClear always set) * @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); @@ -76,7 +76,7 @@ namespace sta /** * @brief Signal startup system event. * - * @ingroup rtos2SysEvent + * @ingroup STA_RTOS_SysEvent */ void signalStartupEvent(); @@ -85,12 +85,12 @@ namespace sta * * Blocking while waiting * - * @ingroup rtos2SysEvent + * @ingroup STA_RTOS_SysEvent */ void waitForStartupEvent(); } // 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 diff --git a/include/sta/rtos/watchdog.hpp b/include/sta/rtos/watchdog.hpp new file mode 100644 index 0000000..8164cb7 --- /dev/null +++ b/include/sta/rtos/watchdog.hpp @@ -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 +#ifdef STA_RTOS_WATCHDOG_ENABLE + +#include + + +// 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 diff --git a/include/sta/rtos2/defs.hpp b/include/sta/rtos2/defs.hpp deleted file mode 100644 index 0fd9fb7..0000000 --- a/include/sta/rtos2/defs.hpp +++ /dev/null @@ -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 diff --git a/include/sta/rtos2/easy_config.hpp b/include/sta/rtos2/easy_config.hpp deleted file mode 100644 index 3506e91..0000000 --- a/include/sta/rtos2/easy_config.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @file - * @brief Helper for easy system task setup in ``. - */ -#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 header of your application. - */ - - -#ifdef DOXYGEN -/** - * @brief Don't warn about use of outside of . - * - * @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 " -#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 diff --git a/include/sta/rtos2/queue.tpp b/include/sta/rtos2/queue.tpp deleted file mode 100644 index 0e68204..0000000 --- a/include/sta/rtos2/queue.tpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef STA_RTOS2_QUEUE_TPP -#define STA_RTOS2_QUEUE_TPP - -#ifndef STA_RTOS2_QUEUE_HPP -# error "Internal header. Use instead." -#endif // !STA_RTOS2_QUEUE_HPP - -#include - - -namespace sta -{ - template - Rtos2Queue::Rtos2Queue(osMessageQueueId_t * handle) - : handle_{handle} - { - STA_ASSERT(handle != nullptr); - } - - template - bool Rtos2Queue::put(const Message & msg, uint32_t timeout /* = osWaitForever */) - { - return (osOK == osMessageQueuePut(*handle_, &msg, 0, timeout)); - } - - template - bool Rtos2Queue::get(Message * outMsg, uint32_t timeout /* = osWaitForever */) - { - uint8_t prio; - return (osOK == osMessageQueueGet(*handle_, outMsg, &prio, timeout)); - } - - template - uint32 Rtos2Queue::available() const - { - return osMessageQueueGetCount(*handle_); - } -} // namespace sta - - -#endif // STA_RTOS2_QUEUE_TPP diff --git a/include/sta/rtos2/startup.hpp b/include/sta/rtos2/startup.hpp deleted file mode 100644 index 9047044..0000000 --- a/include/sta/rtos2/startup.hpp +++ /dev/null @@ -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 -#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 diff --git a/include/sta/rtos2/watchdog.hpp b/include/sta/rtos2/watchdog.hpp deleted file mode 100644 index 07abfc2..0000000 --- a/include/sta/rtos2/watchdog.hpp +++ /dev/null @@ -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 -#ifdef STA_RTOS2_WATCHDOG_ENABLE - -#include - - -// 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 diff --git a/library.json b/library.json index c426181..237dfc9 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "owner" : "sta", - "name": "rtos2", + "name": "sta-rtos", "version": "0.1.0", "dependencies": [ { diff --git a/src/rtos2/mutex.cpp b/src/rtos/mutex.cpp similarity index 52% rename from src/rtos2/mutex.cpp rename to src/rtos/mutex.cpp index 9a5cd0c..c0a426c 100644 --- a/src/rtos2/mutex.cpp +++ b/src/rtos/mutex.cpp @@ -1,18 +1,18 @@ -#include +#include namespace sta { - Rtos2Mutex::Rtos2Mutex(osMutexId_t * handle) + RTOSMutex::RTOSMutex(osMutexId_t * handle) : handle_{handle} {} - void Rtos2Mutex::acquire() + void RTOSMutex::acquire() { osMutexAcquire(*handle_, osWaitForever); } - void Rtos2Mutex::release() + void RTOSMutex::release() { osMutexRelease(*handle_); } diff --git a/src/rtos2/signal.cpp b/src/rtos/signal.cpp similarity index 59% rename from src/rtos2/signal.cpp rename to src/rtos/signal.cpp index 106ee76..170ef57 100644 --- a/src/rtos2/signal.cpp +++ b/src/rtos/signal.cpp @@ -1,28 +1,28 @@ -#include +#include namespace sta { - Rtos2Signal::Rtos2Signal(osSemaphoreId_t * semaphore) + RTOSSignal::RTOSSignal(osSemaphoreId_t * semaphore) : semaphore_{semaphore} {} - void Rtos2Signal::notify() + void RTOSSignal::notify() { osSemaphoreRelease(*semaphore_); } - bool Rtos2Signal::peek() + bool RTOSSignal::peek() { return (osSemaphoreGetCount(*semaphore_) != 0); } - bool Rtos2Signal::test() + bool RTOSSignal::test() { return (osSemaphoreAcquire(*semaphore_, 0) == osOK); } - void Rtos2Signal::wait() + void RTOSSignal::wait() { osSemaphoreAcquire(*semaphore_, osWaitForever); } diff --git a/src/rtos2/startup.cpp b/src/rtos/startup.cpp similarity index 63% rename from src/rtos2/startup.cpp rename to src/rtos/startup.cpp index 0922c15..b37b236 100644 --- a/src/rtos2/startup.cpp +++ b/src/rtos/startup.cpp @@ -1,9 +1,9 @@ -#include -#ifdef STA_RTOS2_STARTUP_ENABLE +#include +#ifdef STA_RTOS_STARTUP_ENABLE #include -#include -#include +#include +#include #include #include @@ -21,7 +21,7 @@ namespace sta // Declare with C linkage extern "C" { - void STA_RTOS2_STARTUP_ENTRY_FUNCTION(void * arg) + void STA_RTOS_STARTUP_ENTRY_FUNCTION(void * arg) { // Call further initialization code sta::startupExtras(arg); @@ -29,10 +29,10 @@ extern "C" // Initialize HAL sta::initHAL(); -#ifdef STA_RTOS2_WATCHDOG_ENABLE +#ifdef STA_RTOS_WATCHDOG_ENABLE // Start timers sta::startWatchdogTimer(); -#endif // STA_RTOS2_WATCHDOG_ENABLE +#endif // STA_RTOS_WATCHDOG_ENABLE // Wake tasks sta::signalStartupEvent(); @@ -43,4 +43,4 @@ extern "C" } -#endif // STA_RTOS2_STARTUP_ENABLE +#endif // STA_RTOS_STARTUP_ENABLE diff --git a/src/rtos2/system_event.cpp b/src/rtos/system_event.cpp similarity index 57% rename from src/rtos2/system_event.cpp rename to src/rtos/system_event.cpp index 51fd515..22da936 100644 --- a/src/rtos2/system_event.cpp +++ b/src/rtos/system_event.cpp @@ -1,24 +1,24 @@ -#include +#include -#ifdef STA_RTOS2_SYSTEM_EVENT_ENABLE +#ifdef STA_RTOS_SYSTEM_EVENT_ENABLE #include // Access handle from freertos.c -extern osEventFlagsId_t STA_RTOS2_SYSTEM_EVENT_HANDLE; +extern osEventFlagsId_t STA_RTOS_SYSTEM_EVENT_HANDLE; namespace sta { 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) { - 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 -#endif // STA_RTOS2_SYSTEM_EVENT_ENABLE +#endif // STA_RTOS_SYSTEM_EVENT_ENABLE diff --git a/src/rtos2/watchdog/heartbeat.cpp b/src/rtos/watchdog/heartbeat.cpp similarity index 55% rename from src/rtos2/watchdog/heartbeat.cpp rename to src/rtos/watchdog/heartbeat.cpp index 11a54c2..75a05a2 100644 --- a/src/rtos2/watchdog/heartbeat.cpp +++ b/src/rtos/watchdog/heartbeat.cpp @@ -1,19 +1,19 @@ -#include +#include -#ifdef STA_RTOS2_WATCHDOG_ENABLE +#ifdef STA_RTOS_WATCHDOG_ENABLE #include // Access handles from freertos.c -extern osTimerId_t STA_RTOS2_WATCHDOG_TIMER_HANDLE; +extern osTimerId_t STA_RTOS_WATCHDOG_TIMER_HANDLE; namespace sta { 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 @@ -21,7 +21,7 @@ namespace sta // Declare with C linkage extern "C" { - void STA_RTOS2_WATCHDOG_TIMER_CALLBACK(void *) + void STA_RTOS_WATCHDOG_TIMER_CALLBACK(void *) { // Notify watchdog task to send heartbeat message // 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 diff --git a/src/rtos/watchdog/watchdog.cpp b/src/rtos/watchdog/watchdog.cpp new file mode 100644 index 0000000..28e59e2 --- /dev/null +++ b/src/rtos/watchdog/watchdog.cpp @@ -0,0 +1,45 @@ +#include + +#ifdef STA_RTOS_WATCHDOG_ENABLE + +#include +#include + +#include + +#include + + +// 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 diff --git a/src/rtos2/watchdog/watchdog.cpp b/src/rtos2/watchdog/watchdog.cpp deleted file mode 100644 index 3a3ddf7..0000000 --- a/src/rtos2/watchdog/watchdog.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include - -#ifdef STA_RTOS2_WATCHDOG_ENABLE - -#include -#include - -#include - -#include - - -// 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