From e2fb6820d013420bf9a69ac5b8955f9ebb6af4f0 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sat, 7 Jul 2018 17:05:18 +1000 Subject: Add support for ChibiOS V5 - Thanks Vrollei --- src/gos/gos_chibios.c | 44 +++++++++++++++++++++----------------------- src/gos/gos_chibios.h | 17 +++++++++++------ 2 files changed, 32 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/gos/gos_chibios.c b/src/gos/gos_chibios.c index 725a8763..4d2358b5 100644 --- a/src/gos/gos_chibios.c +++ b/src/gos/gos_chibios.c @@ -11,38 +11,36 @@ #include -#if CH_KERNEL_MAJOR == 2 +#if CH_KERNEL_MAJOR < 2 || CH_KERNEL_MAJOR > 5 + #error "GOS: Unsupported version of ChibiOS" +#endif +#if CH_KERNEL_MAJOR <= 2 #if !CH_USE_MUTEXES #error "GOS: CH_USE_MUTEXES must be defined in chconf.h" #endif #if !CH_USE_SEMAPHORES #error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h" #endif - -#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) - +#else #if !CH_CFG_USE_MUTEXES #error "GOS: CH_CFG_USE_MUTEXES must be defined in chconf.h" #endif #if !CH_CFG_USE_SEMAPHORES #error "GOS: CH_CFG_USE_SEMAPHORES must be defined in chconf.h" #endif - -#else - #error "GOS: Unsupported version of ChibiOS" #endif void _gosInit(void) { #if !GFX_OS_NO_INIT /* Don't Initialize if the user already has */ - #if CH_KERNEL_MAJOR == 2 + #if CH_KERNEL_MAJOR <= 2 if (!chThdSelf()) { halInit(); chSysInit(); } - #elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) + #else if (!chThdGetSelfX()) { halInit(); chSysInit(); @@ -108,9 +106,9 @@ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit) psem->limit = limit; - #if CH_KERNEL_MAJOR == 2 + #if CH_KERNEL_MAJOR <= 2 chSemInit(&psem->sem, val); - #elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) + #else chSemObjectInit(&psem->sem, val); #endif } @@ -122,27 +120,27 @@ void gfxSemDestroy(gfxSem *psem) gBool gfxSemWait(gfxSem *psem, delaytime_t ms) { - #if CH_KERNEL_MAJOR == 2 + #if CH_KERNEL_MAJOR <= 2 switch(ms) { case TIME_IMMEDIATE: return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != RDY_TIMEOUT; case TIME_INFINITE: chSemWait(&psem->sem); return gTrue; - default: return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != RDY_TIMEOUT; + default: return chSemWaitTimeout(&psem->sem, gfxMillisecondsToTicks(ms)) != RDY_TIMEOUT; } - #elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) + #else switch(ms) { case TIME_IMMEDIATE: return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != MSG_TIMEOUT; case TIME_INFINITE: chSemWait(&psem->sem); return gTrue; - default: return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != MSG_TIMEOUT; + default: return chSemWaitTimeout(&psem->sem, gfxMillisecondsToTicks(ms)) != MSG_TIMEOUT; } #endif } gBool gfxSemWaitI(gfxSem *psem) { - #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + #if CH_KERNEL_MAJOR <= 3 if (psem->sem.s_cnt <= 0) return gFalse; - #elif (CH_KERNEL_MAJOR == 4) + #else if (psem->sem.cnt <= 0) return gFalse; #endif @@ -154,10 +152,10 @@ void gfxSemSignal(gfxSem *psem) { chSysLock(); - #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + #if CH_KERNEL_MAJOR <= 3 if (psem->sem.s_cnt < psem->limit) chSemSignalI(&psem->sem); - #elif (CH_KERNEL_MAJOR == 4) + #else if (psem->sem.cnt < psem->limit) chSemSignalI(&psem->sem); #endif @@ -168,10 +166,10 @@ void gfxSemSignal(gfxSem *psem) void gfxSemSignalI(gfxSem *psem) { - #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + #if CH_KERNEL_MAJOR <= 3 if (psem->sem.s_cnt < psem->limit) chSemSignalI(&psem->sem); - #elif (CH_KERNEL_MAJOR == 4) + #else if (psem->sem.cnt < psem->limit) chSemSignalI(&psem->sem); #endif @@ -181,9 +179,9 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_ { if (!stackarea) { if (!stacksz) stacksz = 256; - #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + #if CH_KERNEL_MAJOR <= 3 return chThdCreateFromHeap(0, stacksz, prio, (tfunc_t)fn, param); - #elif CH_KERNEL_MAJOR == 4 + #else return chThdCreateFromHeap(0, stacksz, "ugfx", prio, (tfunc_t)fn, param); #endif } diff --git a/src/gos/gos_chibios.h b/src/gos/gos_chibios.h index 7c0d1447..d97d1e9f 100644 --- a/src/gos/gos_chibios.h +++ b/src/gos/gos_chibios.h @@ -45,7 +45,7 @@ typedef tprio_t threadpriority_t; #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) #define THREAD_RETURN(retval) return retval -#if CH_KERNEL_MAJOR == 2 +#if CH_KERNEL_MAJOR <= 2 typedef struct { Semaphore sem; semcount_t limit; @@ -53,7 +53,7 @@ typedef tprio_t threadpriority_t; typedef Mutex gfxMutex; typedef Thread* gfxThreadHandle; -#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) +#else #undef DECLARE_THREAD_STACK #define DECLARE_THREAD_STACK(a, b) THD_WORKING_AREA(a, b) @@ -72,24 +72,29 @@ typedef tprio_t threadpriority_t; /*===========================================================================*/ // First the kernel version specific ones -#if CH_KERNEL_MAJOR == 2 +#if CH_KERNEL_MAJOR <= 2 #define gfxSystemTicks() chTimeNow() #define gfxMutexInit(pmutex) chMtxInit(pmutex) #define gfxMutexExit(pmutex) chMtxUnlock() #define gfxExit() chSysHalt() #define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); } -#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) +#else #define gfxSystemTicks() chVTGetSystemTimeX() #define gfxMutexInit(pmutex) chMtxObjectInit(pmutex) #define gfxMutexExit(pmutex) chMtxUnlock(pmutex) #define gfxExit() osalSysHalt("gfx_exit") -#define gfxHalt(msg) { chSysHalt(msg); } + #define gfxHalt(msg) { chSysHalt(msg); } +#endif + +#if CH_KERNEL_MAJOR <= 4 + #define gfxMillisecondsToTicks(ms) MS2ST(ms) +#else + #define gfxMillisecondsToTicks(ms) TIME_MS2I(ms) #endif #define gfxAlloc(sz) chHeapAlloc(0, sz) #define gfxFree(ptr) chHeapFree(ptr) #define gfxYield() chThdYield() -#define gfxMillisecondsToTicks(ms) MS2ST(ms) #define gfxSystemLock() chSysLock() #define gfxSystemUnlock() chSysUnlock() #define gfxMutexDestroy(pmutex) (void)pmutex -- cgit v1.2.3