14.2.2.4 FreeRTOS in Zigbee applications
Refer FreeRTOS https://www.freertos.org/ for more details w.r.t Queues, Semaphores APIs and usage.
RTOS Tasks
There are two tasks created in the RTOS, Application task (APP_Tasks) and Zigbee task(ZGB) during system initialization. The Zigbee task is to gain the CPU time to execute stack related activities, whereas APP_Tasks is for application related tasks. Zigbee task is given higher priority over the application. The interaction between these two tasks happens via IPC (e.g. Queue,semaphore) mechanism. Every request/indications from the application and stack to each other are posted in two different queues. Zigbee task is also designed to wait on the Semaphores which are posted on certain internal stack events and RF reception etc,. These tasks are designed to wait and service as shown in the picture below.
Zigbee Task with RTOS
Zigbee task is meant to service two categories of requests. The requests coming from stack and the request coming from the application. A stack request for an instance, can be considered as an interrupt on receiving a new RF packet. App request can be an API call to initiate BDB commissioning or to get short address of the device. When stack receives a packet, an interrupt occurs and a semaphore is posted. API call from application is posted through appQueue to Zigbee task. When Zigbee task is scheduled for execution it is designed in such a way to service the semaphore from stack events first and then the requests from application. Refer the below flow diagram for Zigbee task.