3.4 FreeRTOS in Zigbee Applications

For more details on queues, semaphore APIs and their usage, go to FreeRTOS.

RTOS Tasks

There are two tasks created in the RTOS during system initialization:
  • Application Task (APP_Tasks) – This task handles functions specific to the application. It operates under a lower priority than the Zigbee task to allow for the execution of stack operations in a timely manner.
  • Zigbee Task (ZGB) – This task receives allocation of CPU time to execute activities related to the stack. It holds a higher priority over the application task to ensure the stack operations process promptly.
Inter-Process Communication (IPC) mechanisms, such as queues and semaphores, facilitate the interaction between the application and Zigbee tasks. The system manages requests and indications from both the application and the stack using two separate queues, which maintains organized communication.

In addition, the system configures the Zigbee task to wait for semaphores that specific internal stack events and RF receptions trigger, among other scenarios. This configuration enables the tasks to wait efficiently and react to events (see Figure 3-1).

Figure 3-1. RTOS Management of Zigbee and Application Tasks

Zigbee Task with RTOS

The Zigbee task services two categories of requests:
  • Requests from the stack – Can consider a stack request as an interrupt on receiving a new RF packet.
  • Requests from the application – An application request can involve an API call to start BDB commissioning or to retrieve the device’s short address.

After receiving a packet, the stack generates an interrupt and posts a semaphore. On the other hand, the application submits its API calls to the appQueue, which the Zigbee task, then, processes. When scheduled for execution, the Zigbee task prioritizes servicing the semaphore from stack events before addressing requests from the application. The following figure illustrates the flow diagram for the operation of the Zigbee task.

Figure 3-2. Zigbee Task Request Handling Flow Chart