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/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/nrf-sdk/app_common/hci_mem_pool.h@91:031413cf7a89, 2014-10-29 (annotated)
- Committer:
- Kojto
- Date:
- Wed Oct 29 11:02:04 2014 +0000
- Revision:
- 91:031413cf7a89
Release 91 of the mbed library
Changes:
- RBLAB_NANO - new target addition
- NRF51_DK - new target addition
- NRF51_DONGLE - new target addition
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 91:031413cf7a89 | 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. |
Kojto | 91:031413cf7a89 | 2 | * |
Kojto | 91:031413cf7a89 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
Kojto | 91:031413cf7a89 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
Kojto | 91:031413cf7a89 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
Kojto | 91:031413cf7a89 | 6 | * |
Kojto | 91:031413cf7a89 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
Kojto | 91:031413cf7a89 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
Kojto | 91:031413cf7a89 | 9 | * the file. |
Kojto | 91:031413cf7a89 | 10 | * |
Kojto | 91:031413cf7a89 | 11 | */ |
Kojto | 91:031413cf7a89 | 12 | |
Kojto | 91:031413cf7a89 | 13 | /** @file |
Kojto | 91:031413cf7a89 | 14 | * |
Kojto | 91:031413cf7a89 | 15 | * @defgroup memory_pool Memory pool |
Kojto | 91:031413cf7a89 | 16 | * @{ |
Kojto | 91:031413cf7a89 | 17 | * @ingroup app_common |
Kojto | 91:031413cf7a89 | 18 | * |
Kojto | 91:031413cf7a89 | 19 | * @brief Memory pool implementation |
Kojto | 91:031413cf7a89 | 20 | * |
Kojto | 91:031413cf7a89 | 21 | * Memory pool implementation, based on circular buffer data structure, which supports asynchronous |
Kojto | 91:031413cf7a89 | 22 | * processing of RX data. The current default implementation supports 1 TX buffer and 4 RX buffers. |
Kojto | 91:031413cf7a89 | 23 | * The memory managed by the pool is allocated from static storage instead of heap. The internal |
Kojto | 91:031413cf7a89 | 24 | * design of the circular buffer implementing the RX memory layout is illustrated in the picture |
Kojto | 91:031413cf7a89 | 25 | * below. |
Kojto | 91:031413cf7a89 | 26 | * |
Kojto | 91:031413cf7a89 | 27 | * @image html memory_pool.png "Circular buffer design" |
Kojto | 91:031413cf7a89 | 28 | * |
Kojto | 91:031413cf7a89 | 29 | * The expected call order for the RX APIs is as follows: |
Kojto | 91:031413cf7a89 | 30 | * - hci_mem_pool_rx_produce |
Kojto | 91:031413cf7a89 | 31 | * - hci_mem_pool_rx_data_size_set |
Kojto | 91:031413cf7a89 | 32 | * - hci_mem_pool_rx_extract |
Kojto | 91:031413cf7a89 | 33 | * - hci_mem_pool_rx_consume |
Kojto | 91:031413cf7a89 | 34 | * |
Kojto | 91:031413cf7a89 | 35 | * @warning If the above mentioned expected call order is violated the end result can be undefined. |
Kojto | 91:031413cf7a89 | 36 | * |
Kojto | 91:031413cf7a89 | 37 | * \par Component specific configuration options |
Kojto | 91:031413cf7a89 | 38 | * |
Kojto | 91:031413cf7a89 | 39 | * The following compile time configuration options are available to suit various implementations: |
Kojto | 91:031413cf7a89 | 40 | * - TX_BUF_SIZE TX buffer size in bytes. |
Kojto | 91:031413cf7a89 | 41 | * - RX_BUF_SIZE RX buffer size in bytes. |
Kojto | 91:031413cf7a89 | 42 | * - RX_BUF_QUEUE_SIZE RX buffer element size. |
Kojto | 91:031413cf7a89 | 43 | */ |
Kojto | 91:031413cf7a89 | 44 | |
Kojto | 91:031413cf7a89 | 45 | #ifndef HCI_MEM_POOL_H__ |
Kojto | 91:031413cf7a89 | 46 | #define HCI_MEM_POOL_H__ |
Kojto | 91:031413cf7a89 | 47 | |
Kojto | 91:031413cf7a89 | 48 | #include <stdint.h> |
Kojto | 91:031413cf7a89 | 49 | #include "nrf_error.h" |
Kojto | 91:031413cf7a89 | 50 | |
Kojto | 91:031413cf7a89 | 51 | /**@brief Function for opening the module. |
Kojto | 91:031413cf7a89 | 52 | * |
Kojto | 91:031413cf7a89 | 53 | * @retval NRF_SUCCESS Operation success. |
Kojto | 91:031413cf7a89 | 54 | */ |
Kojto | 91:031413cf7a89 | 55 | uint32_t hci_mem_pool_open(void); |
Kojto | 91:031413cf7a89 | 56 | |
Kojto | 91:031413cf7a89 | 57 | /**@brief Function for closing the module. |
Kojto | 91:031413cf7a89 | 58 | * |
Kojto | 91:031413cf7a89 | 59 | * @retval NRF_SUCCESS Operation success. |
Kojto | 91:031413cf7a89 | 60 | */ |
Kojto | 91:031413cf7a89 | 61 | uint32_t hci_mem_pool_close(void); |
Kojto | 91:031413cf7a89 | 62 | |
Kojto | 91:031413cf7a89 | 63 | /**@brief Function for allocating requested amount of TX memory. |
Kojto | 91:031413cf7a89 | 64 | * |
Kojto | 91:031413cf7a89 | 65 | * @param[out] pp_buffer Pointer to the allocated memory. |
Kojto | 91:031413cf7a89 | 66 | * |
Kojto | 91:031413cf7a89 | 67 | * @retval NRF_SUCCESS Operation success. Memory was allocated. |
Kojto | 91:031413cf7a89 | 68 | * @retval NRF_ERROR_NO_MEM Operation failure. No memory available for allocation. |
Kojto | 91:031413cf7a89 | 69 | * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. |
Kojto | 91:031413cf7a89 | 70 | */ |
Kojto | 91:031413cf7a89 | 71 | uint32_t hci_mem_pool_tx_alloc(void ** pp_buffer); |
Kojto | 91:031413cf7a89 | 72 | |
Kojto | 91:031413cf7a89 | 73 | /**@brief Function for freeing previously allocated TX memory. |
Kojto | 91:031413cf7a89 | 74 | * |
Kojto | 91:031413cf7a89 | 75 | * @note Memory management follows the FIFO principle meaning that free() order must match the |
Kojto | 91:031413cf7a89 | 76 | * alloc(...) order, which is the reason for omitting exact memory block identifier as an |
Kojto | 91:031413cf7a89 | 77 | * input parameter. |
Kojto | 91:031413cf7a89 | 78 | * |
Kojto | 91:031413cf7a89 | 79 | * @retval NRF_SUCCESS Operation success. Memory was freed. |
Kojto | 91:031413cf7a89 | 80 | */ |
Kojto | 91:031413cf7a89 | 81 | uint32_t hci_mem_pool_tx_free(void); |
Kojto | 91:031413cf7a89 | 82 | |
Kojto | 91:031413cf7a89 | 83 | /**@brief Function for producing a free RX memory block for usage. |
Kojto | 91:031413cf7a89 | 84 | * |
Kojto | 91:031413cf7a89 | 85 | * @note Upon produce request amount being 0, NRF_SUCCESS is returned. |
Kojto | 91:031413cf7a89 | 86 | * |
Kojto | 91:031413cf7a89 | 87 | * @param[in] length Amount, in bytes, of free memory to be produced. |
Kojto | 91:031413cf7a89 | 88 | * @param[out] pp_buffer Pointer to the allocated memory. |
Kojto | 91:031413cf7a89 | 89 | * |
Kojto | 91:031413cf7a89 | 90 | * @retval NRF_SUCCESS Operation success. Free RX memory block produced. |
Kojto | 91:031413cf7a89 | 91 | * @retval NRF_ERROR_NO_MEM Operation failure. No suitable memory available for allocation. |
Kojto | 91:031413cf7a89 | 92 | * @retval NRF_ERROR_DATA_SIZE Operation failure. Request size exceeds limit. |
Kojto | 91:031413cf7a89 | 93 | * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. |
Kojto | 91:031413cf7a89 | 94 | */ |
Kojto | 91:031413cf7a89 | 95 | uint32_t hci_mem_pool_rx_produce(uint32_t length, void ** pp_buffer); |
Kojto | 91:031413cf7a89 | 96 | |
Kojto | 91:031413cf7a89 | 97 | /**@brief Function for setting the length of the last produced RX memory block. |
Kojto | 91:031413cf7a89 | 98 | * |
Kojto | 91:031413cf7a89 | 99 | * @warning If call to this API is omitted the end result is that the following call to |
Kojto | 91:031413cf7a89 | 100 | * mem_pool_rx_extract will return incorrect data in the p_length output parameter. |
Kojto | 91:031413cf7a89 | 101 | * |
Kojto | 91:031413cf7a89 | 102 | * @param[in] length Amount, in bytes, of actual memory used. |
Kojto | 91:031413cf7a89 | 103 | * |
Kojto | 91:031413cf7a89 | 104 | * @retval NRF_SUCCESS Operation success. Length was set. |
Kojto | 91:031413cf7a89 | 105 | */ |
Kojto | 91:031413cf7a89 | 106 | uint32_t hci_mem_pool_rx_data_size_set(uint32_t length); |
Kojto | 91:031413cf7a89 | 107 | |
Kojto | 91:031413cf7a89 | 108 | /**@brief Function for extracting a packet, which has been filled with read data, for further |
Kojto | 91:031413cf7a89 | 109 | * processing. |
Kojto | 91:031413cf7a89 | 110 | * |
Kojto | 91:031413cf7a89 | 111 | * @param[out] pp_buffer Pointer to the packet data. |
Kojto | 91:031413cf7a89 | 112 | * @param[out] p_length Length of packet data in bytes. |
Kojto | 91:031413cf7a89 | 113 | * |
Kojto | 91:031413cf7a89 | 114 | * @retval NRF_SUCCESS Operation success. |
Kojto | 91:031413cf7a89 | 115 | * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to extract. |
Kojto | 91:031413cf7a89 | 116 | * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied. |
Kojto | 91:031413cf7a89 | 117 | */ |
Kojto | 91:031413cf7a89 | 118 | uint32_t hci_mem_pool_rx_extract(uint8_t ** pp_buffer, uint32_t * p_length); |
Kojto | 91:031413cf7a89 | 119 | |
Kojto | 91:031413cf7a89 | 120 | /**@brief Function for freeing previously extracted packet, which has been filled with read data. |
Kojto | 91:031413cf7a89 | 121 | * |
Kojto | 91:031413cf7a89 | 122 | * @param[in] p_buffer Pointer to consumed buffer. |
Kojto | 91:031413cf7a89 | 123 | * |
Kojto | 91:031413cf7a89 | 124 | * @retval NRF_SUCCESS Operation success. |
Kojto | 91:031413cf7a89 | 125 | * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to free. |
Kojto | 91:031413cf7a89 | 126 | * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer. |
Kojto | 91:031413cf7a89 | 127 | */ |
Kojto | 91:031413cf7a89 | 128 | uint32_t hci_mem_pool_rx_consume(uint8_t * p_buffer); |
Kojto | 91:031413cf7a89 | 129 | |
Kojto | 91:031413cf7a89 | 130 | #endif // HCI_MEM_POOL_H__ |
Kojto | 91:031413cf7a89 | 131 | |
Kojto | 91:031413cf7a89 | 132 | /** @} */ |