BLE FOTA APP
It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.
nRF51822/nordic/nrf-sdk/ble/ble_services/ble_bas_c.h@1:a607cd9655d7, 2014-10-10 (annotated)
- 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?
User | Revision | Line number | New 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_bas_c Battery Service Client |
yihui | 1:a607cd9655d7 | 13 | * @{ |
yihui | 1:a607cd9655d7 | 14 | * @ingroup ble_sdk_srv |
yihui | 1:a607cd9655d7 | 15 | * @brief Battery Service Client module. |
yihui | 1:a607cd9655d7 | 16 | * |
yihui | 1:a607cd9655d7 | 17 | * @details This module contains APIs to read and interact with the Battery Service of a remote |
yihui | 1:a607cd9655d7 | 18 | * device. |
yihui | 1:a607cd9655d7 | 19 | * |
yihui | 1:a607cd9655d7 | 20 | * @note The application must propagate BLE stack events to this module by calling |
yihui | 1:a607cd9655d7 | 21 | * ble_hrs_c_on_ble_evt(). |
yihui | 1:a607cd9655d7 | 22 | * |
yihui | 1:a607cd9655d7 | 23 | */ |
yihui | 1:a607cd9655d7 | 24 | |
yihui | 1:a607cd9655d7 | 25 | #ifndef BLE_BAS_C_H__ |
yihui | 1:a607cd9655d7 | 26 | #define BLE_BAS_C_H__ |
yihui | 1:a607cd9655d7 | 27 | |
yihui | 1:a607cd9655d7 | 28 | #include <stdint.h> |
yihui | 1:a607cd9655d7 | 29 | #include "ble.h" |
yihui | 1:a607cd9655d7 | 30 | |
yihui | 1:a607cd9655d7 | 31 | /** |
yihui | 1:a607cd9655d7 | 32 | * @defgroup bas_c_enums Enumerations |
yihui | 1:a607cd9655d7 | 33 | * @{ |
yihui | 1:a607cd9655d7 | 34 | */ |
yihui | 1:a607cd9655d7 | 35 | |
yihui | 1:a607cd9655d7 | 36 | /**@brief Battery Service Client event type. */ |
yihui | 1:a607cd9655d7 | 37 | typedef enum |
yihui | 1:a607cd9655d7 | 38 | { |
yihui | 1:a607cd9655d7 | 39 | BLE_BAS_C_EVT_DISCOVERY_COMPLETE, /**< Event indicating that the Battery Service has been discovered at the peer. */ |
yihui | 1:a607cd9655d7 | 40 | BLE_BAS_C_EVT_BATT_NOTIFICATION, /**< Event indicating that a notification of the Battery Level characteristic has been received from the peer. */ |
yihui | 1:a607cd9655d7 | 41 | BLE_BAS_C_EVT_BATT_READ_RESP /**< Event indicating that a read response on Battery Level characteristic has been received from peer. */ |
yihui | 1:a607cd9655d7 | 42 | } ble_bas_c_evt_type_t; |
yihui | 1:a607cd9655d7 | 43 | |
yihui | 1:a607cd9655d7 | 44 | /** @} */ |
yihui | 1:a607cd9655d7 | 45 | |
yihui | 1:a607cd9655d7 | 46 | /** |
yihui | 1:a607cd9655d7 | 47 | * @defgroup bas_c_structs Structures |
yihui | 1:a607cd9655d7 | 48 | * @{ |
yihui | 1:a607cd9655d7 | 49 | */ |
yihui | 1:a607cd9655d7 | 50 | |
yihui | 1:a607cd9655d7 | 51 | /**@brief Battery Service Client Event structure. */ |
yihui | 1:a607cd9655d7 | 52 | typedef struct |
yihui | 1:a607cd9655d7 | 53 | { |
yihui | 1:a607cd9655d7 | 54 | ble_bas_c_evt_type_t evt_type; /**< Event Type. */ |
yihui | 1:a607cd9655d7 | 55 | union |
yihui | 1:a607cd9655d7 | 56 | { |
yihui | 1:a607cd9655d7 | 57 | uint8_t battery_level; /**< Battery level received from peer. This field will be used for the events @ref BLE_BAS_C_EVT_BATT_NOTIFICATION and @ref BLE_BAS_C_EVT_BATT_READ_RESP.*/ |
yihui | 1:a607cd9655d7 | 58 | } params; |
yihui | 1:a607cd9655d7 | 59 | } ble_bas_c_evt_t; |
yihui | 1:a607cd9655d7 | 60 | |
yihui | 1:a607cd9655d7 | 61 | /** @} */ |
yihui | 1:a607cd9655d7 | 62 | |
yihui | 1:a607cd9655d7 | 63 | /** |
yihui | 1:a607cd9655d7 | 64 | * @defgroup bas_c_types Types |
yihui | 1:a607cd9655d7 | 65 | * @{ |
yihui | 1:a607cd9655d7 | 66 | */ |
yihui | 1:a607cd9655d7 | 67 | |
yihui | 1:a607cd9655d7 | 68 | // Forward declaration of the ble_bas_t type. |
yihui | 1:a607cd9655d7 | 69 | typedef struct ble_bas_c_s ble_bas_c_t; |
yihui | 1:a607cd9655d7 | 70 | |
yihui | 1:a607cd9655d7 | 71 | /**@brief Event handler type. |
yihui | 1:a607cd9655d7 | 72 | * |
yihui | 1:a607cd9655d7 | 73 | * @details This is the type of the event handler that should be provided by the application |
yihui | 1:a607cd9655d7 | 74 | * of this module in order to receive events. |
yihui | 1:a607cd9655d7 | 75 | */ |
yihui | 1:a607cd9655d7 | 76 | typedef void (* ble_bas_c_evt_handler_t) (ble_bas_c_t * p_bas_bas_c, ble_bas_c_evt_t * p_evt); |
yihui | 1:a607cd9655d7 | 77 | |
yihui | 1:a607cd9655d7 | 78 | /** @} */ |
yihui | 1:a607cd9655d7 | 79 | |
yihui | 1:a607cd9655d7 | 80 | /** |
yihui | 1:a607cd9655d7 | 81 | * @addtogroup bas_c_structs |
yihui | 1:a607cd9655d7 | 82 | * @{ |
yihui | 1:a607cd9655d7 | 83 | */ |
yihui | 1:a607cd9655d7 | 84 | |
yihui | 1:a607cd9655d7 | 85 | /**@brief Battery Service Client structure. |
yihui | 1:a607cd9655d7 | 86 | |
yihui | 1:a607cd9655d7 | 87 | */ |
yihui | 1:a607cd9655d7 | 88 | typedef struct ble_bas_c_s |
yihui | 1:a607cd9655d7 | 89 | { |
yihui | 1:a607cd9655d7 | 90 | uint16_t conn_handle; /**< Connection handle as provided by the SoftDevice. */ |
yihui | 1:a607cd9655d7 | 91 | uint16_t bl_cccd_handle; /**< Handle of the CCCD of the Battery Level characteristic. */ |
yihui | 1:a607cd9655d7 | 92 | uint16_t bl_handle; /**< Handle of the Battery Level characteristic as provided by the SoftDevice. */ |
yihui | 1:a607cd9655d7 | 93 | ble_bas_c_evt_handler_t evt_handler; /**< Application event handler to be called when there is an event related to the Battery service. */ |
yihui | 1:a607cd9655d7 | 94 | } ble_bas_c_t; |
yihui | 1:a607cd9655d7 | 95 | |
yihui | 1:a607cd9655d7 | 96 | /**@brief Battery Service Client initialization structure. |
yihui | 1:a607cd9655d7 | 97 | */ |
yihui | 1:a607cd9655d7 | 98 | typedef struct |
yihui | 1:a607cd9655d7 | 99 | { |
yihui | 1:a607cd9655d7 | 100 | ble_bas_c_evt_handler_t evt_handler; /**< Event handler to be called by the Battery Service Client module whenever there is an event related to the Battery Service. */ |
yihui | 1:a607cd9655d7 | 101 | } ble_bas_c_init_t; |
yihui | 1:a607cd9655d7 | 102 | |
yihui | 1:a607cd9655d7 | 103 | /** @} */ |
yihui | 1:a607cd9655d7 | 104 | |
yihui | 1:a607cd9655d7 | 105 | /** |
yihui | 1:a607cd9655d7 | 106 | * @defgroup bas_c_functions Functions |
yihui | 1:a607cd9655d7 | 107 | * @{ |
yihui | 1:a607cd9655d7 | 108 | */ |
yihui | 1:a607cd9655d7 | 109 | |
yihui | 1:a607cd9655d7 | 110 | /**@brief Function for initializing the Battery Service Client module. |
yihui | 1:a607cd9655d7 | 111 | * |
yihui | 1:a607cd9655d7 | 112 | * @details This function will initialize the module and set up Database Discovery to discover |
yihui | 1:a607cd9655d7 | 113 | * the Battery Service. After calling this function, call @ref ble_db_discovery_start |
yihui | 1:a607cd9655d7 | 114 | * to start discovery. |
yihui | 1:a607cd9655d7 | 115 | * |
yihui | 1:a607cd9655d7 | 116 | * @param[out] p_ble_bas_c Pointer to the Battery Service client structure. |
yihui | 1:a607cd9655d7 | 117 | * @param[in] p_ble_bas_c_init Pointer to the Battery Service initialization structure containing |
yihui | 1:a607cd9655d7 | 118 | * the initialization information. |
yihui | 1:a607cd9655d7 | 119 | * |
yihui | 1:a607cd9655d7 | 120 | * @retval NRF_SUCCESS Operation success. |
yihui | 1:a607cd9655d7 | 121 | * @retval NRF_ERROR_NULL A parameter is NULL. |
yihui | 1:a607cd9655d7 | 122 | * Otherwise, an error code returned by @ref ble_db_discovery_register. |
yihui | 1:a607cd9655d7 | 123 | */ |
yihui | 1:a607cd9655d7 | 124 | uint32_t ble_bas_c_init(ble_bas_c_t * p_ble_bas_c, ble_bas_c_init_t * p_ble_bas_c_init); |
yihui | 1:a607cd9655d7 | 125 | |
yihui | 1:a607cd9655d7 | 126 | |
yihui | 1:a607cd9655d7 | 127 | /**@brief Function for handling BLE events from the SoftDevice. |
yihui | 1:a607cd9655d7 | 128 | * |
yihui | 1:a607cd9655d7 | 129 | * @details This function will handle the BLE events received from the SoftDevice. If the BLE |
yihui | 1:a607cd9655d7 | 130 | * event is relevant for the Battery Service Client module, then it is used to update |
yihui | 1:a607cd9655d7 | 131 | * interval variables and, if necessary, send events to the application. |
yihui | 1:a607cd9655d7 | 132 | * |
yihui | 1:a607cd9655d7 | 133 | * @note This function must be called by the application. |
yihui | 1:a607cd9655d7 | 134 | * |
yihui | 1:a607cd9655d7 | 135 | * @param[in] p_ble_bas_c Pointer to the Battery Service client structure. |
yihui | 1:a607cd9655d7 | 136 | * @param[in] p_ble_evt Pointer to the BLE event. |
yihui | 1:a607cd9655d7 | 137 | */ |
yihui | 1:a607cd9655d7 | 138 | void ble_bas_c_on_ble_evt(ble_bas_c_t * p_ble_bas_c, const ble_evt_t * p_ble_evt); |
yihui | 1:a607cd9655d7 | 139 | |
yihui | 1:a607cd9655d7 | 140 | |
yihui | 1:a607cd9655d7 | 141 | /**@brief Function for enabling notifications on the Battery Level characteristic. |
yihui | 1:a607cd9655d7 | 142 | * |
yihui | 1:a607cd9655d7 | 143 | * @details This function will enable to notification of the Battery Level characteristic at the |
yihui | 1:a607cd9655d7 | 144 | * peer by writing to the CCCD of the Battery Level Characteristic. |
yihui | 1:a607cd9655d7 | 145 | * |
yihui | 1:a607cd9655d7 | 146 | * @param p_ble_bas_c Pointer to the Battery Service client structure. |
yihui | 1:a607cd9655d7 | 147 | * |
yihui | 1:a607cd9655d7 | 148 | * @retval NRF_SUCCESS If the SoftDevice has been requested to write to the CCCD of the peer. |
yihui | 1:a607cd9655d7 | 149 | * NRF_ERROR_NULL Parameter is NULL. |
yihui | 1:a607cd9655d7 | 150 | * Otherwise, an error code returned by the SoftDevice API @ref |
yihui | 1:a607cd9655d7 | 151 | * sd_ble_gattc_write. |
yihui | 1:a607cd9655d7 | 152 | */ |
yihui | 1:a607cd9655d7 | 153 | uint32_t ble_bas_c_bl_notif_enable(ble_bas_c_t * p_ble_bas_c); |
yihui | 1:a607cd9655d7 | 154 | |
yihui | 1:a607cd9655d7 | 155 | |
yihui | 1:a607cd9655d7 | 156 | /**@brief Function for reading the Battery Level characteristic. |
yihui | 1:a607cd9655d7 | 157 | * |
yihui | 1:a607cd9655d7 | 158 | * @param p_ble_bas_c Pointer to the Battery Service client structure. |
yihui | 1:a607cd9655d7 | 159 | * |
yihui | 1:a607cd9655d7 | 160 | * @retval NRF_SUCCESS If the read request was successfully queued to be sent to peer. |
yihui | 1:a607cd9655d7 | 161 | */ |
yihui | 1:a607cd9655d7 | 162 | uint32_t ble_bas_c_bl_read(ble_bas_c_t * p_ble_bas_c); |
yihui | 1:a607cd9655d7 | 163 | |
yihui | 1:a607cd9655d7 | 164 | |
yihui | 1:a607cd9655d7 | 165 | /** @} */ // End tag for Function group. |
yihui | 1:a607cd9655d7 | 166 | |
yihui | 1:a607cd9655d7 | 167 | #endif // BLE_BAS_C_H__ |
yihui | 1:a607cd9655d7 | 168 | |
yihui | 1:a607cd9655d7 | 169 | /** @} */ // End tag for the file. |