diff --git a/include/sta/rtos/queue.hpp b/include/sta/rtos/queue.hpp index f731c91..3fb127e 100644 --- a/include/sta/rtos/queue.hpp +++ b/include/sta/rtos/queue.hpp @@ -34,6 +34,11 @@ namespace sta */ RtosQueue(osMessageQueueId_t handle); + /** + * @param length The maximum number of elements to be stored in the queue. + */ + RtosQueue(uint32_t length); + /** * @brief Place message in queue. * diff --git a/include/sta/rtos/queue.tpp b/include/sta/rtos/queue.tpp index 0ca5676..a92767c 100644 --- a/include/sta/rtos/queue.tpp +++ b/include/sta/rtos/queue.tpp @@ -21,6 +21,13 @@ namespace sta { STA_ASSERT(handle != nullptr); } + + template + RtosQueue::RtosQueue(uint32_t length) + : handle_{osMessageQueueNew(length, sizeof(Message), NULL)} + { + STA_ASSERT(handle_ != NULL); + } template bool RtosQueue::put(const Message & msg, uint32_t timeout /* = osWaitForever */) diff --git a/include/sta/rtos/thread.hpp b/include/sta/rtos/thread.hpp index 5490026..5d6c849 100644 --- a/include/sta/rtos/thread.hpp +++ b/include/sta/rtos/thread.hpp @@ -98,6 +98,13 @@ namespace sta */ uint32_t wait(uint32_t flags); + /** + * @brief Clears the thread flags set for this thread. + * + * @return Returns the thread flags that set before clearing. + */ + uint32_t clear(uint32_t flags); + /** * @brief Send termination request to thread. */ diff --git a/src/thread.cpp b/src/thread.cpp index a4b95a1..7e88251 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -41,6 +41,15 @@ namespace sta return osThreadFlagsWait(flags, osFlagsWaitAny, osWaitForever); } + uint32_t RtosThread::clear(uint32_t flags) + { + uint32_t setFlags = osThreadFlagsClear(flags); + + STA_ASSERT(setFlags != (uint32_t)osError); + + return setFlags; + } + uint32_t RtosThread::getFlags() { STA_ASSERT(handle_.get() != nullptr);