Other Parts Discussed in Thread: CC2541
I've been developing on the CC2541 creating a platform that serves primarily as a BLE advertising receiver (looking for "beacons"). I recently decided to try to more accurately cover a fringe case I had previously been fudging where a new scan request can arrive while a scan is still in progress. Previously I had just checked a 'scanInProgress' boolean flag and ignored the request if a scan was currently in progress. In the new code I attempt to abort the current scan and start a new one by issuing a "GAPCentralRole_CancelDiscovery()" command, retrieving the current partial scan results, followed by a "GAPCentralRole_StartDiscovery(DEVDISC_MODE_ALL,FALSE,FALSE)" to start the new scan. One additional potentially important thing to note is the discovery that is interrupting can have a different scan duration than the original discovery. I set this using "GAP_SetParamValue( TGAP_GEN_DISC_SCAN, newDuration )" before canceling the current discovery so it is set for the new scan.
Recording the system clock as the code starts and stops scans everything seems to work as intended; however, during one of the early tests the Bluetooth stack appeared to crash and stop detecting advertisers. The microcontroller was still operational by any other measure and responding to serial commands, it was just unable to detect any of the local advertisers over Bluetooth until I power cycled, after which normal operation resumed. I have been unable to recreate this condition which is troubling, but it hadn't occurred before implementing the discovery interrupt stuff so I suspect the two might be related.
Is there some mandatory delay between canceling and starting a new discovery? Is there any way to poll the stack to determine when the previous discovery has actually been terminated? I tried setting a boolean status flag in the GAP_DISCOVERY_EVENT, but it doesn't look like this event is fired is a discovery is terminated by "GAPCentralRole_CancelDiscovery()". Is there some other known issue that could cause the Bluetooth stack to stop working that I should be looking for?
Thanks,
Jeremy