Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:40 2016 +0100
Revision:
19:47192cb9def7
Parent:
10:233fefd8162b
Child:
20:a90c48eb1d30
Synchronized with git rev 9251259f
Author: Liyou Zhou
Copy over coresponding files from nordic-sdk 9.0.0

Who changed what in which revision?

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