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_rscs.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 | /* 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_rsc Running Speed and Cadence Service |
yihui | 1:a607cd9655d7 | 16 | * @{ |
yihui | 1:a607cd9655d7 | 17 | * @ingroup ble_sdk_srv |
yihui | 1:a607cd9655d7 | 18 | * @brief Running Speed and Cadence Service module. |
yihui | 1:a607cd9655d7 | 19 | * |
yihui | 1:a607cd9655d7 | 20 | * @details This module implements the Running Speed and Cadence Service. If enabled, notification |
yihui | 1:a607cd9655d7 | 21 | * of the Running Speead and Candence Measurement is performed when the application |
yihui | 1:a607cd9655d7 | 22 | * calls ble_rscs_measurement_send(). |
yihui | 1:a607cd9655d7 | 23 | * |
yihui | 1:a607cd9655d7 | 24 | * If an event handler is supplied by the application, the Running Speed and Cadence |
yihui | 1:a607cd9655d7 | 25 | * Service will generate Running Speed and Cadence Service events to the application. |
yihui | 1:a607cd9655d7 | 26 | * |
yihui | 1:a607cd9655d7 | 27 | * @note The application must propagate BLE stack events to the Running Speead and Candence Service |
yihui | 1:a607cd9655d7 | 28 | * module by calling ble_rscs_on_ble_evt() from the from the @ref ble_stack_handler function. |
yihui | 1:a607cd9655d7 | 29 | * |
yihui | 1:a607cd9655d7 | 30 | * @note Attention! |
yihui | 1:a607cd9655d7 | 31 | * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile |
yihui | 1:a607cd9655d7 | 32 | * qualification listings, this section of source code must not be modified. |
yihui | 1:a607cd9655d7 | 33 | */ |
yihui | 1:a607cd9655d7 | 34 | |
yihui | 1:a607cd9655d7 | 35 | #ifndef BLE_RSCS_H__ |
yihui | 1:a607cd9655d7 | 36 | #define BLE_RSCS_H__ |
yihui | 1:a607cd9655d7 | 37 | |
yihui | 1:a607cd9655d7 | 38 | #include <stdint.h> |
yihui | 1:a607cd9655d7 | 39 | #include <stdbool.h> |
yihui | 1:a607cd9655d7 | 40 | #include "ble.h" |
yihui | 1:a607cd9655d7 | 41 | #include "ble_srv_common.h" |
yihui | 1:a607cd9655d7 | 42 | |
yihui | 1:a607cd9655d7 | 43 | /**@brief Running Speed and Cadence Service feature bits. */ |
yihui | 1:a607cd9655d7 | 44 | #define BLE_RSCS_FEATURE_INSTANT_STRIDE_LEN_BIT (0x01 << 0) /**< Instantaneous Stride Length Measurement Supported bit. */ |
yihui | 1:a607cd9655d7 | 45 | #define BLE_RSCS_FEATURE_TOTAL_DISTANCE_BIT (0x01 << 1) /**< Total Distance Measurement Supported bit. */ |
yihui | 1:a607cd9655d7 | 46 | #define BLE_RSCS_FEATURE_WALKING_OR_RUNNING_STATUS_BIT (0x01 << 2) /**< Walking or Running Status Supported bit. */ |
yihui | 1:a607cd9655d7 | 47 | #define BLE_RSCS_FEATURE_CALIBRATION_PROCEDURE_BIT (0x01 << 3) /**< Calibration Procedure Supported bit. */ |
yihui | 1:a607cd9655d7 | 48 | #define BLE_RSCS_FEATURE_MULTIPLE_SENSORS_BIT (0x01 << 4) /**< Multiple Sensor Locations Supported bit. */ |
yihui | 1:a607cd9655d7 | 49 | |
yihui | 1:a607cd9655d7 | 50 | /**@brief Running Speed and Cadence Service event type. */ |
yihui | 1:a607cd9655d7 | 51 | typedef enum |
yihui | 1:a607cd9655d7 | 52 | { |
yihui | 1:a607cd9655d7 | 53 | BLE_RSCS_EVT_NOTIFICATION_ENABLED, /**< Running Speed and Cadence value notification enabled event. */ |
yihui | 1:a607cd9655d7 | 54 | BLE_RSCS_EVT_NOTIFICATION_DISABLED /**< Running Speed and Cadence value notification disabled event. */ |
yihui | 1:a607cd9655d7 | 55 | } ble_rscs_evt_type_t; |
yihui | 1:a607cd9655d7 | 56 | |
yihui | 1:a607cd9655d7 | 57 | /**@brief Running Speed and Cadence Service event. */ |
yihui | 1:a607cd9655d7 | 58 | typedef struct |
yihui | 1:a607cd9655d7 | 59 | { |
yihui | 1:a607cd9655d7 | 60 | ble_rscs_evt_type_t evt_type; /**< Type of event. */ |
yihui | 1:a607cd9655d7 | 61 | } ble_rscs_evt_t; |
yihui | 1:a607cd9655d7 | 62 | |
yihui | 1:a607cd9655d7 | 63 | // Forward declaration of the ble_rsc_t type. |
yihui | 1:a607cd9655d7 | 64 | typedef struct ble_rscs_s ble_rscs_t; |
yihui | 1:a607cd9655d7 | 65 | |
yihui | 1:a607cd9655d7 | 66 | /**@brief Running Speed and Cadence Service event handler type. */ |
yihui | 1:a607cd9655d7 | 67 | typedef void (*ble_rscs_evt_handler_t) (ble_rscs_t * p_rscs, ble_rscs_evt_t * p_evt); |
yihui | 1:a607cd9655d7 | 68 | |
yihui | 1:a607cd9655d7 | 69 | /**@brief Running Speed and Cadence Service init structure. This contains all options and data |
yihui | 1:a607cd9655d7 | 70 | * needed for initialization of the service. */ |
yihui | 1:a607cd9655d7 | 71 | typedef struct |
yihui | 1:a607cd9655d7 | 72 | { |
yihui | 1:a607cd9655d7 | 73 | ble_rscs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Running Speed and Cadence Service. */ |
yihui | 1:a607cd9655d7 | 74 | ble_srv_cccd_security_mode_t rsc_meas_attr_md; /**< Initial security level for running speed and cadence measurement attribute */ |
yihui | 1:a607cd9655d7 | 75 | ble_srv_security_mode_t rsc_feature_attr_md; /**< Initial security level for feature attribute */ |
yihui | 1:a607cd9655d7 | 76 | uint16_t feature; /**< Initial value for features of sensor. */ |
yihui | 1:a607cd9655d7 | 77 | } ble_rscs_init_t; |
yihui | 1:a607cd9655d7 | 78 | |
yihui | 1:a607cd9655d7 | 79 | /**@brief Running Speed and Cadence Service structure. This contains various status information for |
yihui | 1:a607cd9655d7 | 80 | * the service. */ |
yihui | 1:a607cd9655d7 | 81 | typedef struct ble_rscs_s |
yihui | 1:a607cd9655d7 | 82 | { |
yihui | 1:a607cd9655d7 | 83 | ble_rscs_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Running Speed and Cadence Service. */ |
yihui | 1:a607cd9655d7 | 84 | uint16_t service_handle; /**< Handle of Running Speed and Cadence Service (as provided by the BLE stack). */ |
yihui | 1:a607cd9655d7 | 85 | ble_gatts_char_handles_t meas_handles; /**< Handles related to the Running Speed and Cadence Measurement characteristic. */ |
yihui | 1:a607cd9655d7 | 86 | ble_gatts_char_handles_t feature_handles; /**< Handles related to the Running Speed and Cadence feature characteristic. */ |
yihui | 1:a607cd9655d7 | 87 | 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 | 88 | uint16_t feature; /**< Bit mask of features available on sensor. */ |
yihui | 1:a607cd9655d7 | 89 | } ble_rscs_t; |
yihui | 1:a607cd9655d7 | 90 | |
yihui | 1:a607cd9655d7 | 91 | /**@brief Running Speed and Cadence Service measurement structure. This contains a Running Speed and |
yihui | 1:a607cd9655d7 | 92 | * Cadence measurement. */ |
yihui | 1:a607cd9655d7 | 93 | typedef struct ble_rscs_meas_s |
yihui | 1:a607cd9655d7 | 94 | { |
yihui | 1:a607cd9655d7 | 95 | bool is_inst_stride_len_present; /**< True if Instantaneous Stride Length is present in the measurement. */ |
yihui | 1:a607cd9655d7 | 96 | bool is_total_distance_present; /**< True if Total Distance is present in the measurement. */ |
yihui | 1:a607cd9655d7 | 97 | bool is_running; /**< True if running, False if walking. */ |
yihui | 1:a607cd9655d7 | 98 | uint16_t inst_speed; /**< Instantaneous Speed. */ |
yihui | 1:a607cd9655d7 | 99 | uint8_t inst_cadence; /**< Instantaneous Cadence. */ |
yihui | 1:a607cd9655d7 | 100 | uint16_t inst_stride_length; /**< Instantaneous Stride Length. */ |
yihui | 1:a607cd9655d7 | 101 | uint32_t total_distance; /**< Total Distance. */ |
yihui | 1:a607cd9655d7 | 102 | } ble_rscs_meas_t; |
yihui | 1:a607cd9655d7 | 103 | |
yihui | 1:a607cd9655d7 | 104 | /**@brief Function for initializing the Running Speed and Cadence Service. |
yihui | 1:a607cd9655d7 | 105 | * |
yihui | 1:a607cd9655d7 | 106 | * @param[out] p_rscs Running Speed and Cadence Service structure. This structure will have to |
yihui | 1:a607cd9655d7 | 107 | * be supplied by the application. It will be initialized by this function, |
yihui | 1:a607cd9655d7 | 108 | * and will later be used to identify this particular service instance. |
yihui | 1:a607cd9655d7 | 109 | * @param[in] p_rscs_init Information needed to initialize the service. |
yihui | 1:a607cd9655d7 | 110 | * |
yihui | 1:a607cd9655d7 | 111 | * @return NRF_SUCCESS on successful initialization of service, otherwise an error code. |
yihui | 1:a607cd9655d7 | 112 | */ |
yihui | 1:a607cd9655d7 | 113 | uint32_t ble_rscs_init(ble_rscs_t * p_rscs, const ble_rscs_init_t * p_rscs_init); |
yihui | 1:a607cd9655d7 | 114 | |
yihui | 1:a607cd9655d7 | 115 | /**@brief Function for handling the Application's BLE Stack events. |
yihui | 1:a607cd9655d7 | 116 | * |
yihui | 1:a607cd9655d7 | 117 | * @details Handles all events from the BLE stack of interest to the Running Speed and Cadence |
yihui | 1:a607cd9655d7 | 118 | * Service. |
yihui | 1:a607cd9655d7 | 119 | * |
yihui | 1:a607cd9655d7 | 120 | * @param[in] p_rscs Running Speed and Cadence Service structure. |
yihui | 1:a607cd9655d7 | 121 | * @param[in] p_ble_evt Event received from the BLE stack. |
yihui | 1:a607cd9655d7 | 122 | */ |
yihui | 1:a607cd9655d7 | 123 | void ble_rscs_on_ble_evt(ble_rscs_t * p_rscs, ble_evt_t * p_ble_evt); |
yihui | 1:a607cd9655d7 | 124 | |
yihui | 1:a607cd9655d7 | 125 | /**@brief Function for sending running speed and cadence measurement if notification has been enabled. |
yihui | 1:a607cd9655d7 | 126 | * |
yihui | 1:a607cd9655d7 | 127 | * @details The application calls this function after having performed a Running Speed and Cadence |
yihui | 1:a607cd9655d7 | 128 | * measurement. If notification has been enabled, the measurement data is encoded and sent |
yihui | 1:a607cd9655d7 | 129 | * to the client. |
yihui | 1:a607cd9655d7 | 130 | * |
yihui | 1:a607cd9655d7 | 131 | * @param[in] p_rscs Running Speed and Cadence Service structure. |
yihui | 1:a607cd9655d7 | 132 | * @param[in] p_measurement Pointer to new running speed and cadence measurement. |
yihui | 1:a607cd9655d7 | 133 | * |
yihui | 1:a607cd9655d7 | 134 | * @return NRF_SUCCESS on success, otherwise an error code. |
yihui | 1:a607cd9655d7 | 135 | */ |
yihui | 1:a607cd9655d7 | 136 | uint32_t ble_rscs_measurement_send(ble_rscs_t * p_rscs, ble_rscs_meas_t * p_measurement); |
yihui | 1:a607cd9655d7 | 137 | |
yihui | 1:a607cd9655d7 | 138 | #endif // BLE_RSCS_H__ |
yihui | 1:a607cd9655d7 | 139 | |
yihui | 1:a607cd9655d7 | 140 | /** @} */ |