Skip to content

Commit dfcbb4c

Browse files
authored
Merge pull request #6308 from donatieng/nrf52x_ble5_events
Support for nRF52x BLE 4.2 and 5 events
2 parents d9b1d87 + fd54e5e commit dfcbb4c

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5x/source/btle/btle.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,53 @@ static void btle_handler(ble_evt_t *p_ble_evt)
369369
break;
370370
}
371371

372+
373+
#if (NRF_SD_BLE_API_VERSION >= 5)
374+
#ifndef S140
375+
// Handle PHY upgrade request
376+
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
377+
{
378+
ble_gap_phys_t const phys =
379+
{
380+
/* rx_phys */ BLE_GAP_PHY_AUTO,
381+
/* tx_phys */ BLE_GAP_PHY_AUTO,
382+
};
383+
ASSERT_STATUS_RET_VOID( sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys) );
384+
break;
385+
}
386+
#endif
387+
388+
// Handle Data length negotiation request
389+
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
390+
{
391+
ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
392+
uint8_t const data_length_peer =
393+
p_gap_evt->params.data_length_update_request.peer_params.max_tx_octets;
394+
395+
const uint8_t max_data_length = NRF_SDH_BLE_GATT_MAX_MTU_SIZE + 4 /* L2CAP header size */;
396+
397+
uint8_t const data_length = MIN(max_data_length, data_length_peer);
398+
399+
ble_gap_data_length_params_t const dlp =
400+
{
401+
/* max_rx_octets */ data_length,
402+
/* max_tx_octets */ data_length
403+
};
404+
405+
ASSERT_STATUS_RET_VOID(sd_ble_gap_data_length_update(p_gap_evt->conn_handle, &dlp, NULL));
406+
break;
407+
}
408+
409+
// Handle MTU exchange request
410+
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
411+
{
412+
// Respond with the server MTU
413+
uint16_t conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
414+
ASSERT_STATUS_RET_VOID(sd_ble_gatts_exchange_mtu_reply(conn_handle, NRF_SDH_BLE_GATT_MAX_MTU_SIZE));
415+
break;
416+
}
417+
#endif
418+
372419
case BLE_GAP_EVT_PASSKEY_DISPLAY:
373420
securityManager.processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
374421
break;

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5x/source/nRF5xn.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ nRF5xn::waitForEvent(void)
222222
}
223223

224224
void nRF5xn::processEvents() {
225-
if (isEventsSignaled) {
225+
core_util_critical_section_enter();
226+
while (isEventsSignaled) {
226227
isEventsSignaled = false;
228+
core_util_critical_section_exit();
227229
#if NRF_SD_BLE_API_VERSION >= 5
228230
// We use the "polling" dispatch model
229231
// http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/group__nrf__sdh.html?cp=4_0_0_6_11_60_20#gab4d7be69304d4f5feefd1d440cc3e6c7
@@ -232,5 +234,8 @@ void nRF5xn::processEvents() {
232234
#else
233235
intern_softdevice_events_execute();
234236
#endif
237+
238+
core_util_critical_section_enter();
235239
}
240+
core_util_critical_section_exit();
236241
}

0 commit comments

Comments
 (0)