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.
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