Docs

You are here:
BP module

Introduction.

The BP module offers memory pool functionality with additional feature allowing to treat many buffers as a single memory chunk (with fully linear and continuous access). Because "allocation" and "deallocation" memory from the buffer (memory) pool has known the worst execution time then this kind of pseudo dynamic memory allocation is allowed to use in the real time environment. Additionally to allow consistent usage of buffers (instead of raw pointers to memory) it is added functionality to create a stand-alone buffer wrapping preallocated memory.

Buffers. Allocated buffers have constant (usually small) size but the single "allocation" (the BP_GetBuffer function) can be made up to total size of allocated memory (buffer_size * no_of_buffers). When accessed by the BP_CopyTo functions the buffer returned by the BP_GetBuffer function can treated as a single continuous memory area. The "deallocation" procedure requires only single call to the BP_ReleaseBuffer function.

BP setup.

There is no special setup required for this module. The user should take into account that BP_Create function uses a real dynamic allocation functions and thus it should be avoided when real time tasks are already started. The recommended way of buffer pool creation is to do it before RTOS scheduler is executed.

Using the BP module

uint8_t mem_chunk[512];
BP_BufferPool nv_buf_pool;
nv_buf_pool = BP_Create(8, 256);
buf = BP_GetBuffer(buf_pool, sizeof(mem_chunk));
(void) BP_CopyToBuf(buf, mem_chunk, 0, 300);
(void) BP_CopyToMem(buf, mem_chunk, 128, 256);

The example of stand-alone buffer usage.

Module configuration.

uint8_t mem_chunk[1024];
BP_InitStandaloneBuf(&buf, mem_chunk, sizeof(mem_chunk));
(void) BP_CopyToBuf(&buf, some_mem_ptr, 0, 300);

To enable the NV module, HAL_ENABLE_BP definition must be set to 1, in hal_config.h.

Go to Top