mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-08-06 11:07:34 +00:00
Added SharedMem impl
This commit is contained in:
70
include/sta/rtos/sharedmem.hpp
Normal file
70
include/sta/rtos/sharedmem.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @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_API
|
||||
*/
|
||||
template <typename T>
|
||||
class RtosMemPool
|
||||
{
|
||||
public:
|
||||
using Message = T; /**< message type */
|
||||
|
||||
public:
|
||||
// Default Constructor
|
||||
RtosSharedMem();
|
||||
|
||||
/**
|
||||
* @brief Create a memory pool. And allocates exavlty one block.
|
||||
*
|
||||
* @param block_size names the size of each block.
|
||||
* @param timeout names the timeout in milliseconds.
|
||||
*/
|
||||
RtosSharedMem(uint32_t block_size, 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
|
Reference in New Issue
Block a user