Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
TARGET_NRF5/source/nRF5xGap.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
638:c90ae1400bf2 | 1 | /* mbed Microcontroller Library |
Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Vincent Coubard |
638:c90ae1400bf2 | 3 | * |
Vincent Coubard |
638:c90ae1400bf2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Vincent Coubard |
638:c90ae1400bf2 | 5 | * you may not use this file except in compliance with the License. |
Vincent Coubard |
638:c90ae1400bf2 | 6 | * You may obtain a copy of the License at |
Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
Vincent Coubard |
638:c90ae1400bf2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Vincent Coubard |
638:c90ae1400bf2 | 9 | * |
Vincent Coubard |
638:c90ae1400bf2 | 10 | * Unless required by applicable law or agreed to in writing, software |
Vincent Coubard |
638:c90ae1400bf2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Vincent Coubard |
638:c90ae1400bf2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Vincent Coubard |
638:c90ae1400bf2 | 13 | * See the License for the specific language governing permissions and |
Vincent Coubard |
638:c90ae1400bf2 | 14 | * limitations under the License. |
Vincent Coubard |
638:c90ae1400bf2 | 15 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 16 | |
Vincent Coubard |
638:c90ae1400bf2 | 17 | #ifndef __NRF5x_GAP_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 18 | #define __NRF5x_GAP_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 19 | |
Vincent Coubard |
638:c90ae1400bf2 | 20 | #ifdef YOTTA_CFG_MBED_OS |
Vincent Coubard |
638:c90ae1400bf2 | 21 | #include "mbed-drivers/mbed.h" |
Vincent Coubard |
638:c90ae1400bf2 | 22 | #else |
Vincent Coubard |
638:c90ae1400bf2 | 23 | #include "mbed.h" |
Vincent Coubard |
638:c90ae1400bf2 | 24 | #endif |
Vincent Coubard |
638:c90ae1400bf2 | 25 | #ifndef YOTTA_CFG_WHITELIST_MAX_SIZE |
Vincent Coubard |
638:c90ae1400bf2 | 26 | #define YOTTA_CFG_WHITELIST_MAX_SIZE BLE_GAP_WHITELIST_ADDR_MAX_COUNT |
Vincent Coubard |
638:c90ae1400bf2 | 27 | #elif YOTTA_CFG_WHITELIST_MAX_SIZE > BLE_GAP_WHITELIST_ADDR_MAX_COUNT |
Vincent Coubard |
638:c90ae1400bf2 | 28 | #undef YOTTA_CFG_WHITELIST_MAX_SIZE |
Vincent Coubard |
638:c90ae1400bf2 | 29 | #define YOTTA_CFG_WHITELIST_MAX_SIZE BLE_GAP_WHITELIST_ADDR_MAX_COUNT |
Vincent Coubard |
638:c90ae1400bf2 | 30 | #endif |
Vincent Coubard |
638:c90ae1400bf2 | 31 | #ifndef YOTTA_CFG_IRK_TABLE_MAX_SIZE |
Vincent Coubard |
638:c90ae1400bf2 | 32 | #define YOTTA_CFG_IRK_TABLE_MAX_SIZE BLE_GAP_WHITELIST_IRK_MAX_COUNT |
Vincent Coubard |
638:c90ae1400bf2 | 33 | #elif YOTTA_CFG_IRK_TABLE_MAX_SIZE > BLE_GAP_WHITELIST_IRK_MAX_COUNT |
Vincent Coubard |
638:c90ae1400bf2 | 34 | #undef YOTTA_CFG_IRK_TABLE_MAX_SIZE |
Vincent Coubard |
638:c90ae1400bf2 | 35 | #define YOTTA_CFG_IRK_TABLE_MAX_SIZE BLE_GAP_WHITELIST_IRK_MAX_COUNT |
Vincent Coubard |
638:c90ae1400bf2 | 36 | #endif |
Vincent Coubard |
638:c90ae1400bf2 | 37 | #include "ble/blecommon.h" |
Vincent Coubard |
638:c90ae1400bf2 | 38 | #include "nrf_ble.h" |
Vincent Coubard |
638:c90ae1400bf2 | 39 | #include "ble/GapAdvertisingParams.h" |
Vincent Coubard |
638:c90ae1400bf2 | 40 | #include "ble/GapAdvertisingData.h" |
Vincent Coubard |
638:c90ae1400bf2 | 41 | #include "ble/Gap.h" |
Vincent Coubard |
638:c90ae1400bf2 | 42 | #include "ble/GapScanningParams.h" |
Vincent Coubard |
638:c90ae1400bf2 | 43 | |
Vincent Coubard |
638:c90ae1400bf2 | 44 | #include "nrf_soc.h" |
Vincent Coubard |
638:c90ae1400bf2 | 45 | |
Vincent Coubard |
638:c90ae1400bf2 | 46 | extern "C" { |
Vincent Coubard |
638:c90ae1400bf2 | 47 | #include "ble_radio_notification.h" |
Vincent Coubard |
638:c90ae1400bf2 | 48 | #include "app_util_platform.h" |
Vincent Coubard |
638:c90ae1400bf2 | 49 | } |
Vincent Coubard |
638:c90ae1400bf2 | 50 | |
Vincent Coubard |
638:c90ae1400bf2 | 51 | #include "btle_security.h" |
Vincent Coubard |
638:c90ae1400bf2 | 52 | |
Vincent Coubard |
638:c90ae1400bf2 | 53 | void radioNotificationStaticCallback(bool param); |
Vincent Coubard |
638:c90ae1400bf2 | 54 | |
Vincent Coubard |
638:c90ae1400bf2 | 55 | /**************************************************************************/ |
Vincent Coubard |
638:c90ae1400bf2 | 56 | /*! |
Vincent Coubard |
638:c90ae1400bf2 | 57 | \brief |
Vincent Coubard |
638:c90ae1400bf2 | 58 | |
Vincent Coubard |
638:c90ae1400bf2 | 59 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 60 | /**************************************************************************/ |
Vincent Coubard |
638:c90ae1400bf2 | 61 | class nRF5xGap : public Gap |
Vincent Coubard |
638:c90ae1400bf2 | 62 | { |
Vincent Coubard |
638:c90ae1400bf2 | 63 | public: |
Vincent Coubard |
638:c90ae1400bf2 | 64 | /* Functions that must be implemented from Gap */ |
Vincent Coubard |
638:c90ae1400bf2 | 65 | virtual ble_error_t setAddress(AddressType_t type, const Address_t address); |
Vincent Coubard |
638:c90ae1400bf2 | 66 | virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address); |
Vincent Coubard |
638:c90ae1400bf2 | 67 | virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &); |
Vincent Coubard |
638:c90ae1400bf2 | 68 | |
Vincent Coubard |
638:c90ae1400bf2 | 69 | virtual uint16_t getMinAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MIN);} |
Vincent Coubard |
638:c90ae1400bf2 | 70 | virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_NONCON_INTERVAL_MIN);} |
Vincent Coubard |
638:c90ae1400bf2 | 71 | virtual uint16_t getMaxAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLE_GAP_ADV_INTERVAL_MAX);} |
Vincent Coubard |
638:c90ae1400bf2 | 72 | |
Vincent Coubard |
638:c90ae1400bf2 | 73 | virtual ble_error_t startAdvertising(const GapAdvertisingParams &); |
Vincent Coubard |
638:c90ae1400bf2 | 74 | virtual ble_error_t stopAdvertising(void); |
Vincent Coubard |
638:c90ae1400bf2 | 75 | virtual ble_error_t connect(const Address_t, BLEProtocol::AddressType_t peerAddrType, const ConnectionParams_t *connectionParams, const GapScanningParams *scanParams); |
Vincent Coubard |
638:c90ae1400bf2 | 76 | virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason); |
Vincent Coubard |
638:c90ae1400bf2 | 77 | virtual ble_error_t disconnect(DisconnectionReason_t reason); |
Vincent Coubard |
638:c90ae1400bf2 | 78 | |
Vincent Coubard |
638:c90ae1400bf2 | 79 | virtual ble_error_t setDeviceName(const uint8_t *deviceName); |
Vincent Coubard |
638:c90ae1400bf2 | 80 | virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP); |
Vincent Coubard |
638:c90ae1400bf2 | 81 | virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance); |
Vincent Coubard |
638:c90ae1400bf2 | 82 | virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP); |
Vincent Coubard |
638:c90ae1400bf2 | 83 | |
Vincent Coubard |
638:c90ae1400bf2 | 84 | virtual ble_error_t setTxPower(int8_t txPower); |
Vincent Coubard |
638:c90ae1400bf2 | 85 | virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP); |
Vincent Coubard |
638:c90ae1400bf2 | 86 | |
Vincent Coubard |
638:c90ae1400bf2 | 87 | void setConnectionHandle(uint16_t con_handle); |
Vincent Coubard |
638:c90ae1400bf2 | 88 | uint16_t getConnectionHandle(void); |
Vincent Coubard |
638:c90ae1400bf2 | 89 | |
Vincent Coubard |
638:c90ae1400bf2 | 90 | virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params); |
Vincent Coubard |
638:c90ae1400bf2 | 91 | virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params); |
Vincent Coubard |
638:c90ae1400bf2 | 92 | virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params); |
Vincent Coubard |
638:c90ae1400bf2 | 93 | |
Vincent Coubard |
638:c90ae1400bf2 | 94 | virtual ble_error_t reset(void); |
Vincent Coubard |
638:c90ae1400bf2 | 95 | |
Vincent Coubard |
638:c90ae1400bf2 | 96 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 97 | * The following functions are part of the whitelisting experimental API. |
Vincent Coubard |
638:c90ae1400bf2 | 98 | * Therefore, this functionality can change in the near future. |
Vincent Coubard |
638:c90ae1400bf2 | 99 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 100 | virtual uint8_t getMaxWhitelistSize(void) const; |
Vincent Coubard |
638:c90ae1400bf2 | 101 | virtual ble_error_t getWhitelist(Gap::Whitelist_t &whitelistOut) const; |
Vincent Coubard |
638:c90ae1400bf2 | 102 | virtual ble_error_t setWhitelist(const Gap::Whitelist_t &whitelistIn); |
Vincent Coubard |
638:c90ae1400bf2 | 103 | |
Vincent Coubard |
638:c90ae1400bf2 | 104 | virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode); |
Vincent Coubard |
638:c90ae1400bf2 | 105 | virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode); |
Vincent Coubard |
638:c90ae1400bf2 | 106 | virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode); |
Vincent Coubard |
638:c90ae1400bf2 | 107 | virtual Gap::AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const; |
Vincent Coubard |
638:c90ae1400bf2 | 108 | virtual Gap::ScanningPolicyMode_t getScanningPolicyMode(void) const; |
Vincent Coubard |
638:c90ae1400bf2 | 109 | virtual Gap::InitiatorPolicyMode_t getInitiatorPolicyMode(void) const; |
Vincent Coubard |
638:c90ae1400bf2 | 110 | |
Vincent Coubard |
638:c90ae1400bf2 | 111 | virtual ble_error_t initRadioNotification(void) { |
Vincent Coubard |
638:c90ae1400bf2 | 112 | if (ble_radio_notification_init(APP_IRQ_PRIORITY_HIGH /*MID*/, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationStaticCallback) == NRF_SUCCESS) { |
Vincent Coubard |
638:c90ae1400bf2 | 113 | return BLE_ERROR_NONE; |
Vincent Coubard |
638:c90ae1400bf2 | 114 | } |
Vincent Coubard |
638:c90ae1400bf2 | 115 | |
Vincent Coubard |
638:c90ae1400bf2 | 116 | return BLE_ERROR_UNSPECIFIED; |
Vincent Coubard |
638:c90ae1400bf2 | 117 | } |
Vincent Coubard |
638:c90ae1400bf2 | 118 | |
Vincent Coubard |
638:c90ae1400bf2 | 119 | /* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */ |
Vincent Coubard |
638:c90ae1400bf2 | 120 | #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) |
Vincent Coubard |
638:c90ae1400bf2 | 121 | virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams); |
Vincent Coubard |
638:c90ae1400bf2 | 122 | virtual ble_error_t stopScan(void); |
Vincent Coubard |
638:c90ae1400bf2 | 123 | #endif |
Vincent Coubard |
638:c90ae1400bf2 | 124 | |
Vincent Coubard |
638:c90ae1400bf2 | 125 | private: |
Vincent Coubard |
638:c90ae1400bf2 | 126 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 127 | * Whitelisting API related structures and helper functions. |
Vincent Coubard |
638:c90ae1400bf2 | 128 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 129 | |
Vincent Coubard |
638:c90ae1400bf2 | 130 | /* Policy modes set by the user. By default these are set to ignore the whitelist */ |
Vincent Coubard |
638:c90ae1400bf2 | 131 | Gap::AdvertisingPolicyMode_t advertisingPolicyMode; |
Vincent Coubard |
638:c90ae1400bf2 | 132 | Gap::ScanningPolicyMode_t scanningPolicyMode; |
Vincent Coubard |
638:c90ae1400bf2 | 133 | |
Vincent Coubard |
638:c90ae1400bf2 | 134 | /* Internal representation of a whitelist */ |
Vincent Coubard |
638:c90ae1400bf2 | 135 | uint8_t whitelistAddressesSize; |
Vincent Coubard |
638:c90ae1400bf2 | 136 | ble_gap_addr_t whitelistAddresses[YOTTA_CFG_WHITELIST_MAX_SIZE]; |
Vincent Coubard |
638:c90ae1400bf2 | 137 | |
Vincent Coubard |
638:c90ae1400bf2 | 138 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 139 | * An internal function used to populate the ble_gap_whitelist_t that will be used by |
Vincent Coubard |
638:c90ae1400bf2 | 140 | * the SoftDevice for filtering requests. This function is needed because for the BLE |
Vincent Coubard |
638:c90ae1400bf2 | 141 | * API the whitelist is just a collection of keys, but for the stack it also includes |
Vincent Coubard |
638:c90ae1400bf2 | 142 | * the IRK table. |
Vincent Coubard |
638:c90ae1400bf2 | 143 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 144 | ble_error_t generateStackWhitelist(ble_gap_whitelist_t &whitelist); |
Vincent Coubard |
638:c90ae1400bf2 | 145 | |
Vincent Coubard |
638:c90ae1400bf2 | 146 | private: |
Vincent Coubard |
638:c90ae1400bf2 | 147 | bool radioNotificationCallbackParam; /* parameter to be passed into the Timeout-generated radio notification callback. */ |
Vincent Coubard |
638:c90ae1400bf2 | 148 | Timeout radioNotificationTimeout; |
Vincent Coubard |
638:c90ae1400bf2 | 149 | |
Vincent Coubard |
638:c90ae1400bf2 | 150 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 151 | * A helper function to post radio notification callbacks with low interrupt priority. |
Vincent Coubard |
638:c90ae1400bf2 | 152 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 153 | void postRadioNotificationCallback(void) { |
Vincent Coubard |
638:c90ae1400bf2 | 154 | #ifdef YOTTA_CFG_MBED_OS |
Vincent Coubard |
638:c90ae1400bf2 | 155 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 156 | * In mbed OS, all user-facing BLE events (interrupts) are posted to the |
Vincent Coubard |
638:c90ae1400bf2 | 157 | * MINAR scheduler to be executed as callbacks in thread mode. MINAR guards |
Vincent Coubard |
638:c90ae1400bf2 | 158 | * its critical sections from interrupts by acquiring CriticalSectionLock, |
Vincent Coubard |
638:c90ae1400bf2 | 159 | * which results in a call to sd_nvic_critical_region_enter(). Thus, it is |
Vincent Coubard |
638:c90ae1400bf2 | 160 | * safe to invoke MINAR APIs from interrupt context as long as those |
Vincent Coubard |
638:c90ae1400bf2 | 161 | * interrupts are blocked by sd_nvic_critical_region_enter(). |
Vincent Coubard |
638:c90ae1400bf2 | 162 | * |
Vincent Coubard |
638:c90ae1400bf2 | 163 | * Radio notifications are a special case for the above. The Radio |
Vincent Coubard |
638:c90ae1400bf2 | 164 | * Notification IRQ is handled at a very high priority--higher than the |
Vincent Coubard |
638:c90ae1400bf2 | 165 | * level blocked by sd_nvic_critical_region_enter(). Thus Radio Notification |
Vincent Coubard |
638:c90ae1400bf2 | 166 | * events can preempt MINAR's critical sections. Using MINAR APIs (such as |
Vincent Coubard |
638:c90ae1400bf2 | 167 | * posting an event) directly in processRadioNotification() may result in a |
Vincent Coubard |
638:c90ae1400bf2 | 168 | * race condition ending in a hard-fault. |
Vincent Coubard |
638:c90ae1400bf2 | 169 | * |
Vincent Coubard |
638:c90ae1400bf2 | 170 | * The solution is to *not* call MINAR APIs directly from the Radio |
Vincent Coubard |
638:c90ae1400bf2 | 171 | * Notification handling; i.e. to do the bulk of RadioNotification |
Vincent Coubard |
638:c90ae1400bf2 | 172 | * processing at a reduced priority which respects MINAR's critical |
Vincent Coubard |
638:c90ae1400bf2 | 173 | * sections. Unfortunately, on a cortex-M0, there is no clean way to demote |
Vincent Coubard |
638:c90ae1400bf2 | 174 | * priority for the currently executing interrupt--we wouldn't want to |
Vincent Coubard |
638:c90ae1400bf2 | 175 | * demote the radio notification handling anyway because it is sensitive to |
Vincent Coubard |
638:c90ae1400bf2 | 176 | * timing, and the system expects to finish this handling very quickly. The |
Vincent Coubard |
638:c90ae1400bf2 | 177 | * workaround is to employ a Timeout to trigger |
Vincent Coubard |
638:c90ae1400bf2 | 178 | * postRadioNotificationCallback() after a very short delay (~0 us) and post |
Vincent Coubard |
638:c90ae1400bf2 | 179 | * the MINAR callback that context. |
Vincent Coubard |
638:c90ae1400bf2 | 180 | * |
Vincent Coubard |
638:c90ae1400bf2 | 181 | * !!!WARNING!!! Radio notifications are very time critical events. The |
Vincent Coubard |
638:c90ae1400bf2 | 182 | * current solution is expected to work under the assumption that |
Vincent Coubard |
638:c90ae1400bf2 | 183 | * postRadioNotificationCalback() will be executed BEFORE the next radio |
Vincent Coubard |
638:c90ae1400bf2 | 184 | * notification event is generated. |
Vincent Coubard |
638:c90ae1400bf2 | 185 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 186 | minar::Scheduler::postCallback( |
Vincent Coubard |
638:c90ae1400bf2 | 187 | mbed::util::FunctionPointer1<void, bool>(&radioNotificationCallback, &FunctionPointerWithContext<bool>::call).bind(radioNotificationCallbackParam) |
Vincent Coubard |
638:c90ae1400bf2 | 188 | ); |
Vincent Coubard |
638:c90ae1400bf2 | 189 | #else |
Vincent Coubard |
638:c90ae1400bf2 | 190 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 191 | * In mbed classic, all user-facing BLE events execute callbacks in interrupt |
Vincent Coubard |
638:c90ae1400bf2 | 192 | * mode. Radio Notifications are a special case because its IRQ is handled at |
Vincent Coubard |
638:c90ae1400bf2 | 193 | * a very high priority. Thus Radio Notification events can preempt other |
Vincent Coubard |
638:c90ae1400bf2 | 194 | * operations that require interaction with the SoftDevice such as advertising |
Vincent Coubard |
638:c90ae1400bf2 | 195 | * payload updates and changing the Gap state. Therefore, executing a Radio |
Vincent Coubard |
638:c90ae1400bf2 | 196 | * Notification callback directly from processRadioNotification() may result |
Vincent Coubard |
638:c90ae1400bf2 | 197 | * in a race condition ending in a hard-fault. |
Vincent Coubard |
638:c90ae1400bf2 | 198 | * |
Vincent Coubard |
638:c90ae1400bf2 | 199 | * The solution is to *not* execute the Radio Notification callback directly |
Vincent Coubard |
638:c90ae1400bf2 | 200 | * from the Radio Notification handling; i.e. to do the bulk of the |
Vincent Coubard |
638:c90ae1400bf2 | 201 | * Radio Notification processing at a reduced priority. Unfortunately, on a |
Vincent Coubard |
638:c90ae1400bf2 | 202 | * cortex-M0, there is no clean way to demote priority for the currently |
Vincent Coubard |
638:c90ae1400bf2 | 203 | * executing interrupt--we wouldn't want to demote the radio notification |
Vincent Coubard |
638:c90ae1400bf2 | 204 | * handling anyway because it is sensitive to timing, and the system expects |
Vincent Coubard |
638:c90ae1400bf2 | 205 | * to finish this handling very quickly. The workaround is to employ a Timeout |
Vincent Coubard |
638:c90ae1400bf2 | 206 | * to trigger postRadioNotificationCallback() after a very short delay (~0 us) |
Vincent Coubard |
638:c90ae1400bf2 | 207 | * and execute the callback in that context. |
Vincent Coubard |
638:c90ae1400bf2 | 208 | * |
Vincent Coubard |
638:c90ae1400bf2 | 209 | * !!!WARNING!!! Radio notifications are very time critical events. The |
Vincent Coubard |
638:c90ae1400bf2 | 210 | * current solution is expected to work under the assumption that |
Vincent Coubard |
638:c90ae1400bf2 | 211 | * postRadioNotificationCalback() will be executed BEFORE the next radio |
Vincent Coubard |
638:c90ae1400bf2 | 212 | * notification event is generated. |
Vincent Coubard |
638:c90ae1400bf2 | 213 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 214 | radioNotificationCallback.call(radioNotificationCallbackParam); |
Vincent Coubard |
638:c90ae1400bf2 | 215 | #endif /* #ifdef YOTTA_CFG_MBED_OS */ |
Vincent Coubard |
638:c90ae1400bf2 | 216 | } |
Vincent Coubard |
638:c90ae1400bf2 | 217 | |
Vincent Coubard |
638:c90ae1400bf2 | 218 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 219 | * A helper function to process radio-notification events; to be called internally. |
Vincent Coubard |
638:c90ae1400bf2 | 220 | * @param param [description] |
Vincent Coubard |
638:c90ae1400bf2 | 221 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 222 | void processRadioNotificationEvent(bool param) { |
Vincent Coubard |
638:c90ae1400bf2 | 223 | radioNotificationCallbackParam = param; |
Vincent Coubard |
638:c90ae1400bf2 | 224 | radioNotificationTimeout.attach_us(this, &nRF5xGap::postRadioNotificationCallback, 0); |
Vincent Coubard |
638:c90ae1400bf2 | 225 | } |
Vincent Coubard |
638:c90ae1400bf2 | 226 | friend void radioNotificationStaticCallback(bool param); /* allow invocations of processRadioNotificationEvent() */ |
Vincent Coubard |
638:c90ae1400bf2 | 227 | |
Vincent Coubard |
638:c90ae1400bf2 | 228 | private: |
Vincent Coubard |
638:c90ae1400bf2 | 229 | uint16_t m_connectionHandle; |
Vincent Coubard |
638:c90ae1400bf2 | 230 | |
Vincent Coubard |
638:c90ae1400bf2 | 231 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 232 | * Allow instantiation from nRF5xn when required. |
Vincent Coubard |
638:c90ae1400bf2 | 233 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 234 | friend class nRF5xn; |
Vincent Coubard |
638:c90ae1400bf2 | 235 | |
Vincent Coubard |
638:c90ae1400bf2 | 236 | nRF5xGap() : |
Vincent Coubard |
638:c90ae1400bf2 | 237 | advertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST), |
Vincent Coubard |
638:c90ae1400bf2 | 238 | scanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST), |
Vincent Coubard |
638:c90ae1400bf2 | 239 | whitelistAddressesSize(0) { |
Vincent Coubard |
638:c90ae1400bf2 | 240 | m_connectionHandle = BLE_CONN_HANDLE_INVALID; |
Vincent Coubard |
638:c90ae1400bf2 | 241 | } |
Vincent Coubard |
638:c90ae1400bf2 | 242 | |
Vincent Coubard |
638:c90ae1400bf2 | 243 | nRF5xGap(nRF5xGap const &); |
Vincent Coubard |
638:c90ae1400bf2 | 244 | void operator=(nRF5xGap const &); |
Vincent Coubard |
638:c90ae1400bf2 | 245 | }; |
Vincent Coubard |
638:c90ae1400bf2 | 246 | |
Vincent Coubard |
638:c90ae1400bf2 | 247 | #endif // ifndef __NRF5x_GAP_H__ |