mbed library

Dependents:   Printf

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Fri Sep 12 16:41:52 2014 +0100
Revision:
89:552587b429a1
Release 89 of the mbed library

Main changes:

- low power optimizations for Nordic targets
- code structure changes for Freescale K64F targets
- bug fixes in various backends

Who changed what in which revision?

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