Nordic stack and drivers for the mbed BLE API

Dependents:   Sensen-classic-v8-IAQ_copy_4

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

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