feat(os): add rt-thread for osal (#4746)

This commit is contained in:
lhdjply 2023-11-03 17:54:11 +08:00 committed by GitHub
parent e86b1a6ec9
commit b95d74bfcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 244 additions and 0 deletions

View File

@ -179,6 +179,7 @@ menu "LVGL configuration"
1:LV_OS_PTHREAD
2:LV_OS_FREERTOS
3:LV_OS_CMSIS_RTOS2
4:LV_OS_RTTHREAD
255:LV_OS_CUSTOM
config LV_USE_DRAW_SW

View File

@ -134,6 +134,7 @@
* - LV_OS_PTHREAD
* - LV_OS_FREERTOS
* - LV_OS_CMSIS_RTOS2
* - LV_OS_RTTHREAD
* - LV_OS_CUSTOM */
#define LV_USE_OS LV_OS_NONE

View File

@ -332,6 +332,7 @@
* - LV_OS_PTHREAD
* - LV_OS_FREERTOS
* - LV_OS_CMSIS_RTOS2
* - LV_OS_RTTHREAD
* - LV_OS_CUSTOM */
#ifndef LV_USE_OS
#ifdef CONFIG_LV_USE_OS

View File

@ -36,6 +36,7 @@ extern "C" {
#define LV_OS_PTHREAD 1
#define LV_OS_FREERTOS 2
#define LV_OS_CMSIS_RTOS2 3
#define LV_OS_RTTHREAD 4
#define LV_OS_CUSTOM 255
#define LV_STDLIB_BUILTIN 0

View File

@ -30,6 +30,8 @@ extern "C" {
#include "lv_freertos.h"
#elif LV_USE_OS == LV_OS_CMSIS_RTOS2
#include "lv_cmsis_rtos2.h"
#elif LV_USE_OS == LV_OS_RTTHREAD
#include "lv_rtthread.h"
#elif LV_USE_OS == LV_OS_CUSTOM
#include LV_OS_CUSTOM_INCLUDE
#endif

184
src/osal/lv_rtthread.c Normal file
View File

@ -0,0 +1,184 @@
/**
* @file lv_rtthread.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_os.h"
#if LV_USE_OS == LV_OS_RTTHREAD
#include "../misc/lv_log.h"
/*********************
* DEFINES
*********************/
#define THREAD_TIMESLICE 20U
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_result_t lv_thread_init(lv_thread_t * thread, lv_thread_prio_t prio, void (*callback)(void *), size_t stack_size,
void * user_data)
{
thread->thread = rt_thread_create("thread",
callback,
user_data,
stack_size,
prio,
THREAD_TIMESLICE);
rt_err_t ret = rt_thread_startup(thread->thread);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_delete(lv_thread_t * thread)
{
rt_err_t ret = rt_thread_delete(thread->thread);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_init(lv_mutex_t * mutex)
{
mutex->mutex = rt_mutex_create("mutex", RT_IPC_FLAG_PRIO);
if(mutex->mutex == RT_NULL) {
LV_LOG_WARN("create mutex failed");
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_lock(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_take(mutex->mutex, RT_WAITING_NO);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_lock_isr(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_take(mutex->mutex, RT_WAITING_FOREVER);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_unlock(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_release(mutex->mutex);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_mutex_delete(lv_mutex_t * mutex)
{
rt_err_t ret = rt_mutex_delete(mutex->mutex);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_init(lv_thread_sync_t * sync)
{
sync->sem = rt_sem_create("sem", RT_IPC_FLAG_PRIO);
if(sync->sem == RT_NULL) {
LV_LOG_WARN("create semaphore failed");
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_wait(lv_thread_sync_t * sync)
{
rt_err_t ret = rt_sem_take(sync->sem, RT_WAITING_FOREVER);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_signal(lv_thread_sync_t * sync)
{
rt_err_t ret = rt_sem_release(sync->sem);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
lv_result_t lv_thread_sync_delete(lv_thread_sync_t * sync)
{
rt_err_t ret = rt_sem_delete(sync->sem);
if(ret) {
LV_LOG_WARN("Error: %d", ret);
return LV_RESULT_INVALID;
}
else {
return LV_RESULT_OK;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /*LV_USE_OS == LV_OS_RTTHREAD*/

54
src/osal/lv_rtthread.h Normal file
View File

@ -0,0 +1,54 @@
/**
* @file lv_rtthread.h
*
*/
#ifndef LV_RTTHREAD_H
#define LV_RTTHREAD_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if LV_USE_OS == LV_OS_RTTHREAD
#include <rtthread.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
rt_thread thread;
} lv_thread_t;
typedef struct {
rt_mutex_t mutex;
} lv_mutex_t;
typedef struct {
rt_sem_t sem;
} lv_thread_sync_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#endif /*LV_USE_OS == LV_OS_RTTHREAD*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_RTTHREAD_H*/