mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 01:55:59 +00:00
54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
#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/debug/assert.hpp>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
template <typename T>
|
|
RtosQueue<T>::RtosQueue()
|
|
{
|
|
}
|
|
|
|
template <typename T>
|
|
RtosQueue<T>::RtosQueue(osMessageQueueId_t handle)
|
|
: handle_{handle}
|
|
{
|
|
STA_ASSERT(handle != NULL);
|
|
}
|
|
|
|
template <typename T>
|
|
RtosQueue<T>::RtosQueue(uint32_t length)
|
|
: handle_{osMessageQueueNew(length, sizeof(T), NULL)}
|
|
{
|
|
STA_ASSERT(handle_ != NULL);
|
|
}
|
|
|
|
template <typename T>
|
|
bool RtosQueue<T>::put(const T msg, uint32_t timeout /* = osWaitForever */)
|
|
{
|
|
return (osOK == osMessageQueuePut(handle_, &msg, 0, timeout));
|
|
}
|
|
|
|
template <typename T>
|
|
bool RtosQueue<T>::get(T * outMsg, uint32_t timeout /* = osWaitForever */)
|
|
{
|
|
uint8_t prio;
|
|
return (osOK == osMessageQueueGet(handle_, outMsg, &prio, timeout));
|
|
}
|
|
|
|
template <typename T>
|
|
uint32_t RtosQueue<T>::available() const
|
|
{
|
|
return osMessageQueueGetCount(handle_);
|
|
}
|
|
} // namespace sta
|
|
|
|
|
|
#endif // STA_RTOS_QUEUE_TPP
|