No changes

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:19:24 2016 +0000
Revision:
576:b699791e1dbc
Parent:
575:7023a8204a1b
Child:
588:65d256258533
Synchronized with git rev 4efa84c8
Author: Andres Amaya Garcia
Remove out-of-date comment from nRF5xn

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 565:cf03471a4ec4 1 /* mbed Microcontroller Library
vcoubard 565:cf03471a4ec4 2 * Copyright (c) 2006-2013 ARM Limited
vcoubard 565:cf03471a4ec4 3 *
vcoubard 565:cf03471a4ec4 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 565:cf03471a4ec4 5 * you may not use this file except in compliance with the License.
vcoubard 565:cf03471a4ec4 6 * You may obtain a copy of the License at
vcoubard 565:cf03471a4ec4 7 *
vcoubard 565:cf03471a4ec4 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 565:cf03471a4ec4 9 *
vcoubard 565:cf03471a4ec4 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 565:cf03471a4ec4 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 565:cf03471a4ec4 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 565:cf03471a4ec4 13 * See the License for the specific language governing permissions and
vcoubard 565:cf03471a4ec4 14 * limitations under the License.
vcoubard 565:cf03471a4ec4 15 */
vcoubard 565:cf03471a4ec4 16
vcoubard 565:cf03471a4ec4 17 #ifndef __NRF51822_H__
vcoubard 565:cf03471a4ec4 18 #define __NRF51822_H__
vcoubard 565:cf03471a4ec4 19
vcoubard 565:cf03471a4ec4 20 #include "ble/BLE.h"
vcoubard 565:cf03471a4ec4 21 #include "ble/blecommon.h"
vcoubard 565:cf03471a4ec4 22 #include "ble/BLEInstanceBase.h"
vcoubard 565:cf03471a4ec4 23
vcoubard 565:cf03471a4ec4 24 #include "nRF5xGap.h"
vcoubard 565:cf03471a4ec4 25 #include "nRF5xGattServer.h"
vcoubard 565:cf03471a4ec4 26 #include "nRF5xGattClient.h"
vcoubard 565:cf03471a4ec4 27 #include "nRF5xSecurityManager.h"
vcoubard 565:cf03471a4ec4 28
vcoubard 565:cf03471a4ec4 29 #include "btle.h"
vcoubard 565:cf03471a4ec4 30
vcoubard 565:cf03471a4ec4 31 class nRF5xn : public BLEInstanceBase
vcoubard 565:cf03471a4ec4 32 {
vcoubard 565:cf03471a4ec4 33 public:
vcoubard 565:cf03471a4ec4 34 nRF5xn(void);
vcoubard 565:cf03471a4ec4 35 virtual ~nRF5xn(void);
vcoubard 565:cf03471a4ec4 36
vcoubard 565:cf03471a4ec4 37 virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback);
vcoubard 565:cf03471a4ec4 38 virtual bool hasInitialized(void) const {
vcoubard 565:cf03471a4ec4 39 return initialized;
vcoubard 565:cf03471a4ec4 40 }
vcoubard 565:cf03471a4ec4 41 virtual ble_error_t shutdown(void);
vcoubard 565:cf03471a4ec4 42 virtual const char *getVersion(void);
vcoubard 565:cf03471a4ec4 43
vcoubard 575:7023a8204a1b 44 /**
vcoubard 575:7023a8204a1b 45 * Accessors to GAP. This function checks whether gapInstance points to an
vcoubard 575:7023a8204a1b 46 * object. If if does not, then the gapInstance is updated to
vcoubard 575:7023a8204a1b 47 * &_getInstance before returning.
vcoubard 575:7023a8204a1b 48 *
vcoubard 575:7023a8204a1b 49 * @return A reference to GattServer.
vcoubard 575:7023a8204a1b 50 *
vcoubard 575:7023a8204a1b 51 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is
vcoubard 575:7023a8204a1b 52 * always needed in a BLE application. Therefore it is allocated
vcoubard 575:7023a8204a1b 53 * statically.
vcoubard 575:7023a8204a1b 54 */
vcoubard 565:cf03471a4ec4 55 virtual Gap &getGap() {
vcoubard 575:7023a8204a1b 56 if (gapInstance == NULL) {
vcoubard 575:7023a8204a1b 57 gapInstance = &_gapInstance;
vcoubard 575:7023a8204a1b 58 }
vcoubard 575:7023a8204a1b 59 return *gapInstance;
vcoubard 575:7023a8204a1b 60 };
vcoubard 575:7023a8204a1b 61
vcoubard 575:7023a8204a1b 62 /**
vcoubard 575:7023a8204a1b 63 * Accessors to GATT Server. This function checks whether a GattServer
vcoubard 575:7023a8204a1b 64 * object was previously instantiated. If such object does not exist, then
vcoubard 575:7023a8204a1b 65 * it is created before returning.
vcoubard 575:7023a8204a1b 66 *
vcoubard 575:7023a8204a1b 67 * @return A reference to GattServer.
vcoubard 575:7023a8204a1b 68 */
vcoubard 575:7023a8204a1b 69 virtual GattServer &getGattServer() {
vcoubard 575:7023a8204a1b 70 if (gattServerInstance == NULL) {
vcoubard 575:7023a8204a1b 71 gattServerInstance = new nRF5xGattServer();
vcoubard 575:7023a8204a1b 72 }
vcoubard 575:7023a8204a1b 73 return *gattServerInstance;
vcoubard 570:f162898cb6c4 74 };
vcoubard 575:7023a8204a1b 75
vcoubard 575:7023a8204a1b 76 /**
vcoubard 575:7023a8204a1b 77 * Accessors to GATT Client. This function checks whether a GattClient
vcoubard 575:7023a8204a1b 78 * object was previously instantiated. If such object does not exist, then
vcoubard 575:7023a8204a1b 79 * it is created before returning.
vcoubard 575:7023a8204a1b 80 *
vcoubard 575:7023a8204a1b 81 * @return A reference to GattClient.
vcoubard 575:7023a8204a1b 82 */
vcoubard 575:7023a8204a1b 83 virtual GattClient &getGattClient() {
vcoubard 575:7023a8204a1b 84 if (gattClientInstance == NULL) {
vcoubard 575:7023a8204a1b 85 gattClientInstance = new nRF5xGattClient();
vcoubard 575:7023a8204a1b 86 }
vcoubard 575:7023a8204a1b 87 return *gattClientInstance;
vcoubard 575:7023a8204a1b 88 }
vcoubard 575:7023a8204a1b 89
vcoubard 575:7023a8204a1b 90 /**
vcoubard 575:7023a8204a1b 91 * Accessors to Security Manager. This function checks whether a SecurityManager
vcoubard 575:7023a8204a1b 92 * object was previously instantiated. If such object does not exist, then
vcoubard 575:7023a8204a1b 93 * it is created before returning.
vcoubard 575:7023a8204a1b 94 *
vcoubard 575:7023a8204a1b 95 * @return A reference to GattServer.
vcoubard 575:7023a8204a1b 96 */
vcoubard 575:7023a8204a1b 97 virtual SecurityManager &getSecurityManager() {
vcoubard 575:7023a8204a1b 98 if (securityManagerInstance == NULL) {
vcoubard 575:7023a8204a1b 99 securityManagerInstance = new nRF5xSecurityManager();
vcoubard 575:7023a8204a1b 100 }
vcoubard 575:7023a8204a1b 101 return *securityManagerInstance;
vcoubard 575:7023a8204a1b 102 }
vcoubard 575:7023a8204a1b 103
vcoubard 575:7023a8204a1b 104 /**
vcoubard 575:7023a8204a1b 105 * Accessors to GAP. This function checks whether gapInstance points to an
vcoubard 575:7023a8204a1b 106 * object. If if does not, then the gapInstance is updated to
vcoubard 575:7023a8204a1b 107 * &_getInstance before returning.
vcoubard 575:7023a8204a1b 108 *
vcoubard 575:7023a8204a1b 109 * @return A const reference to GattServer.
vcoubard 575:7023a8204a1b 110 *
vcoubard 575:7023a8204a1b 111 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is
vcoubard 575:7023a8204a1b 112 * always needed in a BLE application. Therefore it is allocated
vcoubard 575:7023a8204a1b 113 * statically.
vcoubard 575:7023a8204a1b 114 *
vcoubard 575:7023a8204a1b 115 * @note The accessor is able to modify the object's state because the
vcoubard 575:7023a8204a1b 116 * internal pointer has been declared mutable.
vcoubard 575:7023a8204a1b 117 */
vcoubard 571:bbf6410b6a89 118 virtual const Gap &getGap() const {
vcoubard 575:7023a8204a1b 119 if (gapInstance == NULL) {
vcoubard 575:7023a8204a1b 120 gapInstance = &_gapInstance;
vcoubard 575:7023a8204a1b 121 }
vcoubard 575:7023a8204a1b 122 return *gapInstance;
vcoubard 571:bbf6410b6a89 123 };
vcoubard 575:7023a8204a1b 124
vcoubard 575:7023a8204a1b 125 /**
vcoubard 575:7023a8204a1b 126 * Accessors to GATT Server. This function checks whether a GattServer
vcoubard 575:7023a8204a1b 127 * object was previously instantiated. If such object does not exist, then
vcoubard 575:7023a8204a1b 128 * it is created before returning.
vcoubard 575:7023a8204a1b 129 *
vcoubard 575:7023a8204a1b 130 * @return A const reference to GattServer.
vcoubard 575:7023a8204a1b 131 *
vcoubard 575:7023a8204a1b 132 * @note The accessor is able to modify the object's state because the
vcoubard 575:7023a8204a1b 133 * internal pointer has been declared mutable.
vcoubard 575:7023a8204a1b 134 */
vcoubard 571:bbf6410b6a89 135 virtual const GattServer &getGattServer() const {
vcoubard 575:7023a8204a1b 136 if (gattServerInstance == NULL) {
vcoubard 575:7023a8204a1b 137 gattServerInstance = new nRF5xGattServer();
vcoubard 575:7023a8204a1b 138 }
vcoubard 575:7023a8204a1b 139 return *gattServerInstance;
vcoubard 571:bbf6410b6a89 140 };
vcoubard 575:7023a8204a1b 141
vcoubard 575:7023a8204a1b 142 /**
vcoubard 575:7023a8204a1b 143 * Accessors to Security Manager. This function checks whether a SecurityManager
vcoubard 575:7023a8204a1b 144 * object was previously instantiated. If such object does not exist, then
vcoubard 575:7023a8204a1b 145 * it is created before returning.
vcoubard 575:7023a8204a1b 146 *
vcoubard 575:7023a8204a1b 147 * @return A const reference to GattServer.
vcoubard 575:7023a8204a1b 148 *
vcoubard 575:7023a8204a1b 149 * @note The accessor is able to modify the object's state because the
vcoubard 575:7023a8204a1b 150 * internal pointer has been declared mutable.
vcoubard 575:7023a8204a1b 151 */
vcoubard 565:cf03471a4ec4 152 virtual const SecurityManager &getSecurityManager() const {
vcoubard 575:7023a8204a1b 153 if (securityManagerInstance == NULL) {
vcoubard 575:7023a8204a1b 154 securityManagerInstance = new nRF5xSecurityManager();
vcoubard 575:7023a8204a1b 155 }
vcoubard 575:7023a8204a1b 156 return *securityManagerInstance;
vcoubard 565:cf03471a4ec4 157 }
vcoubard 575:7023a8204a1b 158
vcoubard 565:cf03471a4ec4 159 virtual void waitForEvent(void);
vcoubard 565:cf03471a4ec4 160
vcoubard 575:7023a8204a1b 161 public:
vcoubard 575:7023a8204a1b 162 static nRF5xn& Instance(BLE::InstanceID_t instanceId);
vcoubard 575:7023a8204a1b 163
vcoubard 565:cf03471a4ec4 164 private:
vcoubard 565:cf03471a4ec4 165 bool initialized;
vcoubard 565:cf03471a4ec4 166 BLE::InstanceID_t instanceID;
vcoubard 575:7023a8204a1b 167
vcoubard 575:7023a8204a1b 168 private:
vcoubard 575:7023a8204a1b 169 mutable nRF5xGap _gapInstance; /**< Gap instance whose reference is returned from a call to
vcoubard 575:7023a8204a1b 170 * getGap(). Unlike the GattClient, GattServer and
vcoubard 576:b699791e1dbc 171 * SecurityManager, Gap is always needed in a BLE application. */
vcoubard 575:7023a8204a1b 172
vcoubard 575:7023a8204a1b 173 private:
vcoubard 575:7023a8204a1b 174 mutable nRF5xGap *gapInstance; /**< Pointer to the Gap object instance.
vcoubard 575:7023a8204a1b 175 * If NULL, then Gap has not been initialized.
vcoubard 575:7023a8204a1b 176 * The pointer has been declared as 'mutable' so that
vcoubard 575:7023a8204a1b 177 * it can be assigned inside a 'const' function. */
vcoubard 575:7023a8204a1b 178 mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance.
vcoubard 575:7023a8204a1b 179 * If NULL, then GattServer has not been initialized.
vcoubard 575:7023a8204a1b 180 * The pointer has been declared as 'mutable' so that
vcoubard 575:7023a8204a1b 181 * it can be assigned inside a 'const' function. */
vcoubard 575:7023a8204a1b 182 mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance.
vcoubard 575:7023a8204a1b 183 * If NULL, then GattClient has not been initialized.
vcoubard 575:7023a8204a1b 184 * The pointer has been declared as 'mutable' so that
vcoubard 575:7023a8204a1b 185 * it can be assigned inside a 'const' function. */
vcoubard 575:7023a8204a1b 186 mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
vcoubard 575:7023a8204a1b 187 * If NULL, then SecurityManager has not been initialized.
vcoubard 575:7023a8204a1b 188 * The pointer has been declared as 'mutable' so that
vcoubard 575:7023a8204a1b 189 * it can be assigned inside a 'const' function. */
vcoubard 565:cf03471a4ec4 190 };
vcoubard 565:cf03471a4ec4 191
rgrover1 388:db85a09c27ef 192 #endif