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) 2011 Nordic Semiconductor. All Rights Reserved.
yihui 1:a607cd9655d7 2 *
yihui 1:a607cd9655d7 3 * The information contained herein is confidential property of Nordic Semiconductor. The use,
yihui 1:a607cd9655d7 4 * copying, transfer or disclosure of such information is prohibited except by express written
yihui 1:a607cd9655d7 5 * agreement with Nordic Semiconductor.
yihui 1:a607cd9655d7 6 *
yihui 1:a607cd9655d7 7 */
yihui 1:a607cd9655d7 8 /**
yihui 1:a607cd9655d7 9 @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP)
yihui 1:a607cd9655d7 10 @{
yihui 1:a607cd9655d7 11 @brief Definitions and prototypes for the L2CAP interface.
yihui 1:a607cd9655d7 12 */
yihui 1:a607cd9655d7 13
yihui 1:a607cd9655d7 14 #ifndef BLE_L2CAP_H__
yihui 1:a607cd9655d7 15 #define BLE_L2CAP_H__
yihui 1:a607cd9655d7 16
yihui 1:a607cd9655d7 17 #include "ble_types.h"
yihui 1:a607cd9655d7 18 #include "ble_ranges.h"
yihui 1:a607cd9655d7 19 #include "ble_err.h"
yihui 1:a607cd9655d7 20 #include "nrf_svc.h"
yihui 1:a607cd9655d7 21
yihui 1:a607cd9655d7 22 /**@addtogroup BLE_L2CAP_ENUMERATIONS Enumerations
yihui 1:a607cd9655d7 23 * @{ */
yihui 1:a607cd9655d7 24
yihui 1:a607cd9655d7 25 /**@brief L2CAP API SVC numbers. */
yihui 1:a607cd9655d7 26 enum BLE_L2CAP_SVCS
yihui 1:a607cd9655d7 27 {
yihui 1:a607cd9655d7 28 SD_BLE_L2CAP_CID_REGISTER = BLE_L2CAP_SVC_BASE, /**< Register a CID. */
yihui 1:a607cd9655d7 29 SD_BLE_L2CAP_CID_UNREGISTER, /**< Unregister a CID. */
yihui 1:a607cd9655d7 30 SD_BLE_L2CAP_TX /**< Transmit a packet. */
yihui 1:a607cd9655d7 31 };
yihui 1:a607cd9655d7 32
yihui 1:a607cd9655d7 33 /** @} */
yihui 1:a607cd9655d7 34
yihui 1:a607cd9655d7 35 /**@addtogroup BLE_L2CAP_DEFINES Defines
yihui 1:a607cd9655d7 36 * @{ */
yihui 1:a607cd9655d7 37
yihui 1:a607cd9655d7 38 /**@defgroup BLE_ERRORS_L2CAP SVC return values specific to L2CAP
yihui 1:a607cd9655d7 39 * @{ */
yihui 1:a607cd9655d7 40 #define BLE_ERROR_L2CAP_CID_IN_USE (NRF_L2CAP_ERR_BASE + 0x000) /**< CID already in use. */
yihui 1:a607cd9655d7 41 /** @} */
yihui 1:a607cd9655d7 42
yihui 1:a607cd9655d7 43 /**@brief Default L2CAP MTU. */
yihui 1:a607cd9655d7 44 #define BLE_L2CAP_MTU_DEF (23)
yihui 1:a607cd9655d7 45
yihui 1:a607cd9655d7 46 /**@brief Invalid Channel Identifier. */
yihui 1:a607cd9655d7 47 #define BLE_L2CAP_CID_INVALID (0x0000)
yihui 1:a607cd9655d7 48
yihui 1:a607cd9655d7 49 /**@brief Dynamic Channel Identifier base. */
yihui 1:a607cd9655d7 50 #define BLE_L2CAP_CID_DYN_BASE (0x0040)
yihui 1:a607cd9655d7 51
yihui 1:a607cd9655d7 52 /**@brief Maximum amount of dynamic CIDs. */
yihui 1:a607cd9655d7 53 #define BLE_L2CAP_CID_DYN_MAX (8)
yihui 1:a607cd9655d7 54
yihui 1:a607cd9655d7 55 /** @} */
yihui 1:a607cd9655d7 56
yihui 1:a607cd9655d7 57 /**@addtogroup BLE_L2CAP_STRUCTURES Structures
yihui 1:a607cd9655d7 58 * @{ */
yihui 1:a607cd9655d7 59
yihui 1:a607cd9655d7 60 /**@brief Packet header format for L2CAP transmission. */
yihui 1:a607cd9655d7 61 typedef struct
yihui 1:a607cd9655d7 62 {
yihui 1:a607cd9655d7 63 uint16_t len; /**< Length of valid info in data member. */
yihui 1:a607cd9655d7 64 uint16_t cid; /**< Channel ID on which packet is transmitted. */
yihui 1:a607cd9655d7 65 } ble_l2cap_header_t;
yihui 1:a607cd9655d7 66
yihui 1:a607cd9655d7 67 /**@brief L2CAP Event IDs. */
yihui 1:a607cd9655d7 68 enum BLE_L2CAP_EVTS
yihui 1:a607cd9655d7 69 {
yihui 1:a607cd9655d7 70 BLE_L2CAP_EVT_RX = BLE_L2CAP_EVT_BASE /**< L2CAP packet received. */
yihui 1:a607cd9655d7 71 };
yihui 1:a607cd9655d7 72
yihui 1:a607cd9655d7 73
yihui 1:a607cd9655d7 74 /**@brief L2CAP Received packet event report. */
yihui 1:a607cd9655d7 75 typedef struct
yihui 1:a607cd9655d7 76 {
yihui 1:a607cd9655d7 77 ble_l2cap_header_t header; /** L2CAP packet header. */
yihui 1:a607cd9655d7 78 uint8_t data[1]; /**< Packet data, variable length. */
yihui 1:a607cd9655d7 79 } ble_l2cap_evt_rx_t;
yihui 1:a607cd9655d7 80
yihui 1:a607cd9655d7 81
yihui 1:a607cd9655d7 82 /**@brief L2CAP event callback event structure. */
yihui 1:a607cd9655d7 83 typedef struct
yihui 1:a607cd9655d7 84 {
yihui 1:a607cd9655d7 85 uint16_t conn_handle; /**< Connection Handle on which event occured. */
yihui 1:a607cd9655d7 86 union
yihui 1:a607cd9655d7 87 {
yihui 1:a607cd9655d7 88 ble_l2cap_evt_rx_t rx; /**< RX Event parameters. */
yihui 1:a607cd9655d7 89 } params;
yihui 1:a607cd9655d7 90 } ble_l2cap_evt_t;
yihui 1:a607cd9655d7 91
yihui 1:a607cd9655d7 92
yihui 1:a607cd9655d7 93 /**@brief Register a CID with L2CAP.
yihui 1:a607cd9655d7 94 *
yihui 1:a607cd9655d7 95 * @details This registers a higher protocol layer with the L2CAP multiplexer, and is requried prior to all operations on the CID.
yihui 1:a607cd9655d7 96 *
yihui 1:a607cd9655d7 97 * @param[in] cid L2CAP CID.
yihui 1:a607cd9655d7 98 *
yihui 1:a607cd9655d7 99 * @return @ref NRF_SUCCESS Successfully registered a CID with the L2CAP layer.
yihui 1:a607cd9655d7 100 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CID must be above @ref BLE_L2CAP_CID_DYN_BASE.
yihui 1:a607cd9655d7 101 * @return @ref BLE_ERROR_L2CAP_CID_IN_USE L2CAP CID already in use.
yihui 1:a607cd9655d7 102 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
yihui 1:a607cd9655d7 103 */
yihui 1:a607cd9655d7 104 SVCALL(SD_BLE_L2CAP_CID_REGISTER, uint32_t, sd_ble_l2cap_cid_register(uint16_t cid));
yihui 1:a607cd9655d7 105
yihui 1:a607cd9655d7 106 /**@brief Unregister a CID with L2CAP.
yihui 1:a607cd9655d7 107 *
yihui 1:a607cd9655d7 108 * @details This unregisters a previously registerd higher protocol layer with the L2CAP multiplexer.
yihui 1:a607cd9655d7 109 *
yihui 1:a607cd9655d7 110 * @param[in] cid L2CAP CID.
yihui 1:a607cd9655d7 111 *
yihui 1:a607cd9655d7 112 * @return @ref NRF_SUCCESS Successfully unregistered the CID.
yihui 1:a607cd9655d7 113 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
yihui 1:a607cd9655d7 114 * @return @ref NRF_ERROR_NOT_FOUND CID not previously registered.
yihui 1:a607cd9655d7 115 */
yihui 1:a607cd9655d7 116 SVCALL(SD_BLE_L2CAP_CID_UNREGISTER, uint32_t, sd_ble_l2cap_cid_unregister(uint16_t cid));
yihui 1:a607cd9655d7 117
yihui 1:a607cd9655d7 118 /**@brief Transmit an L2CAP packet.
yihui 1:a607cd9655d7 119 *
yihui 1:a607cd9655d7 120 * @note It is important to note that a call to this function will <b>consume an application buffer</b>, and will therefore
yihui 1:a607cd9655d7 121 * generate a @ref BLE_EVT_TX_COMPLETE event when the packet has been transmitted.
yihui 1:a607cd9655d7 122 * Please see the documentation of @ref sd_ble_tx_buffer_count_get for more details.
yihui 1:a607cd9655d7 123 *
yihui 1:a607cd9655d7 124 * @param[in] conn_handle Connection Handle.
yihui 1:a607cd9655d7 125 * @param[in] p_header Pointer to a packet header containing length and CID.
yihui 1:a607cd9655d7 126 * @param[in] p_data Pointer to the data to be transmitted.
yihui 1:a607cd9655d7 127 *
yihui 1:a607cd9655d7 128 * @return @ref NRF_SUCCESS Successfully queued an L2CAP packet for transmission.
yihui 1:a607cd9655d7 129 * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
yihui 1:a607cd9655d7 130 * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, CIDs must be registered beforehand with @ref sd_ble_l2cap_cid_register.
yihui 1:a607cd9655d7 131 * @return @ref NRF_ERROR_NOT_FOUND CID not found.
yihui 1:a607cd9655d7 132 * @return @ref NRF_ERROR_NO_MEM Not enough memory to complete operation.
yihui 1:a607cd9655d7 133 * @return @ref BLE_ERROR_NO_TX_BUFFERS Not enough application buffers available.
yihui 1:a607cd9655d7 134 * @return @ref NRF_ERROR_DATA_SIZE Invalid data size(s) supplied, see @ref BLE_L2CAP_MTU_DEF.
yihui 1:a607cd9655d7 135 */
yihui 1:a607cd9655d7 136 SVCALL(SD_BLE_L2CAP_TX, uint32_t, sd_ble_l2cap_tx(uint16_t conn_handle, ble_l2cap_header_t const * const p_header, uint8_t const * const p_data));
yihui 1:a607cd9655d7 137
yihui 1:a607cd9655d7 138 /** @} */
yihui 1:a607cd9655d7 139
yihui 1:a607cd9655d7 140 #endif // BLE_L2CAP_H__
yihui 1:a607cd9655d7 141
yihui 1:a607cd9655d7 142 /**
yihui 1:a607cd9655d7 143 @}
yihui 1:a607cd9655d7 144 */