PBL mbed final
Fork of nRF51822 by
TARGET_NRF5/source/nRF5xn.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 __NRF51822_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 18 | #define __NRF51822_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 19 | |
Vincent Coubard |
638:c90ae1400bf2 | 20 | #include "ble/BLE.h" |
Vincent Coubard |
638:c90ae1400bf2 | 21 | #include "ble/blecommon.h" |
Vincent Coubard |
638:c90ae1400bf2 | 22 | #include "ble/BLEInstanceBase.h" |
Vincent Coubard |
638:c90ae1400bf2 | 23 | |
Vincent Coubard |
638:c90ae1400bf2 | 24 | #include "nRF5xGap.h" |
Vincent Coubard |
638:c90ae1400bf2 | 25 | #include "nRF5xGattServer.h" |
Vincent Coubard |
638:c90ae1400bf2 | 26 | #include "nRF5xGattClient.h" |
Vincent Coubard |
638:c90ae1400bf2 | 27 | #include "nRF5xSecurityManager.h" |
Vincent Coubard |
638:c90ae1400bf2 | 28 | |
Vincent Coubard |
638:c90ae1400bf2 | 29 | #include "btle.h" |
Vincent Coubard |
638:c90ae1400bf2 | 30 | |
Vincent Coubard |
638:c90ae1400bf2 | 31 | class nRF5xn : public BLEInstanceBase |
Vincent Coubard |
638:c90ae1400bf2 | 32 | { |
Vincent Coubard |
638:c90ae1400bf2 | 33 | public: |
Vincent Coubard |
638:c90ae1400bf2 | 34 | nRF5xn(void); |
Vincent Coubard |
638:c90ae1400bf2 | 35 | virtual ~nRF5xn(void); |
Vincent Coubard |
638:c90ae1400bf2 | 36 | |
Vincent Coubard |
638:c90ae1400bf2 | 37 | virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback); |
Vincent Coubard |
638:c90ae1400bf2 | 38 | virtual bool hasInitialized(void) const { |
Vincent Coubard |
638:c90ae1400bf2 | 39 | return initialized; |
Vincent Coubard |
638:c90ae1400bf2 | 40 | } |
Vincent Coubard |
638:c90ae1400bf2 | 41 | virtual ble_error_t shutdown(void); |
Vincent Coubard |
638:c90ae1400bf2 | 42 | virtual const char *getVersion(void); |
Vincent Coubard |
638:c90ae1400bf2 | 43 | |
Vincent Coubard |
638:c90ae1400bf2 | 44 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 45 | * Accessors to GAP. This function checks whether gapInstance points to an |
Vincent Coubard |
638:c90ae1400bf2 | 46 | * object. If if does not, then the gapInstance is updated to |
Vincent Coubard |
638:c90ae1400bf2 | 47 | * &_getInstance before returning. |
Vincent Coubard |
638:c90ae1400bf2 | 48 | * |
Vincent Coubard |
638:c90ae1400bf2 | 49 | * @return A reference to GattServer. |
Vincent Coubard |
638:c90ae1400bf2 | 50 | * |
Vincent Coubard |
638:c90ae1400bf2 | 51 | * @note Unlike the GattClient, GattServer and SecurityManager, Gap is |
Vincent Coubard |
638:c90ae1400bf2 | 52 | * always needed in a BLE application. Therefore it is allocated |
Vincent Coubard |
638:c90ae1400bf2 | 53 | * statically. |
Vincent Coubard |
638:c90ae1400bf2 | 54 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 55 | virtual Gap &getGap() { |
Vincent Coubard |
638:c90ae1400bf2 | 56 | return gapInstance; |
Vincent Coubard |
638:c90ae1400bf2 | 57 | }; |
Vincent Coubard |
638:c90ae1400bf2 | 58 | |
Vincent Coubard |
638:c90ae1400bf2 | 59 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 60 | * Accessors to GATT Server. This function checks whether a GattServer |
Vincent Coubard |
638:c90ae1400bf2 | 61 | * object was previously instantiated. If such object does not exist, then |
Vincent Coubard |
638:c90ae1400bf2 | 62 | * it is created before returning. |
Vincent Coubard |
638:c90ae1400bf2 | 63 | * |
Vincent Coubard |
638:c90ae1400bf2 | 64 | * @return A reference to GattServer. |
Vincent Coubard |
638:c90ae1400bf2 | 65 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 66 | virtual GattServer &getGattServer() { |
Vincent Coubard |
638:c90ae1400bf2 | 67 | if (gattServerInstance == NULL) { |
Vincent Coubard |
638:c90ae1400bf2 | 68 | gattServerInstance = new nRF5xGattServer(); |
Vincent Coubard |
638:c90ae1400bf2 | 69 | } |
Vincent Coubard |
638:c90ae1400bf2 | 70 | return *gattServerInstance; |
Vincent Coubard |
638:c90ae1400bf2 | 71 | }; |
Vincent Coubard |
638:c90ae1400bf2 | 72 | |
Vincent Coubard |
638:c90ae1400bf2 | 73 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 74 | * Accessors to GATT Client. This function checks whether a GattClient |
Vincent Coubard |
638:c90ae1400bf2 | 75 | * object was previously instantiated. If such object does not exist, then |
Vincent Coubard |
638:c90ae1400bf2 | 76 | * it is created before returning. |
Vincent Coubard |
638:c90ae1400bf2 | 77 | * |
Vincent Coubard |
638:c90ae1400bf2 | 78 | * @return A reference to GattClient. |
Vincent Coubard |
638:c90ae1400bf2 | 79 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 80 | virtual nRF5xGattClient &getGattClient() { |
Vincent Coubard |
638:c90ae1400bf2 | 81 | if (gattClientInstance == NULL) { |
Vincent Coubard |
638:c90ae1400bf2 | 82 | gattClientInstance = new nRF5xGattClient(); |
Vincent Coubard |
638:c90ae1400bf2 | 83 | } |
Vincent Coubard |
638:c90ae1400bf2 | 84 | return *gattClientInstance; |
Vincent Coubard |
638:c90ae1400bf2 | 85 | } |
Vincent Coubard |
638:c90ae1400bf2 | 86 | |
Vincent Coubard |
638:c90ae1400bf2 | 87 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 88 | * Accessors to Security Manager. This function checks whether a SecurityManager |
Vincent Coubard |
638:c90ae1400bf2 | 89 | * object was previously instantiated. If such object does not exist, then |
Vincent Coubard |
638:c90ae1400bf2 | 90 | * it is created before returning. |
Vincent Coubard |
638:c90ae1400bf2 | 91 | * |
Vincent Coubard |
638:c90ae1400bf2 | 92 | * @return A reference to GattServer. |
Vincent Coubard |
638:c90ae1400bf2 | 93 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 94 | virtual nRF5xSecurityManager &getSecurityManager() { |
Vincent Coubard |
638:c90ae1400bf2 | 95 | if (securityManagerInstance == NULL) { |
Vincent Coubard |
638:c90ae1400bf2 | 96 | securityManagerInstance = new nRF5xSecurityManager(); |
Vincent Coubard |
638:c90ae1400bf2 | 97 | } |
Vincent Coubard |
638:c90ae1400bf2 | 98 | return *securityManagerInstance; |
Vincent Coubard |
638:c90ae1400bf2 | 99 | } |
Vincent Coubard |
638:c90ae1400bf2 | 100 | |
Vincent Coubard |
638:c90ae1400bf2 | 101 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 102 | * Accessors to GAP. This function checks whether gapInstance points to an |
Vincent Coubard |
638:c90ae1400bf2 | 103 | * object. If if does not, then the gapInstance is updated to |
Vincent Coubard |
638:c90ae1400bf2 | 104 | * &_getInstance before returning. |
Vincent Coubard |
638:c90ae1400bf2 | 105 | * |
Vincent Coubard |
638:c90ae1400bf2 | 106 | * @return A const reference to GattServer. |
Vincent Coubard |
638:c90ae1400bf2 | 107 | * |
Vincent Coubard |
638:c90ae1400bf2 | 108 | * @note Unlike the GattClient, GattServer and SecurityManager, Gap is |
Vincent Coubard |
638:c90ae1400bf2 | 109 | * always needed in a BLE application. Therefore it is allocated |
Vincent Coubard |
638:c90ae1400bf2 | 110 | * statically. |
Vincent Coubard |
638:c90ae1400bf2 | 111 | * |
Vincent Coubard |
638:c90ae1400bf2 | 112 | * @note The accessor is able to modify the object's state because the |
Vincent Coubard |
638:c90ae1400bf2 | 113 | * internal pointer has been declared mutable. |
Vincent Coubard |
638:c90ae1400bf2 | 114 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 115 | virtual const nRF5xGap &getGap() const { |
Vincent Coubard |
638:c90ae1400bf2 | 116 | return gapInstance; |
Vincent Coubard |
638:c90ae1400bf2 | 117 | }; |
Vincent Coubard |
638:c90ae1400bf2 | 118 | |
Vincent Coubard |
638:c90ae1400bf2 | 119 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 120 | * Accessors to GATT Server. This function checks whether a GattServer |
Vincent Coubard |
638:c90ae1400bf2 | 121 | * object was previously instantiated. If such object does not exist, then |
Vincent Coubard |
638:c90ae1400bf2 | 122 | * it is created before returning. |
Vincent Coubard |
638:c90ae1400bf2 | 123 | * |
Vincent Coubard |
638:c90ae1400bf2 | 124 | * @return A const reference to GattServer. |
Vincent Coubard |
638:c90ae1400bf2 | 125 | * |
Vincent Coubard |
638:c90ae1400bf2 | 126 | * @note The accessor is able to modify the object's state because the |
Vincent Coubard |
638:c90ae1400bf2 | 127 | * internal pointer has been declared mutable. |
Vincent Coubard |
638:c90ae1400bf2 | 128 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 129 | virtual const nRF5xGattServer &getGattServer() const { |
Vincent Coubard |
638:c90ae1400bf2 | 130 | if (gattServerInstance == NULL) { |
Vincent Coubard |
638:c90ae1400bf2 | 131 | gattServerInstance = new nRF5xGattServer(); |
Vincent Coubard |
638:c90ae1400bf2 | 132 | } |
Vincent Coubard |
638:c90ae1400bf2 | 133 | return *gattServerInstance; |
Vincent Coubard |
638:c90ae1400bf2 | 134 | }; |
Vincent Coubard |
638:c90ae1400bf2 | 135 | |
Vincent Coubard |
638:c90ae1400bf2 | 136 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 137 | * Accessors to Security Manager. This function checks whether a SecurityManager |
Vincent Coubard |
638:c90ae1400bf2 | 138 | * object was previously instantiated. If such object does not exist, then |
Vincent Coubard |
638:c90ae1400bf2 | 139 | * it is created before returning. |
Vincent Coubard |
638:c90ae1400bf2 | 140 | * |
Vincent Coubard |
638:c90ae1400bf2 | 141 | * @return A const reference to GattServer. |
Vincent Coubard |
638:c90ae1400bf2 | 142 | * |
Vincent Coubard |
638:c90ae1400bf2 | 143 | * @note The accessor is able to modify the object's state because the |
Vincent Coubard |
638:c90ae1400bf2 | 144 | * internal pointer has been declared mutable. |
Vincent Coubard |
638:c90ae1400bf2 | 145 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 146 | virtual const nRF5xSecurityManager &getSecurityManager() const { |
Vincent Coubard |
638:c90ae1400bf2 | 147 | if (securityManagerInstance == NULL) { |
Vincent Coubard |
638:c90ae1400bf2 | 148 | securityManagerInstance = new nRF5xSecurityManager(); |
Vincent Coubard |
638:c90ae1400bf2 | 149 | } |
Vincent Coubard |
638:c90ae1400bf2 | 150 | return *securityManagerInstance; |
Vincent Coubard |
638:c90ae1400bf2 | 151 | } |
Vincent Coubard |
638:c90ae1400bf2 | 152 | |
Vincent Coubard |
638:c90ae1400bf2 | 153 | virtual void waitForEvent(void); |
Vincent Coubard |
638:c90ae1400bf2 | 154 | |
Vincent Coubard |
638:c90ae1400bf2 | 155 | virtual void processEvents(); |
Vincent Coubard |
638:c90ae1400bf2 | 156 | |
Vincent Coubard |
638:c90ae1400bf2 | 157 | public: |
Vincent Coubard |
638:c90ae1400bf2 | 158 | static nRF5xn& Instance(BLE::InstanceID_t instanceId); |
Vincent Coubard |
638:c90ae1400bf2 | 159 | |
Vincent Coubard |
638:c90ae1400bf2 | 160 | private: |
Vincent Coubard |
638:c90ae1400bf2 | 161 | bool initialized; |
Vincent Coubard |
638:c90ae1400bf2 | 162 | BLE::InstanceID_t instanceID; |
Vincent Coubard |
638:c90ae1400bf2 | 163 | |
Vincent Coubard |
638:c90ae1400bf2 | 164 | private: |
Vincent Coubard |
638:c90ae1400bf2 | 165 | mutable nRF5xGap gapInstance; /**< Gap instance whose reference is returned from a call to |
Vincent Coubard |
638:c90ae1400bf2 | 166 | * getGap(). Unlike the GattClient, GattServer and |
Vincent Coubard |
638:c90ae1400bf2 | 167 | * SecurityManager, Gap is always needed in a BLE application. */ |
Vincent Coubard |
638:c90ae1400bf2 | 168 | |
Vincent Coubard |
638:c90ae1400bf2 | 169 | private: |
Vincent Coubard |
638:c90ae1400bf2 | 170 | mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance. |
Vincent Coubard |
638:c90ae1400bf2 | 171 | * If NULL, then GattServer has not been initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 172 | * The pointer has been declared as 'mutable' so that |
Vincent Coubard |
638:c90ae1400bf2 | 173 | * it can be assigned inside a 'const' function. */ |
Vincent Coubard |
638:c90ae1400bf2 | 174 | mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance. |
Vincent Coubard |
638:c90ae1400bf2 | 175 | * If NULL, then GattClient has not been initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 176 | * The pointer has been declared as 'mutable' so that |
Vincent Coubard |
638:c90ae1400bf2 | 177 | * it can be assigned inside a 'const' function. */ |
Vincent Coubard |
638:c90ae1400bf2 | 178 | mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance. |
Vincent Coubard |
638:c90ae1400bf2 | 179 | * If NULL, then SecurityManager has not been initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 180 | * The pointer has been declared as 'mutable' so that |
Vincent Coubard |
638:c90ae1400bf2 | 181 | * it can be assigned inside a 'const' function. */ |
Vincent Coubard |
638:c90ae1400bf2 | 182 | }; |
Vincent Coubard |
638:c90ae1400bf2 | 183 | |
Vincent Coubard |
638:c90ae1400bf2 | 184 | #endif |