mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 18:15:59 +00:00
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
#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>
|
|
RtosSharedMem<T>::RtosSharedMem(uint32_t timeout /* = osWaitForever */)
|
|
{
|
|
handle_ = osMemoryPoolNew(sizeof(T), 1, NULL);
|
|
STA_ASSERT_MSG(handle_ != nullptr, "Failed to Create RtosMemPool for sharedmem");
|
|
|
|
shared_mem_ = (T*) osMemoryPoolAlloc(handle_, timeout);
|
|
STA_ASSERT_MSG(shared_mem_ != nullptr, "Failed to Alloc RtosMemPool Block");
|
|
}
|
|
|
|
template <typename T>
|
|
RtosSharedMem<T>::~RtosSharedMem()
|
|
{
|
|
osMemoryPoolFree(handle_, shared_mem_);
|
|
osMemoryPoolDelete(handle_);
|
|
}
|
|
|
|
template <typename T>
|
|
void RtosSharedMem<T>::write(T _message)
|
|
{
|
|
*shared_mem_ = _message;
|
|
}
|
|
|
|
template <typename T>
|
|
T RtosSharedMem<T>::read()
|
|
{
|
|
return *shared_mem_;
|
|
}
|
|
} // namespace sta
|
|
|
|
|
|
#endif // STA_RTOS_SHAREDMEM_TPP
|