BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

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