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