Tool/software: TI-RTOS
Hi,
I'm developing a custom application based on the Simple Peripheral example provided in "simplelink_cc2640r2_sdk_1_50_00_58" and I have a requirement that when pairing has successfully completed, a characteristic value is updated. If the client performs a read request immediately after successful pairing I'm finding that approximately 30% of the time the value is not being updated. Using breakpoints in the pair callback and the read attribute callback I'm observing what seems to be a race condition between the two callbacks, and on the occasions where it would fail the read attribute callback is being called before the pair callback even though my sniffer is showing that pairing occurs before any read request. If I add a 5ms delay between the successful completion of pairing and the read request I can't reproduce the issue.
Due to the confidential nature of the project I am unable to share code or sniffer logs so I tried it with the simple peripheral project with one modification: that when pairing succeeds the SIMPLEPROFILE_CHAR2 characteristic value is incremented and I'm seeing exactly the same issue.
I attach the modified simple peripheral project and a sniffer log showing the following steps repeated 7 times:
- Connect
- Read the SIMPLEPROFILE_CHAR2 characteristic
- Pair
- Read the SIMPLEPROFILE_CHAR2 characteristic
- Disconnect
We see that the first two attempts show the value is unchanged between the two reads. The third attempt behaves as expected, as does the 7th but those in between do not. What's interesting about the failing cases is that by the time we connect the next time and perform the read request the value has indeed incremented.
Are there some constraints on the timing of pairing requests and read requests or indeed any other Bluetooth operations? Am I missing something?
https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/538/RaceCondition.7z