Add support for ChibiOS V5 - Thanks Vrollei

This commit is contained in:
inmarket 2018-07-07 17:05:18 +10:00
parent 41271d632b
commit e2fb6820d0
4 changed files with 38 additions and 30 deletions

View File

@ -25,6 +25,7 @@ FIX: Fixed UC1610 driver private area initialisation
FIX: Fixed ST7735 driver and added kapacuk changes FIX: Fixed ST7735 driver and added kapacuk changes
FEATURE: Added keyboard support to radio buttons (by Steffan) FEATURE: Added keyboard support to radio buttons (by Steffan)
FEATURE: Added internal use only GFX_COMPILESTAGE (used to control compilation) FEATURE: Added internal use only GFX_COMPILESTAGE (used to control compilation)
FEATURE: Added support for ChibiOS Kernel V5
*** Release 2.8 *** *** Release 2.8 ***

View File

@ -11,38 +11,36 @@
#include <string.h> #include <string.h>
#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 #if !CH_USE_MUTEXES
#error "GOS: CH_USE_MUTEXES must be defined in chconf.h" #error "GOS: CH_USE_MUTEXES must be defined in chconf.h"
#endif #endif
#if !CH_USE_SEMAPHORES #if !CH_USE_SEMAPHORES
#error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h" #error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h"
#endif #endif
#else
#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
#if !CH_CFG_USE_MUTEXES #if !CH_CFG_USE_MUTEXES
#error "GOS: CH_CFG_USE_MUTEXES must be defined in chconf.h" #error "GOS: CH_CFG_USE_MUTEXES must be defined in chconf.h"
#endif #endif
#if !CH_CFG_USE_SEMAPHORES #if !CH_CFG_USE_SEMAPHORES
#error "GOS: CH_CFG_USE_SEMAPHORES must be defined in chconf.h" #error "GOS: CH_CFG_USE_SEMAPHORES must be defined in chconf.h"
#endif #endif
#else
#error "GOS: Unsupported version of ChibiOS"
#endif #endif
void _gosInit(void) void _gosInit(void)
{ {
#if !GFX_OS_NO_INIT #if !GFX_OS_NO_INIT
/* Don't Initialize if the user already has */ /* Don't Initialize if the user already has */
#if CH_KERNEL_MAJOR == 2 #if CH_KERNEL_MAJOR <= 2
if (!chThdSelf()) { if (!chThdSelf()) {
halInit(); halInit();
chSysInit(); chSysInit();
} }
#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) #else
if (!chThdGetSelfX()) { if (!chThdGetSelfX()) {
halInit(); halInit();
chSysInit(); chSysInit();
@ -108,9 +106,9 @@ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
psem->limit = limit; psem->limit = limit;
#if CH_KERNEL_MAJOR == 2 #if CH_KERNEL_MAJOR <= 2
chSemInit(&psem->sem, val); chSemInit(&psem->sem, val);
#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) #else
chSemObjectInit(&psem->sem, val); chSemObjectInit(&psem->sem, val);
#endif #endif
} }
@ -122,27 +120,27 @@ void gfxSemDestroy(gfxSem *psem)
gBool gfxSemWait(gfxSem *psem, delaytime_t ms) gBool gfxSemWait(gfxSem *psem, delaytime_t ms)
{ {
#if CH_KERNEL_MAJOR == 2 #if CH_KERNEL_MAJOR <= 2
switch(ms) { switch(ms) {
case TIME_IMMEDIATE: return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != RDY_TIMEOUT; case TIME_IMMEDIATE: return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != RDY_TIMEOUT;
case TIME_INFINITE: chSemWait(&psem->sem); return gTrue; 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) { switch(ms) {
case TIME_IMMEDIATE: return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != MSG_TIMEOUT; case TIME_IMMEDIATE: return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != MSG_TIMEOUT;
case TIME_INFINITE: chSemWait(&psem->sem); return gTrue; 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 #endif
} }
gBool gfxSemWaitI(gfxSem *psem) gBool gfxSemWaitI(gfxSem *psem)
{ {
#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) #if CH_KERNEL_MAJOR <= 3
if (psem->sem.s_cnt <= 0) if (psem->sem.s_cnt <= 0)
return gFalse; return gFalse;
#elif (CH_KERNEL_MAJOR == 4) #else
if (psem->sem.cnt <= 0) if (psem->sem.cnt <= 0)
return gFalse; return gFalse;
#endif #endif
@ -154,10 +152,10 @@ void gfxSemSignal(gfxSem *psem)
{ {
chSysLock(); chSysLock();
#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) #if CH_KERNEL_MAJOR <= 3
if (psem->sem.s_cnt < psem->limit) if (psem->sem.s_cnt < psem->limit)
chSemSignalI(&psem->sem); chSemSignalI(&psem->sem);
#elif (CH_KERNEL_MAJOR == 4) #else
if (psem->sem.cnt < psem->limit) if (psem->sem.cnt < psem->limit)
chSemSignalI(&psem->sem); chSemSignalI(&psem->sem);
#endif #endif
@ -168,10 +166,10 @@ void gfxSemSignal(gfxSem *psem)
void gfxSemSignalI(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) if (psem->sem.s_cnt < psem->limit)
chSemSignalI(&psem->sem); chSemSignalI(&psem->sem);
#elif (CH_KERNEL_MAJOR == 4) #else
if (psem->sem.cnt < psem->limit) if (psem->sem.cnt < psem->limit)
chSemSignalI(&psem->sem); chSemSignalI(&psem->sem);
#endif #endif
@ -181,9 +179,9 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_
{ {
if (!stackarea) { if (!stackarea) {
if (!stacksz) stacksz = 256; 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); 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); return chThdCreateFromHeap(0, stacksz, "ugfx", prio, (tfunc_t)fn, param);
#endif #endif
} }

View File

@ -45,7 +45,7 @@ typedef tprio_t threadpriority_t;
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
#define THREAD_RETURN(retval) return retval #define THREAD_RETURN(retval) return retval
#if CH_KERNEL_MAJOR == 2 #if CH_KERNEL_MAJOR <= 2
typedef struct { typedef struct {
Semaphore sem; Semaphore sem;
semcount_t limit; semcount_t limit;
@ -53,7 +53,7 @@ typedef tprio_t threadpriority_t;
typedef Mutex gfxMutex; typedef Mutex gfxMutex;
typedef Thread* gfxThreadHandle; typedef Thread* gfxThreadHandle;
#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) #else
#undef DECLARE_THREAD_STACK #undef DECLARE_THREAD_STACK
#define DECLARE_THREAD_STACK(a, b) THD_WORKING_AREA(a, b) #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 // First the kernel version specific ones
#if CH_KERNEL_MAJOR == 2 #if CH_KERNEL_MAJOR <= 2
#define gfxSystemTicks() chTimeNow() #define gfxSystemTicks() chTimeNow()
#define gfxMutexInit(pmutex) chMtxInit(pmutex) #define gfxMutexInit(pmutex) chMtxInit(pmutex)
#define gfxMutexExit(pmutex) chMtxUnlock() #define gfxMutexExit(pmutex) chMtxUnlock()
#define gfxExit() chSysHalt() #define gfxExit() chSysHalt()
#define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); } #define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); }
#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4) #else
#define gfxSystemTicks() chVTGetSystemTimeX() #define gfxSystemTicks() chVTGetSystemTimeX()
#define gfxMutexInit(pmutex) chMtxObjectInit(pmutex) #define gfxMutexInit(pmutex) chMtxObjectInit(pmutex)
#define gfxMutexExit(pmutex) chMtxUnlock(pmutex) #define gfxMutexExit(pmutex) chMtxUnlock(pmutex)
#define gfxExit() osalSysHalt("gfx_exit") #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 #endif
#define gfxAlloc(sz) chHeapAlloc(0, sz) #define gfxAlloc(sz) chHeapAlloc(0, sz)
#define gfxFree(ptr) chHeapFree(ptr) #define gfxFree(ptr) chHeapFree(ptr)
#define gfxYield() chThdYield() #define gfxYield() chThdYield()
#define gfxMillisecondsToTicks(ms) MS2ST(ms)
#define gfxSystemLock() chSysLock() #define gfxSystemLock() chSysLock()
#define gfxSystemUnlock() chSysUnlock() #define gfxSystemUnlock() chSysUnlock()
#define gfxMutexDestroy(pmutex) (void)pmutex #define gfxMutexDestroy(pmutex) (void)pmutex

View File

@ -9,7 +9,7 @@
# Requirements: # Requirements:
# #
# CHIBIOS_VERSION Which version of ChibiOS is this (2, 3, 16, git) - default is 16 # CHIBIOS_VERSION Which version of ChibiOS is this (2, 3, 4, 5, 16, git) - default is 16
# Note the 'git' option is one we try to keep up to date with the ChibiOS master # Note the 'git' option is one we try to keep up to date with the ChibiOS master
# If you find the 'git' option requires update please let us know. # If you find the 'git' option requires update please let us know.
# #
@ -19,6 +19,10 @@ ifeq ($(CHIBIOS_VERSION),2)
include $(GFXLIB)/tools/gmake_scripts/os_chibios_2.mk include $(GFXLIB)/tools/gmake_scripts/os_chibios_2.mk
else ifeq ($(CHIBIOS_VERSION),3) else ifeq ($(CHIBIOS_VERSION),3)
include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
else ifeq ($(CHIBIOS_VERSION),4)
include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
else ifeq ($(CHIBIOS_VERSION),5)
include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
else ifeq ($(CHIBIOS_VERSION),16) else ifeq ($(CHIBIOS_VERSION),16)
include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk include $(GFXLIB)/tools/gmake_scripts/os_chibios_3.mk
else ifeq ($(CHIBIOS_VERSION),git) else ifeq ($(CHIBIOS_VERSION),git)