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) 2012 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 ble_sdk_srv_bas Battery Service
yihui 1:a607cd9655d7 16 * @{
yihui 1:a607cd9655d7 17 * @ingroup ble_sdk_srv
yihui 1:a607cd9655d7 18 * @brief Battery Service module.
yihui 1:a607cd9655d7 19 *
yihui 1:a607cd9655d7 20 * @details This module implements the Battery Service with the Battery Level characteristic.
yihui 1:a607cd9655d7 21 * During initialization it adds the Battery Service and Battery Level characteristic
yihui 1:a607cd9655d7 22 * to the BLE stack database. Optionally it can also add a Report Reference descriptor
yihui 1:a607cd9655d7 23 * to the Battery Level characteristic (used when including the Battery Service in
yihui 1:a607cd9655d7 24 * the HID service).
yihui 1:a607cd9655d7 25 *
yihui 1:a607cd9655d7 26 * If specified, the module will support notification of the Battery Level characteristic
yihui 1:a607cd9655d7 27 * through the ble_bas_battery_level_update() function.
yihui 1:a607cd9655d7 28 * If an event handler is supplied by the application, the Battery Service will
yihui 1:a607cd9655d7 29 * generate Battery Service events to the application.
yihui 1:a607cd9655d7 30 *
yihui 1:a607cd9655d7 31 * @note The application must propagate BLE stack events to the Battery Service module by calling
yihui 1:a607cd9655d7 32 * ble_bas_on_ble_evt() from the from the @ref ble_stack_handler callback.
yihui 1:a607cd9655d7 33 *
yihui 1:a607cd9655d7 34 * @note Attention!
yihui 1:a607cd9655d7 35 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
yihui 1:a607cd9655d7 36 * qualification listings, this section of source code must not be modified.
yihui 1:a607cd9655d7 37 */
yihui 1:a607cd9655d7 38
yihui 1:a607cd9655d7 39 #ifndef BLE_BAS_H__
yihui 1:a607cd9655d7 40 #define BLE_BAS_H__
yihui 1:a607cd9655d7 41
yihui 1:a607cd9655d7 42 #include <stdint.h>
yihui 1:a607cd9655d7 43 #include <stdbool.h>
yihui 1:a607cd9655d7 44 #include "ble.h"
yihui 1:a607cd9655d7 45 #include "ble_srv_common.h"
yihui 1:a607cd9655d7 46
yihui 1:a607cd9655d7 47 /**@brief Battery Service event type. */
yihui 1:a607cd9655d7 48 typedef enum
yihui 1:a607cd9655d7 49 {
yihui 1:a607cd9655d7 50 BLE_BAS_EVT_NOTIFICATION_ENABLED, /**< Battery value notification enabled event. */
yihui 1:a607cd9655d7 51 BLE_BAS_EVT_NOTIFICATION_DISABLED /**< Battery value notification disabled event. */
yihui 1:a607cd9655d7 52 } ble_bas_evt_type_t;
yihui 1:a607cd9655d7 53
yihui 1:a607cd9655d7 54 /**@brief Battery Service event. */
yihui 1:a607cd9655d7 55 typedef struct
yihui 1:a607cd9655d7 56 {
yihui 1:a607cd9655d7 57 ble_bas_evt_type_t evt_type; /**< Type of event. */
yihui 1:a607cd9655d7 58 } ble_bas_evt_t;
yihui 1:a607cd9655d7 59
yihui 1:a607cd9655d7 60 // Forward declaration of the ble_bas_t type.
yihui 1:a607cd9655d7 61 typedef struct ble_bas_s ble_bas_t;
yihui 1:a607cd9655d7 62
yihui 1:a607cd9655d7 63 /**@brief Battery Service event handler type. */
yihui 1:a607cd9655d7 64 typedef void (*ble_bas_evt_handler_t) (ble_bas_t * p_bas, ble_bas_evt_t * p_evt);
yihui 1:a607cd9655d7 65
yihui 1:a607cd9655d7 66 /**@brief Battery Service init structure. This contains all options and data needed for
yihui 1:a607cd9655d7 67 * initialization of the service.*/
yihui 1:a607cd9655d7 68 typedef struct
yihui 1:a607cd9655d7 69 {
yihui 1:a607cd9655d7 70 ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */
yihui 1:a607cd9655d7 71 bool support_notification; /**< TRUE if notification of Battery Level measurement is supported. */
yihui 1:a607cd9655d7 72 ble_srv_report_ref_t * p_report_ref; /**< If not NULL, a Report Reference descriptor with the specified value will be added to the Battery Level characteristic */
yihui 1:a607cd9655d7 73 uint8_t initial_batt_level; /**< Initial battery level */
yihui 1:a607cd9655d7 74 ble_srv_cccd_security_mode_t battery_level_char_attr_md; /**< Initial security level for battery characteristics attribute */
yihui 1:a607cd9655d7 75 ble_gap_conn_sec_mode_t battery_level_report_read_perm; /**< Initial security level for battery report read attribute */
yihui 1:a607cd9655d7 76 } ble_bas_init_t;
yihui 1:a607cd9655d7 77
yihui 1:a607cd9655d7 78 /**@brief Battery Service structure. This contains various status information for the service. */
yihui 1:a607cd9655d7 79 typedef struct ble_bas_s
yihui 1:a607cd9655d7 80 {
yihui 1:a607cd9655d7 81 ble_bas_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Battery Service. */
yihui 1:a607cd9655d7 82 uint16_t service_handle; /**< Handle of Battery Service (as provided by the BLE stack). */
yihui 1:a607cd9655d7 83 ble_gatts_char_handles_t battery_level_handles; /**< Handles related to the Battery Level characteristic. */
yihui 1:a607cd9655d7 84 uint16_t report_ref_handle; /**< Handle of the Report Reference descriptor. */
yihui 1:a607cd9655d7 85 uint8_t battery_level_last; /**< Last Battery Level measurement passed to the Battery Service. */
yihui 1:a607cd9655d7 86 uint16_t conn_handle; /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
yihui 1:a607cd9655d7 87 bool is_notification_supported; /**< TRUE if notification of Battery Level is supported. */
yihui 1:a607cd9655d7 88 } ble_bas_t;
yihui 1:a607cd9655d7 89
yihui 1:a607cd9655d7 90 /**@brief Function for initializing the Battery Service.
yihui 1:a607cd9655d7 91 *
yihui 1:a607cd9655d7 92 * @param[out] p_bas Battery Service structure. This structure will have to be supplied by
yihui 1:a607cd9655d7 93 * the application. It will be initialized by this function, and will later
yihui 1:a607cd9655d7 94 * be used to identify this particular service instance.
yihui 1:a607cd9655d7 95 * @param[in] p_bas_init Information needed to initialize the service.
yihui 1:a607cd9655d7 96 *
yihui 1:a607cd9655d7 97 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
yihui 1:a607cd9655d7 98 */
yihui 1:a607cd9655d7 99 uint32_t ble_bas_init(ble_bas_t * p_bas, const ble_bas_init_t * p_bas_init);
yihui 1:a607cd9655d7 100
yihui 1:a607cd9655d7 101 /**@brief Function for handling the Application's BLE Stack events.
yihui 1:a607cd9655d7 102 *
yihui 1:a607cd9655d7 103 * @details Handles all events from the BLE stack of interest to the Battery Service.
yihui 1:a607cd9655d7 104 *
yihui 1:a607cd9655d7 105 * @note For the requirements in the BAS specification to be fulfilled,
yihui 1:a607cd9655d7 106 * ble_bas_battery_level_update() must be called upon reconnection if the
yihui 1:a607cd9655d7 107 * battery level has changed while the service has been disconnected from a bonded
yihui 1:a607cd9655d7 108 * client.
yihui 1:a607cd9655d7 109 *
yihui 1:a607cd9655d7 110 * @param[in] p_bas Battery Service structure.
yihui 1:a607cd9655d7 111 * @param[in] p_ble_evt Event received from the BLE stack.
yihui 1:a607cd9655d7 112 */
yihui 1:a607cd9655d7 113 void ble_bas_on_ble_evt(ble_bas_t * p_bas, ble_evt_t * p_ble_evt);
yihui 1:a607cd9655d7 114
yihui 1:a607cd9655d7 115 /**@brief Function for updating the battery level.
yihui 1:a607cd9655d7 116 *
yihui 1:a607cd9655d7 117 * @details The application calls this function after having performed a battery measurement. If
yihui 1:a607cd9655d7 118 * notification has been enabled, the battery level characteristic is sent to the client.
yihui 1:a607cd9655d7 119 *
yihui 1:a607cd9655d7 120 * @note For the requirements in the BAS specification to be fulfilled,
yihui 1:a607cd9655d7 121 * this function must be called upon reconnection if the battery level has changed
yihui 1:a607cd9655d7 122 * while the service has been disconnected from a bonded client.
yihui 1:a607cd9655d7 123 *
yihui 1:a607cd9655d7 124 * @param[in] p_bas Battery Service structure.
yihui 1:a607cd9655d7 125 * @param[in] battery_level New battery measurement value (in percent of full capacity).
yihui 1:a607cd9655d7 126 *
yihui 1:a607cd9655d7 127 * @return NRF_SUCCESS on success, otherwise an error code.
yihui 1:a607cd9655d7 128 */
yihui 1:a607cd9655d7 129 uint32_t ble_bas_battery_level_update(ble_bas_t * p_bas, uint8_t battery_level);
yihui 1:a607cd9655d7 130
yihui 1:a607cd9655d7 131 #endif // BLE_BAS_H__
yihui 1:a607cd9655d7 132
yihui 1:a607cd9655d7 133 /** @} */