Skip to main content
JJ.Lin
Associate III
June 23, 2021
Solved

Work with UCOS III

Has anyone port touchgfx to work with UCOSIII?

This topic has been closed for replies.
JJ.Lin
JJ.LinBest answer
Associate III
June 29, 2021
#include <cassert>
#include <touchgfx/hal/HAL.hpp>
#include <touchgfx/hal/OSWrappers.hpp>
 
#include "os.h"
 
static OS_SEM frame_buffer_sem;
CPU_CHAR frame_buffer_sem_str[20] = "frame_buffer_sem";
CPU_CHAR vsync_queue_str[20] = "vsync_queue";
OS_Q vsync_queue;
static uint32_t dummy = 0x5a;
 
using namespace touchgfx;
 
void OSWrappers::initialize()
{
 OS_ERR err;
 OSSemCreate(&frame_buffer_sem, frame_buffer_sem_str, 0u, &err);
 OSQCreate(&vsync_queue, vsync_queue_str, 1, &err);
}
void OSWrappers::takeFrameBufferSemaphore()
{
 OS_ERR err;
 CPU_TS ts;
 
 (void)OSSemPend(&frame_buffer_sem, 0u, OS_OPT_PEND_BLOCKING, &ts, &err);
}
void OSWrappers::giveFrameBufferSemaphore()
{
 OS_ERR err;
 
 OSSemPost(&frame_buffer_sem, OS_OPT_POST_1, &err);
}
void OSWrappers::tryTakeFrameBufferSemaphore()
{
 OS_ERR err;
 CPU_TS ts;
 
 (void)OSSemPend(&frame_buffer_sem, 0u, OS_OPT_PEND_NON_BLOCKING, &ts, &err);
}
void OSWrappers::giveFrameBufferSemaphoreFromISR()
{
 OS_ERR err;
 
 OSSemPost(&frame_buffer_sem, OS_OPT_POST_NO_SCHED, &err);
}
void OSWrappers::signalVSync()
{
 OS_ERR err;
 
 OSQPost(&vsync_queue, &dummy, sizeof(uint32_t), OS_OPT_POST_FIFO, &err);
}
void OSWrappers::signalRenderingDone()
{
 
}
void OSWrappers::waitForVSync()
{
 OS_ERR err;
 CPU_TS ts;
 OS_MSG_SIZE msg_size;
 
 OSQPend(&vsync_queue, 0, OS_OPT_PEND_NON_BLOCKING, &msg_size, &ts, &err);
 OSQPend(&vsync_queue, 0, OS_OPT_PEND_BLOCKING, &msg_size, &ts, &err);
}
void OSWrappers::taskDelay(uint16_t ms)
{
 OS_ERR err;
 
 OSTimeDly(ms, OS_OPT_TIME_DLY, &err);
}

Now it works well, you can rell me if you find any fault.

3 replies

Alexandre RENOUX
Visitor II
June 29, 2021

Hello JJ.Lin,

We've never worked with UCOSIII so unfortunately I cannot help you.

Hope someone will be able to.

/Alexandre

JJ.Lin
JJ.LinAuthor
Associate III
June 29, 2021

Thank you for your reply, I have done the porting by simply changing the function realization of freeRTOS with uCOS in OSWappers.cpp.

JJ.Lin
JJ.LinAuthorBest answer
Associate III
June 29, 2021
#include <cassert>
#include <touchgfx/hal/HAL.hpp>
#include <touchgfx/hal/OSWrappers.hpp>
 
#include "os.h"
 
static OS_SEM frame_buffer_sem;
CPU_CHAR frame_buffer_sem_str[20] = "frame_buffer_sem";
CPU_CHAR vsync_queue_str[20] = "vsync_queue";
OS_Q vsync_queue;
static uint32_t dummy = 0x5a;
 
using namespace touchgfx;
 
void OSWrappers::initialize()
{
 OS_ERR err;
 OSSemCreate(&frame_buffer_sem, frame_buffer_sem_str, 0u, &err);
 OSQCreate(&vsync_queue, vsync_queue_str, 1, &err);
}
void OSWrappers::takeFrameBufferSemaphore()
{
 OS_ERR err;
 CPU_TS ts;
 
 (void)OSSemPend(&frame_buffer_sem, 0u, OS_OPT_PEND_BLOCKING, &ts, &err);
}
void OSWrappers::giveFrameBufferSemaphore()
{
 OS_ERR err;
 
 OSSemPost(&frame_buffer_sem, OS_OPT_POST_1, &err);
}
void OSWrappers::tryTakeFrameBufferSemaphore()
{
 OS_ERR err;
 CPU_TS ts;
 
 (void)OSSemPend(&frame_buffer_sem, 0u, OS_OPT_PEND_NON_BLOCKING, &ts, &err);
}
void OSWrappers::giveFrameBufferSemaphoreFromISR()
{
 OS_ERR err;
 
 OSSemPost(&frame_buffer_sem, OS_OPT_POST_NO_SCHED, &err);
}
void OSWrappers::signalVSync()
{
 OS_ERR err;
 
 OSQPost(&vsync_queue, &dummy, sizeof(uint32_t), OS_OPT_POST_FIFO, &err);
}
void OSWrappers::signalRenderingDone()
{
 
}
void OSWrappers::waitForVSync()
{
 OS_ERR err;
 CPU_TS ts;
 OS_MSG_SIZE msg_size;
 
 OSQPend(&vsync_queue, 0, OS_OPT_PEND_NON_BLOCKING, &msg_size, &ts, &err);
 OSQPend(&vsync_queue, 0, OS_OPT_PEND_BLOCKING, &msg_size, &ts, &err);
}
void OSWrappers::taskDelay(uint16_t ms)
{
 OS_ERR err;
 
 OSTimeDly(ms, OS_OPT_TIME_DLY, &err);
}

Now it works well, you can rell me if you find any fault.