Array-backed-FIFO Buffer Manager

Embedded application typically use statically allocated arrays to manage buffers to avoid the complexity of dynamic memory allocations.

To use this, the module can initialize the manager via rs_array_fifo_buf_mgr_init by specifying the way the status member inside each buffer is to be compared along with the value associated with free and in-use status. Then the memory can be set using the rs_array_fifo_buf_mgr_config by passing the starting address of the buffer array, number of buffers, size of each element and offset of the status member in each element. Once done, free buffer can be obtained via rs_array_fifo_buf_mgr_get and and after use the same can be released using rs_array_fifo_buf_mgr_put call.

Note: Since this is a FIFO, the buffers should be submitted back in the same order, it was obtained from.

Array-FIFO Buffer Manager Header

Documentation from the relevant header as follows:

Definitions for RAPIDSEA Buffer Manager to manage array/linked list based buffers.

Defines

RS_BUFFER_MGR_STATUS_UINT8_COMPARE_FREE

8-bit status value compared with a fixed value to check if free

RS_BUFFER_MGR_STATUS_UINT8_COMPARE_USED

8-bit status value compared with a fixed value to check if it is used

RS_BUFFER_MGR_STATUS_UINT32_COMPARE_FREE

32-bit status value compared with a fixed value to check if free

Typedefs

typedef struct tag_rs_buffer_mgr rs_buffer_mgr_t

To store Buffer information.

Functions

rs_ret_val_t rs_array_fifo_buf_mgr_init(rs_buffer_mgr_t *ptr_mgr, uint8_t u8_status_type, uint32_t u32_free_value, uint32_t u32_used_value)

Initializes the Buffer-Array-backed-FIFO buffer manager.

This function initializes the manager with the given configuration

Parameters:
  • ptr_mgr[in] - Pointer to the Buffer-Array-backed-FIFO buffer manager memory

  • u8_status_type[in] - Type of comparison to be done on status variable to know if it is free or used

  • u32_free_value[in] - Value associated with free status

  • u32_used_value[in] - Value associated with in-use status

Returns:

Zero for success or negative error code

rs_ret_val_t rs_array_fifo_buf_mgr_config(rs_buffer_mgr_t *ptr_mgr, void *ptr_mem, uint32_t u32_num_buffers, uint32_t u32_buffer_size, uint32_t u32_status_offset)

Configures the memory for the Buffer-Array-backed-FIFO buffer manager.

This function sets the array based memory to be used by the manager

Parameters:
  • ptr_mgr[in] - Pointer to the Buffer-Array-backed-FIFO buffer manager memory

  • ptr_mem[in] - Starting address of the memory assigned for the FIFO

  • u32_num_buffers[in] -Number of elements in the array

  • u32_buffer_size[in] - Size of each element in the array in bytes

  • u32_status_offset[in] - Offset to the status variable inside the element in bytes

Returns:

Zero for success or negative error code

void *rs_array_fifo_buf_mgr_get(rs_buffer_mgr_t *ptr_mgr)

Requests free buffer the Buffer-Array-backed-FIFO buffer manager.

This function is used to get a free buffer from the manager

Parameters:

ptr_mgr[in] - Pointer to the Buffer-Array-backed-FIFO buffer manager memory

Returns:

Pointer to buffer on success or NULL if no free buffer found

rs_ret_val_t rs_array_fifo_buf_mgr_put(rs_buffer_mgr_t *ptr_mgr, void *ptr_buf)

Puts back the buffer in the Buffer-Array-backed-FIFO buffer manager.

This function is used to release and submit back the previously allocated buffer memory to the manager

Parameters:
  • ptr_mgr[in] - Pointer to the Buffer-Array-backed-FIFO buffer manager memory

  • ptr_buf[in] - Pointer to the buffer that was allocated via rs_array_fifo_buf_mgr_get and to be released

Returns:

Zero for success or negative error code

struct tag_rs_buffer_mgr
#include <rs_array_fifo_buf_mgr.h>

To store Buffer information.

Public Members

uint8_t buffer_type

Type of buffer allocation.

uint8_t status_type

How to compare the status.

uint8_t reserved1

Reserved.

uint8_t reserved2

Reserved.

uint16_t read_index

Next read position.

uint16_t write_index

Next write position.

uint32_t num_buffers

Number of buffer.

uint32_t buffer_size

Size of each buffer.

uint32_t status_offset

Offset to status information in each buffer.

uint32_t free_value

Value to be used for free state.

uint32_t used_value

Value to be used for used state.

void *ptr_buffer

Pointer to memory region.