28 #include "cmsis_os2.h" 29 #include "mbed_rtos1_types.h" 30 #include "mbed_rtos_storage.h" 31 #include "platform/NonCopyable.h" 49 template<
typename T, u
int32_t pool_sz>
51 MBED_STATIC_ASSERT(pool_sz > 0,
"Invalid memory pool size. Must be greater than 0.");
59 memset(_pool_mem, 0,
sizeof(_pool_mem));
60 osMemoryPoolAttr_t attr = { 0 };
61 attr.mp_mem = _pool_mem;
62 attr.mp_size =
sizeof(_pool_mem);
63 attr.cb_mem = &_obj_mem;
64 attr.cb_size =
sizeof(_obj_mem);
65 _id = osMemoryPoolNew(pool_sz,
sizeof(T), &attr);
75 osMemoryPoolDelete(_id);
85 return (T *)osMemoryPoolAlloc(_id, 0);
96 return (T *)osMemoryPoolAlloc(_id, millisec);
113 if (now >= millisec) {
115 }
else if (millisec - now >= osWaitForever) {
116 delay = osWaitForever - 1;
118 delay = millisec - now;
132 memset(item, 0,
sizeof(T));
147 memset(item, 0,
sizeof(T));
166 memset(item, 0,
sizeof(T));
181 return osMemoryPoolFree(_id, block);
185 osMemoryPoolId_t _id;
186 char _pool_mem[MBED_RTOS_STORAGE_MEM_POOL_MEM_SIZE(pool_sz,
sizeof(T))];
187 mbed_rtos_storage_mem_pool_t _obj_mem;
~MemoryPool()
Destroy a memory pool.
Define and manage fixed-size memory pools of objects of a given type.
T * calloc_until(uint64_t millisec)
Allocate a memory block from a memory pool, blocking, and set memory block to zero.
T * alloc_until(uint64_t millisec)
Allocate a memory block from a memory pool, blocking.
T * alloc_for(uint32_t millisec)
Allocate a memory block from a memory pool, optionally blocking.
Prevents generation of copy constructor and copy assignment operator in derived classes.
osStatus free(T *block)
Free a memory block.
T * calloc(void)
Allocate a memory block from a memory pool, without blocking, and set memory block to zero...
uint64_t get_ms_count()
Read the current RTOS kernel millisecond tick count.
MemoryPool()
Create and Initialize a memory pool.
T * calloc_for(uint32_t millisec)
Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero...
T * alloc(void)
Allocate a memory block from a memory pool, without blocking.