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_hrs Heart Rate Service
yihui 1:a607cd9655d7 16 * @{
yihui 1:a607cd9655d7 17 * @ingroup ble_sdk_srv
yihui 1:a607cd9655d7 18 * @brief Heart Rate Service module.
yihui 1:a607cd9655d7 19 *
yihui 1:a607cd9655d7 20 * @details This module implements the Heart Rate Service with the Heart Rate Measurement,
yihui 1:a607cd9655d7 21 * Body Sensor Location and Heart Rate Control Point characteristics.
yihui 1:a607cd9655d7 22 * During initialization it adds the Heart Rate Service and Heart Rate Measurement
yihui 1:a607cd9655d7 23 * characteristic to the BLE stack database. Optionally it also adds the
yihui 1:a607cd9655d7 24 * Body Sensor Location and Heart Rate Control Point characteristics.
yihui 1:a607cd9655d7 25 *
yihui 1:a607cd9655d7 26 * If enabled, notification of the Heart Rate Measurement characteristic is performed
yihui 1:a607cd9655d7 27 * when the application calls ble_hrs_heart_rate_measurement_send().
yihui 1:a607cd9655d7 28 *
yihui 1:a607cd9655d7 29 * The Heart Rate Service also provides a set of functions for manipulating the
yihui 1:a607cd9655d7 30 * various fields in the Heart Rate Measurement characteristic, as well as setting
yihui 1:a607cd9655d7 31 * the Body Sensor Location characteristic value.
yihui 1:a607cd9655d7 32 *
yihui 1:a607cd9655d7 33 * If an event handler is supplied by the application, the Heart Rate Service will
yihui 1:a607cd9655d7 34 * generate Heart Rate Service events to the application.
yihui 1:a607cd9655d7 35 *
yihui 1:a607cd9655d7 36 * @note The application must propagate BLE stack events to the Heart Rate Service module by calling
yihui 1:a607cd9655d7 37 * ble_hrs_on_ble_evt() from the from the @ref ble_stack_handler callback.
yihui 1:a607cd9655d7 38 *
yihui 1:a607cd9655d7 39 * @note Attention!
yihui 1:a607cd9655d7 40 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
yihui 1:a607cd9655d7 41 * qualification listings, this section of source code must not be modified.
yihui 1:a607cd9655d7 42 */
yihui 1:a607cd9655d7 43
yihui 1:a607cd9655d7 44 #ifndef BLE_HRS_H__
yihui 1:a607cd9655d7 45 #define BLE_HRS_H__
yihui 1:a607cd9655d7 46
yihui 1:a607cd9655d7 47 #include <stdint.h>
yihui 1:a607cd9655d7 48 #include <stdbool.h>
yihui 1:a607cd9655d7 49 #include "ble.h"
yihui 1:a607cd9655d7 50 #include "ble_srv_common.h"
yihui 1:a607cd9655d7 51
yihui 1:a607cd9655d7 52 // Body Sensor Location values
yihui 1:a607cd9655d7 53 #define BLE_HRS_BODY_SENSOR_LOCATION_OTHER 0
yihui 1:a607cd9655d7 54 #define BLE_HRS_BODY_SENSOR_LOCATION_CHEST 1
yihui 1:a607cd9655d7 55 #define BLE_HRS_BODY_SENSOR_LOCATION_WRIST 2
yihui 1:a607cd9655d7 56 #define BLE_HRS_BODY_SENSOR_LOCATION_FINGER 3
yihui 1:a607cd9655d7 57 #define BLE_HRS_BODY_SENSOR_LOCATION_HAND 4
yihui 1:a607cd9655d7 58 #define BLE_HRS_BODY_SENSOR_LOCATION_EAR_LOBE 5
yihui 1:a607cd9655d7 59 #define BLE_HRS_BODY_SENSOR_LOCATION_FOOT 6
yihui 1:a607cd9655d7 60
yihui 1:a607cd9655d7 61 #define BLE_HRS_MAX_BUFFERED_RR_INTERVALS 20 /**< Size of RR Interval buffer inside service. */
yihui 1:a607cd9655d7 62
yihui 1:a607cd9655d7 63 /**@brief Heart Rate Service event type. */
yihui 1:a607cd9655d7 64 typedef enum
yihui 1:a607cd9655d7 65 {
yihui 1:a607cd9655d7 66 BLE_HRS_EVT_NOTIFICATION_ENABLED, /**< Heart Rate value notification enabled event. */
yihui 1:a607cd9655d7 67 BLE_HRS_EVT_NOTIFICATION_DISABLED /**< Heart Rate value notification disabled event. */
yihui 1:a607cd9655d7 68 } ble_hrs_evt_type_t;
yihui 1:a607cd9655d7 69
yihui 1:a607cd9655d7 70 /**@brief Heart Rate Service event. */
yihui 1:a607cd9655d7 71 typedef struct
yihui 1:a607cd9655d7 72 {
yihui 1:a607cd9655d7 73 ble_hrs_evt_type_t evt_type; /**< Type of event. */
yihui 1:a607cd9655d7 74 } ble_hrs_evt_t;
yihui 1:a607cd9655d7 75
yihui 1:a607cd9655d7 76 // Forward declaration of the ble_hrs_t type.
yihui 1:a607cd9655d7 77 typedef struct ble_hrs_s ble_hrs_t;
yihui 1:a607cd9655d7 78
yihui 1:a607cd9655d7 79 /**@brief Heart Rate Service event handler type. */
yihui 1:a607cd9655d7 80 typedef void (*ble_hrs_evt_handler_t) (ble_hrs_t * p_hrs, ble_hrs_evt_t * p_evt);
yihui 1:a607cd9655d7 81
yihui 1:a607cd9655d7 82 /**@brief Heart Rate Service init structure. This contains all options and data needed for
yihui 1:a607cd9655d7 83 * initialization of the service. */
yihui 1:a607cd9655d7 84 typedef struct
yihui 1:a607cd9655d7 85 {
yihui 1:a607cd9655d7 86 ble_hrs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Heart Rate Service. */
yihui 1:a607cd9655d7 87 bool is_sensor_contact_supported; /**< Determines if sensor contact detection is to be supported. */
yihui 1:a607cd9655d7 88 uint8_t * p_body_sensor_location; /**< If not NULL, initial value of the Body Sensor Location characteristic. */
yihui 1:a607cd9655d7 89 ble_srv_cccd_security_mode_t hrs_hrm_attr_md; /**< Initial security level for heart rate service measurement attribute */
yihui 1:a607cd9655d7 90 ble_srv_security_mode_t hrs_bsl_attr_md; /**< Initial security level for body sensor location attribute */
yihui 1:a607cd9655d7 91 } ble_hrs_init_t;
yihui 1:a607cd9655d7 92
yihui 1:a607cd9655d7 93 /**@brief Heart Rate Service structure. This contains various status information for the service. */
yihui 1:a607cd9655d7 94 typedef struct ble_hrs_s
yihui 1:a607cd9655d7 95 {
yihui 1:a607cd9655d7 96 ble_hrs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Heart Rate Service. */
yihui 1:a607cd9655d7 97 bool is_expended_energy_supported; /**< TRUE if Expended Energy measurement is supported. */
yihui 1:a607cd9655d7 98 bool is_sensor_contact_supported; /**< TRUE if sensor contact detection is supported. */
yihui 1:a607cd9655d7 99 uint16_t service_handle; /**< Handle of Heart Rate Service (as provided by the BLE stack). */
yihui 1:a607cd9655d7 100 ble_gatts_char_handles_t hrm_handles; /**< Handles related to the Heart Rate Measurement characteristic. */
yihui 1:a607cd9655d7 101 ble_gatts_char_handles_t bsl_handles; /**< Handles related to the Body Sensor Location characteristic. */
yihui 1:a607cd9655d7 102 ble_gatts_char_handles_t hrcp_handles; /**< Handles related to the Heart Rate Control Point characteristic. */
yihui 1:a607cd9655d7 103 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 104 bool is_sensor_contact_detected; /**< TRUE if sensor contact has been detected. */
yihui 1:a607cd9655d7 105 uint16_t rr_interval[BLE_HRS_MAX_BUFFERED_RR_INTERVALS]; /**< Set of RR Interval measurements since the last Heart Rate Measurement transmission. */
yihui 1:a607cd9655d7 106 uint16_t rr_interval_count; /**< Number of RR Interval measurements since the last Heart Rate Measurement transmission. */
yihui 1:a607cd9655d7 107 } ble_hrs_t;
yihui 1:a607cd9655d7 108
yihui 1:a607cd9655d7 109 /**@brief Function for initializing the Heart Rate Service.
yihui 1:a607cd9655d7 110 *
yihui 1:a607cd9655d7 111 * @param[out] p_hrs Heart Rate Service structure. This structure will have to be supplied by
yihui 1:a607cd9655d7 112 * the application. It will be initialized by this function, and will later
yihui 1:a607cd9655d7 113 * be used to identify this particular service instance.
yihui 1:a607cd9655d7 114 * @param[in] p_hrs_init Information needed to initialize the service.
yihui 1:a607cd9655d7 115 *
yihui 1:a607cd9655d7 116 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
yihui 1:a607cd9655d7 117 */
yihui 1:a607cd9655d7 118 uint32_t ble_hrs_init(ble_hrs_t * p_hrs, const ble_hrs_init_t * p_hrs_init);
yihui 1:a607cd9655d7 119
yihui 1:a607cd9655d7 120 /**@brief Function for handling the Application's BLE Stack events.
yihui 1:a607cd9655d7 121 *
yihui 1:a607cd9655d7 122 * @details Handles all events from the BLE stack of interest to the Heart Rate Service.
yihui 1:a607cd9655d7 123 *
yihui 1:a607cd9655d7 124 * @param[in] p_hrs Heart Rate Service structure.
yihui 1:a607cd9655d7 125 * @param[in] p_ble_evt Event received from the BLE stack.
yihui 1:a607cd9655d7 126 */
yihui 1:a607cd9655d7 127 void ble_hrs_on_ble_evt(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt);
yihui 1:a607cd9655d7 128
yihui 1:a607cd9655d7 129 /**@brief Function for sending heart rate measurement if notification has been enabled.
yihui 1:a607cd9655d7 130 *
yihui 1:a607cd9655d7 131 * @details The application calls this function after having performed a heart rate measurement.
yihui 1:a607cd9655d7 132 * If notification has been enabled, the heart rate measurement data is encoded and sent to
yihui 1:a607cd9655d7 133 * the client.
yihui 1:a607cd9655d7 134 *
yihui 1:a607cd9655d7 135 * @param[in] p_hrs Heart Rate Service structure.
yihui 1:a607cd9655d7 136 * @param[in] heart_rate New heart rate measurement.
yihui 1:a607cd9655d7 137 * @param[in] include_expended_energy Determines if expended energy will be included in the
yihui 1:a607cd9655d7 138 * heart rate measurement data.
yihui 1:a607cd9655d7 139 *
yihui 1:a607cd9655d7 140 * @return NRF_SUCCESS on success, otherwise an error code.
yihui 1:a607cd9655d7 141 */
yihui 1:a607cd9655d7 142 uint32_t ble_hrs_heart_rate_measurement_send(ble_hrs_t * p_hrs, uint16_t heart_rate);
yihui 1:a607cd9655d7 143
yihui 1:a607cd9655d7 144 /**@brief Function for adding a RR Interval measurement to the RR Interval buffer.
yihui 1:a607cd9655d7 145 *
yihui 1:a607cd9655d7 146 * @details All buffered RR Interval measurements will be included in the next heart rate
yihui 1:a607cd9655d7 147 * measurement message, up to the maximum number of measurements that will fit into the
yihui 1:a607cd9655d7 148 * message. If the buffer is full, the oldest measurement in the buffer will be deleted.
yihui 1:a607cd9655d7 149 *
yihui 1:a607cd9655d7 150 * @param[in] p_hrs Heart Rate Service structure.
yihui 1:a607cd9655d7 151 * @param[in] rr_interval New RR Interval measurement (will be buffered until the next
yihui 1:a607cd9655d7 152 * transmission of Heart Rate Measurement).
yihui 1:a607cd9655d7 153 */
yihui 1:a607cd9655d7 154 void ble_hrs_rr_interval_add(ble_hrs_t * p_hrs, uint16_t rr_interval);
yihui 1:a607cd9655d7 155
yihui 1:a607cd9655d7 156 /**@brief Function for checking if RR Interval buffer is full.
yihui 1:a607cd9655d7 157 *
yihui 1:a607cd9655d7 158 * @param[in] p_hrs Heart Rate Service structure.
yihui 1:a607cd9655d7 159 *
yihui 1:a607cd9655d7 160 * @return true if RR Interval buffer is full, false otherwise.
yihui 1:a607cd9655d7 161 */
yihui 1:a607cd9655d7 162 bool ble_hrs_rr_interval_buffer_is_full(ble_hrs_t * p_hrs);
yihui 1:a607cd9655d7 163
yihui 1:a607cd9655d7 164 /**@brief Function for setting the state of the Sensor Contact Supported bit.
yihui 1:a607cd9655d7 165 *
yihui 1:a607cd9655d7 166 * @param[in] p_hrs Heart Rate Service structure.
yihui 1:a607cd9655d7 167 * @param[in] is_sensor_contact_supported New state of the Sensor Contact Supported bit.
yihui 1:a607cd9655d7 168 *
yihui 1:a607cd9655d7 169 * @return NRF_SUCCESS on success, otherwise an error code.
yihui 1:a607cd9655d7 170 */
yihui 1:a607cd9655d7 171 uint32_t ble_hrs_sensor_contact_supported_set(ble_hrs_t * p_hrs, bool is_sensor_contact_supported);
yihui 1:a607cd9655d7 172
yihui 1:a607cd9655d7 173 /**@brief Function for setting the state of the Sensor Contact Detected bit.
yihui 1:a607cd9655d7 174 *
yihui 1:a607cd9655d7 175 * @param[in] p_hrs Heart Rate Service structure.
yihui 1:a607cd9655d7 176 * @param[in] is_sensor_contact_detected TRUE if sensor contact is detected, FALSE otherwise.
yihui 1:a607cd9655d7 177 */
yihui 1:a607cd9655d7 178 void ble_hrs_sensor_contact_detected_update(ble_hrs_t * p_hrs, bool is_sensor_contact_detected);
yihui 1:a607cd9655d7 179
yihui 1:a607cd9655d7 180 /**@brief Function for setting the Body Sensor Location.
yihui 1:a607cd9655d7 181 *
yihui 1:a607cd9655d7 182 * @details Sets a new value of the Body Sensor Location characteristic. The new value will be sent
yihui 1:a607cd9655d7 183 * to the client the next time the client reads the Body Sensor Location characteristic.
yihui 1:a607cd9655d7 184 *
yihui 1:a607cd9655d7 185 * @param[in] p_hrs Heart Rate Service structure.
yihui 1:a607cd9655d7 186 * @param[in] body_sensor_location New Body Sensor Location.
yihui 1:a607cd9655d7 187 *
yihui 1:a607cd9655d7 188 * @return NRF_SUCCESS on success, otherwise an error code.
yihui 1:a607cd9655d7 189 */
yihui 1:a607cd9655d7 190 uint32_t ble_hrs_body_sensor_location_set(ble_hrs_t * p_hrs, uint8_t body_sensor_location);
yihui 1:a607cd9655d7 191
yihui 1:a607cd9655d7 192 #endif // BLE_HRS_H__
yihui 1:a607cd9655d7 193
yihui 1:a607cd9655d7 194 /** @} */