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) 2013 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_sc_ctrlpt Speed and Cadence Control Point
yihui 1:a607cd9655d7 16 * @{
yihui 1:a607cd9655d7 17 * @ingroup ble_sdk_srv
yihui 1:a607cd9655d7 18 * @brief Speed and Cadence Control Point module.
yihui 1:a607cd9655d7 19 *
yihui 1:a607cd9655d7 20 * @details This module implements the Speed and Cadence control point behavior. It is used
yihui 1:a607cd9655d7 21 * by the @ref ble_sdk_srv_csc module and the ble_sdk_srv_rsc module for control point
yihui 1:a607cd9655d7 22 * mechanisms like setting a cumulative value, Start an automatic calibration,
yihui 1:a607cd9655d7 23 * Update the sensor location or request the supported locations.
yihui 1:a607cd9655d7 24 *
yihui 1:a607cd9655d7 25 * @note Attention!
yihui 1:a607cd9655d7 26 * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
yihui 1:a607cd9655d7 27 * qualification listings, this section of source code must not be modified.
yihui 1:a607cd9655d7 28 */
yihui 1:a607cd9655d7 29
yihui 1:a607cd9655d7 30 #ifndef BLE_SC_CTRLPT_H__
yihui 1:a607cd9655d7 31 #define BLE_SC_CTRLPT_H__
yihui 1:a607cd9655d7 32
yihui 1:a607cd9655d7 33 #include <stdint.h>
yihui 1:a607cd9655d7 34 #include <stdbool.h>
yihui 1:a607cd9655d7 35 #include "ble.h"
yihui 1:a607cd9655d7 36 #include "ble_srv_common.h"
yihui 1:a607cd9655d7 37 #include "ble_sensor_location.h"
yihui 1:a607cd9655d7 38
yihui 1:a607cd9655d7 39 #define BLE_SC_CTRLPT_MAX_LEN 19 /**< maximum lenght for Speed and cadence control point characteristic value. */
yihui 1:a607cd9655d7 40 #define BLE_SC_CTRLPT_MIN_LEN 1 /**< minimum length for Speed and cadence control point characteristic value. */
yihui 1:a607cd9655d7 41
yihui 1:a607cd9655d7 42 // Forward declaration of the ble_sc_ctrlpt_t type.
yihui 1:a607cd9655d7 43 typedef struct ble_sc_ctrlpt_s ble_sc_ctrlpt_t;
yihui 1:a607cd9655d7 44
yihui 1:a607cd9655d7 45
yihui 1:a607cd9655d7 46 /**@brief Speed and Cadence Control Point event type. */
yihui 1:a607cd9655d7 47 typedef enum
yihui 1:a607cd9655d7 48 {
yihui 1:a607cd9655d7 49 BLE_SC_CTRLPT_EVT_UPDATE_LOCATION, /**< rcvd update location opcode (the control point handles the change of location automatically, the event just informs the application in case it needs to adjust its algorithm). */
yihui 1:a607cd9655d7 50 BLE_SC_CTRLPT_EVT_SET_CUMUL_VALUE, /**< rcvd set cumulative value opcode, it is then up to the application to use the new cumulative value. */
yihui 1:a607cd9655d7 51 BLE_SC_CTRLPT_EVT_START_CALIBRATION, /**< rcvd start calibration opcode, the application needs, at the end ot the calibration to call ble_sc_ctrlpt_send_rsp. */
yihui 1:a607cd9655d7 52 } ble_sc_ctrlpt_evt_type_t;
yihui 1:a607cd9655d7 53
yihui 1:a607cd9655d7 54
yihui 1:a607cd9655d7 55 /**@brief Speed and Cadence Control point event. */
yihui 1:a607cd9655d7 56 typedef struct
yihui 1:a607cd9655d7 57 {
yihui 1:a607cd9655d7 58 ble_sc_ctrlpt_evt_type_t evt_type; /**< Type of event. */
yihui 1:a607cd9655d7 59 union
yihui 1:a607cd9655d7 60 {
yihui 1:a607cd9655d7 61 ble_sensor_location_t update_location;
yihui 1:a607cd9655d7 62 uint32_t cumulative_value;
yihui 1:a607cd9655d7 63 }params;
yihui 1:a607cd9655d7 64 } ble_sc_ctrlpt_evt_t;
yihui 1:a607cd9655d7 65
yihui 1:a607cd9655d7 66
yihui 1:a607cd9655d7 67 /** Speed and Cadence Control Point operator code (see RSC service specification)*/
yihui 1:a607cd9655d7 68 typedef enum {
yihui 1:a607cd9655d7 69 BLE_SCPT_SET_CUMULATIVE_VALUE = 0x01, /**< Operator to set a given cumulative value. */
yihui 1:a607cd9655d7 70 BLE_SCPT_START_AUTOMATIC_CALIBRATION = 0x02, /**< Operator to start automatic calibration. */
yihui 1:a607cd9655d7 71 BLE_SCPT_UPDATE_SENSOR_LOCATION = 0x03, /**< Operator to update the sensor location. */
yihui 1:a607cd9655d7 72 BLE_SCPT_REQUEST_SUPPORTED_SENSOR_LOCATIONS = 0x04, /**< Operator to request the supported sensor locations. */
yihui 1:a607cd9655d7 73 BLE_SCPT_RESPONSE_CODE = 0x10, /**< Response Code. */
yihui 1:a607cd9655d7 74 } ble_scpt_operator_t;
yihui 1:a607cd9655d7 75
yihui 1:a607cd9655d7 76
yihui 1:a607cd9655d7 77 /** Speed and Cadence Control Point response parameter (see RSC service specification)*/
yihui 1:a607cd9655d7 78 typedef enum {
yihui 1:a607cd9655d7 79 BLE_SCPT_SUCCESS = 0x01, /**< Sucess Response. */
yihui 1:a607cd9655d7 80 BLE_SCPT_OP_CODE_NOT_SUPPORTED = 0x02, /**< Error Response received opcode not supported. */
yihui 1:a607cd9655d7 81 BLE_SCPT_INVALID_PARAMETER = 0x03, /**< Error Response received parameter invalid. */
yihui 1:a607cd9655d7 82 BLE_SCPT_OPERATION_FAILED = 0x04, /**< Error Response operation failed. */
yihui 1:a607cd9655d7 83 } ble_scpt_response_t;
yihui 1:a607cd9655d7 84
yihui 1:a607cd9655d7 85
yihui 1:a607cd9655d7 86 /** Speed and Cadence Control Point procedure status (indicates is a procedure is in progress or not and which procedure is in progress*/
yihui 1:a607cd9655d7 87 typedef enum {
yihui 1:a607cd9655d7 88 BLE_SCPT_NO_PROC_IN_PROGRESS = 0x00, /**< No procedure in progress. */
yihui 1:a607cd9655d7 89 BLE_SCPT_AUTOMATIC_CALIB_IN_PROGRESS = 0x01, /**< Automatic Calibration is in progress. */
yihui 1:a607cd9655d7 90 BLE_SCPT_INDICATION_PENDING = 0x02, /**< Control Point Indication is pending. */
yihui 1:a607cd9655d7 91 BLE_SCPT_IND_CONFIRM_PENDING = 0x03, /**< Waiting for the indication confirmation. */
yihui 1:a607cd9655d7 92 }ble_scpt_procedure_status_t;
yihui 1:a607cd9655d7 93
yihui 1:a607cd9655d7 94 /**@brief Speed and Cadence Control point event handler type. */
yihui 1:a607cd9655d7 95 typedef ble_scpt_response_t (*ble_sc_ctrlpt_evt_handler_t) (ble_sc_ctrlpt_t * p_sc_ctrlpt,
yihui 1:a607cd9655d7 96 ble_sc_ctrlpt_evt_t * p_evt);
yihui 1:a607cd9655d7 97
yihui 1:a607cd9655d7 98
yihui 1:a607cd9655d7 99 typedef struct{
yihui 1:a607cd9655d7 100 ble_scpt_operator_t opcode;
yihui 1:a607cd9655d7 101 uint32_t cumulative_value;
yihui 1:a607cd9655d7 102 ble_sensor_location_t location;
yihui 1:a607cd9655d7 103 }ble_sc_ctrlpt_val_t;
yihui 1:a607cd9655d7 104
yihui 1:a607cd9655d7 105
yihui 1:a607cd9655d7 106 typedef struct{
yihui 1:a607cd9655d7 107 ble_scpt_operator_t opcode;
yihui 1:a607cd9655d7 108 ble_scpt_response_t status;
yihui 1:a607cd9655d7 109 ble_sensor_location_t location_list[BLE_NB_MAX_SENSOR_LOCATIONS];
yihui 1:a607cd9655d7 110 }ble_sc_ctrlpt_rsp_t;
yihui 1:a607cd9655d7 111
yihui 1:a607cd9655d7 112
yihui 1:a607cd9655d7 113
yihui 1:a607cd9655d7 114 #define BLE_SRV_SC_CTRLPT_SENSOR_LOCATIONS_OP_SUPPORTED 0x01 /**< Support for sensor location related operations */
yihui 1:a607cd9655d7 115 #define BLE_SRV_SC_CTRLPT_CUM_VAL_OP_SUPPORTED 0x02 /**< Support for setting cumulative value related operations */
yihui 1:a607cd9655d7 116 #define BLE_SRV_SC_CTRLPT_START_CALIB_OP_SUPPORTED 0x04 /**< Support for starting calibration related operations */
yihui 1:a607cd9655d7 117
yihui 1:a607cd9655d7 118
yihui 1:a607cd9655d7 119 /**@brief Speed and Cadence Control Point init structure. This contains all options and data
yihui 1:a607cd9655d7 120 * needed for initialization of the Speed and Cadence Control Point module. */
yihui 1:a607cd9655d7 121 typedef struct
yihui 1:a607cd9655d7 122 {
yihui 1:a607cd9655d7 123 ble_srv_cccd_security_mode_t sc_ctrlpt_attr_md; /**< Initial security level for cycling speed and cadence control point attribute */
yihui 1:a607cd9655d7 124 uint8_t supported_functions; /**< supported control point functionnalities see @ref BLE_SRV_SC_CTRLPT_SUPP_FUNC. */
yihui 1:a607cd9655d7 125 uint16_t service_handle; /**< Handle of the parent service (as provided by the BLE stack). */
yihui 1:a607cd9655d7 126 ble_sc_ctrlpt_evt_handler_t evt_handler; /**< event handler */
yihui 1:a607cd9655d7 127 ble_sensor_location_t *list_supported_locations; /**< list of supported sensor locations.*/
yihui 1:a607cd9655d7 128 uint8_t size_list_supported_locations; /**< number of supported sensor locations in the list.*/
yihui 1:a607cd9655d7 129 uint16_t sensor_location_handle; /**< handle for the sensor location characteristic (if sensor_location related operation are supported).*/
yihui 1:a607cd9655d7 130 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
yihui 1:a607cd9655d7 131 } ble_cs_ctrlpt_init_t;
yihui 1:a607cd9655d7 132
yihui 1:a607cd9655d7 133
yihui 1:a607cd9655d7 134 /**@brief Speed and Cadence Control Point response indication structure. */
yihui 1:a607cd9655d7 135 typedef struct
yihui 1:a607cd9655d7 136 {
yihui 1:a607cd9655d7 137 ble_scpt_response_t status; /**< control point response status .*/
yihui 1:a607cd9655d7 138 uint8_t len; /**< control point response length .*/
yihui 1:a607cd9655d7 139 uint8_t encoded_ctrl_rsp[BLE_SC_CTRLPT_MAX_LEN]; /**< control point encoded response.*/
yihui 1:a607cd9655d7 140 }ble_sc_ctrlpt_resp_t;
yihui 1:a607cd9655d7 141
yihui 1:a607cd9655d7 142
yihui 1:a607cd9655d7 143 /**@brief Speed and Cadence Control Point structure. This contains various status information for
yihui 1:a607cd9655d7 144 * the Speed and Cadence Control Point behavior. */
yihui 1:a607cd9655d7 145 typedef struct ble_sc_ctrlpt_s
yihui 1:a607cd9655d7 146 {
yihui 1:a607cd9655d7 147 uint8_t supported_functions; /**< supported control point functionnalities see @ref BLE_SRV_SC_CTRLPT_SUPP_FUNC. */
yihui 1:a607cd9655d7 148 uint16_t service_handle; /**< Handle of the parent service (as provided by the BLE stack). */
yihui 1:a607cd9655d7 149 ble_gatts_char_handles_t sc_ctrlpt_handles; /**< Handles related to the Speed and Cadence Control Point characteristic. */
yihui 1:a607cd9655d7 150 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 151 ble_sensor_location_t list_supported_locations[BLE_NB_MAX_SENSOR_LOCATIONS]; /**< list of supported sensor locations.*/
yihui 1:a607cd9655d7 152 uint8_t size_list_supported_locations; /**< number of supported sensor locations in the list.*/
yihui 1:a607cd9655d7 153 ble_sc_ctrlpt_evt_handler_t evt_handler; /**< Handle of the parent service (as provided by the BLE stack). */
yihui 1:a607cd9655d7 154 uint16_t sensor_location_handle; /**< handle for the sensor location characteristic (if sensor_location related operation are supported).*/
yihui 1:a607cd9655d7 155 ble_scpt_procedure_status_t procedure_status; /**< status of possible procedure*/
yihui 1:a607cd9655d7 156 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
yihui 1:a607cd9655d7 157 ble_sc_ctrlpt_resp_t response; /**< pending response data.*/
yihui 1:a607cd9655d7 158 } ble_sc_ctrlpt_t;
yihui 1:a607cd9655d7 159
yihui 1:a607cd9655d7 160 #define SCPT_OPCODE_POS 0 /**< Request opcode position. */
yihui 1:a607cd9655d7 161 #define SCPT_PARAMETER_POS 1 /**< Request parameter position. */
yihui 1:a607cd9655d7 162
yihui 1:a607cd9655d7 163 #define SCPT_RESPONSE_REQUEST_OPCODE_POS 1 /**< Response position of requested opcode. */
yihui 1:a607cd9655d7 164 #define SCPT_RESPONSE_CODE_POS 2 /**< Response position of response code. */
yihui 1:a607cd9655d7 165 #define SCPT_RESPONSE_PARAMETER 3 /**< Response position of response parameter. */
yihui 1:a607cd9655d7 166
yihui 1:a607cd9655d7 167 #define SCPT_MIN_RESPONSE_SIZE 3 /**< Minimum size for control point response. */
yihui 1:a607cd9655d7 168 #define SCPT_MAX_RESPONSE_SIZE (SCPT_MIN_RESPONSE_SIZE + NB_MAX_SENSOR_LOCATIONS) /**< Maximum size for control point response. */
yihui 1:a607cd9655d7 169
yihui 1:a607cd9655d7 170
yihui 1:a607cd9655d7 171 /**@brief Function for Initializing the Speed and Cadence Control Point.
yihui 1:a607cd9655d7 172 *
yihui 1:a607cd9655d7 173 * @details Function for Initializing the Speed and Cadence Control Point.
yihui 1:a607cd9655d7 174 * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure.
yihui 1:a607cd9655d7 175 * @param[in] p_cscs_init Information needed to initialize the control point behavior.
yihui 1:a607cd9655d7 176 *
yihui 1:a607cd9655d7 177 * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
yihui 1:a607cd9655d7 178 */
yihui 1:a607cd9655d7 179 uint32_t ble_sc_ctrlpt_init(ble_sc_ctrlpt_t * p_sc_ctrlpt,
yihui 1:a607cd9655d7 180 const ble_cs_ctrlpt_init_t * p_sc_ctrlpt_init);
yihui 1:a607cd9655d7 181
yihui 1:a607cd9655d7 182
yihui 1:a607cd9655d7 183 /**@brief Function for sending a control point response.
yihui 1:a607cd9655d7 184 *
yihui 1:a607cd9655d7 185 * @details Function for sending a control point response when the control point received was
yihui 1:a607cd9655d7 186 * BLE_SCPT_START_AUTOMATIC_CALIBRATION. To be called after the calibration procedure is finished.
yihui 1:a607cd9655d7 187 *
yihui 1:a607cd9655d7 188 * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure.
yihui 1:a607cd9655d7 189 * @param[in] response_status status to include in the control point response.
yihui 1:a607cd9655d7 190 */
yihui 1:a607cd9655d7 191 uint32_t ble_sc_ctrlpt_rsp_send(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_scpt_response_t response_status);
yihui 1:a607cd9655d7 192
yihui 1:a607cd9655d7 193
yihui 1:a607cd9655d7 194 /**@brief Speed and Cadence Control Point BLE stack event handler.
yihui 1:a607cd9655d7 195 *
yihui 1:a607cd9655d7 196 * @details Handles all events from the BLE stack of interest to the Speed and Cadence Control Point.
yihui 1:a607cd9655d7 197 *
yihui 1:a607cd9655d7 198 * @param[in] p_sc_ctrlpt Speed and Cadence Control Point structure.
yihui 1:a607cd9655d7 199 * @param[in] p_ble_evt Event received from the BLE stack.
yihui 1:a607cd9655d7 200 */
yihui 1:a607cd9655d7 201 void ble_sc_ctrlpt_on_ble_evt(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_evt_t * p_ble_evt);
yihui 1:a607cd9655d7 202
yihui 1:a607cd9655d7 203
yihui 1:a607cd9655d7 204 #endif // BLE_SC_CTRLPT_H__
yihui 1:a607cd9655d7 205
yihui 1:a607cd9655d7 206 /** @} */