Other Parts Discussed in Thread: CC2640
Hey TI CC26xx team and fellow community members, I'm reading up on the CC2640 & TI-RTOS and have a question that's been stumping me and a coworker:
Is TI's recommended use of the TI-RTOS Queue for handling application messages thread safe? Specifically when messages are being pushed to the queue by a mix of HWI, SWI, and task contexts. The example projects' implementations using Util_enqueueMsg and Util_dequeueMsg uses non-atomic APIs of the TI-RTOS's Queue module.
The CC2640 Software Developer's Guide and published examples recommend we use a TI/RTOS Queue for application messages. (Section 4.3.3 Callbacks") The recommended architecture uses the Queue in a multiple-writer/single-reader model, where callbacks running in a variety of contexts can push events to the queue. The main Application tasks is the sole receiver of messages, popping them from the queue. The software examples shipped with the stack, including SimpleBLEPeripheral and glucose_sensor, use this recommended model and leverage two queue wrapper functions called Util_enqueueMsg and Util_dequeueMsg.
In SimpleBLEPeripheral, the SimpleBLEPeripheral_enqueueMsg function calls "Util_enqueueMsg" and the taskFxn calls "Util_dequeueMsg". Both of these Util functions use the non-atomic versions of the TI-RTOS Queue API. (Queue_enqueue and Queue_dequeue)
The "glucose_sensor" example also uses "Util_enqueueMsg" to enqueue events in callbacks both from key presses (debounce Clock callback SWI from board_key.c) and also other callbacks from the GAP Peripheral Role task. In the case of this glucose project, couldn't there be task-unsafe conflict where the "GlucoseSensor_stateChangeCB" is in the middle of using the non-atomic Util_enqueueMsg, when it's preempted by the "GlucoseSensor_keyPressHandler" callback which also will use Util_enqueueMsg?
Robert Tivy (3168) mentions here, that to use the TI-RTOS Queue in a multiple-writer/single-reader model, the atomic APIs must be used (Queue_get and Queue_put) : e2e.ti.com/.../1766272
If this is the case, I could modify the Util.c file to use the atomic APIs, but the CC2640 SDG contains the note shown in the image above: "No blocking RTOS function calls or protocol stack APIs should be performed in a callback function"
Any help/feedback here would be appreciated. Are the example projects somehow using the Queue in a thread-safe way that we're overlooking?
@svendbt, do you have any thoughts on this? You mention the atomic version of the Queue APIs here: e2e.ti.com/.../1675218
