Skip to content

Commit 8e19b04

Browse files
anhmoltlemrey
authored andcommitted
nrf_sdh: optimize the idx get functionality when limited to one link
When only a single connection at a time is supported and CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT is set to one, the idx get and idx<->conn_handle management can be simplified to save code space. Signed-off-by: Andreas Moltumyr <[email protected]>
1 parent ef767b8 commit 8e19b04

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

include/nrf_sdh_ble.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,18 @@ int nrf_sdh_ble_enable(uint8_t conn_cfg_tag);
9393
* @returns An integer in the range from 0 to (CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT - 1) if the
9494
* connection handle has been assigned to an index, otherwise -1.
9595
*/
96-
int nrf_sdh_ble_idx_get(uint16_t conn_handle);
96+
static inline int nrf_sdh_ble_idx_get(uint16_t conn_handle)
97+
{
98+
/* Code size optimization when supporting only one connection. */
99+
if (CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT == 1) {
100+
ARG_UNUSED(conn_handle);
101+
return 0;
102+
}
103+
104+
/* This is used when supporting multiple connections. */
105+
int _nrf_sdh_ble_idx_get(uint16_t conn_handle);
106+
return _nrf_sdh_ble_idx_get(conn_handle);
107+
}
97108

98109
#ifdef __cplusplus
99110
}

subsys/softdevice_handler/nrf_sdh_ble.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static uint16_t conn_handles[CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT] = {
155155
[0 ... CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT - 1] = BLE_CONN_HANDLE_INVALID,
156156
};
157157

158-
int nrf_sdh_ble_idx_get(uint16_t conn_handle)
158+
int _nrf_sdh_ble_idx_get(uint16_t conn_handle)
159159
{
160160
for (int idx = 0; idx < ARRAY_SIZE(conn_handles); idx++) {
161161
if (conn_handles[idx] == conn_handle) {
@@ -222,7 +222,8 @@ static void ble_evt_poll(void *context)
222222
LOG_DBG("BLE event: %#x", ble_evt->header.evt_id);
223223
}
224224

225-
if (ble_evt->header.evt_id == BLE_GAP_EVT_CONNECTED) {
225+
if ((CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT > 1) &&
226+
(ble_evt->header.evt_id == BLE_GAP_EVT_CONNECTED)) {
226227
idx_assign(ble_evt->evt.gap_evt.conn_handle);
227228
}
228229

@@ -232,7 +233,8 @@ static void ble_evt_poll(void *context)
232233
obs->handler(ble_evt, obs->context);
233234
}
234235

235-
if (ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED) {
236+
if ((CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT > 1) &&
237+
(ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED)) {
236238
idx_unassign(ble_evt->evt.gap_evt.conn_handle);
237239
}
238240
}

0 commit comments

Comments
 (0)