HALFRED  0.4.0
Data Structures | Macros | Typedefs | Functions
hal_bp.h File Reference

Buffer pool API. More...

Detailed Description

Buffer pool API.

HAL buffer memory pool.

Purpose
HALFRED Hardware Abstraction Layer
Version
Revision
1577
License
$License$
#include "hal_core.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  BP_PartialBuf_Tag
 

Macros

#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()
 

Typedefs

typedef struct BP_BufferPool_Tag * BP_BufferPool
 
typedef struct BP_PartialBuf_Tag BP_PartialBuf_T
 
typedef BP_PartialBuf_TBP_PartialBuffer
 

Functions

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)
 

Function Documentation

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_buffersthe number of buffers associated with given buffer pool object
buffer_sizethe size of a single buffer
Returns
when allocation is not possible then it is NULL, otherwise it is pointer to created buffer pool
BP_PartialBuffer BP_GetBuffer ( BP_BufferPool  bp,
uint32_t  buf_len 
)

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
bpthe BP_BufferPool object
buf_lenthe size of requested memory
Returns
when allocation is not possible then it is NULL, otherwise it is pointer to partial buffer
void BP_ReleaseBuffer ( BP_PartialBuffer  buf)

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
bufthe 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
srcthe partial buffer object returned by the BP_GetBuffer function
dstthe pointer to the memory area
src_offsetthe starting offset (in bytes) in the source (buffer pool memory)
data_lenthe 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
dsta partial buffer object returned by the BP_GetBuffer function
srca pointer to the memory area
dst_offseta starting offset (in bytes) in the destination (buffer pool memory)
data_lena 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
bufa pointer to the partial buffer object, it has to be already allocated (e.g. as a local variable)
mem_areaa pointer to the (already allocated) memory area
mem_sizea size of the memory area