The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_NRF51_DK/TOOLCHAIN_GCC_ARM/hci_mem_pool.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 143:86740a56073b | 1 | /* |
AnnaBridge | 143:86740a56073b | 2 | * Copyright (c) 2013 Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 3 | * All rights reserved. |
AnnaBridge | 143:86740a56073b | 4 | * |
AnnaBridge | 143:86740a56073b | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 143:86740a56073b | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 143:86740a56073b | 7 | * |
AnnaBridge | 143:86740a56073b | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 143:86740a56073b | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 143:86740a56073b | 10 | * |
AnnaBridge | 143:86740a56073b | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 143:86740a56073b | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 143:86740a56073b | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 143:86740a56073b | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 143:86740a56073b | 15 | * |
AnnaBridge | 143:86740a56073b | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 143:86740a56073b | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 143:86740a56073b | 18 | * written permission. |
AnnaBridge | 143:86740a56073b | 19 | * |
AnnaBridge | 143:86740a56073b | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 143:86740a56073b | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 143:86740a56073b | 22 | * |
AnnaBridge | 143:86740a56073b | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 143:86740a56073b | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 143:86740a56073b | 25 | * |
AnnaBridge | 143:86740a56073b | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 143:86740a56073b | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 143:86740a56073b | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 143:86740a56073b | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 143:86740a56073b | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 143:86740a56073b | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 143:86740a56073b | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 143:86740a56073b | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 143:86740a56073b | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 143:86740a56073b | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 143:86740a56073b | 36 | * |
AnnaBridge | 143:86740a56073b | 37 | */ |
AnnaBridge | 143:86740a56073b | 38 | |
AnnaBridge | 143:86740a56073b | 39 | |
AnnaBridge | 143:86740a56073b | 40 | /** @file |
AnnaBridge | 143:86740a56073b | 41 | * |
AnnaBridge | 143:86740a56073b | 42 | * @defgroup memory_pool Memory pool |
AnnaBridge | 143:86740a56073b | 43 | * @{ |
AnnaBridge | 143:86740a56073b | 44 | * @ingroup app_common |
AnnaBridge | 143:86740a56073b | 45 | * |
AnnaBridge | 143:86740a56073b | 46 | * @brief Memory pool implementation |
AnnaBridge | 143:86740a56073b | 47 | * |
AnnaBridge | 143:86740a56073b | 48 | * Memory pool implementation, based on circular buffer data structure, which supports asynchronous |
AnnaBridge | 143:86740a56073b | 49 | * processing of RX data. The current default implementation supports 1 TX buffer and 4 RX buffers. |
AnnaBridge | 143:86740a56073b | 50 | * The memory managed by the pool is allocated from static storage instead of heap. The internal |
AnnaBridge | 143:86740a56073b | 51 | * design of the circular buffer implementing the RX memory layout is illustrated in the picture |
AnnaBridge | 143:86740a56073b | 52 | * below. |
AnnaBridge | 143:86740a56073b | 53 | * |
AnnaBridge | 143:86740a56073b | 54 | * @image html memory_pool.png "Circular buffer design" |
AnnaBridge | 143:86740a56073b | 55 | * |
AnnaBridge | 143:86740a56073b | 56 | * The expected call order for the RX APIs is as follows: |
AnnaBridge | 143:86740a56073b | 57 | * - hci_mem_pool_rx_produce |
AnnaBridge | 143:86740a56073b | 58 | * - hci_mem_pool_rx_data_size_set |
AnnaBridge | 143:86740a56073b | 59 | * - hci_mem_pool_rx_extract |
AnnaBridge | 143:86740a56073b | 60 | * - hci_mem_pool_rx_consume |
AnnaBridge | 143:86740a56073b | 61 | * |
AnnaBridge | 143:86740a56073b | 62 | * @warning If the above mentioned expected call order is violated the end result can be undefined. |
AnnaBridge | 143:86740a56073b | 63 | * |
AnnaBridge | 143:86740a56073b | 64 | * \par Component specific configuration options |
AnnaBridge | 143:86740a56073b | 65 | * |
AnnaBridge | 143:86740a56073b | 66 | * The following compile time configuration options are available to suit various implementations: |
AnnaBridge | 143:86740a56073b | 67 | * - TX_BUF_SIZE TX buffer size in bytes. |
AnnaBridge | 143:86740a56073b | 68 | * - RX_BUF_SIZE RX buffer size in bytes. |
AnnaBridge | 143:86740a56073b | 69 | * - RX_BUF_QUEUE_SIZE RX buffer element size. |
AnnaBridge | 143:86740a56073b | 70 | */ |
AnnaBridge | 143:86740a56073b | 71 | |
AnnaBridge | 143:86740a56073b | 72 | #ifndef HCI_MEM_POOL_H__ |
AnnaBridge | 143:86740a56073b | 73 | #define HCI_MEM_POOL_H__ |
AnnaBridge | 143:86740a56073b | 74 | |
AnnaBridge | 143:86740a56073b | 75 | #include <stdint.h> |
AnnaBridge | 143:86740a56073b | 76 | #include "nrf_error.h" |
AnnaBridge | 143:86740a56073b | 77 | |
AnnaBridge | 143:86740a56073b | 78 | /**@brief Function for opening the module. |
AnnaBridge | 143:86740a56073b | 79 | * |
AnnaBridge | 143:86740a56073b | 80 | * @retval NRF_SUCCESS Operation success. |
AnnaBridge | 143:86740a56073b | 81 | */ |
AnnaBridge | 143:86740a56073b | 82 | uint32_t hci_mem_pool_open(void); |
AnnaBridge | 143:86740a56073b | 83 | |
AnnaBridge | 143:86740a56073b | 84 | /**@brief Function for closing the module. |
AnnaBridge | 143:86740a56073b | 85 | * |
AnnaBridge | 143:86740a56073b | 86 | * @retval NRF_SUCCESS Operation success. |
AnnaBridge | 143:86740a56073b | 87 | */ |
AnnaBridge | 143:86740a56073b | 88 | uint32_t hci_mem_pool_close(void); |
AnnaBridge | 143:86740a56073b | 89 | |
AnnaBridge | 143:86740a56073b | 90 | /**@brief Function for allocating requested amount of TX memory. |
AnnaBridge | 143:86740a56073b | 91 | * |
AnnaBridge | 143:86740a56073b | 92 | * @param[out] pp_buffer Pointer to the allocated memory. |
AnnaBridge | 143:86740a56073b | 93 | * |
AnnaBridge | 143:86740a56073b | 94 | * @retval NRF_SUCCESS Operation success. Memory was allocated. |
AnnaBridge | 143:86740a56073b | 95 | * @retval NRF_ERROR_NO_MEM Operation failure. No memory available for allocation. |
AnnaBridge | 143:86740a56073b | 96 | * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. |
AnnaBridge | 143:86740a56073b | 97 | */ |
AnnaBridge | 143:86740a56073b | 98 | uint32_t hci_mem_pool_tx_alloc(void ** pp_buffer); |
AnnaBridge | 143:86740a56073b | 99 | |
AnnaBridge | 143:86740a56073b | 100 | /**@brief Function for freeing previously allocated TX memory. |
AnnaBridge | 143:86740a56073b | 101 | * |
AnnaBridge | 143:86740a56073b | 102 | * @note Memory management follows the FIFO principle meaning that free() order must match the |
AnnaBridge | 143:86740a56073b | 103 | * alloc(...) order, which is the reason for omitting exact memory block identifier as an |
AnnaBridge | 143:86740a56073b | 104 | * input parameter. |
AnnaBridge | 143:86740a56073b | 105 | * |
AnnaBridge | 143:86740a56073b | 106 | * @retval NRF_SUCCESS Operation success. Memory was freed. |
AnnaBridge | 143:86740a56073b | 107 | */ |
AnnaBridge | 143:86740a56073b | 108 | uint32_t hci_mem_pool_tx_free(void); |
AnnaBridge | 143:86740a56073b | 109 | |
AnnaBridge | 143:86740a56073b | 110 | /**@brief Function for producing a free RX memory block for usage. |
AnnaBridge | 143:86740a56073b | 111 | * |
AnnaBridge | 143:86740a56073b | 112 | * @note Upon produce request amount being 0, NRF_SUCCESS is returned. |
AnnaBridge | 143:86740a56073b | 113 | * |
AnnaBridge | 143:86740a56073b | 114 | * @param[in] length Amount, in bytes, of free memory to be produced. |
AnnaBridge | 143:86740a56073b | 115 | * @param[out] pp_buffer Pointer to the allocated memory. |
AnnaBridge | 143:86740a56073b | 116 | * |
AnnaBridge | 143:86740a56073b | 117 | * @retval NRF_SUCCESS Operation success. Free RX memory block produced. |
AnnaBridge | 143:86740a56073b | 118 | * @retval NRF_ERROR_NO_MEM Operation failure. No suitable memory available for allocation. |
AnnaBridge | 143:86740a56073b | 119 | * @retval NRF_ERROR_DATA_SIZE Operation failure. Request size exceeds limit. |
AnnaBridge | 143:86740a56073b | 120 | * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. |
AnnaBridge | 143:86740a56073b | 121 | */ |
AnnaBridge | 143:86740a56073b | 122 | uint32_t hci_mem_pool_rx_produce(uint32_t length, void ** pp_buffer); |
AnnaBridge | 143:86740a56073b | 123 | |
AnnaBridge | 143:86740a56073b | 124 | /**@brief Function for setting the length of the last produced RX memory block. |
AnnaBridge | 143:86740a56073b | 125 | * |
AnnaBridge | 143:86740a56073b | 126 | * @warning If call to this API is omitted the end result is that the following call to |
AnnaBridge | 143:86740a56073b | 127 | * mem_pool_rx_extract will return incorrect data in the p_length output parameter. |
AnnaBridge | 143:86740a56073b | 128 | * |
AnnaBridge | 143:86740a56073b | 129 | * @param[in] length Amount, in bytes, of actual memory used. |
AnnaBridge | 143:86740a56073b | 130 | * |
AnnaBridge | 143:86740a56073b | 131 | * @retval NRF_SUCCESS Operation success. Length was set. |
AnnaBridge | 143:86740a56073b | 132 | */ |
AnnaBridge | 143:86740a56073b | 133 | uint32_t hci_mem_pool_rx_data_size_set(uint32_t length); |
AnnaBridge | 143:86740a56073b | 134 | |
AnnaBridge | 143:86740a56073b | 135 | /**@brief Function for extracting a packet, which has been filled with read data, for further |
AnnaBridge | 143:86740a56073b | 136 | * processing. |
AnnaBridge | 143:86740a56073b | 137 | * |
AnnaBridge | 143:86740a56073b | 138 | * @param[out] pp_buffer Pointer to the packet data. |
AnnaBridge | 143:86740a56073b | 139 | * @param[out] p_length Length of packet data in bytes. |
AnnaBridge | 143:86740a56073b | 140 | * |
AnnaBridge | 143:86740a56073b | 141 | * @retval NRF_SUCCESS Operation success. |
AnnaBridge | 143:86740a56073b | 142 | * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to extract. |
AnnaBridge | 143:86740a56073b | 143 | * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. |
AnnaBridge | 143:86740a56073b | 144 | */ |
AnnaBridge | 143:86740a56073b | 145 | uint32_t hci_mem_pool_rx_extract(uint8_t ** pp_buffer, uint32_t * p_length); |
AnnaBridge | 143:86740a56073b | 146 | |
AnnaBridge | 143:86740a56073b | 147 | /**@brief Function for freeing previously extracted packet, which has been filled with read data. |
AnnaBridge | 143:86740a56073b | 148 | * |
AnnaBridge | 143:86740a56073b | 149 | * @param[in] p_buffer Pointer to consumed buffer. |
AnnaBridge | 143:86740a56073b | 150 | * |
AnnaBridge | 143:86740a56073b | 151 | * @retval NRF_SUCCESS Operation success. |
AnnaBridge | 143:86740a56073b | 152 | * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to free. |
AnnaBridge | 143:86740a56073b | 153 | * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer. |
AnnaBridge | 143:86740a56073b | 154 | */ |
AnnaBridge | 143:86740a56073b | 155 | uint32_t hci_mem_pool_rx_consume(uint8_t * p_buffer); |
AnnaBridge | 143:86740a56073b | 156 | |
AnnaBridge | 143:86740a56073b | 157 | #endif // HCI_MEM_POOL_H__ |
AnnaBridge | 143:86740a56073b | 158 | |
AnnaBridge | 143:86740a56073b | 159 | /** @} */ |