Buffer pool API.
More...
Buffer pool API.
HAL buffer memory pool.
- Purpose
- HALFRED Hardware Abstraction Layer
- Version
- Revision
- 1577
- License
- $License$
- Copyright
- $Copyright$
#include "hal_core.h"
#include <stdint.h>
Go to the source code of this file.
|
#define | HAL_BP_MEM_ALIGN 4UL |
|
#define | HAL_BP_MUTEX_DECLARE(name) void* name |
|
#define | HAL_BP_MUTEX_CREATE(name) name = NULL |
|
#define | HAL_BP_MUTEX_LOCK(name) CORE_EnterCritical() |
|
#define | HAL_BP_MUTEX_UNLOCK(name) CORE_ExitCritical() |
|
|
BP_BufferPool | BP_Create (uint32_t no_buffers, uint32_t buffer_size) |
|
BP_PartialBuffer | BP_GetBuffer (BP_BufferPool bp, uint32_t buf_len) |
|
void | BP_ReleaseBuffer (BP_PartialBuffer buf) |
|
uint32_t | BP_CopyToMem (BP_PartialBuffer src, void *dst, uint32_t src_offset, uint32_t data_len) |
|
uint32_t | BP_CopyToBuf (BP_PartialBuffer dst, const void *src, uint32_t dst_offset, uint32_t data_len) |
|
void | BP_InitStandaloneBuf (BP_PartialBuffer buf, void *mem_area, uint32_t mem_size) |
|
BP_BufferPool BP_Create |
( |
uint32_t |
no_buffers, |
|
|
uint32_t |
buffer_size |
|
) |
| |
Creates the BP_BufferPool object. This functions dynamically (using malloc) allocates memory for the buffer pool object and for managed buffers as well.
- Parameters
-
no_buffers | the number of buffers associated with given buffer pool object |
buffer_size | the size of a single buffer |
- Returns
- when allocation is not possible then it is NULL, otherwise it is pointer to created buffer pool
Allocates memory using buffers from the BP_BufferPool object. This functions allocates requested amount of memory using preallocated memory chunks (partial buffers) from the BP_BufferPool object. All further accesses to the allocated memory should be made using API functions from this module. When allocated memory is no longer needed then it should be released using BP_ReleaseBuffer
function.
- Parameters
-
bp | the BP_BufferPool object |
buf_len | the size of requested memory |
- Returns
- when allocation is not possible then it is NULL, otherwise it is pointer to partial buffer
Releases memory allocated previously from the BP_BufferPool object. This functions returns back allocated memory to the parent BP_BufferPool object. After this call buf
object shall not be used anymore.
- Parameters
-
buf | the partial buffer object returned by the BP_GetBuffer function |
uint32_t BP_CopyToMem |
( |
BP_PartialBuffer |
src, |
|
|
void * |
dst, |
|
|
uint32_t |
src_offset, |
|
|
uint32_t |
data_len |
|
) |
| |
Copy data from buffer pool memory to user memory. This functions copies data_len bytes from memory allocated in buffer pool into specified RAM location. The copy operation is performed starting from (supplied as parameter) offset. This allow to use buffer pool memory as it was continuous.
- Parameters
-
src | the partial buffer object returned by the BP_GetBuffer function |
dst | the pointer to the memory area |
src_offset | the starting offset (in bytes) in the source (buffer pool memory) |
data_len | the length (in bytes) of the requested copy operation |
- Returns
- the number of copied bytes
uint32_t BP_CopyToBuf |
( |
BP_PartialBuffer |
dst, |
|
|
const void * |
src, |
|
|
uint32_t |
dst_offset, |
|
|
uint32_t |
data_len |
|
) |
| |
Copy data from user memory to buffer pool memory. This functions copies data_len bytes from RAM location into specified memory allocated in buffer pool. The copy operation is performed starting from (supplied as parameter) offset. This allow to use buffer pool memory as it was continuous.
- Parameters
-
dst | a partial buffer object returned by the BP_GetBuffer function |
src | a pointer to the memory area |
dst_offset | a starting offset (in bytes) in the destination (buffer pool memory) |
data_len | a length (in bytes) of the requested copy operation |
- Returns
- a number of copied bytes
void BP_InitStandaloneBuf |
( |
BP_PartialBuffer |
buf, |
|
|
void * |
mem_area, |
|
|
uint32_t |
mem_size |
|
) |
| |
Initializes the BP_PartialBuffer_T object as a stand-alone object (not associated with buffer pool).
- Parameters
-
buf | a pointer to the partial buffer object, it has to be already allocated (e.g. as a local variable) |
mem_area | a pointer to the (already allocated) memory area |
mem_size | a size of the memory area |