mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
Add ZeusOS adaptation code
This commit is contained in:
parent
0d4f91efa7
commit
859d3443f7
@ -197,6 +197,8 @@ PIKA_WEAK void pika_platform_sleep_ms(uint32_t ms) {
|
|||||||
Sleep(ms);
|
Sleep(ms);
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
rt_thread_mdelay(ms);
|
rt_thread_mdelay(ms);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
zos_task_msleep(ms);
|
||||||
#elif PIKA_FREERTOS_ENABLE
|
#elif PIKA_FREERTOS_ENABLE
|
||||||
vTaskDelay(ms / portTICK_PERIOD_MS);
|
vTaskDelay(ms / portTICK_PERIOD_MS);
|
||||||
#else
|
#else
|
||||||
@ -223,6 +225,9 @@ PIKA_WEAK int64_t pika_platform_get_tick(void) {
|
|||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
uint32_t tick = rt_tick_get() * 1000;
|
uint32_t tick = rt_tick_get() * 1000;
|
||||||
return (uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
return (uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
uint32_t tick = zos_tick_get() * 1000;
|
||||||
|
return (uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||||
#elif defined(_WIN32) && !defined(CROSS_BUILD)
|
#elif defined(_WIN32) && !defined(CROSS_BUILD)
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
ULARGE_INTEGER ull;
|
ULARGE_INTEGER ull;
|
||||||
@ -611,6 +616,8 @@ PIKA_WEAK void pika_platform_thread_yield(void) {
|
|||||||
return;
|
return;
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
rt_thread_yield();
|
rt_thread_yield();
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
zos_task_yield();
|
||||||
#else
|
#else
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
@ -689,6 +696,22 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init(
|
|||||||
} else {
|
} else {
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
pika_platform_thread_t* thread;
|
||||||
|
static int thread_count = 0;
|
||||||
|
char task_name[ZOS_NAME_MAX+1] = {0};
|
||||||
|
zos_sprintf(task_name, "%s%d", name,thread_count++);
|
||||||
|
thread = pikaMalloc(sizeof(pika_platform_thread_t));
|
||||||
|
if(ZOS_NULL == thread) {
|
||||||
|
return ZOS_NULL;
|
||||||
|
}
|
||||||
|
thread->thread = zos_task_create(task_name,entry,param,stack_size,priority);
|
||||||
|
if (thread->thread == ZOS_NULL) {
|
||||||
|
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||||
|
return ZOS_NULL;
|
||||||
|
} else {
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -704,6 +727,8 @@ PIKA_WEAK uint64_t pika_platform_thread_self(void) {
|
|||||||
return (uint64_t)xTaskGetCurrentTaskHandle();
|
return (uint64_t)xTaskGetCurrentTaskHandle();
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
return (uint64_t)(uintptr_t)rt_thread_self();
|
return (uint64_t)(uintptr_t)rt_thread_self();
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
return (uint64_t)zos_task_self();
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return 0;
|
return 0;
|
||||||
@ -714,6 +739,8 @@ PIKA_WEAK void pika_platform_thread_startup(pika_platform_thread_t* thread) {
|
|||||||
(void)thread;
|
(void)thread;
|
||||||
#if PIKA_RTTHREAD_ENABLE
|
#if PIKA_RTTHREAD_ENABLE
|
||||||
rt_thread_startup(thread->thread);
|
rt_thread_startup(thread->thread);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
zos_task_startup(thread->thread);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,6 +753,8 @@ PIKA_WEAK void pika_platform_thread_stop(pika_platform_thread_t* thread) {
|
|||||||
vTaskSuspend(thread->thread);
|
vTaskSuspend(thread->thread);
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
rt_thread_suspend(thread->thread);
|
rt_thread_suspend(thread->thread);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
zos_task_suspend(thread->thread);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
#endif
|
#endif
|
||||||
@ -740,6 +769,8 @@ PIKA_WEAK void pika_platform_thread_start(pika_platform_thread_t* thread) {
|
|||||||
vTaskResume(thread->thread);
|
vTaskResume(thread->thread);
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
rt_thread_resume(thread->thread);
|
rt_thread_resume(thread->thread);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
zos_task_resume(thread->thread);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
#endif
|
#endif
|
||||||
@ -766,6 +797,12 @@ PIKA_WEAK void pika_platform_thread_destroy(pika_platform_thread_t* thread) {
|
|||||||
pikaFree(thread, sizeof(pika_platform_thread_t));
|
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
if (NULL != thread) {
|
||||||
|
zos_task_destroy(thread->thread);
|
||||||
|
pikaFree(thread, sizeof(pika_platform_thread_t));
|
||||||
|
return;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
#endif
|
#endif
|
||||||
@ -789,6 +826,13 @@ PIKA_WEAK void pika_platform_thread_exit(pika_platform_thread_t* thread) {
|
|||||||
}
|
}
|
||||||
rt_thread_delete(thread->thread);
|
rt_thread_delete(thread->thread);
|
||||||
return;
|
return;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
if (NULL == thread) {
|
||||||
|
zos_task_exit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
zos_task_destroy(thread->thread);
|
||||||
|
return;
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
#endif
|
#endif
|
||||||
@ -803,6 +847,9 @@ PIKA_WEAK int pika_platform_thread_mutex_init(pika_platform_thread_mutex_t* m) {
|
|||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
m->mutex = rt_mutex_create("pika_platform_mutex", RT_IPC_FLAG_PRIO);
|
m->mutex = rt_mutex_create("pika_platform_mutex", RT_IPC_FLAG_PRIO);
|
||||||
return 0;
|
return 0;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
m->mutex = zos_mutex_create("pika_platform_mutex",ZOS_FALSE);
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return -1;
|
return -1;
|
||||||
@ -819,6 +866,8 @@ PIKA_WEAK int pika_platform_thread_mutex_lock(pika_platform_thread_mutex_t* m) {
|
|||||||
return -1;
|
return -1;
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
return rt_mutex_take((m->mutex), RT_WAITING_FOREVER);
|
return rt_mutex_take((m->mutex), RT_WAITING_FOREVER);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
return zos_mutex_lock(m->mutex,ZOS_WAIT_FOREVER);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return -1;
|
return -1;
|
||||||
@ -836,6 +885,8 @@ PIKA_WEAK int pika_platform_thread_mutex_trylock(
|
|||||||
return -1;
|
return -1;
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
return rt_mutex_take((m->mutex), 0);
|
return rt_mutex_take((m->mutex), 0);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
return zos_mutex_lock(m->mutex,0);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return -1;
|
return -1;
|
||||||
@ -850,6 +901,8 @@ PIKA_WEAK int pika_platform_thread_mutex_unlock(
|
|||||||
return xSemaphoreGive(m->mutex);
|
return xSemaphoreGive(m->mutex);
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
return rt_mutex_release((m->mutex));
|
return rt_mutex_release((m->mutex));
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
return zos_mutex_unlock(m->mutex);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return -1;
|
return -1;
|
||||||
@ -865,6 +918,8 @@ PIKA_WEAK int pika_platform_thread_mutex_destroy(
|
|||||||
return 0;
|
return 0;
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
return rt_mutex_delete((m->mutex));
|
return rt_mutex_delete((m->mutex));
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
return zos_mutex_destroy(m->mutex);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return -1;
|
return -1;
|
||||||
@ -937,6 +992,8 @@ PIKA_WEAK void pika_platform_thread_timer_init(pika_platform_timer_t* timer) {
|
|||||||
timer->time = 0;
|
timer->time = 0;
|
||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
timer->time = 0;
|
timer->time = 0;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
timer->time = 0;
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
#endif
|
#endif
|
||||||
@ -963,6 +1020,11 @@ PIKA_WEAK void pika_platform_thread_timer_cutdown(pika_platform_timer_t* timer,
|
|||||||
timer->time =
|
timer->time =
|
||||||
(uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
(uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
||||||
timer->time += timeout;
|
timer->time += timeout;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
zos_uint32_t tick = zos_tick_get() * 1000;
|
||||||
|
timer->time =
|
||||||
|
(uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||||
|
timer->time += timeout;
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
#endif
|
#endif
|
||||||
@ -988,6 +1050,11 @@ PIKA_WEAK char pika_platform_thread_timer_is_expired(
|
|||||||
uint32_t time =
|
uint32_t time =
|
||||||
(uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
(uint32_t)((tick + RT_TICK_PER_SECOND - 1) / RT_TICK_PER_SECOND);
|
||||||
return time > timer->time ? 1 : 0;
|
return time > timer->time ? 1 : 0;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
uint32_t tick = zos_tick_get() * 1000;
|
||||||
|
uint32_t time =
|
||||||
|
(uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||||
|
return time > timer->time ? 1 : 0;
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return 1;
|
return 1;
|
||||||
@ -1021,6 +1088,14 @@ PIKA_WEAK int pika_platform_thread_timer_remain(pika_platform_timer_t* timer) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return timer->time - now;
|
return timer->time - now;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
uint32_t now;
|
||||||
|
uint32_t tick = zos_tick_get() * 1000;
|
||||||
|
now = (uint32_t)((tick + ZOS_TICK_PER_SECOND - 1) / ZOS_TICK_PER_SECOND);
|
||||||
|
if (timer->time <= now) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return timer->time - now;
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return -1;
|
return -1;
|
||||||
@ -1036,6 +1111,10 @@ PIKA_WEAK unsigned long pika_platform_thread_timer_now(void) {
|
|||||||
uint32_t tick = rt_tick_get() * 1000;
|
uint32_t tick = rt_tick_get() * 1000;
|
||||||
return (unsigned long)((tick + RT_TICK_PER_SECOND - 1) /
|
return (unsigned long)((tick + RT_TICK_PER_SECOND - 1) /
|
||||||
RT_TICK_PER_SECOND);
|
RT_TICK_PER_SECOND);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
uint32_t tick = zos_tick_get() * 1000;
|
||||||
|
return (unsigned long)((tick + ZOS_TICK_PER_SECOND - 1) /
|
||||||
|
ZOS_TICK_PER_SECOND);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
return 1;
|
return 1;
|
||||||
@ -1063,6 +1142,15 @@ PIKA_WEAK void pika_platform_thread_timer_usleep(unsigned long usec) {
|
|||||||
tick = 1;
|
tick = 1;
|
||||||
}
|
}
|
||||||
rt_thread_mdelay(tick);
|
rt_thread_mdelay(tick);
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
zos_tick_t tick = 1;
|
||||||
|
if (usec != 0) {
|
||||||
|
tick = usec / ZOS_TICK_PER_SECOND;
|
||||||
|
|
||||||
|
if (tick == 0)
|
||||||
|
tick = 1;
|
||||||
|
}
|
||||||
|
zos_task_tsleep(tick);
|
||||||
#else
|
#else
|
||||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_);
|
||||||
#endif
|
#endif
|
||||||
|
@ -116,6 +116,9 @@ extern "C" {
|
|||||||
#if defined(__RTTHREAD__) && PIKA_RTTHREAD_ENABLE
|
#if defined(__RTTHREAD__) && PIKA_RTTHREAD_ENABLE
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#define pika_platform_printf(...) rt_kprintf(__VA_ARGS__)
|
#define pika_platform_printf(...) rt_kprintf(__VA_ARGS__)
|
||||||
|
#elif defined(__ZeusOS__) && PIKA_ZeusOS_ENABLE
|
||||||
|
#include "zos.h"
|
||||||
|
#define pika_platform_printf(...) zos_kprintf(__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -289,6 +292,11 @@ typedef struct pika_platform_thread {
|
|||||||
typedef struct pika_platform_thread {
|
typedef struct pika_platform_thread {
|
||||||
rt_thread_t thread;
|
rt_thread_t thread;
|
||||||
} pika_platform_thread_t;
|
} pika_platform_thread_t;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
#include "zos.h"
|
||||||
|
typedef struct pika_platform_thread {
|
||||||
|
zos_task_t thread;
|
||||||
|
} pika_platform_thread_t;
|
||||||
#else
|
#else
|
||||||
typedef struct pika_platform_thread {
|
typedef struct pika_platform_thread {
|
||||||
void* platform_data;
|
void* platform_data;
|
||||||
@ -319,6 +327,9 @@ typedef SemaphoreHandle_t pika_mutex_platform_data_t;
|
|||||||
#elif PIKA_RTTHREAD_ENABLE
|
#elif PIKA_RTTHREAD_ENABLE
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
typedef rt_mutex_t pika_mutex_platform_data_t;
|
typedef rt_mutex_t pika_mutex_platform_data_t;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
#include "zos.h"
|
||||||
|
typedef zos_mutex_t pika_mutex_platform_data_t;
|
||||||
#else
|
#else
|
||||||
typedef void* pika_mutex_platform_data_t;
|
typedef void* pika_mutex_platform_data_t;
|
||||||
#endif
|
#endif
|
||||||
@ -364,6 +375,11 @@ typedef struct pika_platform_timer {
|
|||||||
typedef struct pika_platform_timer {
|
typedef struct pika_platform_timer {
|
||||||
uint32_t time;
|
uint32_t time;
|
||||||
} pika_platform_timer_t;
|
} pika_platform_timer_t;
|
||||||
|
#elif PIKA_ZeusOS_ENABLE
|
||||||
|
#include "zos.h"
|
||||||
|
typedef struct pika_platform_timer {
|
||||||
|
uint32_t time;
|
||||||
|
} pika_platform_timer_t;
|
||||||
#else
|
#else
|
||||||
typedef struct pika_platform_timer {
|
typedef struct pika_platform_timer {
|
||||||
void* platform_data;
|
void* platform_data;
|
||||||
|
@ -419,6 +419,10 @@ extern "C" {
|
|||||||
#define PIKA_RTTHREAD_ENABLE 0
|
#define PIKA_RTTHREAD_ENABLE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PIKA_ZeusOS_ENABLE
|
||||||
|
#define PIKA_ZeusOS_ENABLE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef PIKA_LINUX_COMPATIBLE
|
#ifndef PIKA_LINUX_COMPATIBLE
|
||||||
#define PIKA_LINUX_COMPATIBLE 0
|
#define PIKA_LINUX_COMPATIBLE 0
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user