mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Enable Generic client on Nordic targets.
parent
f5ac72f6c0
commit
502bdf5038
|
@ -51,11 +51,9 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "nrf_ble_hci.h"
|
#include "nrf_ble_hci.h"
|
||||||
#include "btle_discovery.h"
|
|
||||||
|
|
||||||
#include "nRF5xGattClient.h"
|
#include "nRF5XPalGattClient.h"
|
||||||
#include "nRF5xServiceDiscovery.h"
|
|
||||||
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
|
|
||||||
|
|
||||||
|
|
||||||
bool isEventsSignaled = false;
|
bool isEventsSignaled = false;
|
||||||
|
@ -67,23 +65,6 @@ extern "C" void SD_EVT_IRQHandler(void); // export the softdevice event handler
|
||||||
|
|
||||||
static void btle_handler(ble_evt_t *p_ble_evt);
|
static void btle_handler(ble_evt_t *p_ble_evt);
|
||||||
|
|
||||||
#if 0
|
|
||||||
#define CENTRAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS) /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
|
|
||||||
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
|
|
||||||
#define PERIPHERAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS) /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
|
||||||
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
|
|
||||||
#define GATTS_ATTR_TAB_SIZE (YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE) /**< GATTS attribite table size. */
|
|
||||||
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
|
|
||||||
#else
|
|
||||||
#define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
|
|
||||||
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
|
|
||||||
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
|
||||||
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
|
|
||||||
#define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
|
|
||||||
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void sys_evt_dispatch(uint32_t sys_evt)
|
static void sys_evt_dispatch(uint32_t sys_evt)
|
||||||
{
|
{
|
||||||
#if (IS_LEGACY_DEVICE_MANAGER_ENABLED)
|
#if (IS_LEGACY_DEVICE_MANAGER_ENABLED)
|
||||||
|
@ -121,7 +102,7 @@ error_t btle_init(void)
|
||||||
|
|
||||||
// register softdevice handler vector
|
// register softdevice handler vector
|
||||||
NVIC_SetVector(SD_EVT_IRQn, (uint32_t) SD_EVT_IRQHandler);
|
NVIC_SetVector(SD_EVT_IRQn, (uint32_t) SD_EVT_IRQHandler);
|
||||||
|
|
||||||
// Configure the LF clock according to values provided by btle_clock.h.
|
// Configure the LF clock according to values provided by btle_clock.h.
|
||||||
// It is input from the chain of the yotta configuration system.
|
// It is input from the chain of the yotta configuration system.
|
||||||
clockConfiguration.source = LFCLK_CONF_SOURCE;
|
clockConfiguration.source = LFCLK_CONF_SOURCE;
|
||||||
|
@ -189,6 +170,8 @@ error_t btle_init(void)
|
||||||
|
|
||||||
static void btle_handler(ble_evt_t *p_ble_evt)
|
static void btle_handler(ble_evt_t *p_ble_evt)
|
||||||
{
|
{
|
||||||
|
using ble::pal::vendor::nordic::nRF5XGattClient;
|
||||||
|
|
||||||
/* Library service handlers */
|
/* Library service handlers */
|
||||||
#if SDK_CONN_PARAMS_MODULE_ENABLE
|
#if SDK_CONN_PARAMS_MODULE_ENABLE
|
||||||
ble_conn_params_on_ble_evt(p_ble_evt);
|
ble_conn_params_on_ble_evt(p_ble_evt);
|
||||||
|
@ -206,7 +189,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
||||||
bleGattcEventHandler(p_ble_evt);
|
nRF5XGattClient::handle_events(p_ble_evt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
|
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
|
||||||
|
@ -229,7 +212,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
|
||||||
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
|
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
|
||||||
#if (NRF_SD_BLE_API_VERSION <= 2)
|
#if (NRF_SD_BLE_API_VERSION <= 2)
|
||||||
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
|
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
|
||||||
|
|
||||||
gap.processConnectionEvent(handle,
|
gap.processConnectionEvent(handle,
|
||||||
role,
|
role,
|
||||||
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
|
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
|
||||||
|
@ -275,9 +258,7 @@ static void btle_handler(ble_evt_t *p_ble_evt)
|
||||||
|
|
||||||
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
||||||
// Close all pending discoveries for this connection
|
// Close all pending discoveries for this connection
|
||||||
nRF5xGattClient& gattClient = ble.getGattClient();
|
nRF5XGattClient::handle_connection_termination(handle);
|
||||||
gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
|
|
||||||
gattClient.discovery().terminate(handle);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gap.processDisconnectionEvent(handle, reason);
|
gap.processDisconnectionEvent(handle, reason);
|
||||||
|
|
|
@ -26,6 +26,13 @@ extern "C" {
|
||||||
#include "ble_srv_common.h"
|
#include "ble_srv_common.h"
|
||||||
#include "headers/nrf_ble.h"
|
#include "headers/nrf_ble.h"
|
||||||
|
|
||||||
|
#define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
|
||||||
|
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
|
||||||
|
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||||
|
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
|
||||||
|
#define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
|
||||||
|
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
|
||||||
|
|
||||||
error_t btle_init(void);
|
error_t btle_init(void);
|
||||||
|
|
||||||
// flag indicating if events have been signaled or not
|
// flag indicating if events have been signaled or not
|
||||||
|
|
|
@ -31,6 +31,8 @@ extern "C" {
|
||||||
#include "softdevice_handler.h"
|
#include "softdevice_handler.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "nRF5XPalGattClient.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The singleton which represents the nRF51822 transport for the BLE.
|
* The singleton which represents the nRF51822 transport for the BLE.
|
||||||
*/
|
*/
|
||||||
|
@ -60,7 +62,7 @@ nRF5xn::nRF5xn(void) :
|
||||||
instanceID(BLE::DEFAULT_INSTANCE),
|
instanceID(BLE::DEFAULT_INSTANCE),
|
||||||
gapInstance(),
|
gapInstance(),
|
||||||
gattServerInstance(NULL),
|
gattServerInstance(NULL),
|
||||||
gattClientInstance(NULL),
|
gattClient(&(ble::pal::vendor::nordic::nRF5XGattClient::get_client())),
|
||||||
securityManagerInstance(NULL)
|
securityManagerInstance(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -189,11 +191,9 @@ ble_error_t nRF5xn::shutdown(void)
|
||||||
|
|
||||||
/* S110 does not support BLE client features, nothing to reset. */
|
/* S110 does not support BLE client features, nothing to reset. */
|
||||||
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
||||||
if (gattClientInstance != NULL) {
|
error = getGattClient().reset();
|
||||||
error = gattClientInstance->reset();
|
if (error != BLE_ERROR_NONE) {
|
||||||
if (error != BLE_ERROR_NONE) {
|
return error;
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
#include "ble/BLE.h"
|
#include "ble/BLE.h"
|
||||||
#include "ble/blecommon.h"
|
#include "ble/blecommon.h"
|
||||||
#include "ble/BLEInstanceBase.h"
|
#include "ble/BLEInstanceBase.h"
|
||||||
|
#include "ble/generic/GenericGattClient.h"
|
||||||
|
|
||||||
#include "nRF5xGap.h"
|
#include "nRF5xGap.h"
|
||||||
#include "nRF5xGattServer.h"
|
#include "nRF5xGattServer.h"
|
||||||
#include "nRF5xGattClient.h"
|
|
||||||
#include "nRF5xSecurityManager.h"
|
#include "nRF5xSecurityManager.h"
|
||||||
|
|
||||||
#include "btle.h"
|
#include "btle.h"
|
||||||
|
@ -77,11 +77,8 @@ public:
|
||||||
*
|
*
|
||||||
* @return A reference to GattClient.
|
* @return A reference to GattClient.
|
||||||
*/
|
*/
|
||||||
virtual nRF5xGattClient &getGattClient() {
|
virtual GattClient &getGattClient() {
|
||||||
if (gattClientInstance == NULL) {
|
return gattClient;
|
||||||
gattClientInstance = new nRF5xGattClient();
|
|
||||||
}
|
|
||||||
return *gattClientInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,10 +168,8 @@ private:
|
||||||
* If NULL, then GattServer has not been initialized.
|
* If NULL, then GattServer has not been initialized.
|
||||||
* The pointer has been declared as 'mutable' so that
|
* The pointer has been declared as 'mutable' so that
|
||||||
* it can be assigned inside a 'const' function. */
|
* it can be assigned inside a 'const' function. */
|
||||||
mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance.
|
ble::generic::GenericGattClient gattClient;
|
||||||
* If NULL, then GattClient has not been initialized.
|
|
||||||
* The pointer has been declared as 'mutable' so that
|
|
||||||
* it can be assigned inside a 'const' function. */
|
|
||||||
mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
|
mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
|
||||||
* If NULL, then SecurityManager has not been initialized.
|
* If NULL, then SecurityManager has not been initialized.
|
||||||
* The pointer has been declared as 'mutable' so that
|
* The pointer has been declared as 'mutable' so that
|
||||||
|
|
Loading…
Reference in New Issue