8000 nrf: bleio: parameterize softradio configuration · domdfcoding/circuitpython@c04e6d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit c04e6d6

Browse files
committed
nrf: bleio: parameterize softradio configuration
Allow for setting various softradio memory settings as part of a board in order to support lower-memory configurations. If a parameter is unspecified then the previously-defined value is used. Signed-off-by: Sean Cross <sean@xobs.io>
1 parent 3537ad4 commit c04e6d6

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

ports/nrf/common-hal/_bleio/Adapter.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@
5656
#define BLE_SLAVE_LATENCY 0
5757
#define BLE_CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS)
5858

59+
#ifndef BLEIO_VS_UUID_COUNT
60+
#define BLEIO_VS_UUID_COUNT 75
61+
#endif
62+
63+
#ifndef BLEIO_HVN_TX_QUEUE_SIZE
64+
#define BLEIO_HVN_TX_QUEUE_SIZE 9
65+
#endif
66+
67+
#ifndef BLEIO_CENTRAL_ROLE_COUNT
68+
#define BLEIO_CENTRAL_ROLE_COUNT 4
69+
#endif
70+
71+
#ifndef BLEIO_PERIPH_ROLE_COUNT
72+
#define BLEIO_PERIPH_ROLE_COUNT 4
73+
#endif
74+
75+
#ifndef BLEIO_ATTR_TAB_SIZE
76+
#define BLEIO_ATTR_TAB_SIZE (BLE_GATTS_ATTR_TAB_SIZE_DEFAULT * 5)
77+
#endif
78+
5979
const nvm_bytearray_obj_t common_hal_bleio_nvm_obj = {
6080
.base = {
6181
.type = &nvm_bytearray_type,
@@ -124,9 +144,9 @@ STATIC uint32_t ble_stack_enable(void) {
124144
// adv_set_count must be == 1 for S140. Cannot be increased.
125145
ble_conf.gap_cfg.role_count_cfg.adv_set_count = 1;
126146
// periph_role_count costs 1232 bytes for 2 to 3, then ~1840 for each further increment.
127-
ble_conf.gap_cfg.role_count_cfg.periph_role_count = 4;
147+
ble_conf.gap_cfg.role_count_cfg.periph_role_count = BLEIO_PERIPH_ROLE_COUNT;
128148
// central_role_count costs 648 bytes for 1 to 2, then ~1250 for each further increment.
129-
ble_conf.gap_cfg.role_count_cfg.central_role_count = 4;
149+
ble_conf.gap_cfg.role_count_cfg.central_role_count = BLEIO_CENTRAL_ROLE_COUNT;
130150
err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_conf, app_ram_start);
131151
if (err_code != NRF_SUCCESS) {
132152
return err_code;
@@ -137,7 +157,7 @@ STATIC uint32_t ble_stack_enable(void) {
137157
// Each increment to hvn_tx_queue_size costs 2064 bytes.
138158
// DevZone recommends not setting this directly, but instead changing gap_conn_cfg.event_length.
139159
// However, we are setting connection extension, so this seems to make sense.
140-
ble_conf.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = 9;
160+
ble_conf.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = BLEIO_HVN_TX_QUEUE_SIZE;
141161
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_conf, app_ram_start);
142162
if (err_code != NRF_SUCCESS) {
143163
return err_code;
@@ -156,7 +176,7 @@ STATIC uint32_t ble_stack_enable(void) {
156176
// and anything the user does.
157177
memset(&ble_conf, 0, sizeof(ble_conf));
158178
// Each increment to the BLE_GATTS_ATTR_TAB_SIZE_DEFAULT multiplier costs 1408 bytes.
159-
ble_conf.gatts_cfg.attr_tab_size.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT * 5;
179+
ble_conf.gatts_cfg.attr_tab_size.attr_tab_size = BLEIO_ATTR_TAB_SIZE;
160180
err_code = sd_ble_cfg_set(BLE_GATTS_CFG_ATTR_TAB_SIZE, &ble_conf, app_ram_start);
161181
if (err_code != NRF_SUCCESS) {
162182
return err_code;
@@ -166,7 +186,7 @@ STATIC uint32_t ble_stack_enable(void) {
166186
// service and characteristic.
167187
memset(&ble_conf, 0, sizeof(ble_conf));
168188
// Each additional vs_uuid_count costs 16 bytes.
169-
ble_conf.common_cfg.vs_uuid_cfg.vs_uuid_count = 75; // Defaults to 10.
189+
ble_conf.common_cfg.vs_uuid_cfg.vs_uuid_count = BLEIO_VS_UUID_COUNT; // Defaults to 10.
170190
err_code = sd_ble_cfg_set(BLE_COMMON_CFG_VS_UUID, &ble_conf, app_ram_start);
171191
if (err_code != NRF_SUCCESS) {
172192
return err_code;

ports/nrf/common-hal/_bleio/Adapter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#include "shared-bindings/_bleio/Connection.h"
3636
#include "shared-bindings/_bleio/ScanResults.h"
3737

38+
#ifndef BLEIO_TOTAL_CONNECTION_COUNT
3839
#define BLEIO_TOTAL_CONNECTION_COUNT 5
40+
#endif
3941

4042
extern bleio_connection_internal_t bleio_connections[BLEIO_TOTAL_CONNECTION_COUNT];
4143

0 commit comments

Comments
 (0)
0