mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 01:55:59 +00:00
76 lines
1.5 KiB
C++
76 lines
1.5 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>
|
|
|
|
/**
|
|
* @defgroup STA_RTOS_SHAREDMEM SharedMem
|
|
* @ingroup STA_RTOS_API
|
|
* @brief RTOS Shared Memory.
|
|
*/
|
|
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @brief Interface object for using CMSIS RTOS2 MemPool for one variable.
|
|
*
|
|
* @tparam Message type
|
|
*
|
|
* @ingroup STA_RTOS_SHAREDMEM
|
|
*/
|
|
template <typename T>
|
|
class RtosSharedMem
|
|
{
|
|
public:
|
|
using Message = T; /**< message type */
|
|
|
|
public:
|
|
// Default Constructor
|
|
RtosSharedMem();
|
|
|
|
/**
|
|
* @brief Create a memory pool. And allocates exavlty one block.
|
|
*
|
|
* @param timeout names the timeout in milliseconds.
|
|
*/
|
|
RtosSharedMem(uint32_t timeout);
|
|
|
|
/**
|
|
* @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
|