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:
49
include/sta/rtos/sharedmem.tpp
Normal file
49
include/sta/rtos/sharedmem.tpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef STA_RTOS_SHAREDMEM_TPP
|
||||
#define STA_RTOS_SHAREDMEM_TPP
|
||||
|
||||
#ifndef STA_RTOS_SHAREDMEM_HPP
|
||||
# error "Internal header. Use <sta/rtos/sharedmem.hpp> instead."
|
||||
#endif // !STA_RTOS_MEMPOOL_HPP
|
||||
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
template <typename T>
|
||||
RtosMemPool<T>::RtosMemPool()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
RtosMemPool<T>::RtosMemPool(uint32_t block_size, uint32_t timeout /* = osWaitForever */)
|
||||
{
|
||||
handle_ = osMemoryPoolNew(block_size, block_count, NULL);
|
||||
STA_ASSERT_MSG(handle_ != nullptr, "Failed to Create RtosMemPool for sharedmem");
|
||||
|
||||
shared_mem_ = osMemoryPoolAlloc(handle_, timeout)
|
||||
STA_ASSERT_MSG(shared_mem_ != nullptr, "Failed to Alloc RtosMemPool Block");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
RtosMemPool<T>::~RtosSharedMem()
|
||||
{
|
||||
osMemoryPoolFree(handle_, shared_mem_);
|
||||
osMemoryPoolDelete(handle_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void RtosMemPool<T>::write(T _message)
|
||||
{
|
||||
*shared_mem_ = _message;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T RtosMemPool<T>::read(void * block)
|
||||
{
|
||||
return *shared_mem_;
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_RTOS_SHAREDMEM_TPP
|
Reference in New Issue
Block a user