Implement an OSAL (Operating System Abstraction Layer)?

Hi,

At the moment the NXP GPU code have the only references to FreeRTOS code:

#if defined(FSL_RTOS_FREE_RTOS)
    static SemaphoreHandle_t s_pxpIdle;
#else
    static volatile bool s_pxpIdle;
#endif
static void _lv_gpu_nxp_pxp_run(void)
{
#if !defined(FSL_RTOS_FREE_RTOS)
    s_pxpIdle = false;
#endif

    PXP_EnableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
    PXP_Start(LV_GPU_NXP_PXP_ID);

#if defined(FSL_RTOS_FREE_RTOS)
    if(xSemaphoreTake(s_pxpIdle, portMAX_DELAY) != pdTRUE) {
        LV_LOG_ERROR("xSemaphoreTake error. Task halted.");
        for(; ;) ;
    }
#else
    while(s_pxpIdle == false) {
    }
#endif
}

Do you think is it possible to create an OSAL layer so there’s no RTOS specific code in the LVGL source code?

For reference the TinyUSB project have a pretty nice OSAL layer.

What do you think?

Hi,

I think developing an OSAL is possible. The next logical question is: can we make LVGL threadsafe by default? Do you think it’d be also important?

Making LVGL thread-safe would be nice, but I think it would introduce a lot of extra lock/unlock calls in functions. There is also the opportunity for a rare bug as soon as we forget a single lock somewhere.

There is then the question of whether to require recursive mutexes. If not, that adds another layer of complexity, since we now need to keep track of how many times a mutex has been locked.

Personally I feel like the single-threaded model suits our target platforms better, and it should be left to the user to lock/unlock a mutex as necessary. It’s significantly cleaner and less error-prone, in my experience.

1 Like

Maybe the first baby step would be to have something like lv_osal_semaphore_take instead of the FreeRTOS specific xSemaphoreTake.

I agree with @embeddedt.

I’d wait with OSAL until there is a larger need for it (needed by more modules).
Or @Carlos_Diaz, can you mention other modules that can already profit from the OSAL?