diff options
author | inmarket <andrewh@inmarket.com.au> | 2014-09-29 16:21:31 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2014-09-29 16:21:31 +1000 |
commit | 65315ac16263ab81f90ca2de20d09b6eda4cf29a (patch) | |
tree | 997d7a2472213cc3422d75c08d470a0e4d6f84c9 /src/gos/gos_chibios.h | |
parent | 445fadaa4a1319733ca64ed3c720809b2de75815 (diff) | |
parent | 32a4969b7d4d92b1d40e60fae676d798bacb780f (diff) | |
download | uGFX-65315ac16263ab81f90ca2de20d09b6eda4cf29a.tar.gz uGFX-65315ac16263ab81f90ca2de20d09b6eda4cf29a.tar.bz2 uGFX-65315ac16263ab81f90ca2de20d09b6eda4cf29a.zip |
Merge remote-tracking branch 'origin/newmouse' into newmouse
Diffstat (limited to 'src/gos/gos_chibios.h')
-rw-r--r-- | src/gos/gos_chibios.h | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/gos/gos_chibios.h b/src/gos/gos_chibios.h new file mode 100644 index 00000000..a07c72ab --- /dev/null +++ b/src/gos/gos_chibios.h @@ -0,0 +1,118 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GOS_CHIBIOS_H +#define _GOS_CHIBIOS_H + +#if GFX_USE_OS_CHIBIOS + +#include "ch.h" +#include "hal.h" + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +/** + * bool_t, + * int8_t, uint8_t, + * int16_t, uint16_t, + * int32_t, uint32_t, + * size_t + * TRUE, FALSE + * TIME_IMMEDIATE, TIME_INFINITE + * are already defined by ChibiOS + */ + +typedef systime_t delaytime_t; +typedef systime_t systemticks_t; +typedef cnt_t semcount_t; +typedef msg_t threadreturn_t; +typedef tprio_t threadpriority_t; + +#define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1)) +#define LOW_PRIORITY LOWPRIO +#define NORMAL_PRIORITY NORMALPRIO +#define HIGH_PRIORITY HIGHPRIO + +#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz) +#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) + +#if CH_KERNEL_MAJOR == 2 + typedef struct { + Semaphore sem; + semcount_t limit; + } gfxSem; + + typedef Mutex gfxMutex; + typedef Thread* gfxThreadHandle; +#elif CH_KERNEL_MAJOR == 3 + #undef DECLARE_THREAD_STACK + #define DECLARE_THREAD_STACK(a, b) THD_WORKING_AREA(a, b) + + typedef struct { + semaphore_t sem; + semcount_t limit; + } gfxSem; + + typedef mutex_t gfxMutex; + typedef thread_t* gfxThreadHandle; +#endif + + +/*===========================================================================*/ +/* Function declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +// First the kernel version specific ones +#if CH_KERNEL_MAJOR == 2 + #define gfxSystemTicks() chTimeNow() + #define gfxMutexInit(pmutex) chMtxInit(pmutex) + #define gfxMutexExit(pmutex) chMtxUnlock() + #define gfxExit() chSysHalt() +#elif CH_KERNEL_MAJOR == 3 + #define gfxSystemTicks() chVTGetSystemTimeX() + #define gfxMutexInit(pmutex) chMtxObjectInit(pmutex) + #define gfxMutexExit(pmutex) chMtxUnlock(pmutex) + #define gfxExit() osalSysHalt("gfx_exit") +#endif + +#define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); } +#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 +#define gfxMutexEnter(pmutex) chMtxLock(pmutex) +void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz); +void gfxSleepMilliseconds(delaytime_t ms); +void gfxSleepMicroseconds(delaytime_t ms); +void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit); +void gfxSemDestroy(gfxSem *psem); +bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); +bool_t gfxSemWaitI(gfxSem *psem); +void gfxSemSignal(gfxSem *psem); +void gfxSemSignalI(gfxSem *psem); +#define gfxSemCounterI(psem) ((psem)->sem.s_cnt) +#define gfxSemCounter(psem) ((psem)->sem.s_cnt) +gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); +#define gfxThreadWait(thread) chThdWait(thread) +#define gfxThreadMe() chThdSelf() +#define gfxThreadClose(thread) (void)thread + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_OS_CHIBIOS */ +#endif /* _GOS_CHIBIOS_H */ |