rtos2-utils/include/sta/rtos/sharedmem.hpp
2024-06-22 15:13:31 +02:00

66 lines
1.3 KiB
C++

/**
* @file
* @brief RTOS MemPool implementation for one variable.
*/
#ifndef STA_RTOS_SHAREDMEM_HPP
#define STA_RTOS_SHAREDMEM_HPP
#include <cmsis_os2.h>
#include <cstdint>
namespace sta
{
/**
* @brief Interface object for using CMSIS RTOS2 MemPool for one variable.
*
* @tparam Message type
*
* @ingroup STA_RTOS_IPC
*/
template <typename T>
class RtosSharedMem
{
public:
using Message = T; /**< message type */
public:
/**
* @brief Create a memory pool. And allocates exavlty one block.
*
* @param timeout names the timeout in milliseconds.
*/
RtosSharedMem(uint32_t timeout = osWaitForever);
/**
* @brief Destroy the Rtos Mem Pool object and frees the memory.
*
*/
~RtosSharedMem();
/**
* @brief Allocate a new Memory Block.
*
* @param _message names the message to write.
*/
void write(T _message);
/**
* @brief Gets the value of the shared memory.
*
* @return T Value of the shared memory.
*/
T read();
private:
osMemoryPoolId_t handle_; /**< CMSIS RTOS2 queue handle */
T * shared_mem_; /**< Pointer to the shared memory */
};
} // namespace sta
#include <sta/rtos/sharedmem.tpp>
#endif // STA_RTOS_SHAREDMEM_HPP