MPLAB® Harmony Graphics Suite > Advanced Topics > Enabling RTOS with Aria Graphics
MPLAB® Harmony Graphics Suite
Enabling RTOS with Aria Graphics

In an RTOS-based system, the Aria Graphics Library can be configured to run as a stand-alone task that blocks and waits for external events from the input/touch task or the application task. This offers a couple of advantages: (1) this allows the Aria Graphics library to run efficiently by relinquishing CPU time to other tasks when the UI is idle, (2) the Aria Graphics library can be run as a high priority task and be more responsive to user input since it can preempt lower priority tasks. 

To create a Harmony Graphics project with RTOS, the initial configuration is similar to a bare-metal Graphics project. The following Harmony components must be added to the project: 

1. Display 

2. Display controller interface peripheral and driver 

3. Touch interface peripheral and driver 

4. GFX Core (Hardware Abstraction Layer) 

5. Input System Service 

6. Harmony Core 

7. Aria Graphics Library 

The project graph for this initial (bare-metal) configuration would look something like the one below: 

 

 

 

To add RTOS, the FreeRTOS component from Third Party Libraries -> RTOS -> FreeRTOS needs to be added to the project. 

 

 

 

After the FreeRTOS component is added to the Project, “RTOS settings” will be available in the Aria Graphics Library Configuration Options. By default, the “Use RTOS Extensions” setting is enabled. This configures the Aria task to run as a stand-alone, blocking task. To make the UI more responsive, the Aria Task Priority can be manually increased to 2. 

 

 

 

These files contain the RTOS extensions: 

 

RTOS extension files 
Description 
libaria_rtos.c/h 
RTOS extension to libaria.c/h. Contains RTOS version of the laUpdate() function. 
libaria_context_rtos.c/h 
RTOS extension to libaria_context.c/h. Contains the RTOS version of the laContext_Update() function. It also contains APIs that must be used to send events to the library to refresh the UI or change the screen. 
libaria_event_rtos.c/h 
RTOS extension to libaria_event.c/h. Contains thread-safe APIs and routines for sending and processing Aria Graphics events. 
libaria_input_rtos.c/h 
RTOS extension to libaria_input.c/h. Contains thread-safe callbacks for sending touch events to the graphics library. 

 

The RTOS extensions provides APIs that need to be called from external tasks (e.g., application code) to interface with the Aria Graphics library in a thread-safe way. These functions have _Ext_RTOS() suffix, which means they can be safely called by other tasks. 

 

RTOS Extension APIs 
Description 
laEvent_SendEvent_Ext_RTOS() 
API to use to send events to graphics library. 
Wrapper for laEvent_SendEvent_Ext_RTOS()to send an event to change the active screen. 
Wrapper for laEvent_SendEvent_Ext_RTOS()to send an event to the graphics library to repaint the frame. This needs to be called after widget properties are changed, so that the widget is updated and repainted. 
laInput_SendTouchDown_Ext_RTOS() 
Wrapper for laEvent_SendEvent_Ext_RTOS()to send a touch down event to the graphics library. This typically registered as a callback to the System Input Service and called when a touch down event is detected. 
laInput_SendTouchUp_Ext_RTOS() 
Wrapper for laEvent_SendEvent_Ext_RTOS()to send a touch up event to the graphics library. This typically registered as a callback to the System Input Service and called when a touch down event is detected. 
laInput_SendTouchMoved_Ext_RTOS() 
Wrapper for laEvent_SendEvent_Ext_RTOS()to send a touch moved event to the graphics library. This typically registered as a callback to the System Input Service and called when a touch down event is detected. 

 

Here’s a diagram of how the Aria Graphics library runs in an RTOS environment with the Input System Service and Application as source of events: 

 

 

 

After initialization, the Aria Task calls laUpdate_RTOS(). In this function, it will block to wait for events. 

For a touch event, the Input System Service task calls the laInput_SendTouchDown_Ext_RTOS() callback function to send an LA_EVENT_TOUCH_DOWN event to the Aria Task. This will unblock the Aria Task to start processing events. The Aria Task will call laEvent_ProcessEvents_RTOS() to process the touch event, call laContext_Update() to update and mark widgets that need to be repainted, and calls laContext_Paint() to repaint the layers. The Aria Task repeats this process while there are pending events that needs to be process. The Aria task blocks again when all events are handled. 

If the application updates a widget, say to move its position using laWidget_Translate(), it needs to call laContext_RefreshActiveScreen_Ext_RTOS() that sends a dummy event to unblock the Aria Task so it can process the event and update the widget and screen. The Aria Task repeats this process while there are events in its events list or while the counting semaphore has a non-zero value. The Aria task blocks again when the counting semaphore is back to zero.

MPLAB® Harmony Graphics Suite