cancel
Showing results for 
Search instead for 
Did you mean: 

Work with UCOS III

JJ.Lin
Associate III

Has anyone port touchgfx to work with UCOSIII?

1 ACCEPTED SOLUTION

Accepted Solutions
JJ.Lin
Associate III
#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.

View solution in original post

3 REPLIES 3
Alexandre RENOUX
Principal

Hello JJ.Lin,

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

Hope someone will be able to.

/Alexandre

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
Associate III
#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.