Skip to content

Commit 90fa585

Browse files
authored
Merge pull request #2211 from pan-/nrf52_nrf51_unified_integration
NRF52 target and unification with NRF51
2 parents 1e069aa + 9a92da8 commit 90fa585

File tree

331 files changed

+129210
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+129210
-3
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/CHANGELOG.md

Lines changed: 344 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This module contains softdevice which comes with The Nordic Softdevice License Agreement,
2+
a BSD-like licence for binary distributions, offered by Nordic for use in mbed. Some
3+
other files come from the mbed SDK, and are licensed under Apache-2.0. Unless
4+
specifically indicated otherwise in a file, files are licensed under the
5+
Apache 2.0 license, as can be found in: apache-2.0.txt. The Nordic Semiconductor Softdevice
6+
License Agreement can be found in softdevice_nrf51822_licence_agreement.txt.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2015 ARM Limited
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/bootloader/s110_nrf51822_8.0.0_bootloader.hex

Lines changed: 463 additions & 0 deletions
Large diffs are not rendered by default.

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/bootloader/s130_nrf51_1.0.0_bootloader.hex

Lines changed: 463 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* S110/S120/S130 License Agreement
3+
*
4+
* Copyright (c) 2015, Nordic Semiconductor ASA, All rights reserved.
5+
*
6+
* Redistribution. Redistribution and use in binary form, without modification,
7+
* are permitted provided that the following conditions are met:
8+
*
9+
* • Redistributions must reproduce the above copyright notice and the following
10+
* disclaimer in the documentation and/or other materials provided with the
11+
* distribution.
12+
* • Neither the name of the copyright holder nor the names of its contributors
13+
* may be used to endorse or promote products derived from this software
14+
* without specific prior written permission.
15+
* • No reverse engineering, decompilation, or disassembly of this software is
16+
* permitted.
17+
*
18+
* DISCLAIMER.
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*
30+
* /
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "ble-nrf51822",
3+
"version": "2.7.1",
4+
"description": "Nordic stack and drivers for the mbed BLE API.",
5+
"keywords": [
6+
"Bluetooth",
7+
"BLE",
8+
"mbed",
9+
"mbed-official"
10+
],
11+
"author": "Rohit Grover",
12+
"repository": {
13+
"url": "git@github.com:ARMmbed/ble-nRF51822.git",
14+
"type": "git"
15+
},
16+
"homepage": "https://developer.mbed.org/teams/Nordic-Semiconductor/",
17+
"licenses": [
18+
{
19+
"url": "https://spdx.org/licenses/Apache-2.0",
20+
"type": "Apache-2.0"
21+
},
22+
{
23+
"type": "LicenseRef-softdevice_nrf51822_licence_agreement.txt"
24+
}
25+
],
26+
"dependencies": {
27+
"ble": "^2.6.0",
28+
"nrf51-sdk": "^2.4.0"
29+
},
30+
"extraIncludes": [
31+
"source/btle",
32+
"source/btle/custom",
33+
"source/common"
34+
],
35+
"targetDependencies": {}
36+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* S110/S120/S130 License Agreement
3+
*
4+
* Copyright (c) 2015, Nordic Semiconductor ASA, All rights reserved.
5+
*
6+
* Redistribution. Redistribution and use in binary form, without modification,
7+
* are permitted provided that the following conditions are met:
8+
*
9+
* • Redistributions must reproduce the above copyright notice and the following
10+
* disclaimer in the documentation and/or other materials provided with the
11+
* distribution.
12+
* • Neither the name of the copyright holder nor the names of its contributors
13+
* may be used to endorse or promote products derived from this software
14+
* without specific prior written permission.
15+
* • No reverse engineering, decompilation, or disassembly of this software is
16+
* permitted.
17+
*
18+
* DISCLAIMER.
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*
30+
* /
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "common/common.h"
18+
#include "nordic_common.h"
19+
20+
#include "btle.h"
21+
#include "btle_clock.h"
22+
23+
#include "ble_flash.h"
24+
#include "ble_conn_params.h"
25+
26+
#include "btle_gap.h"
27+
#include "btle_advertising.h"
28+
#include "custom/custom_helper.h"
29+
30+
#include "ble/GapEvents.h"
31+
#include "nRF5xn.h"
32+
33+
extern "C" {
34+
#include "pstorage.h"
35+
#include "device_manager.h"
36+
#include "softdevice_handler.h"
37+
#include "ble_stack_handler_types.h"
38+
}
39+
40+
#include "nrf_ble_hci.h"
41+
#include "btle_discovery.h"
42+
43+
#include "nRF5xGattClient.h"
44+
#include "nRF5xServiceDiscovery.h"
45+
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
46+
47+
bool isEventsSignaled = false;
48+
49+
extern "C" void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name);
50+
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name);
51+
52+
static void btle_handler(ble_evt_t *p_ble_evt);
53+
54+
#if 0
55+
#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 */
56+
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
57+
#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*/
58+
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
59+
#define GATTS_ATTR_TAB_SIZE (YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE) /**< GATTS attribite table size. */
60+
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
61+
#else
62+
#define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
63+
/** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
64+
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
65+
/** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
66+
#define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
67+
/** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
68+
69+
#endif
70+
71+
static void sys_evt_dispatch(uint32_t sys_evt)
72+
{
73+
pstorage_sys_event_handler(sys_evt);
74+
}
75+
76+
/**
77+
* This function is called in interrupt context to handle BLE events; i.e. pull
78+
* system and user events out of the pending events-queue of the BLE stack. The
79+
* BLE stack signals the availability of events by the triggering the SWI2
80+
* interrupt, which forwards the handling to this function.
81+
*
82+
* The event processing loop is implemented in intern_softdevice_events_execute().
83+
*
84+
* This function will signal to the user code by calling signalEventsToProcess
85+
* that their is events to process and BLE::processEvents should be called.
86+
*/
87+
static uint32_t signalEvent()
88+
{
89+
if(isEventsSignaled == false) {
90+
isEventsSignaled = true;
91+
nRF5xn::Instance(BLE::DEFAULT_INSTANCE).signalEventsToProcess(BLE::DEFAULT_INSTANCE);
92+
}
93+
return NRF_SUCCESS;
94+
}
95+
96+
error_t btle_init(void)
97+
{
98+
nrf_clock_lf_cfg_t clockConfiguration;
99+
100+
// Configure the LF clock according to values provided by btle_clock.h.
101+
// It is input from the chain of the yotta configuration system.
102+
clockConfiguration.source = LFCLK_CONF_SOURCE;
103+
clockConfiguration.xtal_accuracy = LFCLK_CONF_ACCURACY;
104+
clockConfiguration.rc_ctiv = LFCLK_CONF_RC_CTIV;
105+
clockConfiguration.rc_temp_ctiv = LFCLK_CONF_RC_TEMP_CTIV;
106+
107+
SOFTDEVICE_HANDLER_INIT(&clockConfiguration, signalEvent);
108+
109+
// Enable BLE stack
110+
/**
111+
* Using this call, the application can select whether to include the
112+
* Service Changed characteristic in the GATT Server. The default in all
113+
* previous releases has been to include the Service Changed characteristic,
114+
* but this affects how GATT clients behave. Specifically, it requires
115+
* clients to subscribe to this attribute and not to cache attribute handles
116+
* between connections unless the devices are bonded. If the application
117+
* does not need to change the structure of the GATT server attributes at
118+
* runtime this adds unnecessary complexity to the interaction with peer
119+
* clients. If the SoftDevice is enabled with the Service Changed
120+
* Characteristics turned off, then clients are allowed to cache attribute
121+
* handles making applications simpler on both sides.
122+
*/
123+
static const bool IS_SRVC_CHANGED_CHARACT_PRESENT = true;
124+
125+
ble_enable_params_t ble_enable_params;
126+
uint32_t err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
127+
PERIPHERAL_LINK_COUNT,
128+
&ble_enable_params);
129+
130+
ble_enable_params.gatts_enable_params.attr_tab_size = GATTS_ATTR_TAB_SIZE;
131+
ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
132+
ble_enable_params.common_enable_params.vs_uuid_count = UUID_TABLE_MAX_ENTRIES;
133+
134+
if(err_code != NRF_SUCCESS) {
135+
return ERROR_INVALID_PARAM;
136+
}
137+
138+
if (softdevice_enable(&ble_enable_params) != NRF_SUCCESS) {
139+
return ERROR_INVALID_PARAM;
140+
}
141+
142+
ble_gap_addr_t addr;
143+
if (sd_ble_gap_address_get(&addr) != NRF_SUCCESS) {
144+
return ERROR_INVALID_PARAM;
145+
}
146+
if (sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr) != NRF_SUCCESS) {
147+
return ERROR_INVALID_PARAM;
148+
}
149+
150+
ASSERT_STATUS( softdevice_ble_evt_handler_set(btle_handler));
151+
ASSERT_STATUS( softdevice_sys_evt_handler_set(sys_evt_dispatch));
152+
153+
return btle_gap_init();
154+
}
155+
156+
static void btle_handler(ble_evt_t *p_ble_evt)
157+
{
158+
/* Library service handlers */
159+
#if SDK_CONN_PARAMS_MODULE_ENABLE
160+
ble_conn_params_on_ble_evt(p_ble_evt);
161+
#endif
162+
163+
dm_ble_evt_handler(p_ble_evt);
164+
165+
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
166+
bleGattcEventHandler(p_ble_evt);
167+
#endif
168+
169+
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
170+
nRF5xGap &gap = (nRF5xGap &) ble.getGap();
171+
nRF5xGattServer &gattServer = (nRF5xGattServer &) ble.getGattServer();
172+
nRF5xSecurityManager &securityManager = (nRF5xSecurityManager &) ble.getSecurityManager();
173+
174+
/* Custom event handler */
175+
switch (p_ble_evt->header.evt_id) {
176+
case BLE_GAP_EVT_CONNECTED: {
177+
Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
178+
#if defined(TARGET_MCU_NRF51_16K_S110) || defined(TARGET_MCU_NRF51_32K_S110)
179+
/* Only peripheral role is supported by S110 */
180+
Gap::Role_t role = Gap::PERIPHERAL;
181+
#else
182+
Gap::Role_t role = static_cast<Gap::Role_t>(p_ble_evt->evt.gap_evt.params.connected.role);
183+
#endif
184+
gap.setConnectionHandle(handle);
185+
const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params));
186+
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
187+
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
188+
gap.processConnectionEvent(handle,
189+
role,
190+
static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
191+
static_cast<BLEProtocol::AddressType_t>(own->addr_type), own->addr,
192+
params);
193+
break;
194+
}
195+
196+
case BLE_GAP_EVT_DISCONNECTED: {
197+
Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
198+
// Since we are not in a connection and have not started advertising,
199+
// store bonds
200+
gap.setConnectionHandle (BLE_CONN_HANDLE_INVALID);
201+
202+
Gap::DisconnectionReason_t reason;
203+
switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) {
204+
case BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION:
205+
reason = Gap::LOCAL_HOST_TERMINATED_CONNECTION;
206+
break;
207+
case BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION:
208+
reason = Gap::REMOTE_USER_TERMINATED_CONNECTION;
209+
break;
210+
case BLE_HCI_CONN_INTERVAL_UNACCEPTABLE:
211+
reason = Gap::CONN_INTERVAL_UNACCEPTABLE;
212+
break;
213+
default:
214+
/* Please refer to the underlying transport library for an
215+
* interpretion of this reason's value. */
216+
reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason);
217+
break;
218+
}
219+
220+
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
221+
// Close all pending discoveries for this connection
222+
nRF5xGattClient& gattClient = ble.getGattClient();
223+
gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
224+
gattClient.discovery().terminate(handle);
225+
#endif
226+
227+
gap.processDisconnectionEvent(handle, reason);
228+
break;
229+
}
230+
231+
case BLE_GAP_EVT_PASSKEY_DISPLAY:
232+
securityManager.processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
233+
break;
234+
235+
case BLE_GAP_EVT_TIMEOUT:
236+
gap.processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src));
237+
break;
238+
239+
case BLE_GATTC_EVT_TIMEOUT:
240+
case BLE_GATTS_EVT_TIMEOUT:
241+
// Disconnect on GATT Server and Client timeout events.
242+
// ASSERT_STATUS_RET_VOID (sd_ble_gap_disconnect(m_conn_handle,
243+
// BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION));
244+
break;
245+
246+
case BLE_GAP_EVT_ADV_REPORT: {
247+
const ble_gap_evt_adv_report_t *advReport = &p_ble_evt->evt.gap_evt.params.adv_report;
248+
gap.processAdvertisementReport(advReport->peer_addr.addr,
249+
advReport->rssi,
250+
advReport->scan_rsp,
251+
static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type),
252+
advReport->dlen,
253+
advReport->data);
254+
break;
255+
}
256+
257+
default:
258+
break;
259+
}
260+
261+
gattServer.hwCallback(p_ble_evt);
262+
}
263+
264+
/*! @brief Callback when an error occurs inside the SoftDevice */
265+
void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name)
266+
{
267+
ASSERT(false, (void) 0);
268+
}
269+
270+
/*!
271+
@brief Handler for general errors above the SoftDevice layer.
272+
Typically we can' recover from this so we do a reset.
273+
*/
274+
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name)
275+
{
276+
ASSERT_STATUS_RET_VOID( error_code );
277+
NVIC_SystemReset();
278+
}

0 commit comments

Comments
 (0)