【これは旧バージョンです】 AndroidのBLEラジコンプロポアプリ「BLEPropo」と接続し、RCサーボとDCモータを制御するプログラムです。 mbed HRM1017で動作を確認しています。 BLEPropo → https://github.com/lipoyang/BLEPropo
Fork of BLE_RCBController2 by
BLEを使ったAndroid用ラジコンプロポアプリ「BLEPropo」に対応するmbed HRM1017用ファームウェアです。
BLEPropoは、GitHubにて公開中。
https://github.com/lipoyang/BLEPropo
ラジコンは、mbed HRM1017とRCサーボやDCモータを組み合わせて作ります。
HRM1017/nordic/softdevice_handler.cpp@13:2075c4878557, 2014-09-18 (annotated)
- Committer:
- lipoyang
- Date:
- Thu Sep 18 04:47:00 2014 +0000
- Revision:
- 13:2075c4878557
- Parent:
- 4:ebda47d22091
Servo????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 1:48f6e08a3ac2 | 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. |
jksoft | 1:48f6e08a3ac2 | 2 | * |
jksoft | 1:48f6e08a3ac2 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
jksoft | 1:48f6e08a3ac2 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
jksoft | 1:48f6e08a3ac2 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
jksoft | 1:48f6e08a3ac2 | 6 | * |
jksoft | 1:48f6e08a3ac2 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
jksoft | 1:48f6e08a3ac2 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jksoft | 1:48f6e08a3ac2 | 9 | * the file. |
jksoft | 1:48f6e08a3ac2 | 10 | * |
jksoft | 1:48f6e08a3ac2 | 11 | */ |
jksoft | 1:48f6e08a3ac2 | 12 | |
jksoft | 1:48f6e08a3ac2 | 13 | #include "softdevice_handler.h" |
jksoft | 1:48f6e08a3ac2 | 14 | #include <stdlib.h> |
jksoft | 1:48f6e08a3ac2 | 15 | #include "nordic_common.h" |
jksoft | 1:48f6e08a3ac2 | 16 | #include "app_error.h" |
jksoft | 1:48f6e08a3ac2 | 17 | #include "app_util.h" |
jksoft | 1:48f6e08a3ac2 | 18 | #include "nrf_assert.h" |
jksoft | 1:48f6e08a3ac2 | 19 | #include "nrf_soc.h" |
jksoft | 1:48f6e08a3ac2 | 20 | |
jksoft | 1:48f6e08a3ac2 | 21 | #if defined(ANT_STACK_SUPPORT_REQD) && defined(BLE_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 22 | #include "ant_interface.h" |
jksoft | 1:48f6e08a3ac2 | 23 | #elif defined(ANT_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 24 | #include "ant_interface.h" |
jksoft | 1:48f6e08a3ac2 | 25 | #elif defined(BLE_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 26 | #include "ble.h" |
jksoft | 1:48f6e08a3ac2 | 27 | #endif |
jksoft | 1:48f6e08a3ac2 | 28 | |
jksoft | 1:48f6e08a3ac2 | 29 | |
jksoft | 1:48f6e08a3ac2 | 30 | static softdevice_evt_schedule_func_t m_evt_schedule_func; /**< Pointer to function for propagating SoftDevice events to the scheduler. */ |
jksoft | 1:48f6e08a3ac2 | 31 | |
jksoft | 1:48f6e08a3ac2 | 32 | #if defined (BLE_STACK_SUPPORT_REQD) || defined (ANT_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 33 | // The following two definition is needed only if ANT or BLE events are needed to be pulled from the stack. |
jksoft | 1:48f6e08a3ac2 | 34 | static uint8_t * m_evt_buffer; /**< Buffer for receiving events from the SoftDevice. */ |
jksoft | 1:48f6e08a3ac2 | 35 | #endif |
jksoft | 1:48f6e08a3ac2 | 36 | |
jksoft | 1:48f6e08a3ac2 | 37 | #ifdef BLE_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 38 | static uint16_t m_ble_evt_buffer_size; /**< Size of BLE event buffer. */ |
jksoft | 1:48f6e08a3ac2 | 39 | #endif |
jksoft | 1:48f6e08a3ac2 | 40 | |
jksoft | 1:48f6e08a3ac2 | 41 | static volatile bool m_softdevice_enabled = false; /**< Variable to indicate whether the SoftDevice is enabled. */ |
jksoft | 1:48f6e08a3ac2 | 42 | |
jksoft | 1:48f6e08a3ac2 | 43 | #ifdef BLE_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 44 | static ble_evt_handler_t m_ble_evt_handler; /**< Application event handler for handling BLE events. */ |
jksoft | 1:48f6e08a3ac2 | 45 | #endif |
jksoft | 1:48f6e08a3ac2 | 46 | |
jksoft | 1:48f6e08a3ac2 | 47 | #ifdef ANT_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 48 | static ant_evt_handler_t m_ant_evt_handler; /**< Application event handler for handling ANT events. */ |
jksoft | 1:48f6e08a3ac2 | 49 | #endif |
jksoft | 1:48f6e08a3ac2 | 50 | |
jksoft | 1:48f6e08a3ac2 | 51 | static sys_evt_handler_t m_sys_evt_handler; /**< Application event handler for handling System (SOC) events. */ |
jksoft | 1:48f6e08a3ac2 | 52 | |
jksoft | 1:48f6e08a3ac2 | 53 | |
jksoft | 1:48f6e08a3ac2 | 54 | /**@brief Callback function for asserts in the SoftDevice. |
jksoft | 1:48f6e08a3ac2 | 55 | * |
jksoft | 1:48f6e08a3ac2 | 56 | * @details A pointer to this function will be passed to the SoftDevice. This function will be |
jksoft | 1:48f6e08a3ac2 | 57 | * called if an ASSERT statement in the SoftDevice fails. |
jksoft | 1:48f6e08a3ac2 | 58 | * |
jksoft | 1:48f6e08a3ac2 | 59 | * @param[in] pc The value of the program counter when the ASSERT call failed. |
jksoft | 1:48f6e08a3ac2 | 60 | * @param[in] line_num Line number of the failing ASSERT call. |
jksoft | 1:48f6e08a3ac2 | 61 | * @param[in] file_name File name of the failing ASSERT call. |
jksoft | 1:48f6e08a3ac2 | 62 | */ |
jksoft | 1:48f6e08a3ac2 | 63 | void softdevice_assertion_handler(uint32_t pc, uint16_t line_num, const uint8_t * file_name) |
jksoft | 1:48f6e08a3ac2 | 64 | { |
jksoft | 1:48f6e08a3ac2 | 65 | UNUSED_PARAMETER(pc); |
jksoft | 1:48f6e08a3ac2 | 66 | assert_nrf_callback(line_num, file_name); |
jksoft | 1:48f6e08a3ac2 | 67 | } |
jksoft | 1:48f6e08a3ac2 | 68 | |
jksoft | 1:48f6e08a3ac2 | 69 | |
jksoft | 1:48f6e08a3ac2 | 70 | void intern_softdevice_events_execute(void) |
jksoft | 1:48f6e08a3ac2 | 71 | { |
jksoft | 1:48f6e08a3ac2 | 72 | if (!m_softdevice_enabled) |
jksoft | 1:48f6e08a3ac2 | 73 | { |
jksoft | 1:48f6e08a3ac2 | 74 | // SoftDevice not enabled. This can be possible if the SoftDevice was enabled by the |
jksoft | 1:48f6e08a3ac2 | 75 | // application without using this module's API (i.e softdevice_handler_init) |
jksoft | 1:48f6e08a3ac2 | 76 | |
jksoft | 1:48f6e08a3ac2 | 77 | return; |
jksoft | 1:48f6e08a3ac2 | 78 | } |
jksoft | 1:48f6e08a3ac2 | 79 | |
jksoft | 1:48f6e08a3ac2 | 80 | bool no_more_soc_evts = (m_sys_evt_handler == NULL); |
jksoft | 1:48f6e08a3ac2 | 81 | #ifdef BLE_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 82 | bool no_more_ble_evts = (m_ble_evt_handler == NULL); |
jksoft | 1:48f6e08a3ac2 | 83 | #endif |
jksoft | 1:48f6e08a3ac2 | 84 | #ifdef ANT_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 85 | bool no_more_ant_evts = (m_ant_evt_handler == NULL); |
jksoft | 1:48f6e08a3ac2 | 86 | #endif |
jksoft | 1:48f6e08a3ac2 | 87 | |
jksoft | 1:48f6e08a3ac2 | 88 | for (;;) |
jksoft | 1:48f6e08a3ac2 | 89 | { |
jksoft | 1:48f6e08a3ac2 | 90 | uint32_t err_code; |
jksoft | 1:48f6e08a3ac2 | 91 | |
jksoft | 1:48f6e08a3ac2 | 92 | if (!no_more_soc_evts) |
jksoft | 1:48f6e08a3ac2 | 93 | { |
jksoft | 1:48f6e08a3ac2 | 94 | uint32_t evt_id; |
jksoft | 1:48f6e08a3ac2 | 95 | |
jksoft | 1:48f6e08a3ac2 | 96 | // Pull event from SOC. |
jksoft | 1:48f6e08a3ac2 | 97 | err_code = sd_evt_get(&evt_id); |
jksoft | 1:48f6e08a3ac2 | 98 | |
jksoft | 1:48f6e08a3ac2 | 99 | if (err_code == NRF_ERROR_NOT_FOUND) |
jksoft | 1:48f6e08a3ac2 | 100 | { |
jksoft | 1:48f6e08a3ac2 | 101 | no_more_soc_evts = true; |
jksoft | 1:48f6e08a3ac2 | 102 | } |
jksoft | 1:48f6e08a3ac2 | 103 | else if (err_code != NRF_SUCCESS) |
jksoft | 1:48f6e08a3ac2 | 104 | { |
jksoft | 1:48f6e08a3ac2 | 105 | APP_ERROR_HANDLER(err_code); |
jksoft | 1:48f6e08a3ac2 | 106 | } |
jksoft | 1:48f6e08a3ac2 | 107 | else |
jksoft | 1:48f6e08a3ac2 | 108 | { |
jksoft | 1:48f6e08a3ac2 | 109 | // Call application's SOC event handler. |
jksoft | 1:48f6e08a3ac2 | 110 | m_sys_evt_handler(evt_id); |
jksoft | 1:48f6e08a3ac2 | 111 | } |
jksoft | 1:48f6e08a3ac2 | 112 | } |
jksoft | 1:48f6e08a3ac2 | 113 | |
jksoft | 1:48f6e08a3ac2 | 114 | #ifdef BLE_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 115 | // Fetch BLE Events. |
jksoft | 1:48f6e08a3ac2 | 116 | if (!no_more_ble_evts) |
jksoft | 1:48f6e08a3ac2 | 117 | { |
jksoft | 1:48f6e08a3ac2 | 118 | // Pull event from stack |
jksoft | 1:48f6e08a3ac2 | 119 | uint16_t evt_len = m_ble_evt_buffer_size; |
jksoft | 1:48f6e08a3ac2 | 120 | |
jksoft | 1:48f6e08a3ac2 | 121 | err_code = sd_ble_evt_get(m_evt_buffer, &evt_len); |
jksoft | 1:48f6e08a3ac2 | 122 | if (err_code == NRF_ERROR_NOT_FOUND) |
jksoft | 1:48f6e08a3ac2 | 123 | { |
jksoft | 1:48f6e08a3ac2 | 124 | no_more_ble_evts = true; |
jksoft | 1:48f6e08a3ac2 | 125 | } |
jksoft | 1:48f6e08a3ac2 | 126 | else if (err_code != NRF_SUCCESS) |
jksoft | 1:48f6e08a3ac2 | 127 | { |
jksoft | 1:48f6e08a3ac2 | 128 | APP_ERROR_HANDLER(err_code); |
jksoft | 1:48f6e08a3ac2 | 129 | } |
jksoft | 1:48f6e08a3ac2 | 130 | else |
jksoft | 1:48f6e08a3ac2 | 131 | { |
jksoft | 1:48f6e08a3ac2 | 132 | // Call application's BLE stack event handler. |
jksoft | 1:48f6e08a3ac2 | 133 | m_ble_evt_handler((ble_evt_t *)m_evt_buffer); |
jksoft | 1:48f6e08a3ac2 | 134 | } |
jksoft | 1:48f6e08a3ac2 | 135 | } |
jksoft | 1:48f6e08a3ac2 | 136 | #endif |
jksoft | 1:48f6e08a3ac2 | 137 | |
jksoft | 1:48f6e08a3ac2 | 138 | #ifdef ANT_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 139 | // Fetch ANT Events. |
jksoft | 1:48f6e08a3ac2 | 140 | if (!no_more_ant_evts) |
jksoft | 1:48f6e08a3ac2 | 141 | { |
jksoft | 1:48f6e08a3ac2 | 142 | // Pull event from stack |
jksoft | 1:48f6e08a3ac2 | 143 | err_code = sd_ant_event_get(&((ant_evt_t *)m_evt_buffer)->channel, |
jksoft | 1:48f6e08a3ac2 | 144 | &((ant_evt_t *)m_evt_buffer)->event, |
jksoft | 1:48f6e08a3ac2 | 145 | ((ant_evt_t *)m_evt_buffer)->evt_buffer); |
jksoft | 1:48f6e08a3ac2 | 146 | if (err_code == NRF_ERROR_NOT_FOUND) |
jksoft | 1:48f6e08a3ac2 | 147 | { |
jksoft | 1:48f6e08a3ac2 | 148 | no_more_ant_evts = true; |
jksoft | 1:48f6e08a3ac2 | 149 | } |
jksoft | 1:48f6e08a3ac2 | 150 | else if (err_code != NRF_SUCCESS) |
jksoft | 1:48f6e08a3ac2 | 151 | { |
jksoft | 1:48f6e08a3ac2 | 152 | APP_ERROR_HANDLER(err_code); |
jksoft | 1:48f6e08a3ac2 | 153 | } |
jksoft | 1:48f6e08a3ac2 | 154 | else |
jksoft | 1:48f6e08a3ac2 | 155 | { |
jksoft | 1:48f6e08a3ac2 | 156 | // Call application's ANT stack event handler. |
jksoft | 1:48f6e08a3ac2 | 157 | m_ant_evt_handler((ant_evt_t *)m_evt_buffer); |
jksoft | 1:48f6e08a3ac2 | 158 | } |
jksoft | 1:48f6e08a3ac2 | 159 | } |
jksoft | 1:48f6e08a3ac2 | 160 | #endif |
jksoft | 1:48f6e08a3ac2 | 161 | |
jksoft | 1:48f6e08a3ac2 | 162 | if (no_more_soc_evts) |
jksoft | 1:48f6e08a3ac2 | 163 | { |
jksoft | 1:48f6e08a3ac2 | 164 | // There are no remaining System (SOC) events to be fetched from the SoftDevice. |
jksoft | 1:48f6e08a3ac2 | 165 | #if defined(ANT_STACK_SUPPORT_REQD) && defined(BLE_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 166 | // Check if there are any remaining BLE and ANT events. |
jksoft | 1:48f6e08a3ac2 | 167 | if (no_more_ble_evts && no_more_ant_evts) |
jksoft | 1:48f6e08a3ac2 | 168 | { |
jksoft | 1:48f6e08a3ac2 | 169 | break; |
jksoft | 1:48f6e08a3ac2 | 170 | } |
jksoft | 1:48f6e08a3ac2 | 171 | #elif defined(BLE_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 172 | // Check if there are any remaining BLE events. |
jksoft | 1:48f6e08a3ac2 | 173 | if (no_more_ble_evts) |
jksoft | 1:48f6e08a3ac2 | 174 | { |
jksoft | 1:48f6e08a3ac2 | 175 | break; |
jksoft | 1:48f6e08a3ac2 | 176 | } |
jksoft | 1:48f6e08a3ac2 | 177 | #elif defined(ANT_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 178 | // Check if there are any remaining ANT events. |
jksoft | 1:48f6e08a3ac2 | 179 | if (no_more_ant_evts) |
jksoft | 1:48f6e08a3ac2 | 180 | { |
jksoft | 1:48f6e08a3ac2 | 181 | break; |
jksoft | 1:48f6e08a3ac2 | 182 | } |
jksoft | 1:48f6e08a3ac2 | 183 | #else |
jksoft | 1:48f6e08a3ac2 | 184 | // No need to check for BLE or ANT events since there is no support for BLE and ANT |
jksoft | 1:48f6e08a3ac2 | 185 | // required. |
jksoft | 1:48f6e08a3ac2 | 186 | break; |
jksoft | 1:48f6e08a3ac2 | 187 | #endif |
jksoft | 1:48f6e08a3ac2 | 188 | } |
jksoft | 1:48f6e08a3ac2 | 189 | } |
jksoft | 1:48f6e08a3ac2 | 190 | } |
jksoft | 1:48f6e08a3ac2 | 191 | |
jksoft | 1:48f6e08a3ac2 | 192 | |
jksoft | 1:48f6e08a3ac2 | 193 | uint32_t softdevice_handler_init(nrf_clock_lfclksrc_t clock_source, |
jksoft | 1:48f6e08a3ac2 | 194 | void * p_evt_buffer, |
jksoft | 1:48f6e08a3ac2 | 195 | uint16_t evt_buffer_size, |
jksoft | 1:48f6e08a3ac2 | 196 | softdevice_evt_schedule_func_t evt_schedule_func) |
jksoft | 1:48f6e08a3ac2 | 197 | { |
jksoft | 1:48f6e08a3ac2 | 198 | uint32_t err_code; |
jksoft | 1:48f6e08a3ac2 | 199 | |
jksoft | 1:48f6e08a3ac2 | 200 | // Save configuration. |
jksoft | 1:48f6e08a3ac2 | 201 | #if defined (BLE_STACK_SUPPORT_REQD) || defined (ANT_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 202 | // Check that buffer is not NULL. |
jksoft | 1:48f6e08a3ac2 | 203 | if (p_evt_buffer == NULL) |
jksoft | 1:48f6e08a3ac2 | 204 | { |
jksoft | 1:48f6e08a3ac2 | 205 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 1:48f6e08a3ac2 | 206 | } |
jksoft | 1:48f6e08a3ac2 | 207 | |
jksoft | 1:48f6e08a3ac2 | 208 | // Check that buffer is correctly aligned. |
jksoft | 1:48f6e08a3ac2 | 209 | if (!is_word_aligned(p_evt_buffer)) |
jksoft | 1:48f6e08a3ac2 | 210 | { |
jksoft | 1:48f6e08a3ac2 | 211 | return NRF_ERROR_INVALID_PARAM; |
jksoft | 1:48f6e08a3ac2 | 212 | } |
jksoft | 1:48f6e08a3ac2 | 213 | |
jksoft | 1:48f6e08a3ac2 | 214 | m_evt_buffer = (uint8_t *)p_evt_buffer; |
jksoft | 1:48f6e08a3ac2 | 215 | #else |
jksoft | 1:48f6e08a3ac2 | 216 | // The variable p_evt_buffer is not needed if neither BLE Stack nor ANT stack support is |
jksoft | 1:48f6e08a3ac2 | 217 | // required. |
jksoft | 1:48f6e08a3ac2 | 218 | UNUSED_PARAMETER(p_evt_buffer); |
jksoft | 1:48f6e08a3ac2 | 219 | #endif |
jksoft | 1:48f6e08a3ac2 | 220 | |
jksoft | 1:48f6e08a3ac2 | 221 | #if defined (BLE_STACK_SUPPORT_REQD) |
jksoft | 1:48f6e08a3ac2 | 222 | m_ble_evt_buffer_size = evt_buffer_size; |
jksoft | 1:48f6e08a3ac2 | 223 | #else |
jksoft | 1:48f6e08a3ac2 | 224 | // The variable evt_buffer_size is not needed if BLE Stack support is NOT required. |
jksoft | 1:48f6e08a3ac2 | 225 | UNUSED_PARAMETER(evt_buffer_size); |
jksoft | 1:48f6e08a3ac2 | 226 | #endif |
jksoft | 1:48f6e08a3ac2 | 227 | |
jksoft | 1:48f6e08a3ac2 | 228 | m_evt_schedule_func = evt_schedule_func; |
jksoft | 1:48f6e08a3ac2 | 229 | |
jksoft | 1:48f6e08a3ac2 | 230 | // Initialize SoftDevice. |
jksoft | 1:48f6e08a3ac2 | 231 | |
jksoft | 1:48f6e08a3ac2 | 232 | err_code = sd_softdevice_enable(clock_source, softdevice_assertion_handler); |
jksoft | 1:48f6e08a3ac2 | 233 | if (err_code != NRF_SUCCESS) |
jksoft | 1:48f6e08a3ac2 | 234 | { |
jksoft | 1:48f6e08a3ac2 | 235 | return err_code; |
jksoft | 1:48f6e08a3ac2 | 236 | } |
jksoft | 1:48f6e08a3ac2 | 237 | |
jksoft | 1:48f6e08a3ac2 | 238 | /** |
jksoft | 1:48f6e08a3ac2 | 239 | * Using this call, the application can select whether to include the |
jksoft | 1:48f6e08a3ac2 | 240 | * Service Changed characteristic in the GATT Server. The default in all |
jksoft | 1:48f6e08a3ac2 | 241 | * previous releases has been to include the Service Changed characteristic, |
jksoft | 1:48f6e08a3ac2 | 242 | * but this affects how GATT clients behave. Specifically, it requires |
jksoft | 1:48f6e08a3ac2 | 243 | * clients to subscribe to this attribute and not to cache attribute handles |
jksoft | 1:48f6e08a3ac2 | 244 | * between connections unless the devices are bonded. If the application |
jksoft | 1:48f6e08a3ac2 | 245 | * does not need to change the structure of the GATT server attributes at |
jksoft | 1:48f6e08a3ac2 | 246 | * runtime this adds unnecessary complexity to the interaction with peer |
jksoft | 1:48f6e08a3ac2 | 247 | * clients. If the SoftDevice is enabled with the Service Changed |
jksoft | 1:48f6e08a3ac2 | 248 | * Characteristics turned off, then clients are allowed to cache attribute |
jksoft | 1:48f6e08a3ac2 | 249 | * handles making applications simpler on both sides. |
jksoft | 1:48f6e08a3ac2 | 250 | */ |
jksoft | 1:48f6e08a3ac2 | 251 | ble_enable_params_t enableParams = { |
jksoft | 1:48f6e08a3ac2 | 252 | .gatts_enable_params = { |
jksoft | 1:48f6e08a3ac2 | 253 | .service_changed = 0 |
jksoft | 1:48f6e08a3ac2 | 254 | } |
jksoft | 1:48f6e08a3ac2 | 255 | }; |
jksoft | 1:48f6e08a3ac2 | 256 | if ((err_code = sd_ble_enable(&enableParams)) != NRF_SUCCESS) { |
jksoft | 1:48f6e08a3ac2 | 257 | return err_code; |
jksoft | 1:48f6e08a3ac2 | 258 | } |
jksoft | 1:48f6e08a3ac2 | 259 | |
jksoft | 1:48f6e08a3ac2 | 260 | ble_gap_addr_t addr; |
jksoft | 1:48f6e08a3ac2 | 261 | if ((err_code = sd_ble_gap_address_get(&addr)) != NRF_SUCCESS) { |
jksoft | 1:48f6e08a3ac2 | 262 | return err_code; |
jksoft | 1:48f6e08a3ac2 | 263 | } |
jksoft | 1:48f6e08a3ac2 | 264 | if ((err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr)) != NRF_SUCCESS) { |
jksoft | 1:48f6e08a3ac2 | 265 | return err_code; |
jksoft | 1:48f6e08a3ac2 | 266 | } |
jksoft | 1:48f6e08a3ac2 | 267 | |
jksoft | 1:48f6e08a3ac2 | 268 | m_softdevice_enabled = true; |
jksoft | 1:48f6e08a3ac2 | 269 | // Enable BLE event interrupt (interrupt priority has already been set by the stack). |
jksoft | 1:48f6e08a3ac2 | 270 | return sd_nvic_EnableIRQ(SWI2_IRQn); |
jksoft | 1:48f6e08a3ac2 | 271 | } |
jksoft | 1:48f6e08a3ac2 | 272 | |
jksoft | 1:48f6e08a3ac2 | 273 | |
jksoft | 1:48f6e08a3ac2 | 274 | uint32_t softdevice_handler_sd_disable(void) |
jksoft | 1:48f6e08a3ac2 | 275 | { |
jksoft | 1:48f6e08a3ac2 | 276 | uint32_t err_code = sd_softdevice_disable(); |
jksoft | 1:48f6e08a3ac2 | 277 | |
jksoft | 1:48f6e08a3ac2 | 278 | m_softdevice_enabled = !(err_code == NRF_SUCCESS); |
jksoft | 1:48f6e08a3ac2 | 279 | |
jksoft | 1:48f6e08a3ac2 | 280 | return err_code; |
jksoft | 1:48f6e08a3ac2 | 281 | } |
jksoft | 1:48f6e08a3ac2 | 282 | |
jksoft | 1:48f6e08a3ac2 | 283 | |
jksoft | 1:48f6e08a3ac2 | 284 | #ifdef BLE_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 285 | uint32_t softdevice_ble_evt_handler_set(ble_evt_handler_t ble_evt_handler) |
jksoft | 1:48f6e08a3ac2 | 286 | { |
jksoft | 1:48f6e08a3ac2 | 287 | if (ble_evt_handler == NULL) |
jksoft | 1:48f6e08a3ac2 | 288 | { |
jksoft | 1:48f6e08a3ac2 | 289 | return NRF_ERROR_NULL; |
jksoft | 1:48f6e08a3ac2 | 290 | } |
jksoft | 1:48f6e08a3ac2 | 291 | |
jksoft | 1:48f6e08a3ac2 | 292 | m_ble_evt_handler = ble_evt_handler; |
jksoft | 1:48f6e08a3ac2 | 293 | |
jksoft | 1:48f6e08a3ac2 | 294 | return NRF_SUCCESS; |
jksoft | 1:48f6e08a3ac2 | 295 | } |
jksoft | 1:48f6e08a3ac2 | 296 | #endif |
jksoft | 1:48f6e08a3ac2 | 297 | |
jksoft | 1:48f6e08a3ac2 | 298 | |
jksoft | 1:48f6e08a3ac2 | 299 | #ifdef ANT_STACK_SUPPORT_REQD |
jksoft | 1:48f6e08a3ac2 | 300 | uint32_t softdevice_ant_evt_handler_set(ant_evt_handler_t ant_evt_handler) |
jksoft | 1:48f6e08a3ac2 | 301 | { |
jksoft | 1:48f6e08a3ac2 | 302 | if (ant_evt_handler == NULL) |
jksoft | 1:48f6e08a3ac2 | 303 | { |
jksoft | 1:48f6e08a3ac2 | 304 | return NRF_ERROR_NULL; |
jksoft | 1:48f6e08a3ac2 | 305 | } |
jksoft | 1:48f6e08a3ac2 | 306 | |
jksoft | 1:48f6e08a3ac2 | 307 | m_ant_evt_handler = ant_evt_handler; |
jksoft | 1:48f6e08a3ac2 | 308 | |
jksoft | 1:48f6e08a3ac2 | 309 | return NRF_SUCCESS; |
jksoft | 1:48f6e08a3ac2 | 310 | } |
jksoft | 1:48f6e08a3ac2 | 311 | #endif |
jksoft | 1:48f6e08a3ac2 | 312 | |
jksoft | 1:48f6e08a3ac2 | 313 | |
jksoft | 1:48f6e08a3ac2 | 314 | uint32_t softdevice_sys_evt_handler_set(sys_evt_handler_t sys_evt_handler) |
jksoft | 1:48f6e08a3ac2 | 315 | { |
jksoft | 1:48f6e08a3ac2 | 316 | if (sys_evt_handler == NULL) |
jksoft | 1:48f6e08a3ac2 | 317 | { |
jksoft | 1:48f6e08a3ac2 | 318 | return NRF_ERROR_NULL; |
jksoft | 1:48f6e08a3ac2 | 319 | } |
jksoft | 1:48f6e08a3ac2 | 320 | |
jksoft | 1:48f6e08a3ac2 | 321 | m_sys_evt_handler = sys_evt_handler; |
jksoft | 1:48f6e08a3ac2 | 322 | |
jksoft | 1:48f6e08a3ac2 | 323 | return NRF_SUCCESS; |
jksoft | 1:48f6e08a3ac2 | 324 | } |
jksoft | 1:48f6e08a3ac2 | 325 | |
jksoft | 1:48f6e08a3ac2 | 326 | |
jksoft | 1:48f6e08a3ac2 | 327 | /**@brief Function for handling the Application's BLE Stack events interrupt. |
jksoft | 1:48f6e08a3ac2 | 328 | * |
jksoft | 1:48f6e08a3ac2 | 329 | * @details This function is called whenever an event is ready to be pulled. |
jksoft | 1:48f6e08a3ac2 | 330 | */ |
jksoft | 1:48f6e08a3ac2 | 331 | extern "C" void SWI2_IRQHandler(void) |
jksoft | 1:48f6e08a3ac2 | 332 | { |
jksoft | 1:48f6e08a3ac2 | 333 | if (m_evt_schedule_func != NULL) |
jksoft | 1:48f6e08a3ac2 | 334 | { |
jksoft | 1:48f6e08a3ac2 | 335 | uint32_t err_code = m_evt_schedule_func(); |
jksoft | 1:48f6e08a3ac2 | 336 | APP_ERROR_CHECK(err_code); |
jksoft | 1:48f6e08a3ac2 | 337 | } |
jksoft | 1:48f6e08a3ac2 | 338 | else |
jksoft | 1:48f6e08a3ac2 | 339 | { |
jksoft | 1:48f6e08a3ac2 | 340 | intern_softdevice_events_execute(); |
jksoft | 1:48f6e08a3ac2 | 341 | } |
jksoft | 1:48f6e08a3ac2 | 342 | } |