test
Fork of nrf51-sdk by
Embed:
(wiki syntax)
Show/hide line numbers
hci_mem_pool.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 /** @file 00034 * 00035 * @defgroup memory_pool Memory pool 00036 * @{ 00037 * @ingroup app_common 00038 * 00039 * @brief Memory pool implementation 00040 * 00041 * Memory pool implementation, based on circular buffer data structure, which supports asynchronous 00042 * processing of RX data. The current default implementation supports 1 TX buffer and 4 RX buffers. 00043 * The memory managed by the pool is allocated from static storage instead of heap. The internal 00044 * design of the circular buffer implementing the RX memory layout is illustrated in the picture 00045 * below. 00046 * 00047 * @image html memory_pool.png "Circular buffer design" 00048 * 00049 * The expected call order for the RX APIs is as follows: 00050 * - hci_mem_pool_rx_produce 00051 * - hci_mem_pool_rx_data_size_set 00052 * - hci_mem_pool_rx_extract 00053 * - hci_mem_pool_rx_consume 00054 * 00055 * @warning If the above mentioned expected call order is violated the end result can be undefined. 00056 * 00057 * \par Component specific configuration options 00058 * 00059 * The following compile time configuration options are available to suit various implementations: 00060 * - TX_BUF_SIZE TX buffer size in bytes. 00061 * - RX_BUF_SIZE RX buffer size in bytes. 00062 * - RX_BUF_QUEUE_SIZE RX buffer element size. 00063 */ 00064 00065 #ifndef HCI_MEM_POOL_H__ 00066 #define HCI_MEM_POOL_H__ 00067 00068 #include <stdint.h> 00069 #include "nrf_error.h" 00070 00071 /**@brief Function for opening the module. 00072 * 00073 * @retval NRF_SUCCESS Operation success. 00074 */ 00075 uint32_t hci_mem_pool_open(void); 00076 00077 /**@brief Function for closing the module. 00078 * 00079 * @retval NRF_SUCCESS Operation success. 00080 */ 00081 uint32_t hci_mem_pool_close(void); 00082 00083 /**@brief Function for allocating requested amount of TX memory. 00084 * 00085 * @param[out] pp_buffer Pointer to the allocated memory. 00086 * 00087 * @retval NRF_SUCCESS Operation success. Memory was allocated. 00088 * @retval NRF_ERROR_NO_MEM Operation failure. No memory available for allocation. 00089 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. 00090 */ 00091 uint32_t hci_mem_pool_tx_alloc(void ** pp_buffer); 00092 00093 /**@brief Function for freeing previously allocated TX memory. 00094 * 00095 * @note Memory management follows the FIFO principle meaning that free() order must match the 00096 * alloc(...) order, which is the reason for omitting exact memory block identifier as an 00097 * input parameter. 00098 * 00099 * @retval NRF_SUCCESS Operation success. Memory was freed. 00100 */ 00101 uint32_t hci_mem_pool_tx_free(void); 00102 00103 /**@brief Function for producing a free RX memory block for usage. 00104 * 00105 * @note Upon produce request amount being 0, NRF_SUCCESS is returned. 00106 * 00107 * @param[in] length Amount, in bytes, of free memory to be produced. 00108 * @param[out] pp_buffer Pointer to the allocated memory. 00109 * 00110 * @retval NRF_SUCCESS Operation success. Free RX memory block produced. 00111 * @retval NRF_ERROR_NO_MEM Operation failure. No suitable memory available for allocation. 00112 * @retval NRF_ERROR_DATA_SIZE Operation failure. Request size exceeds limit. 00113 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. 00114 */ 00115 uint32_t hci_mem_pool_rx_produce(uint32_t length, void ** pp_buffer); 00116 00117 /**@brief Function for setting the length of the last produced RX memory block. 00118 * 00119 * @warning If call to this API is omitted the end result is that the following call to 00120 * mem_pool_rx_extract will return incorrect data in the p_length output parameter. 00121 * 00122 * @param[in] length Amount, in bytes, of actual memory used. 00123 * 00124 * @retval NRF_SUCCESS Operation success. Length was set. 00125 */ 00126 uint32_t hci_mem_pool_rx_data_size_set(uint32_t length); 00127 00128 /**@brief Function for extracting a packet, which has been filled with read data, for further 00129 * processing. 00130 * 00131 * @param[out] pp_buffer Pointer to the packet data. 00132 * @param[out] p_length Length of packet data in bytes. 00133 * 00134 * @retval NRF_SUCCESS Operation success. 00135 * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to extract. 00136 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. 00137 */ 00138 uint32_t hci_mem_pool_rx_extract(uint8_t ** pp_buffer, uint32_t * p_length); 00139 00140 /**@brief Function for freeing previously extracted packet, which has been filled with read data. 00141 * 00142 * @param[in] p_buffer Pointer to consumed buffer. 00143 * 00144 * @retval NRF_SUCCESS Operation success. 00145 * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to free. 00146 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer. 00147 */ 00148 uint32_t hci_mem_pool_rx_consume(uint8_t * p_buffer); 00149 00150 #endif // HCI_MEM_POOL_H__ 00151 00152 /** @} */
Generated on Tue Jul 12 2022 15:51:26 by 1.7.2