add configPrphBandwidth() and configCentralBandwidth()

This commit is contained in:
hathach committed 2017-12-22 13:40:10 +07:00
1 parent f39421f4ef
commit 43b7637a60
7 files changed
+94 -35

No files matched your search

+6 -18
View File
@@ -8,25 +8,13 @@ MEMORY
FLASH (rx) : ORIGIN = 0x23000, LENGTH = 0x25000 /* Max 148 KB for dual banks */
/* SRAM required by S132 depend on
* - Attribute Table Size 0x800
* - Vendor UUID count 10
* - Max ATT MTU is 247
* - Role concurrent connection peripherl (1) + central (0) + secure links (1)
* - Event Len = 3, HVN queue = 3, Write CMD queue = 0
* - Attribute Table Size
* - Vendor UUID count
* - Max ATT MTU
* - Concurrent connection peripheral + central + secure links
* - Event Len, HVN queue, Write CMD queue
*/
/* RAM (rwx) : ORIGIN = 0x20003000, LENGTH = 0x20010000 - 0x20003000 */
RAM (rwx) : ORIGIN = 0x20003800, LENGTH = 0x20010000 - 0x20003800
/* Reference configuration
- MTU = 247, hvn = 7, wrcmd = 3 , evt len = 3
ram_start = 0x20003310
- MTU = 247, hvn = 3, wrcmd = 3, evt len = 3
ram_start = 0x20002F10
- MTU = 23, hvn = 7, wrcmd = 3, evt len = 3
ram_start = 0x200025A0
*/
RAM (rwx) : ORIGIN = 0x20003200, LENGTH = 0x20010000 - 0x20003200
}
SECTIONS
@@ -91,9 +91,9 @@ void setup()
Serial.println("Bluefruit52 Central Multi BLEUART Example");
Serial.println("-----------------------------------------\n");
// Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
// SRAM usage required by SoftDevice will increase dramatically with number of connections
Bluefruit.begin(0, BLE_CENTRAL_MAX_CONN);
// Initialize Bluefruit with max concurrent connections as Peripheral = 1, Central = 1
// SRAM usage required by SoftDevice will increase with number of connections
Bluefruit.begin(0, 4);
// Set Name
Bluefruit.setName("Bluefruit52 Central");
@@ -34,8 +34,9 @@ void setup()
Serial.println("Bluefruit52 Dual Role BLEUART Example");
Serial.println("-------------------------------------\n");
// Enable both peripheral and central
Bluefruit.begin(true, true);
// Initialize Bluefruit with max concurrent connections as Peripheral = 1, Central = 1
// SRAM usage required by SoftDevice will increase with number of connections
Bluefruit.begin(1, 1);
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
Bluefruit.setTxPower(4);
Bluefruit.setName("Bluefruit52 duo");
+5 -5
View File
@@ -41,12 +41,12 @@ BLEGap::BLEGap(void)
memclr(_peers, sizeof(_peers));
#if SD_VER >= 500
_cfg_prph.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
_cfg_prph.event_len = BLE_GAP_EVENT_LENGTH_DEFAULT;
_cfg_prph.hvn_tx_qsize = BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT;
_cfg_prph.wr_cmd_qsize = BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT;
_cfg_prph.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
_cfg_prph.event_len = BLE_GAP_EVENT_LENGTH_DEFAULT;
_cfg_prph.hvn_tx_qsize = BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT;
_cfg_prph.wr_cmd_qsize = BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT;
_cfg_central.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
_cfg_central.mtu_max = BLE_GATT_ATT_MTU_DEFAULT;
_cfg_central.event_len = BLE_GAP_EVENT_LENGTH_DEFAULT;
_cfg_central.hvn_tx_qsize = BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT;
_cfg_central.wr_cmd_qsize = BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT;
+6
View File
@@ -40,6 +40,12 @@
#include "bluefruit_common.h"
#include "BLEUuid.h"
enum
{
CONN_CFG_PERIPHERAL = 1,
CONN_CFG_CENTRAL = 2,
};
class BLEGap
{
public:
+60 -2
View File
@@ -92,7 +92,7 @@ static void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info)
* Constructor
*/
AdafruitBluefruit::AdafruitBluefruit(void)
: Central()
: Central(), Gap()
{
/*------------------------------------------------------------------*/
/* SoftDevice Default Configuration
@@ -167,7 +167,7 @@ void AdafruitBluefruit::configUuid128Count(uint8_t uuid128_max)
void AdafruitBluefruit::configAttrTableSize(uint32_t attr_table_size)
{
_sd_cfg.attr_table_size = maxof(attr_table_size, BLE_GATTS_ATTR_TAB_SIZE_MIN);
_sd_cfg.attr_table_size = align4( maxof(attr_table_size, BLE_GATTS_ATTR_TAB_SIZE_MIN) );
}
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
Gap.configCentralConn(mtu_max, event_len, hvn_qsize, wrcmd_qsize);
}
void AdafruitBluefruit::configPrphBandwidth(uint8_t bw)
{
/* Note default value from SoftDevice are
* MTU = 23, Event Len = 3, HVN QSize = 1, WrCMD QSize =1
*/
switch (bw)
{
case BANDWIDTH_LOW:
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);
break;
// TODO Bandwidth auto
case BANDWIDTH_AUTO:
case BANDWIDTH_NORMAL:
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);
break;
case BANDWIDTH_HIGH:
configPrphConn(128, 6, 2, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
break;
case BANDWIDTH_MAX:
configPrphConn(247, 6, 3, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
break;
default: break;
}
}
void AdafruitBluefruit::configCentralBandwidth(uint8_t bw)
{
/* Note default value from SoftDevice are
* MTU = 23, Event Len = 3, HVN QSize = 1, WrCMD QSize =1
*/
switch (bw)
{
case BANDWIDTH_LOW:
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);
break;
// TODO Bandwidth auto
case BANDWIDTH_AUTO:
case BANDWIDTH_NORMAL:
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);
break;
case BANDWIDTH_HIGH:
configCentralConn(128, 6, 2, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
break;
case BANDWIDTH_MAX:
configCentralConn(247, 6, 3, BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT);
break;
default: break;
}
}
err_t AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
{
+11 -5
View File
@@ -92,8 +92,11 @@
enum
{
CONN_CFG_PERIPHERAL = 1,
CONN_CFG_CENTRAL = 2,
BANDWIDTH_AUTO = 0,
BANDWIDTH_LOW,
BANDWIDTH_NORMAL,
BANDWIDTH_HIGH,
BANDWIDTH_MAX,
};
extern "C"
@@ -129,9 +132,12 @@ class AdafruitBluefruit
void configUuid128Count (uint8_t uuid128_max);
void configAttrTableSize (uint32_t attr_table_size);
// Bandwidth config for connections
void configPrphConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
void configCentralConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
// Config Bandwidth for connections
void configPrphConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
void configCentralConn (uint16_t mtu_max, uint8_t event_len, uint8_t hvn_qsize, uint8_t wrcmd_qsize);
// Convenient function to config connection
void configPrphBandwidth (uint8_t bw);
void configCentralBandwidth(uint8_t bw);
err_t begin(uint8_t prph_count = 1, uint8_t central_count = 0);