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 /*
yihui 1:a607cd9655d7 2 * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
yihui 1:a607cd9655d7 3 *
yihui 1:a607cd9655d7 4 * The information contained herein is confidential property of Nordic Semiconductor. The use,
yihui 1:a607cd9655d7 5 * copying, transfer or disclosure of such information is prohibited except by express written
yihui 1:a607cd9655d7 6 * agreement with Nordic Semiconductor.
yihui 1:a607cd9655d7 7 *
yihui 1:a607cd9655d7 8 */
yihui 1:a607cd9655d7 9
yihui 1:a607cd9655d7 10 /**@file
yihui 1:a607cd9655d7 11 *
yihui 1:a607cd9655d7 12 * @defgroup ble_sdk_srv_hrs_c Heart Rate Service Client
yihui 1:a607cd9655d7 13 * @{
yihui 1:a607cd9655d7 14 * @ingroup ble_sdk_srv
yihui 1:a607cd9655d7 15 * @brief Heart Rate Service Client module.
yihui 1:a607cd9655d7 16 *
yihui 1:a607cd9655d7 17 * @details This module contains the APIs and types exposed by the Heart Rate Service Client
yihui 1:a607cd9655d7 18 * module. These APIs and types can be used by the application to perform discovery of
yihui 1:a607cd9655d7 19 * Heart Rate Service at the peer and interact with it.
yihui 1:a607cd9655d7 20 *
yihui 1:a607cd9655d7 21 * @warning Currently this module only has support for Heart Rate Measurement characteristic. This
yihui 1:a607cd9655d7 22 * means that it will be able to enable notification of the characteristic at the peer and
yihui 1:a607cd9655d7 23 * be able to receive Heart Rate Measurement notifications from the peer. It does not
yihui 1:a607cd9655d7 24 * support the Body Sensor Location and the Heart Rate Control Point characteristics.
yihui 1:a607cd9655d7 25 * When a Heart Rate Measurement is received, this module will decode only the
yihui 1:a607cd9655d7 26 * Heart Rate Measurement Value (both 8 bit and 16 bit) field from it and provide it to
yihui 1:a607cd9655d7 27 * the application.
yihui 1:a607cd9655d7 28 *
yihui 1:a607cd9655d7 29 * @note The application must propagate BLE stack events to this module by calling
yihui 1:a607cd9655d7 30 * ble_hrs_c_on_ble_evt().
yihui 1:a607cd9655d7 31 *
yihui 1:a607cd9655d7 32 */
yihui 1:a607cd9655d7 33
yihui 1:a607cd9655d7 34 #ifndef BLE_HRS_C_H__
yihui 1:a607cd9655d7 35 #define BLE_HRS_C_H__
yihui 1:a607cd9655d7 36
yihui 1:a607cd9655d7 37 #include <stdint.h>
yihui 1:a607cd9655d7 38 #include "ble.h"
yihui 1:a607cd9655d7 39
yihui 1:a607cd9655d7 40 /**
yihui 1:a607cd9655d7 41 * @defgroup hrs_c_enums Enumerations
yihui 1:a607cd9655d7 42 * @{
yihui 1:a607cd9655d7 43 */
yihui 1:a607cd9655d7 44
yihui 1:a607cd9655d7 45 /**@brief HRS Client event type. */
yihui 1:a607cd9655d7 46 typedef enum
yihui 1:a607cd9655d7 47 {
yihui 1:a607cd9655d7 48 BLE_HRS_C_EVT_DISCOVERY_COMPLETE = 1, /**< Event indicating that the Heart Rate Service has been discovered at the peer. */
yihui 1:a607cd9655d7 49 BLE_HRS_C_EVT_HRM_NOTIFICATION /**< Event indicating that a notification of the Heart Rate Measurement characteristic has been received from the peer. */
yihui 1:a607cd9655d7 50 } ble_hrs_c_evt_type_t;
yihui 1:a607cd9655d7 51
yihui 1:a607cd9655d7 52 /** @} */
yihui 1:a607cd9655d7 53
yihui 1:a607cd9655d7 54 /**
yihui 1:a607cd9655d7 55 * @defgroup hrs_c_structs Structures
yihui 1:a607cd9655d7 56 * @{
yihui 1:a607cd9655d7 57 */
yihui 1:a607cd9655d7 58
yihui 1:a607cd9655d7 59 /**@brief Structure containing the heart rate measurement received from the peer. */
yihui 1:a607cd9655d7 60 typedef struct
yihui 1:a607cd9655d7 61 {
yihui 1:a607cd9655d7 62 uint16_t hr_value; /**< Heart Rate Value. */
yihui 1:a607cd9655d7 63 } ble_hrm_t;
yihui 1:a607cd9655d7 64
yihui 1:a607cd9655d7 65 /**@brief Heart Rate Event structure. */
yihui 1:a607cd9655d7 66 typedef struct
yihui 1:a607cd9655d7 67 {
yihui 1:a607cd9655d7 68 ble_hrs_c_evt_type_t evt_type; /**< Type of the event. */
yihui 1:a607cd9655d7 69 union
yihui 1:a607cd9655d7 70 {
yihui 1:a607cd9655d7 71 ble_hrm_t hrm; /**< Heart rate measurement received. This will be filled if the evt_type is @ref BLE_HRS_C_EVT_HRM_NOTIFICATION. */
yihui 1:a607cd9655d7 72 } params;
yihui 1:a607cd9655d7 73 } ble_hrs_c_evt_t;
yihui 1:a607cd9655d7 74
yihui 1:a607cd9655d7 75 /** @} */
yihui 1:a607cd9655d7 76
yihui 1:a607cd9655d7 77 /**
yihui 1:a607cd9655d7 78 * @defgroup hrs_c_types Types
yihui 1:a607cd9655d7 79 * @{
yihui 1:a607cd9655d7 80 */
yihui 1:a607cd9655d7 81
yihui 1:a607cd9655d7 82 // Forward declaration of the ble_bas_t type.
yihui 1:a607cd9655d7 83 typedef struct ble_hrs_c_s ble_hrs_c_t;
yihui 1:a607cd9655d7 84
yihui 1:a607cd9655d7 85 /**@brief Event handler type.
yihui 1:a607cd9655d7 86 *
yihui 1:a607cd9655d7 87 * @details This is the type of the event handler that should be provided by the application
yihui 1:a607cd9655d7 88 * of this module in order to receive events.
yihui 1:a607cd9655d7 89 */
yihui 1:a607cd9655d7 90 typedef void (* ble_hrs_c_evt_handler_t) (ble_hrs_c_t * p_ble_hrs_c, ble_hrs_c_evt_t * p_evt);
yihui 1:a607cd9655d7 91
yihui 1:a607cd9655d7 92 /** @} */
yihui 1:a607cd9655d7 93
yihui 1:a607cd9655d7 94 /**
yihui 1:a607cd9655d7 95 * @addtogroup hrs_c_structs
yihui 1:a607cd9655d7 96 * @{
yihui 1:a607cd9655d7 97 */
yihui 1:a607cd9655d7 98
yihui 1:a607cd9655d7 99 /**@brief Heart Rate Client structure.
yihui 1:a607cd9655d7 100 */
yihui 1:a607cd9655d7 101 typedef struct ble_hrs_c_s
yihui 1:a607cd9655d7 102 {
yihui 1:a607cd9655d7 103 uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */
yihui 1:a607cd9655d7 104 uint16_t hrm_cccd_handle; /**< Handle of the CCCD of the Heart Rate Measurement characteristic. */
yihui 1:a607cd9655d7 105 uint16_t hrm_handle; /**< Handle of the Heart Rate Measurement characteristic as provided by the SoftDevice. */
yihui 1:a607cd9655d7 106 ble_hrs_c_evt_handler_t evt_handler; /**< Application event handler to be called when there is an event related to the heart rate service. */
yihui 1:a607cd9655d7 107 } ble_hrs_c_t;
yihui 1:a607cd9655d7 108
yihui 1:a607cd9655d7 109 /**@brief Heart Rate Client initialization structure.
yihui 1:a607cd9655d7 110 */
yihui 1:a607cd9655d7 111 typedef struct
yihui 1:a607cd9655d7 112 {
yihui 1:a607cd9655d7 113 ble_hrs_c_evt_handler_t evt_handler; /**< Event handler to be called by the Heart Rate Client module whenever there is an event related to the Heart Rate Service. */
yihui 1:a607cd9655d7 114 } ble_hrs_c_init_t;
yihui 1:a607cd9655d7 115
yihui 1:a607cd9655d7 116 /** @} */
yihui 1:a607cd9655d7 117
yihui 1:a607cd9655d7 118 /**
yihui 1:a607cd9655d7 119 * @defgroup hrs_c_functions Functions
yihui 1:a607cd9655d7 120 * @{
yihui 1:a607cd9655d7 121 */
yihui 1:a607cd9655d7 122
yihui 1:a607cd9655d7 123 /**@brief Function for initializing the heart rate client module.
yihui 1:a607cd9655d7 124 *
yihui 1:a607cd9655d7 125 * @details This function will register with the DB Discovery module. There it
yihui 1:a607cd9655d7 126 * registers for the Heart Rate Service. Doing so will make the DB Discovery
yihui 1:a607cd9655d7 127 * module look for the presence of a Heart Rate Service instance at the peer when a
yihui 1:a607cd9655d7 128 * discovery is started.
yihui 1:a607cd9655d7 129 *
yihui 1:a607cd9655d7 130 * @param[in] p_ble_hrs_c Pointer to the heart rate client structure.
yihui 1:a607cd9655d7 131 * @param[in] p_ble_hrs_c_init Pointer to the heart rate initialization structure containing the
yihui 1:a607cd9655d7 132 * initialization information.
yihui 1:a607cd9655d7 133 *
yihui 1:a607cd9655d7 134 * @retval NRF_SUCCESS On successful initialization. Otherwise an error code. This function
yihui 1:a607cd9655d7 135 * propagates the error code returned by the Database Discovery module API
yihui 1:a607cd9655d7 136 * @ref ble_db_discovery_evt_register.
yihui 1:a607cd9655d7 137 */
yihui 1:a607cd9655d7 138 uint32_t ble_hrs_c_init(ble_hrs_c_t * p_ble_hrs_c, ble_hrs_c_init_t * p_ble_hrs_c_init);
yihui 1:a607cd9655d7 139
yihui 1:a607cd9655d7 140 /**@brief Function for handling BLE events from the SoftDevice.
yihui 1:a607cd9655d7 141 *
yihui 1:a607cd9655d7 142 * @details This function will handle the BLE events received from the SoftDevice. If a BLE
yihui 1:a607cd9655d7 143 * event is relevant to the Heart Rate Client module, then it uses it to update
yihui 1:a607cd9655d7 144 * interval variables and, if necessary, send events to the application.
yihui 1:a607cd9655d7 145 *
yihui 1:a607cd9655d7 146 * @param[in] p_ble_hrs_c Pointer to the heart rate client structure.
yihui 1:a607cd9655d7 147 * @param[in] p_ble_evt Pointer to the BLE event.
yihui 1:a607cd9655d7 148 */
yihui 1:a607cd9655d7 149 void ble_hrs_c_on_ble_evt(ble_hrs_c_t * p_ble_hrs_c, const ble_evt_t * p_ble_evt);
yihui 1:a607cd9655d7 150
yihui 1:a607cd9655d7 151
yihui 1:a607cd9655d7 152 /**@brief Function for requesting the peer to start sending notification of Heart Rate
yihui 1:a607cd9655d7 153 * Measurement.
yihui 1:a607cd9655d7 154 *
yihui 1:a607cd9655d7 155 * @details This function will enable to notification of the Heart Rate Measurement at the peer
yihui 1:a607cd9655d7 156 * by writing to the CCCD of the Heart Rate Measurement Characteristic.
yihui 1:a607cd9655d7 157 *
yihui 1:a607cd9655d7 158 * @param p_ble_hrs_c Pointer to the heart rate client structure.
yihui 1:a607cd9655d7 159 *
yihui 1:a607cd9655d7 160 * @retval NRF_SUCCESS If the SoftDevice has been requested to write to the CCCD of the peer.
yihui 1:a607cd9655d7 161 * Otherwise, an error code. This function propagates the error code returned
yihui 1:a607cd9655d7 162 * by the SoftDevice API @ref sd_ble_gattc_write.
yihui 1:a607cd9655d7 163 */
yihui 1:a607cd9655d7 164 uint32_t ble_hrs_c_hrm_notif_enable(ble_hrs_c_t * p_ble_hrs_c);
yihui 1:a607cd9655d7 165
yihui 1:a607cd9655d7 166 /** @} */ // End tag for Function group.
yihui 1:a607cd9655d7 167
yihui 1:a607cd9655d7 168 #endif // BLE_HRS_C_H__
yihui 1:a607cd9655d7 169
yihui 1:a607cd9655d7 170 /** @} */ // End tag for the file.