Nordic stack and drivers for the mbed BLE API

Dependents:   idd_hw5_bleFanProto

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hci_mem_pool.h Source File

hci_mem_pool.h

Go to the documentation of this file.
00001 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is property of Nordic Semiconductor ASA.
00004  * Terms and conditions of usage are described in detail in NORDIC
00005  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *
00011  */
00012  
00013 /** @file
00014  *
00015  * @defgroup memory_pool Memory pool
00016  * @{
00017  * @ingroup app_common
00018  *
00019  * @brief Memory pool implementation
00020  *
00021  * Memory pool implementation, based on circular buffer data structure, which supports asynchronous 
00022  * processing of RX data. The current default implementation supports 1 TX buffer and 4 RX buffers.
00023  * The memory managed by the pool is allocated from static storage instead of heap. The internal 
00024  * design of the circular buffer implementing the RX memory layout is illustrated in the picture 
00025  * below. 
00026  *
00027  * @image html memory_pool.png "Circular buffer design"
00028  *
00029  * The expected call order for the RX APIs is as follows:
00030  * - hci_mem_pool_rx_produce
00031  * - hci_mem_pool_rx_data_size_set
00032  * - hci_mem_pool_rx_extract
00033  * - hci_mem_pool_rx_consume
00034  *
00035  * @warning If the above mentioned expected call order is violated the end result can be undefined.
00036  *
00037  * \par Component specific configuration options
00038  *
00039  * The following compile time configuration options are available to suit various implementations:
00040  * - TX_BUF_SIZE TX buffer size in bytes. 
00041  * - RX_BUF_SIZE RX buffer size in bytes. 
00042  * - RX_BUF_QUEUE_SIZE RX buffer element size.
00043  */
00044  
00045 #ifndef HCI_MEM_POOL_H__
00046 #define HCI_MEM_POOL_H__
00047 
00048 #include <stdint.h>
00049 #include "nrf_error.h"
00050 
00051 /**@brief Function for opening the module.
00052  *
00053  * @retval NRF_SUCCESS          Operation success. 
00054  */
00055 uint32_t hci_mem_pool_open(void);
00056 
00057 /**@brief Function for closing the module.
00058  *
00059  * @retval NRF_SUCCESS          Operation success. 
00060  */
00061 uint32_t hci_mem_pool_close(void);
00062 
00063 /**@brief Function for allocating requested amount of TX memory.
00064  *
00065  * @param[out] pp_buffer        Pointer to the allocated memory.
00066  *
00067  * @retval NRF_SUCCESS          Operation success. Memory was allocated.
00068  * @retval NRF_ERROR_NO_MEM     Operation failure. No memory available for allocation.
00069  * @retval NRF_ERROR_NULL       Operation failure. NULL pointer supplied.  
00070  */
00071 uint32_t hci_mem_pool_tx_alloc(void ** pp_buffer);
00072  
00073 /**@brief Function for freeing previously allocated TX memory.
00074  *
00075  * @note Memory management follows the FIFO principle meaning that free() order must match the 
00076  *       alloc(...) order, which is the reason for omitting exact memory block identifier as an 
00077  *       input parameter.
00078  *
00079  * @retval NRF_SUCCESS          Operation success. Memory was freed.
00080  */
00081 uint32_t hci_mem_pool_tx_free(void);
00082  
00083 /**@brief Function for producing a free RX memory block for usage.
00084  *
00085  * @note Upon produce request amount being 0, NRF_SUCCESS is returned.   
00086  *
00087  * @param[in]  length           Amount, in bytes, of free memory to be produced.
00088  * @param[out] pp_buffer        Pointer to the allocated memory.
00089  *
00090  * @retval NRF_SUCCESS          Operation success. Free RX memory block produced.
00091  * @retval NRF_ERROR_NO_MEM     Operation failure. No suitable memory available for allocation.
00092  * @retval NRF_ERROR_DATA_SIZE  Operation failure. Request size exceeds limit.  
00093  * @retval NRF_ERROR_NULL       Operation failure. NULL pointer supplied.   
00094  */
00095 uint32_t hci_mem_pool_rx_produce(uint32_t length, void ** pp_buffer);
00096 
00097 /**@brief Function for setting the length of the last produced RX memory block.
00098  *
00099  * @warning If call to this API is omitted the end result is that the following call to 
00100  *          mem_pool_rx_extract will return incorrect data in the p_length output parameter.
00101  *
00102  * @param[in]  length           Amount, in bytes, of actual memory used.
00103  *
00104  * @retval NRF_SUCCESS          Operation success. Length was set.
00105  */
00106 uint32_t hci_mem_pool_rx_data_size_set(uint32_t length);
00107  
00108 /**@brief Function for extracting a packet, which has been filled with read data, for further 
00109  * processing.
00110  *
00111  * @param[out] pp_buffer        Pointer to the packet data.
00112  * @param[out] p_length         Length of packet data in bytes.  
00113  *
00114  * @retval NRF_SUCCESS          Operation success. 
00115  * @retval NRF_ERROR_NO_MEM     Operation failure. No packet available to extract.
00116  * @retval NRF_ERROR_NULL       Operation failure. NULL pointer supplied.    
00117  */
00118 uint32_t hci_mem_pool_rx_extract(uint8_t ** pp_buffer, uint32_t * p_length);
00119  
00120 /**@brief Function for freeing previously extracted packet, which has been filled with read data.
00121  *
00122  * @param[in] p_buffer             Pointer to consumed buffer.
00123  *
00124  * @retval NRF_SUCCESS             Operation success. 
00125  * @retval NRF_ERROR_NO_MEM        Operation failure. No packet available to free. 
00126  * @retval NRF_ERROR_INVALID_ADDR  Operation failure. Not a valid pointer. 
00127  */
00128 uint32_t hci_mem_pool_rx_consume(uint8_t * p_buffer);
00129  
00130 #endif // HCI_MEM_POOL_H__
00131  
00132 /** @} */