Skip to content

Commit 43b7637

Browse files
committed
add configPrphBandwidth() and configCentralBandwidth()
1 parent f39421f commit 43b7637

File tree

7 files changed

+94
-35
lines changed

7 files changed

+94
-35
lines changed

cores/nRF5/linker/bluefruit52_s132_5.1.0.ld

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,13 @@ MEMORY
88
FLASH (rx) : ORIGIN = 0x23000, LENGTH = 0x25000 /* Max 148 KB for dual banks */
99

1010
/* SRAM required by S132 depend on
11-
* - Attribute Table Size 0x800
12-
* - Vendor UUID count 10
13-
* - Max ATT MTU is 247
14-
* - Role concurrent connection peripherl (1) + central (0) + secure links (1)
15-
* - Event Len = 3, HVN queue = 3, Write CMD queue = 0
11+
* - Attribute Table Size
12+
* - Vendor UUID count
13+
* - Max ATT MTU
14+
* - Concurrent connection peripheral + central + secure links
15+
* - Event Len, HVN queue, Write CMD queue
1616
*/
17-
/* RAM (rwx) : ORIGIN = 0x20003000, LENGTH = 0x20010000 - 0x20003000 */
18-
RAM (rwx) : ORIGIN = 0x20003800, LENGTH = 0x20010000 - 0x20003800
19-
20-
/* Reference configuration
21-
- MTU = 247, hvn = 7, wrcmd = 3 , evt len = 3
22-
ram_start = 0x20003310
23-
24-
- MTU = 247, hvn = 3, wrcmd = 3, evt len = 3
25-
ram_start = 0x20002F10
26-
27-
- MTU = 23, hvn = 7, wrcmd = 3, evt len = 3
28-
ram_start = 0x200025A0
29-
*/
17+
RAM (rwx) : ORIGIN = 0x20003200, LENGTH = 0x20010000 - 0x20003200
3018
}
3119

3220
SECTIONS

libraries/Bluefruit52Lib/examples/Central/central_bleuart_multi/central_bleuart_multi.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ void setup()
9191
Serial.println("Bluefruit52 Central Multi BLEUART Example");
9292
Serial.println("-----------------------------------------\n");
9393

94-
// Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
95-
// SRAM usage required by SoftDevice will increase dramatically with number of connections
96-
Bluefruit.begin(0, BLE_CENTRAL_MAX_CONN);
94+
// Initialize Bluefruit with max concurrent connections as Peripheral = 1, Central = 1
95+
// SRAM usage required by SoftDevice will increase with number of connections
96+
Bluefruit.begin(0, 4);
9797

9898
// Set Name
9999
Bluefruit.setName("Bluefruit52 Central");

libraries/Bluefruit52Lib/examples/DualRoles/dual_bleuart/dual_bleuart.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ void setup()
3434
Serial.println("Bluefruit52 Dual Role BLEUART Example");
3535
Serial.println("-------------------------------------\n");
3636

37-
// Enable both peripheral and central
38-
Bluefruit.begin(true, true);
37+
// Initialize Bluefruit with max concurrent connections as Peripheral = 1, Central = 1
38+
// SRAM usage required by SoftDevice will increase with number of connections
39+
Bluefruit.begin(1, 1);
3940
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
4041
Bluefruit.setTxPower(4);
4142
Bluefruit.setName("Bluefruit52 duo");

libraries/Bluefruit52Lib/src/BLEGap.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ BLEGap::BLEGap(void)
4141
memclr(_peers, sizeof(_peers));
4242

4343
#if SD_VER >= 500
44-
_cfg_prph.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
45-
_cfg_prph.event_len = BLE_GAP_EVENT_LENGTH_DEFAULT;
46-
_cfg_prph.hvn_tx_qsize = BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT;
47-
_cfg_prph.wr_cmd_qsize = BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT;
44+
_cfg_prph.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
45+
_cfg_prph.event_len = BLE_GAP_EVENT_LENGTH_DEFAULT;
46+
_cfg_prph.hvn_tx_qsize = BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT;
47+
_cfg_prph.wr_cmd_qsize = BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT;
4848

49-
_cfg_central.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
49+
_cfg_central.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
5050
_cfg_central.event_len = BLE_GAP_EVENT_LENGTH_DEFAULT;
5151
_cfg_central.hvn_tx_qsize = BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT;
5252
_cfg_central.wr_cmd_qsize = BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT;

libraries/Bluefruit52Lib/src/BLEGap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
#include "bluefruit_common.h"
4141
#include "BLEUuid.h"
4242

43+
enum
44+
{
45+
CONN_CFG_PERIPHERAL = 1,
46+
CONN_CFG_CENTRAL = 2,
47+
};
48+
4349
class BLEGap
4450
{
4551
public:

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info)
9292
* Constructor
9393
*/
9494
AdafruitBluefruit::AdafruitBluefruit(void)
95-
: Central()
95+
: Central(), Gap()
9696
{
9797
/*------------------------------------------------------------------*/
9898
/* SoftDevice Default Configuration
@@ -167,7 +167,7 @@ void AdafruitBluefruit::configUuid128Count(uint8_t uuid128_max)
167167

168168
void AdafruitBluefruit::configAttrTableSize(uint32_t attr_table_size)
169169
{
170-
_sd_cfg.attr_table_size = maxof(attr_table_size, BLE_GATTS_ATTR_TAB_SIZE_MIN);
170+
_sd_cfg.attr_table_size = align4( maxof(attr_table_size, BLE_GATTS_ATTR_TAB_SIZE_MIN) );
171171
}
172172

173173
void AdafruitBluefruit::configPrphConn(uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize)
@@ -180,6 +180,64 @@ void AdafruitBluefruit::configCentralConn(uint16_t mtu_max, uint8_t event_len, u
180180
Gap.configCentralConn(mtu_max, event_len, hvn_qsize, wrcmd_qsize);
181181
}
182182

183+
void AdafruitBluefruit::configPrphBandwidth(uint8_t bw)
184+
{
185+
/* Note default value from SoftDevice are
186+
* MTU = 23, Event Len = 3, HVN QSize = 1, WrCMD QSize =1
187+
*/
188+
switch (bw)
189+
{
190+
case BANDWIDTH_LOW:
191+
configPrphConn(BLE_GATT_ATT_MTU_DEFAULT, BLE_GAP_EVENT_LENGTH_MIN, BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
192+
break;
193+
194+
// TODO Bandwidth auto
195+
case BANDWIDTH_AUTO:
196+
case BANDWIDTH_NORMAL:
197+
configPrphConn(BLE_GATT_ATT_MTU_DEFAULT, BLE_GAP_EVENT_LENGTH_DEFAULT, BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
198+
break;
199+
200+
case BANDWIDTH_HIGH:
201+
configPrphConn(128, 6, 2, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
202+
break;
203+
204+
case BANDWIDTH_MAX:
205+
configPrphConn(247, 6, 3, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
206+
break;
207+
208+
default: break;
209+
}
210+
}
211+
212+
void AdafruitBluefruit::configCentralBandwidth(uint8_t bw)
213+
{
214+
/* Note default value from SoftDevice are
215+
* MTU = 23, Event Len = 3, HVN QSize = 1, WrCMD QSize =1
216+
*/
217+
switch (bw)
218+
{
219+
case BANDWIDTH_LOW:
220+
configCentralConn(BLE_GATT_ATT_MTU_DEFAULT, BLE_GAP_EVENT_LENGTH_MIN, BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
221+
break;
222+
223+
// TODO Bandwidth auto
224+
case BANDWIDTH_AUTO:
225+
case BANDWIDTH_NORMAL:
226+
configCentralConn(BLE_GATT_ATT_MTU_DEFAULT, BLE_GAP_EVENT_LENGTH_DEFAULT, BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
227+
break;
228+
229+
case BANDWIDTH_HIGH:
230+
configCentralConn(128, 6, 2, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
231+
break;
232+
233+
case BANDWIDTH_MAX:
234+
configCentralConn(247, 6, 3, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
235+
break;
236+
237+
default: break;
238+
}
239+
}
240+
183241

184242
err_t AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
185243
{

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@
9292

9393
enum
9494
{
95-
CONN_CFG_PERIPHERAL = 1,
96-
CONN_CFG_CENTRAL = 2,
95+
BANDWIDTH_AUTO = 0,
96+
BANDWIDTH_LOW,
97+
BANDWIDTH_NORMAL,
98+
BANDWIDTH_HIGH,
99+
BANDWIDTH_MAX,
97100
};
98101

99102
extern "C"
@@ -129,9 +132,12 @@ class AdafruitBluefruit
129132
void configUuid128Count (uint8_t uuid128_max);
130133
void configAttrTableSize (uint32_t attr_table_size);
131134

132-
// Bandwidth config for connections
133-
void configPrphConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
134-
void configCentralConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
135+
// Config Bandwidth for connections
136+
void configPrphConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
137+
void configCentralConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
138+
// Convenient function to config connection
139+
void configPrphBandwidth (uint8_t bw);
140+
void configCentralBandwidth(uint8_t bw);
135141

136142
err_t begin(uint8_t prph_count = 1, uint8_t central_count = 0);
137143

0 commit comments

Comments
 (0)