Mem_SegAllocHW()

Allocates memory from specified segment for a "hardware buffer" (a buffer that can be accessed via a DMA engine). The returned buffer will be padded in function of memory segment's properties.

Files

lib_mem.h/lib_mem.c

Prototype

void  *Mem_SegAllocHW (const  CPU_CHAR    *p_name,
                              MEM_SEG     *p_seg,
                              CPU_SIZE_T   size,
                              CPU_SIZE_T   align,
                              CPU_SIZE_T  *p_bytes_reqd,
                              LIB_ERR     *p_err)

Arguments

p_name

Pointer to allocated object name. Used for allocations tracking. May be DEF_NULL.

p_seg

Pointer to segment from which to allocate memory.

size

Size of memory block to allocate, in bytes.

align

Required alignment of memory block, in bytes. MUST be a power of 2.

p_bytes_reqd

Pointer to variable that will receive the number of free bytes missing for the allocation to succeed. Set to DEF_NULL to skip calculation.

p_err

Pointer to variable that will receive the return error code from this function.

LIB_MEM_ERR_NONE

LIB_MEM_ERR_INVALID_MEM_SIZE

LIB_MEM_ERR_INVALID_MEM_ALIGN

LIB_MEM_ERR_NULL_PTR

LIB_MEM_ERR_SEG_OVF

Returned Value

Pointer to allocated memory block, if successful.

DEF_NULL, otherwise.

Required Configuration

None.

Notes / Warnings

  1. The buffer returned by this function will be padded according to the padding_align argument passed at creation of this memory segment. This is particularly useful with systems that use cache memory and DMA engine to copy buffers as it guarantees that nothing else will be allocated on the same cache line (as long as the padding_align argument is set to the length of a cache line).
  2. For an usage example of this function, refer to Memory Segments page.

Related pages