separated TX packet to HVN and Write CMD packet
This commit is contained in:
1 parent
2da5145cbc
commit
abeb3825db
6 files changed
+52
-33
No files matched your search
@@ -487,7 +487,7 @@ bool BLECharacteristic::notify(const void* data, uint16_t len)
|
||||
while ( remaining )
|
||||
{
|
||||
// TODO multiple connection support
|
||||
if ( !Bluefruit.Gap.getTxPacket( Bluefruit.connHandle() ) ) return NRF_ERROR_RESOURCES; //BLE_ERROR_NO_TX_PACKETS;
|
||||
if ( !Bluefruit.Gap.getHvnPacket( Bluefruit.connHandle() ) ) return NRF_ERROR_RESOURCES; //BLE_ERROR_NO_TX_PACKETS;
|
||||
|
||||
uint16_t packet_len = min16(MTU_MPS, remaining);
|
||||
|
||||
|
||||
@@ -225,9 +225,8 @@ uint16_t BLEClientCharacteristic::write(const void* data, uint16_t len)
|
||||
uint16_t remaining = len;
|
||||
while( remaining )
|
||||
{
|
||||
// Write CMD consume a TX buffer
|
||||
// TODO BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE
|
||||
if ( !Bluefruit.Gap.getTxPacket(_service->connHandle()) ) return NRF_ERROR_RESOURCES; //BLE_ERROR_NO_TX_PACKETS;
|
||||
// TODO only Write without response consume a TX buffer
|
||||
if ( !Bluefruit.Gap.getWriteCmdPacket(_service->connHandle()) ) return NRF_ERROR_RESOURCES; //BLE_ERROR_NO_TX_PACKETS;
|
||||
|
||||
uint16_t packet_len = min16(MTU_MPS, remaining);
|
||||
|
||||
@@ -269,9 +268,8 @@ bool BLEClientCharacteristic::writeCCCD(uint16_t value)
|
||||
.p_value = (uint8_t*) &value
|
||||
};
|
||||
|
||||
// Write consume a TX buffer
|
||||
// TODO BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE
|
||||
if ( !Bluefruit.Gap.getTxPacket(conn_handle) ) return NRF_ERROR_RESOURCES; //BLE_ERROR_NO_TX_PACKETS;
|
||||
// TODO only Write without response consume a TX buffer
|
||||
if ( !Bluefruit.Gap.getWriteCmdPacket(conn_handle) ) return NRF_ERROR_RESOURCES; //BLE_ERROR_NO_TX_PACKETS;
|
||||
|
||||
VERIFY_STATUS( sd_ble_gattc_write(conn_handle, ¶m), false );
|
||||
|
||||
|
||||
@@ -105,11 +105,21 @@ ble_gap_addr_t BLEGap::getPeerAddr(uint16_t conn_handle)
|
||||
return _peers[conn_handle].addr;
|
||||
}
|
||||
|
||||
bool BLEGap::getTxPacket(uint16_t conn_handle)
|
||||
bool BLEGap::getHvnPacket(uint16_t conn_handle)
|
||||
{
|
||||
VERIFY( (conn_handle < BLE_MAX_CONN) && (_peers[conn_handle].txpacket_sem != NULL) );
|
||||
VERIFY( (conn_handle < BLE_MAX_CONN) && (_peers[conn_handle].hvn_tx_sem != NULL) );
|
||||
|
||||
return xSemaphoreTake(_peers[conn_handle].txpacket_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
return xSemaphoreTake(_peers[conn_handle].hvn_tx_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
}
|
||||
|
||||
bool BLEGap::getWriteCmdPacket(uint16_t conn_handle)
|
||||
{
|
||||
#if SD_VER < 500
|
||||
return getHvnPacket(conn_handle);
|
||||
#else
|
||||
VERIFY( (conn_handle < BLE_MAX_CONN) && (_peers[conn_handle].wrcmd_tx_sem != NULL) );
|
||||
return xSemaphoreTake(_peers[conn_handle].wrcmd_tx_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t BLEGap::getMTU (uint16_t conn_handle)
|
||||
@@ -147,11 +157,12 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
#if SD_VER < 500
|
||||
uint8_t txbuf_max;
|
||||
(void) sd_ble_tx_packet_count_get(conn_handle, &txbuf_max);
|
||||
peer->txpacket_sem = xSemaphoreCreateCounting(txbuf_max, txbuf_max);
|
||||
peer->hvn_tx_sem = xSemaphoreCreateCounting(txbuf_max, txbuf_max);
|
||||
#else
|
||||
peer->txpacket_sem = xSemaphoreCreateCounting(BLEGAP_HVN_TX_QUEUE_SIZE, BLEGAP_HVN_TX_QUEUE_SIZE);
|
||||
// TODO BLEGAP_WRITECMD_TX_QUEUE_SIZE
|
||||
peer->hvn_tx_sem = xSemaphoreCreateCounting(BLEGAP_HVN_TX_QUEUE_SIZE, BLEGAP_HVN_TX_QUEUE_SIZE);
|
||||
#endif
|
||||
|
||||
peer->wrcmd_tx_sem = xSemaphoreCreateCounting(BLEGAP_WRITECMD_TX_QUEUE_SIZE, BLEGAP_WRITECMD_TX_QUEUE_SIZE);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -162,40 +173,42 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
// mark as disconnected, but keep the role for sub sequence event handler
|
||||
peer->connected = false;
|
||||
|
||||
vSemaphoreDelete( peer->txpacket_sem );
|
||||
peer->txpacket_sem = NULL;
|
||||
vSemaphoreDelete( peer->hvn_tx_sem );
|
||||
peer->hvn_tx_sem = NULL;
|
||||
|
||||
vSemaphoreDelete( peer->wrcmd_tx_sem );
|
||||
peer->wrcmd_tx_sem = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
#if SD_VER < 500
|
||||
case BLE_EVT_TX_COMPLETE:
|
||||
if ( peer->txpacket_sem )
|
||||
if ( peer->hvn_tx_sem )
|
||||
{
|
||||
for(uint8_t i=0; i<evt->evt.common_evt.params.tx_complete.count; i++)
|
||||
{
|
||||
xSemaphoreGive(peer->txpacket_sem);
|
||||
xSemaphoreGive(peer->hvn_tx_sem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
#else
|
||||
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
|
||||
if ( peer->txpacket_sem )
|
||||
if ( peer->hvn_tx_sem )
|
||||
{
|
||||
for(uint8_t i=0; i<evt->evt.gatts_evt.params.hvn_tx_complete.count; i++)
|
||||
{
|
||||
xSemaphoreGive(peer->txpacket_sem);
|
||||
xSemaphoreGive(peer->hvn_tx_sem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE:
|
||||
if ( peer->txpacket_sem )
|
||||
if ( peer->wrcmd_tx_sem )
|
||||
{
|
||||
for(uint8_t i=0; i<evt->evt.gattc_evt.params.write_cmd_tx_complete.count; i++)
|
||||
{
|
||||
// TODO BLEGAP_WRITECMD_TX_QUEUE_SIZE
|
||||
xSemaphoreGive(peer->txpacket_sem);
|
||||
xSemaphoreGive(peer->wrcmd_tx_sem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#include "BLEUuid.h"
|
||||
|
||||
#define BLEGAP_HVN_TX_QUEUE_SIZE 7 // BLE_GATTS_HVN_TX_QUEUE_SIZE_DEFAULT
|
||||
#define BLEGAP_WRITECMD_TX_QUEUE_SIZE BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT
|
||||
#define BLEGAP_WRITECMD_TX_QUEUE_SIZE 1 // BLE_GATTC_WRITE_CMD_TX_QUEUE_SIZE_DEFAULT
|
||||
|
||||
class BLEGap
|
||||
{
|
||||
@@ -63,7 +63,8 @@ class BLEGap
|
||||
ble_gap_addr_t getPeerAddr(uint16_t conn_handle);
|
||||
|
||||
uint16_t getPeerName(uint16_t conn_handle, char* buf, uint16_t bufsize);
|
||||
bool getTxPacket(uint16_t conn_handle);
|
||||
bool getHvnPacket(uint16_t conn_handle);
|
||||
bool getWriteCmdPacket(uint16_t conn_handle);
|
||||
|
||||
uint16_t getMTU(uint16_t conn_handle);
|
||||
|
||||
@@ -83,7 +84,8 @@ class BLEGap
|
||||
|
||||
ble_gap_addr_t addr;
|
||||
|
||||
SemaphoreHandle_t txpacket_sem;
|
||||
SemaphoreHandle_t hvn_tx_sem;
|
||||
SemaphoreHandle_t wrcmd_tx_sem;
|
||||
} gap_peer_t;
|
||||
|
||||
gap_peer_t _peers[BLE_MAX_CONN];
|
||||
|
||||
@@ -136,9 +136,9 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
|
||||
_central_enabled = central_enable;
|
||||
|
||||
// Configure Clock
|
||||
#if defined( USE_LFXO )
|
||||
nrf_clock_lf_cfg_t clock_cfg =
|
||||
{
|
||||
#if defined( USE_LFXO )
|
||||
// LFXO
|
||||
.source = NRF_CLOCK_LF_SRC_XTAL,
|
||||
.rc_ctiv = 0,
|
||||
@@ -148,14 +148,8 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
|
||||
#else
|
||||
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
|
||||
#endif
|
||||
#else
|
||||
// LFRC
|
||||
.source = NRF_CLOCK_LF_SRC_RC,
|
||||
.rc_ctiv = 16,
|
||||
.rc_temp_ctiv = 2,
|
||||
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
VERIFY_STATUS( sd_softdevice_enable(&clock_cfg, NULL) );
|
||||
|
||||
@@ -190,6 +184,13 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
|
||||
blecfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = BLEGAP_HVN_TX_QUEUE_SIZE;
|
||||
sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &blecfg, ram_start);
|
||||
|
||||
// WRITE COMMAND queue size
|
||||
varclr(&blecfg);
|
||||
blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_TAG_DEFAULT;
|
||||
blecfg.conn_cfg.params.gattc_conn_cfg.write_cmd_tx_queue_size = BLEGAP_WRITECMD_TX_QUEUE_SIZE;
|
||||
sd_ble_cfg_set(BLE_CONN_CFG_GATTC, &blecfg, ram_start);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*------------- Configure GAP -------------*/
|
||||
|
||||
@@ -142,8 +142,13 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
|
||||
|
||||
// Set GPReset to DFU OTA
|
||||
enum { DFU_OTA_MAGIC = 0xB1 };
|
||||
#if SD_VER < 500
|
||||
sd_power_gpregret_clr(0xFF);
|
||||
VERIFY_STATUS( sd_power_gpregret_set(DFU_OTA_MAGIC), RETURN_VOID);
|
||||
#else
|
||||
sd_power_gpregret_clr(0, 0xFF);
|
||||
VERIFY_STATUS( sd_power_gpregret_set(0, DFU_OTA_MAGIC), RETURN_VOID);
|
||||
#endif
|
||||
VERIFY_STATUS( sd_softdevice_disable(), RETURN_VOID );
|
||||
|
||||
// Disable Systick to prevent Interrupt happens after changing vector table
|
||||
|
||||
Reference in new issue
Block a user