SWRU271I October 2010 – January 2020 CC2540 , CC2540T , CC2541 , CC2541-Q1 , CC2640R2F
After the OSAL initializes, it runs in an infinite loop checking for task events. You can find this loop in the osal_start_system() function in the OSAL.c file. Task events are stored as unique bits in a 16-bit variable where each bit corresponds to a unique event. The application determines the definition and use of these event flags. Figure 3-1 shows a flow diagram of the OSAL processing scheme.
If the SimpleBLEPeripheral application defines a flag in simpleBLEPeripheral.h: SBP_START_DEVICE_EVT (0x0001) indicating the initial device start is complete, the application processing begins. The application cannot define one reserved flag value (0x8000). This value corresponds to the event SYS_EVENT_MSG for messaging between tasks. For more information, see Section 3.5.
When the OSAL detects an event set for a task, it calls the event processing routine of that task to process the event. The task layer must add its own event processing routine to the table formed by the array of function pointers called tasksArr (defined in OSAL_SimpleBLEPeripheral.c for the SimpleBLEPeripheral example project). The order of the event processing routines in tasksArr is the same as the order of task IDs in the osalInitTasks() function. Maintaining this task order is required for the correct software layer to process events.
In the SimpleBLEPeripheral application, the event processing function is called SimpleBLEPeripheral_ProcessEvent() to handle all active events associated with the task. After processing, the events must be cleared to prevent duplicate processing of the same event. The SimpleBLEPeripheral_ProcessEvent() application function shows that after the START_DEVICE_EVT event occurs it returns the 16-bit events variable with the SBP_START_DEVICE_EVT flag cleared.
Any layer of the software can set an OSAL event for any layer. Use the osal_set_event() function (prototype in OSAL.h) to immediately schedule a new OSAL event. With this function, you specify the task ID (of the task that will process the event) and the event flag as parameters.
An alternate method to set an OSAL event for any layer is to use the osal_start_timerEx() function (prototype in OSAL_Timers.h). This function operates similarly to the osal_set_event() function. You select the task ID of the task that will process the event and the event flag as parameters. The osal_start_timerEx() function has a third parameter that you must use to input a time-out value in milliseconds. This timeout parameter causes the OSAL to set a timer and set the specified event when the timer expires.