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 hci_transport HCI Transport
yihui 1:a607cd9655d7 16 * @{
yihui 1:a607cd9655d7 17 * @ingroup app_common
yihui 1:a607cd9655d7 18 *
yihui 1:a607cd9655d7 19 * @brief HCI transport module implementation.
yihui 1:a607cd9655d7 20 *
yihui 1:a607cd9655d7 21 * This module implements certain specific features from the three-wire UART transport layer,
yihui 1:a607cd9655d7 22 * defined by the Bluetooth specification version 4.0 [Vol 4] part D.
yihui 1:a607cd9655d7 23 *
yihui 1:a607cd9655d7 24 * \par Features supported
yihui 1:a607cd9655d7 25 * - Transmission and reception of Vendor Specific HCI packet type application packets.
yihui 1:a607cd9655d7 26 * - Transmission and reception of reliable packets: defined by chapter 6 of the specification.
yihui 1:a607cd9655d7 27 *
yihui 1:a607cd9655d7 28 * \par Features not supported
yihui 1:a607cd9655d7 29 * - Link establishment procedure: defined by chapter 8 of the specification.
yihui 1:a607cd9655d7 30 * - Low power: defined by chapter 9 of the specification.
yihui 1:a607cd9655d7 31 *
yihui 1:a607cd9655d7 32 * \par Implementation specific behaviour
yihui 1:a607cd9655d7 33 * - As Link establishment procedure is not supported following static link configuration parameters
yihui 1:a607cd9655d7 34 * are used:
yihui 1:a607cd9655d7 35 * + TX window size is 1.
yihui 1:a607cd9655d7 36 * + 16 bit CCITT-CRC must be used.
yihui 1:a607cd9655d7 37 * + Out of frame software flow control not supported.
yihui 1:a607cd9655d7 38 * + Parameters specific for resending reliable packets are compile time configurable (clarifed
yihui 1:a607cd9655d7 39 * later in this document).
yihui 1:a607cd9655d7 40 * + Acknowledgement packet transmissions are not timeout driven , meaning they are delivered for
yihui 1:a607cd9655d7 41 * transmission within same context which the corresponding application packet was received.
yihui 1:a607cd9655d7 42 *
yihui 1:a607cd9655d7 43 * \par Implementation specific limitations
yihui 1:a607cd9655d7 44 * Current implementation has the following limitations which will have impact to system wide
yihui 1:a607cd9655d7 45 * behaviour:
yihui 1:a607cd9655d7 46 * - Delayed acknowledgement scheduling not implemented:
yihui 1:a607cd9655d7 47 * There exists a possibility that acknowledgement TX packet and application TX packet will collide
yihui 1:a607cd9655d7 48 * in the TX pipeline having the end result that acknowledgement packet will be excluded from the TX
yihui 1:a607cd9655d7 49 * pipeline which will trigger the retransmission algorithm within the peer protocol entity.
yihui 1:a607cd9655d7 50 * - Delayed retransmission scheduling not implemented:
yihui 1:a607cd9655d7 51 * There exists a possibility that retransmitted application TX packet and acknowledgement TX packet
yihui 1:a607cd9655d7 52 * will collide in the TX pipeline having the end result that retransmitted application TX packet
yihui 1:a607cd9655d7 53 * will be excluded from the TX pipeline.
yihui 1:a607cd9655d7 54 * - Processing of the acknowledgement number from RX application packets:
yihui 1:a607cd9655d7 55 * Acknowledgement number is not processed from the RX application packets having the end result
yihui 1:a607cd9655d7 56 * that unnecessary application packet retransmissions can occur.
yihui 1:a607cd9655d7 57 *
yihui 1:a607cd9655d7 58 * The application TX packet processing flow is illustrated by the statemachine below.
yihui 1:a607cd9655d7 59 *
yihui 1:a607cd9655d7 60 * @image html hci_transport_tx_sm.png "TX - application packet statemachine"
yihui 1:a607cd9655d7 61 *
yihui 1:a607cd9655d7 62 * \par Component specific configuration options
yihui 1:a607cd9655d7 63 *
yihui 1:a607cd9655d7 64 * The following compile time configuration options are available, and used to configure the
yihui 1:a607cd9655d7 65 * application TX packet retransmission interval, in order to suite various application specific
yihui 1:a607cd9655d7 66 * implementations:
yihui 1:a607cd9655d7 67 * - MAC_PACKET_SIZE_IN_BITS Maximum size of a single application packet in bits.
yihui 1:a607cd9655d7 68 * - USED_BAUD_RATE Used uart baudrate.
yihui 1:a607cd9655d7 69 *
yihui 1:a607cd9655d7 70 * The following compile time configuration option is available to configure module specific
yihui 1:a607cd9655d7 71 * behaviour:
yihui 1:a607cd9655d7 72 * - MAX_RETRY_COUNT Max retransmission retry count for applicaton packets.
yihui 1:a607cd9655d7 73 */
yihui 1:a607cd9655d7 74
yihui 1:a607cd9655d7 75 #ifndef HCI_TRANSPORT_H__
yihui 1:a607cd9655d7 76 #define HCI_TRANSPORT_H__
yihui 1:a607cd9655d7 77
yihui 1:a607cd9655d7 78 #include <stdint.h>
yihui 1:a607cd9655d7 79 #include "nrf_error.h"
yihui 1:a607cd9655d7 80
yihui 1:a607cd9655d7 81 /**@brief Generic event callback function events. */
yihui 1:a607cd9655d7 82 typedef enum
yihui 1:a607cd9655d7 83 {
yihui 1:a607cd9655d7 84 HCI_TRANSPORT_RX_RDY, /**< An event indicating that RX packet is ready for read. */
yihui 1:a607cd9655d7 85 HCI_TRANSPORT_EVT_TYPE_MAX /**< Enumeration upper bound. */
yihui 1:a607cd9655d7 86 } hci_transport_evt_type_t;
yihui 1:a607cd9655d7 87
yihui 1:a607cd9655d7 88 /**@brief Struct containing events from the Transport layer.
yihui 1:a607cd9655d7 89 */
yihui 1:a607cd9655d7 90 typedef struct
yihui 1:a607cd9655d7 91 {
yihui 1:a607cd9655d7 92 hci_transport_evt_type_t evt_type; /**< Type of event. */
yihui 1:a607cd9655d7 93 } hci_transport_evt_t;
yihui 1:a607cd9655d7 94
yihui 1:a607cd9655d7 95 /**@brief Transport layer generic event callback function type.
yihui 1:a607cd9655d7 96 *
yihui 1:a607cd9655d7 97 * @param[in] event Transport layer event.
yihui 1:a607cd9655d7 98 */
yihui 1:a607cd9655d7 99 typedef void (*hci_transport_event_handler_t)(hci_transport_evt_t event);
yihui 1:a607cd9655d7 100
yihui 1:a607cd9655d7 101 /**@brief TX done event callback function result codes. */
yihui 1:a607cd9655d7 102 typedef enum
yihui 1:a607cd9655d7 103 {
yihui 1:a607cd9655d7 104 HCI_TRANSPORT_TX_DONE_SUCCESS, /**< Transmission success, peer transport entity has acknowledged the transmission. */
yihui 1:a607cd9655d7 105 HCI_TRANSPORT_TX_DONE_FAILURE /**< Transmission failure. */
yihui 1:a607cd9655d7 106 } hci_transport_tx_done_result_t;
yihui 1:a607cd9655d7 107
yihui 1:a607cd9655d7 108 /**@brief Transport layer TX done event callback function type.
yihui 1:a607cd9655d7 109 *
yihui 1:a607cd9655d7 110 * @param[in] result TX done event result code.
yihui 1:a607cd9655d7 111 */
yihui 1:a607cd9655d7 112 typedef void (*hci_transport_tx_done_handler_t)(hci_transport_tx_done_result_t result);
yihui 1:a607cd9655d7 113
yihui 1:a607cd9655d7 114 /**@brief Function for registering a generic event handler.
yihui 1:a607cd9655d7 115 *
yihui 1:a607cd9655d7 116 * @note Multiple registration requests will overwrite any possible existing registration.
yihui 1:a607cd9655d7 117 *
yihui 1:a607cd9655d7 118 * @param[in] event_handler The function to be called by the transport layer upon an event.
yihui 1:a607cd9655d7 119 *
yihui 1:a607cd9655d7 120 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 121 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
yihui 1:a607cd9655d7 122 */
yihui 1:a607cd9655d7 123 uint32_t hci_transport_evt_handler_reg(hci_transport_event_handler_t event_handler);
yihui 1:a607cd9655d7 124
yihui 1:a607cd9655d7 125 /**@brief Function for registering a handler for TX done event.
yihui 1:a607cd9655d7 126 *
yihui 1:a607cd9655d7 127 * @note Multiple registration requests will overwrite any possible existing registration.
yihui 1:a607cd9655d7 128 *
yihui 1:a607cd9655d7 129 * @param[in] event_handler The function to be called by the transport layer upon TX done
yihui 1:a607cd9655d7 130 * event.
yihui 1:a607cd9655d7 131 *
yihui 1:a607cd9655d7 132 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 133 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
yihui 1:a607cd9655d7 134 */
yihui 1:a607cd9655d7 135 uint32_t hci_transport_tx_done_register(hci_transport_tx_done_handler_t event_handler);
yihui 1:a607cd9655d7 136
yihui 1:a607cd9655d7 137 /**@brief Function for opening the transport channel and initializing the transport layer.
yihui 1:a607cd9655d7 138 *
yihui 1:a607cd9655d7 139 * @warning Must not be called for a channel which has been allready opened.
yihui 1:a607cd9655d7 140 *
yihui 1:a607cd9655d7 141 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 142 * @retval NRF_ERROR_INTERNAL Operation failure. Internal error ocurred.
yihui 1:a607cd9655d7 143 */
yihui 1:a607cd9655d7 144 uint32_t hci_transport_open(void);
yihui 1:a607cd9655d7 145
yihui 1:a607cd9655d7 146 /**@brief Function for closing the transport channel.
yihui 1:a607cd9655d7 147 *
yihui 1:a607cd9655d7 148 * @note Can be called multiple times and also for not opened channel.
yihui 1:a607cd9655d7 149 *
yihui 1:a607cd9655d7 150 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 151 */
yihui 1:a607cd9655d7 152 uint32_t hci_transport_close(void);
yihui 1:a607cd9655d7 153
yihui 1:a607cd9655d7 154 /**@brief Function for allocating tx packet memory.
yihui 1:a607cd9655d7 155 *
yihui 1:a607cd9655d7 156 * @param[out] pp_memory Pointer to the packet data.
yihui 1:a607cd9655d7 157 *
yihui 1:a607cd9655d7 158 * @retval NRF_SUCCESS Operation success. Memory was allocated.
yihui 1:a607cd9655d7 159 * @retval NRF_ERROR_NO_MEM Operation failure. No memory available.
yihui 1:a607cd9655d7 160 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
yihui 1:a607cd9655d7 161 */
yihui 1:a607cd9655d7 162 uint32_t hci_transport_tx_alloc(uint8_t ** pp_memory);
yihui 1:a607cd9655d7 163
yihui 1:a607cd9655d7 164 /**@brief Function for freeing tx packet memory.
yihui 1:a607cd9655d7 165 *
yihui 1:a607cd9655d7 166 * @note Memory management works in FIFO principle meaning that free order must match the alloc
yihui 1:a607cd9655d7 167 * order.
yihui 1:a607cd9655d7 168 *
yihui 1:a607cd9655d7 169 * @retval NRF_SUCCESS Operation success. Memory was freed.
yihui 1:a607cd9655d7 170 */
yihui 1:a607cd9655d7 171 uint32_t hci_transport_tx_free(void);
yihui 1:a607cd9655d7 172
yihui 1:a607cd9655d7 173 /**@brief Function for writing a packet.
yihui 1:a607cd9655d7 174 *
yihui 1:a607cd9655d7 175 * @note Completion of this method does not guarantee that actual peripheral transmission would
yihui 1:a607cd9655d7 176 * have completed.
yihui 1:a607cd9655d7 177 *
yihui 1:a607cd9655d7 178 * @note In case of 0 byte packet length write request, message will consist of only transport
yihui 1:a607cd9655d7 179 * module specific headers.
yihui 1:a607cd9655d7 180 *
yihui 1:a607cd9655d7 181 * @retval NRF_SUCCESS Operation success. Packet was added to the transmission queue
yihui 1:a607cd9655d7 182 * and an event will be send upon transmission completion.
yihui 1:a607cd9655d7 183 * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
yihui 1:a607cd9655d7 184 * added to the transmission queue. User should wait for
yihui 1:a607cd9655d7 185 * a appropriate event prior issuing this operation again.
yihui 1:a607cd9655d7 186 * @retval NRF_ERROR_DATA_SIZE Operation failure. Packet size exceeds limit.
yihui 1:a607cd9655d7 187 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
yihui 1:a607cd9655d7 188 * @retval NRF_ERROR_INVALID_STATE Operation failure. Channel is not open.
yihui 1:a607cd9655d7 189 */
yihui 1:a607cd9655d7 190 uint32_t hci_transport_pkt_write(const uint8_t * p_buffer, uint32_t length);
yihui 1:a607cd9655d7 191
yihui 1:a607cd9655d7 192 /**@brief Function for extracting received packet.
yihui 1:a607cd9655d7 193 *
yihui 1:a607cd9655d7 194 * @note Extracted memory can't be reused by the underlying transport layer untill freed by call to
yihui 1:a607cd9655d7 195 * hci_transport_rx_pkt_consume().
yihui 1:a607cd9655d7 196 *
yihui 1:a607cd9655d7 197 * @param[out] pp_buffer Pointer to the packet data.
yihui 1:a607cd9655d7 198 * @param[out] p_length Length of packet data in bytes.
yihui 1:a607cd9655d7 199 *
yihui 1:a607cd9655d7 200 * @retval NRF_SUCCESS Operation success. Packet was extracted.
yihui 1:a607cd9655d7 201 * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to extract.
yihui 1:a607cd9655d7 202 * @retval NRF_ERROR_NULL Operation failure. NULL pointer supplied.
yihui 1:a607cd9655d7 203 */
yihui 1:a607cd9655d7 204 uint32_t hci_transport_rx_pkt_extract(uint8_t ** pp_buffer, uint32_t * p_length);
yihui 1:a607cd9655d7 205
yihui 1:a607cd9655d7 206 /**@brief Function for consuming extracted packet described by p_buffer.
yihui 1:a607cd9655d7 207 *
yihui 1:a607cd9655d7 208 * RX memory pointed to by p_buffer is freed and can be reused by the underlying transport layer.
yihui 1:a607cd9655d7 209 *
yihui 1:a607cd9655d7 210 * @param[in] p_buffer Pointer to the buffer that has been consumed.
yihui 1:a607cd9655d7 211 *
yihui 1:a607cd9655d7 212 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 213 * @retval NRF_ERROR_NO_MEM Operation failure. No packet available to consume.
yihui 1:a607cd9655d7 214 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Not a valid pointer.
yihui 1:a607cd9655d7 215 */
yihui 1:a607cd9655d7 216 uint32_t hci_transport_rx_pkt_consume(uint8_t * p_buffer);
yihui 1:a607cd9655d7 217
yihui 1:a607cd9655d7 218 #endif // HCI_TRANSPORT_H__
yihui 1:a607cd9655d7 219
yihui 1:a607cd9655d7 220 /** @} */