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_slip SLIP module
yihui 1:a607cd9655d7 16 * @{
yihui 1:a607cd9655d7 17 * @ingroup app_common
yihui 1:a607cd9655d7 18 *
yihui 1:a607cd9655d7 19 * @brief SLIP layer for supporting packet framing in HCI transport.
yihui 1:a607cd9655d7 20 *
yihui 1:a607cd9655d7 21 * @details This module implements SLIP packet framing as described in the Bluetooth Core
yihui 1:a607cd9655d7 22 * Specification 4.0, Volume 4, Part D, Chapter 3 SLIP Layer.
yihui 1:a607cd9655d7 23 *
yihui 1:a607cd9655d7 24 * SLIP framing ensures that all packets sent on the UART are framed as:
yihui 1:a607cd9655d7 25 * <0xC0> SLIP packet 1 <0xC0> <0xC0> SLIP packet 2 <0xC0>.
yihui 1:a607cd9655d7 26 *
yihui 1:a607cd9655d7 27 * The SLIP layer uses events to notify the upper layer when data transmission is complete
yihui 1:a607cd9655d7 28 * and when a SLIP packet is received.
yihui 1:a607cd9655d7 29 */
yihui 1:a607cd9655d7 30
yihui 1:a607cd9655d7 31 #ifndef HCI_SLIP_H__
yihui 1:a607cd9655d7 32 #define HCI_SLIP_H__
yihui 1:a607cd9655d7 33
yihui 1:a607cd9655d7 34 #include <stdint.h>
yihui 1:a607cd9655d7 35
yihui 1:a607cd9655d7 36 /**@brief Event types from the SLIP Layer. */
yihui 1:a607cd9655d7 37 typedef enum
yihui 1:a607cd9655d7 38 {
yihui 1:a607cd9655d7 39 HCI_SLIP_RX_RDY, /**< An event indicating that an RX packet is ready to be read. */
yihui 1:a607cd9655d7 40 HCI_SLIP_TX_DONE, /**< An event indicating write completion of the TX packet provided in the function call \ref hci_slip_write . */
yihui 1:a607cd9655d7 41 HCI_SLIP_RX_OVERFLOW, /**< An event indicating that RX data has been discarded due to lack of free RX memory. */
yihui 1:a607cd9655d7 42 HCI_SLIP_ERROR, /**< An event indicating that an unrecoverable error has occurred. */
yihui 1:a607cd9655d7 43 HCI_SLIP_EVT_TYPE_MAX /**< Enumeration upper bound. */
yihui 1:a607cd9655d7 44 } hci_slip_evt_type_t;
yihui 1:a607cd9655d7 45
yihui 1:a607cd9655d7 46 /**@brief Structure containing an event from the SLIP layer.
yihui 1:a607cd9655d7 47 */
yihui 1:a607cd9655d7 48 typedef struct
yihui 1:a607cd9655d7 49 {
yihui 1:a607cd9655d7 50 hci_slip_evt_type_t evt_type; /**< Type of event. */
yihui 1:a607cd9655d7 51 const uint8_t * packet; /**< This field contains a pointer to the packet for which the event relates, i.e. SLIP_TX_DONE: the packet transmitted, SLIP_RX_RDY: the packet received, SLIP_RX_OVERFLOW: The packet which overflow/or NULL if no receive buffer is available. */
yihui 1:a607cd9655d7 52 uint32_t packet_length; /**< Packet length, i.e. SLIP_TX_DONE: Bytes transmitted, SLIP_RX_RDY: Bytes received, SLIP_RX_OVERFLOW: index at which the packet overflowed. */
yihui 1:a607cd9655d7 53 } hci_slip_evt_t;
yihui 1:a607cd9655d7 54
yihui 1:a607cd9655d7 55 /**@brief Function for the SLIP layer event callback.
yihui 1:a607cd9655d7 56 */
yihui 1:a607cd9655d7 57 typedef void (*hci_slip_event_handler_t)(hci_slip_evt_t event);
yihui 1:a607cd9655d7 58
yihui 1:a607cd9655d7 59 /**@brief Function for registering the event handler provided as parameter and this event handler
yihui 1:a607cd9655d7 60 * will be used by SLIP layer to send events described in \ref hci_slip_evt_type_t.
yihui 1:a607cd9655d7 61 *
yihui 1:a607cd9655d7 62 * @note Multiple registration requests will overwrite any existing registration.
yihui 1:a607cd9655d7 63 *
yihui 1:a607cd9655d7 64 * @param[in] event_handler This function is called by the SLIP layer upon an event.
yihui 1:a607cd9655d7 65 *
yihui 1:a607cd9655d7 66 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 67 */
yihui 1:a607cd9655d7 68 uint32_t hci_slip_evt_handler_register(hci_slip_event_handler_t event_handler);
yihui 1:a607cd9655d7 69
yihui 1:a607cd9655d7 70 /**@brief Function for opening the SLIP layer. This function must be called before
yihui 1:a607cd9655d7 71 * \ref hci_slip_write and before any data can be received.
yihui 1:a607cd9655d7 72 *
yihui 1:a607cd9655d7 73 * @note Can be called multiple times.
yihui 1:a607cd9655d7 74 *
yihui 1:a607cd9655d7 75 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 76 *
yihui 1:a607cd9655d7 77 * The SLIP layer module will propagate errors from underlying sub-modules.
yihui 1:a607cd9655d7 78 * This implementation is using UART module as a physical transmission layer, and hci_slip_open
yihui 1:a607cd9655d7 79 * executes \ref app_uart_init . For an extended error list, please refer to \ref app_uart_init .
yihui 1:a607cd9655d7 80 */
yihui 1:a607cd9655d7 81 uint32_t hci_slip_open(void);
yihui 1:a607cd9655d7 82
yihui 1:a607cd9655d7 83 /**@brief Function for closing the SLIP layer. After this function is called no data can be
yihui 1:a607cd9655d7 84 * transmitted or received in this layer.
yihui 1:a607cd9655d7 85 *
yihui 1:a607cd9655d7 86 * @note This function can be called multiple times and also for an unopened channel.
yihui 1:a607cd9655d7 87 *
yihui 1:a607cd9655d7 88 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 89 */
yihui 1:a607cd9655d7 90 uint32_t hci_slip_close(void);
yihui 1:a607cd9655d7 91
yihui 1:a607cd9655d7 92 /**@brief Function for writing a packet with SLIP encoding. Packet transmission is confirmed when
yihui 1:a607cd9655d7 93 * the HCI_SLIP_TX_DONE event is received by the function caller.
yihui 1:a607cd9655d7 94 *
yihui 1:a607cd9655d7 95 * @param[in] p_buffer Pointer to the packet to transmit.
yihui 1:a607cd9655d7 96 * @param[in] length Packet length, in bytes.
yihui 1:a607cd9655d7 97 *
yihui 1:a607cd9655d7 98 * @retval NRF_SUCCESS Operation success. Packet was encoded and added to the
yihui 1:a607cd9655d7 99 * transmission queue and an event will be sent upon transmission
yihui 1:a607cd9655d7 100 * completion.
yihui 1:a607cd9655d7 101 * @retval NRF_ERROR_NO_MEM Operation failure. Transmission queue is full and packet was not
yihui 1:a607cd9655d7 102 * added to the transmission queue. Application shall wait for
yihui 1:a607cd9655d7 103 * the \ref HCI_SLIP_TX_DONE event. After HCI_SLIP_TX_DONE this
yihui 1:a607cd9655d7 104 * function can be executed for transmission of next packet.
yihui 1:a607cd9655d7 105 * @retval NRF_ERROR_INVALID_ADDR If a NULL pointer is provided.
yihui 1:a607cd9655d7 106 * @retval NRF_ERROR_INVALID_STATE Operation failure. Module is not open.
yihui 1:a607cd9655d7 107 */
yihui 1:a607cd9655d7 108 uint32_t hci_slip_write(const uint8_t * p_buffer, uint32_t length);
yihui 1:a607cd9655d7 109
yihui 1:a607cd9655d7 110 /**@brief Function for registering a receive buffer. The receive buffer will be used for storage of
yihui 1:a607cd9655d7 111 * received and SLIP decoded data.
yihui 1:a607cd9655d7 112 * No data can be received by the SLIP layer until a receive buffer has been registered.
yihui 1:a607cd9655d7 113 *
yihui 1:a607cd9655d7 114 * @note The lifetime of the buffer must be valid during complete reception of data. A static
yihui 1:a607cd9655d7 115 * buffer is recommended.
yihui 1:a607cd9655d7 116 *
yihui 1:a607cd9655d7 117 * @warning Multiple registration requests will overwrite any existing registration.
yihui 1:a607cd9655d7 118 *
yihui 1:a607cd9655d7 119 * @param[in] p_buffer Pointer to receive buffer. The received and SLIP decoded packet
yihui 1:a607cd9655d7 120 * will be placed in this buffer.
yihui 1:a607cd9655d7 121 * @param[in] length Buffer length, in bytes.
yihui 1:a607cd9655d7 122 *
yihui 1:a607cd9655d7 123 * @retval NRF_SUCCESS Operation success.
yihui 1:a607cd9655d7 124 */
yihui 1:a607cd9655d7 125 uint32_t hci_slip_rx_buffer_register(uint8_t * p_buffer, uint32_t length);
yihui 1:a607cd9655d7 126
yihui 1:a607cd9655d7 127 #endif // HCI_SLIP_H__
yihui 1:a607cd9655d7 128
yihui 1:a607cd9655d7 129 /** @} */