Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of X_NUCLEO_IDB0XA1 by
Revision 162:667f97a4db7f, committed 2015-10-30
- Comitter:
- Wolfgang Betz
- Date:
- Fri Oct 30 09:08:25 2015 +0100
- Parent:
- 161:7eb0eb7adbe6
- Child:
- 163:4c008b1089e9
- Commit message:
- Use minar scheduling in place of busy waiting
Changed in this revision
| source/BlueNRGGap.cpp | Show annotated file Show diff for this revision Revisions of this file |
| source/bluenrg-hci/hci/hci.c | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/BlueNRGGap.cpp Thu Oct 29 15:24:04 2015 +0100
+++ b/source/BlueNRGGap.cpp Fri Oct 30 09:08:25 2015 +0100
@@ -697,7 +697,7 @@
{
for(int i=0; i<BDADDR_SIZE; i++) {
address[i] = bdaddr[i];
- //PRINTF("i[%d]:0x%x\n\r",i,bdaddr[i]);
+ PRINTF("i[%d]:0x%x\n\r",i,bdaddr[i]);
}
}
@@ -984,6 +984,11 @@
BlueNRGGap::getInstance().startRadioScan(*scanningParams);
}
+static void makeConn()
+{
+ BlueNRGGap::getInstance().makeConnection();
+}
+
// ANDREA
void BlueNRGGap::Discovery_CB(Reason_t reason,
uint8_t adv_type,
@@ -1034,11 +1039,10 @@
PRINTF("DISCOVERY_COMPLETE\n\r");
_scanning = false;
- if(_connecting) {
- makeConnection();
+ if(_connecting) {
+ minar::Scheduler::postCallback(makeConn);
} else {
PRINTF("re-startRadioScan\n\r");
- //startRadioScan(_scanningParams);
minar::Scheduler::postCallback(radioScanning);
}
@@ -1063,17 +1067,19 @@
PRINTF("BTLE re-init\n\r");
}
- while((ret = aci_gap_start_general_discovery_proc(scanningParams.getInterval(),
- scanningParams.getWindow(),
- addr_type,
- 1) // 1 to filter duplicates
- ) == ERR_COMMAND_DISALLOWED) {
- PRINTF("betzw: wait a bit ...\n\r");
-
- // FIXME: We need to wait for a while before starting discovery proc
- // due to BlueNRG process queue handling
- // NOTE: this workaround causes a potential risk for an endless loop!!!
- Clock_Wait(100);
+ if((ret = aci_gap_start_general_discovery_proc(scanningParams.getInterval(),
+ scanningParams.getWindow(),
+ addr_type,
+ 1) // 1 to filter duplicates
+ ) == ERR_COMMAND_DISALLOWED) {
+ PRINTF("\t==>betzw: wait a bit ...<==\n\r");
+
+ // FIXME: We need to wait for a while before starting discovery proc
+ // due to BlueNRG process queue handling
+ // NOTE: this workaround causes a potential risk for an endless loop!!!
+ minar::Scheduler::postCallback(radioScanning).delay(minar::milliseconds(100));
+
+ return BLE_STACK_BUSY;
}
if (ret != BLE_STATUS_SUCCESS) {
@@ -1151,29 +1157,30 @@
{
tBleStatus ret;
- _connecting = false;
-
/*
Scan_Interval, Scan_Window, Peer_Address_Type, Peer_Address, Own_Address_Type, Conn_Interval_Min,
Conn_Interval_Max, Conn_Latency, Supervision_Timeout, Conn_Len_Min, Conn_Len_Max
*/
- while((ret = aci_gap_create_connection(SCAN_P,
- SCAN_L,
- PUBLIC_ADDR,
- (unsigned char*)_peerAddr,
- PUBLIC_ADDR,
- CONN_P1, CONN_P2, 0,
- SUPERV_TIMEOUT, CONN_L1 , CONN_L2)
- ) == ERR_COMMAND_DISALLOWED) {
- PRINTF("wait a bit ...\n\r");
-
- // FIXME: We need to wait for a while before creating a connection
- // due to BlueNRG process queue handling
- // NOTE: this workaround causes a potential risk for an endless loop!!!
- Clock_Wait(100);
+ if((ret = aci_gap_create_connection(SCAN_P,
+ SCAN_L,
+ PUBLIC_ADDR,
+ (unsigned char*)_peerAddr,
+ PUBLIC_ADDR,
+ CONN_P1, CONN_P2, 0,
+ SUPERV_TIMEOUT, CONN_L1 , CONN_L2)
+ ) == ERR_COMMAND_DISALLOWED) {
+ PRINTF("\t==>betzw: wait a bit ...<==\n\r");
+
+ // FIXME: We need to wait for a while before creating a connection
+ // due to BlueNRG process queue handling
+ // NOTE: this workaround causes a potential risk for an endless loop!!!
+ minar::Scheduler::postCallback(makeConn).delay(minar::milliseconds(100));
+
+ return BLE_STACK_BUSY;
}
-
+ _connecting = false;
+
if (ret != BLE_STATUS_SUCCESS){
printf("Error while starting connection (ret=0x%02X).\n\r", ret);
return BLE_ERROR_UNSPECIFIED;
@@ -1198,7 +1205,7 @@
_peerAddr[i] = peerAddr[i];
}
- _connecting = true;
+ _connecting = true;
if(_scanning) {
stopScan();
--- a/source/bluenrg-hci/hci/hci.c Thu Oct 29 15:24:04 2015 +0100
+++ b/source/bluenrg-hci/hci/hci.c Fri Oct 30 09:08:25 2015 +0100
@@ -32,7 +32,7 @@
#define HCI_LOG_ON 0
-#define HCI_READ_PACKET_NUM_MAX (5)
+#define HCI_READ_PACKET_NUM_MAX (15)
#define MIN(a,b) ((a) < (b) )? (a) : (b)
#define MAX(a,b) ((a) > (b) )? (a) : (b)
@@ -156,6 +156,9 @@
}
else{
// HCI Read Packet Pool is empty, wait for a free packet.
+#ifdef AST_FOR_MBED_OS
+ Call_BTLE_Handler();
+#endif
readPacketListFull = TRUE;
Clear_SPI_EXTI_Flag();
return;
