テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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