2014-07-30 10:36:32 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-12-15 13:56:47 +00:00
|
|
|
#ifdef YOTTA_CFG_MBED_OS
|
|
|
|
#include "mbed-drivers/mbed.h"
|
|
|
|
#else
|
|
|
|
#include "mbed.h"
|
|
|
|
#endif
|
2015-07-06 13:17:22 +00:00
|
|
|
#include "nRF5xn.h"
|
2015-10-30 10:18:37 +00:00
|
|
|
#include "ble/blecommon.h"
|
2014-07-30 10:36:32 +00:00
|
|
|
#include "nrf_soc.h"
|
|
|
|
|
|
|
|
#include "btle/btle.h"
|
2014-08-12 10:34:57 +00:00
|
|
|
#include "nrf_delay.h"
|
2014-07-30 10:36:32 +00:00
|
|
|
|
2015-11-16 15:08:31 +00:00
|
|
|
extern "C" {
|
2014-12-03 11:45:02 +00:00
|
|
|
#include "softdevice_handler.h"
|
2015-11-16 15:08:31 +00:00
|
|
|
}
|
2014-12-03 11:45:02 +00:00
|
|
|
|
2014-07-30 10:36:32 +00:00
|
|
|
/**
|
2015-06-17 08:25:18 +00:00
|
|
|
* The singleton which represents the nRF51822 transport for the BLE.
|
2014-07-30 10:36:32 +00:00
|
|
|
*/
|
2016-01-02 20:05:05 +00:00
|
|
|
static nRF5xn *deviceInstance = NULL;
|
2014-07-30 10:36:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BLE-API requires an implementation of the following function in order to
|
|
|
|
* obtain its transport handle.
|
|
|
|
*/
|
2015-06-17 08:25:18 +00:00
|
|
|
BLEInstanceBase *
|
|
|
|
createBLEInstance(void)
|
2014-07-30 10:36:32 +00:00
|
|
|
{
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
return &nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nRF5xn& nRF5xn::Instance(BLE::InstanceID_t instanceId)
|
|
|
|
{
|
2016-01-02 20:05:05 +00:00
|
|
|
if (deviceInstance == NULL)
|
|
|
|
deviceInstance = new nRF5xn();
|
|
|
|
|
|
|
|
return *deviceInstance;
|
2014-07-30 10:36:32 +00:00
|
|
|
}
|
|
|
|
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
nRF5xn::nRF5xn(void) :
|
|
|
|
initialized(false),
|
|
|
|
instanceID(BLE::DEFAULT_INSTANCE),
|
2015-12-22 15:49:12 +00:00
|
|
|
gapInstance(),
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
gattServerInstance(NULL),
|
|
|
|
gattClientInstance(NULL),
|
|
|
|
securityManagerInstance(NULL)
|
2014-07-30 10:36:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:17:22 +00:00
|
|
|
nRF5xn::~nRF5xn(void)
|
2014-07-30 10:36:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:17:22 +00:00
|
|
|
const char *nRF5xn::getVersion(void)
|
2014-07-30 10:36:32 +00:00
|
|
|
{
|
2015-10-30 10:18:37 +00:00
|
|
|
if (!initialized) {
|
|
|
|
return "INITIALIZATION_INCOMPLETE";
|
|
|
|
}
|
|
|
|
|
2015-04-01 09:45:08 +00:00
|
|
|
static char versionString[32];
|
2014-07-30 10:36:32 +00:00
|
|
|
static bool versionFetched = false;
|
|
|
|
|
|
|
|
if (!versionFetched) {
|
|
|
|
ble_version_t version;
|
2015-04-01 09:45:08 +00:00
|
|
|
if ((sd_ble_version_get(&version) == NRF_SUCCESS) && (version.company_id == 0x0059)) {
|
|
|
|
switch (version.version_number) {
|
|
|
|
case 0x07:
|
2015-07-29 11:08:55 +00:00
|
|
|
case 0x08:
|
2015-07-29 11:12:29 +00:00
|
|
|
snprintf(versionString, sizeof(versionString), "Nordic BLE4.1 ver:%u fw:%04x", version.version_number, version.subversion_number);
|
2015-04-01 09:45:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-07-29 11:12:29 +00:00
|
|
|
snprintf(versionString, sizeof(versionString), "Nordic (spec unknown) ver:%u fw:%04x", version.version_number, version.subversion_number);
|
2015-04-01 09:45:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-07-30 10:36:32 +00:00
|
|
|
versionFetched = true;
|
|
|
|
} else {
|
|
|
|
strncpy(versionString, "unknown", sizeof(versionString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return versionString;
|
|
|
|
}
|
|
|
|
|
2015-12-21 09:30:01 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/*!
|
|
|
|
@brief Initialize the BLE stack.
|
|
|
|
|
|
|
|
@returns ble_error_t
|
|
|
|
|
|
|
|
@retval BLE_ERROR_NONE if everything executed properly and
|
|
|
|
BLE_ERROR_ALREADY_INITIALIZED if the stack has already
|
2015-12-21 09:35:49 +00:00
|
|
|
been initialized (possibly through a call to nRF5xn::init()).
|
2015-12-21 09:30:01 +00:00
|
|
|
BLE_ERROR_INTERNAL_STACK_FAILURE is returned if initialization
|
|
|
|
of the internal stack (SoftDevice) failed.
|
|
|
|
|
|
|
|
*/
|
|
|
|
/**************************************************************************/
|
2015-11-03 12:40:34 +00:00
|
|
|
ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback)
|
2014-07-30 10:36:32 +00:00
|
|
|
{
|
2015-10-28 14:05:27 +00:00
|
|
|
if (initialized) {
|
2015-11-03 12:40:34 +00:00
|
|
|
BLE::InitializationCompleteCallbackContext context = {
|
|
|
|
BLE::Instance(instanceID),
|
|
|
|
BLE_ERROR_ALREADY_INITIALIZED
|
|
|
|
};
|
|
|
|
callback.call(&context);
|
2015-10-28 14:05:27 +00:00
|
|
|
return BLE_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
instanceID = instanceID;
|
|
|
|
|
2014-07-30 10:36:32 +00:00
|
|
|
/* ToDo: Clear memory contents, reset the SD, etc. */
|
2015-12-21 09:30:01 +00:00
|
|
|
if (btle_init() != ERROR_NONE) {
|
|
|
|
return BLE_ERROR_INTERNAL_STACK_FAILURE;
|
|
|
|
}
|
2014-07-30 10:36:32 +00:00
|
|
|
|
2015-10-28 14:05:27 +00:00
|
|
|
initialized = true;
|
2015-11-03 12:40:34 +00:00
|
|
|
BLE::InitializationCompleteCallbackContext context = {
|
|
|
|
BLE::Instance(instanceID),
|
|
|
|
BLE_ERROR_NONE
|
|
|
|
};
|
|
|
|
callback.call(&context);
|
2014-07-30 10:36:32 +00:00
|
|
|
return BLE_ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
Improve shutdown to clear BLE API and not just SD
Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:
* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.
The shutdown procedure is as follows:
1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.
If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
returned.
2015-12-11 17:37:58 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/*!
|
|
|
|
@brief Purge the BLE stack of GATT and GAP state.
|
|
|
|
|
|
|
|
@returns ble_error_t
|
|
|
|
|
|
|
|
@retval BLE_ERROR_NONE
|
|
|
|
Everything executed properly
|
|
|
|
|
|
|
|
@note When using S110, GattClient::shutdown() will not be called
|
|
|
|
since Gatt client features are not supported.
|
|
|
|
*/
|
|
|
|
/**************************************************************************/
|
2015-07-06 13:17:22 +00:00
|
|
|
ble_error_t nRF5xn::shutdown(void)
|
2014-12-03 11:45:02 +00:00
|
|
|
{
|
2015-10-30 10:18:37 +00:00
|
|
|
if (!initialized) {
|
|
|
|
return BLE_ERROR_INITIALIZATION_INCOMPLETE;
|
|
|
|
}
|
|
|
|
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
/*
|
|
|
|
* Shutdown the SoftDevice first. This is because we need to disable all
|
|
|
|
* interrupts. Otherwise if we clear the BLE API and glue code first there
|
|
|
|
* will be many NULL references and no config information which could lead
|
|
|
|
* to errors if the shutdown process is interrupted.
|
|
|
|
*/
|
2015-12-16 10:19:22 +00:00
|
|
|
if (softdevice_handler_sd_disable() != NRF_SUCCESS) {
|
2015-11-02 17:04:47 +00:00
|
|
|
return BLE_STACK_BUSY;
|
|
|
|
}
|
|
|
|
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
|
Improve shutdown to clear BLE API and not just SD
Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:
* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.
The shutdown procedure is as follows:
1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.
If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
returned.
2015-12-11 17:37:58 +00:00
|
|
|
/* Shutdown the BLE API and nRF51 glue code */
|
2015-12-15 10:54:11 +00:00
|
|
|
ble_error_t error;
|
|
|
|
|
|
|
|
if (gattServerInstance != NULL) {
|
|
|
|
error = gattServerInstance->reset();
|
|
|
|
if (error != BLE_ERROR_NONE) {
|
|
|
|
return error;
|
|
|
|
}
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 10:54:11 +00:00
|
|
|
if (securityManagerInstance != NULL) {
|
|
|
|
error = securityManagerInstance->reset();
|
|
|
|
if (error != BLE_ERROR_NONE) {
|
|
|
|
return error;
|
|
|
|
}
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* S110 does not support BLE client features, nothing to reset. */
|
Improve shutdown to clear BLE API and not just SD
Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:
* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.
The shutdown procedure is as follows:
1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.
If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
returned.
2015-12-11 17:37:58 +00:00
|
|
|
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
2015-12-15 10:54:11 +00:00
|
|
|
if (gattClientInstance != NULL) {
|
|
|
|
error = gattClientInstance->reset();
|
|
|
|
if (error != BLE_ERROR_NONE) {
|
|
|
|
return error;
|
|
|
|
}
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
}
|
Improve shutdown to clear BLE API and not just SD
Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:
* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.
The shutdown procedure is as follows:
1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.
If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
returned.
2015-12-11 17:37:58 +00:00
|
|
|
#endif
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
|
2015-12-22 15:51:34 +00:00
|
|
|
/* Gap instance is always present */
|
2015-12-22 15:49:12 +00:00
|
|
|
error = gapInstance.reset();
|
2015-12-15 10:54:11 +00:00
|
|
|
if (error != BLE_ERROR_NONE) {
|
|
|
|
return error;
|
Improve shutdown to clear BLE API and not just SD
Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:
* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.
The shutdown procedure is as follows:
1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.
If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
returned.
2015-12-11 17:37:58 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:04:47 +00:00
|
|
|
initialized = false;
|
|
|
|
return BLE_ERROR_NONE;
|
2014-12-03 11:45:02 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 10:36:32 +00:00
|
|
|
void
|
2015-07-06 13:17:22 +00:00
|
|
|
nRF5xn::waitForEvent(void)
|
2014-07-30 10:36:32 +00:00
|
|
|
{
|
|
|
|
sd_app_evt_wait();
|
|
|
|
}
|