SharedMemFixes

This commit is contained in:
CarlWachter 2023-09-23 11:31:59 +02:00
parent 6f64a06164
commit 3e28326798
2 changed files with 9 additions and 10 deletions

View File

@ -20,7 +20,7 @@ namespace sta
* @ingroup STA_RTOS_API * @ingroup STA_RTOS_API
*/ */
template <typename T> template <typename T>
class RtosMemPool class RtosSharedMem
{ {
public: public:
using Message = T; /**< message type */ using Message = T; /**< message type */
@ -32,10 +32,9 @@ namespace sta
/** /**
* @brief Create a memory pool. And allocates exavlty one block. * @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. * @param timeout names the timeout in milliseconds.
*/ */
RtosSharedMem(uint32_t block_size, uint32_t timeout); RtosSharedMem(uint32_t timeout);
/** /**
* @brief Destroy the Rtos Mem Pool object and frees the memory. * @brief Destroy the Rtos Mem Pool object and frees the memory.

View File

@ -11,35 +11,35 @@
namespace sta namespace sta
{ {
template <typename T> template <typename T>
RtosMemPool<T>::RtosMemPool() RtosSharedMem<T>::RtosSharedMem()
{ {
} }
template <typename T> template <typename T>
RtosMemPool<T>::RtosMemPool(uint32_t block_size, uint32_t timeout /* = osWaitForever */) RtosSharedMem<T>::RtosSharedMem(uint32_t timeout /* = osWaitForever */)
{ {
handle_ = osMemoryPoolNew(block_size, block_count, NULL); handle_ = osMemoryPoolNew(sizeof(T), 1, NULL);
STA_ASSERT_MSG(handle_ != nullptr, "Failed to Create RtosMemPool for sharedmem"); STA_ASSERT_MSG(handle_ != nullptr, "Failed to Create RtosMemPool for sharedmem");
shared_mem_ = osMemoryPoolAlloc(handle_, timeout) shared_mem_ = (T*) osMemoryPoolAlloc(handle_, timeout);
STA_ASSERT_MSG(shared_mem_ != nullptr, "Failed to Alloc RtosMemPool Block"); STA_ASSERT_MSG(shared_mem_ != nullptr, "Failed to Alloc RtosMemPool Block");
} }
template <typename T> template <typename T>
RtosMemPool<T>::~RtosSharedMem() RtosSharedMem<T>::~RtosSharedMem()
{ {
osMemoryPoolFree(handle_, shared_mem_); osMemoryPoolFree(handle_, shared_mem_);
osMemoryPoolDelete(handle_); osMemoryPoolDelete(handle_);
} }
template <typename T> template <typename T>
void RtosMemPool<T>::write(T _message) void RtosSharedMem<T>::write(T _message)
{ {
*shared_mem_ = _message; *shared_mem_ = _message;
} }
template <typename T> template <typename T>
T RtosMemPool<T>::read(void * block) T RtosSharedMem<T>::read()
{ {
return *shared_mem_; return *shared_mem_;
} }