2013-05-24 15:26:52 +00:00
|
|
|
/*
|
2013-06-15 11:37:22 +00:00
|
|
|
* 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:
|
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2013-06-15 11:37:22 +00:00
|
|
|
*/
|
2013-05-24 15:26:52 +00:00
|
|
|
|
|
|
|
#ifndef _GOS_CHIBIOS_H
|
|
|
|
#define _GOS_CHIBIOS_H
|
|
|
|
|
|
|
|
#if GFX_USE_OS_CHIBIOS
|
|
|
|
|
2018-02-27 07:44:21 +00:00
|
|
|
#if GFX_COMPAT_V2
|
|
|
|
// This shouldn't be needed but some people are complaining
|
|
|
|
// about TRUE/FALSE redefinition so we fix it here.
|
|
|
|
// ChibiOS will define them in its own header files.
|
|
|
|
#undef TRUE
|
|
|
|
#undef FALSE
|
|
|
|
#endif
|
2014-12-31 02:27:04 +00:00
|
|
|
|
2013-05-24 15:26:52 +00:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Type definitions */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2018-07-08 05:15:15 +00:00
|
|
|
#define gDelayNone TIME_IMMEDIATE
|
|
|
|
#define gDelayForever TIME_INFINITE
|
2013-05-24 15:26:52 +00:00
|
|
|
|
2018-07-07 23:46:29 +00:00
|
|
|
#if CH_KERNEL_MAJOR <= 4
|
2018-07-08 04:30:31 +00:00
|
|
|
typedef systime_t gDelay;
|
2018-07-07 23:46:29 +00:00
|
|
|
#else
|
2018-07-08 04:30:31 +00:00
|
|
|
typedef sysinterval_t gDelay;
|
2018-07-07 23:46:29 +00:00
|
|
|
#endif
|
2018-07-08 04:30:31 +00:00
|
|
|
typedef systime_t gTicks;
|
|
|
|
typedef cnt_t gSemcount;
|
2021-08-12 10:47:08 +00:00
|
|
|
#if CH_KERNEL_MAJOR >= 6
|
|
|
|
typedef void gThreadreturn;
|
|
|
|
#else
|
|
|
|
typedef msg_t gThreadreturn;
|
|
|
|
#endif
|
2018-07-08 04:30:31 +00:00
|
|
|
typedef tprio_t gThreadpriority;
|
2013-05-24 15:26:52 +00:00
|
|
|
|
2018-11-03 02:29:30 +00:00
|
|
|
#define gSemMaxCount ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
|
|
|
|
#define gThreadpriorityLow LOWPRIO
|
|
|
|
#define gThreadpriorityNormal NORMALPRIO
|
|
|
|
#define gThreadpriorityHigh HIGHPRIO
|
2013-05-24 15:26:52 +00:00
|
|
|
|
2018-11-03 02:29:30 +00:00
|
|
|
#define GFX_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
|
|
|
|
#define GFX_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
|
2021-08-26 00:08:42 +00:00
|
|
|
|
|
|
|
#if CH_KERNEL_MAJOR >= 6
|
|
|
|
#define gfxThreadReturn(retval) return
|
|
|
|
#else
|
|
|
|
#define gfxThreadReturn(retval) return retval
|
|
|
|
#endif
|
2013-05-24 15:26:52 +00:00
|
|
|
|
2018-07-07 07:05:18 +00:00
|
|
|
#if CH_KERNEL_MAJOR <= 2
|
2014-04-18 11:20:50 +00:00
|
|
|
typedef struct {
|
|
|
|
Semaphore sem;
|
2018-07-08 04:30:31 +00:00
|
|
|
gSemcount limit;
|
2018-11-03 02:29:30 +00:00
|
|
|
} gSem;
|
2013-05-24 15:26:52 +00:00
|
|
|
|
2018-11-03 02:29:30 +00:00
|
|
|
typedef Mutex gMutex;
|
2018-07-08 05:40:27 +00:00
|
|
|
typedef Thread* gThread;
|
2018-07-07 07:05:18 +00:00
|
|
|
#else
|
2018-11-03 02:29:30 +00:00
|
|
|
#undef GFX_THREAD_STACK
|
|
|
|
#define GFX_THREAD_STACK(a, b) THD_WORKING_AREA(a, b)
|
2018-06-23 03:02:07 +00:00
|
|
|
|
2014-04-18 11:20:50 +00:00
|
|
|
typedef struct {
|
|
|
|
semaphore_t sem;
|
2018-07-08 04:30:31 +00:00
|
|
|
gSemcount limit;
|
2018-11-03 02:29:30 +00:00
|
|
|
} gSem;
|
2014-04-18 11:20:50 +00:00
|
|
|
|
2018-11-03 02:29:30 +00:00
|
|
|
typedef mutex_t gMutex;
|
2018-07-08 05:40:27 +00:00
|
|
|
typedef thread_t* gThread;
|
2014-04-18 11:20:50 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-24 15:26:52 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Function declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2014-04-18 11:20:50 +00:00
|
|
|
// First the kernel version specific ones
|
2018-07-07 07:05:18 +00:00
|
|
|
#if CH_KERNEL_MAJOR <= 2
|
2014-04-18 11:20:50 +00:00
|
|
|
#define gfxSystemTicks() chTimeNow()
|
|
|
|
#define gfxMutexInit(pmutex) chMtxInit(pmutex)
|
|
|
|
#define gfxMutexExit(pmutex) chMtxUnlock()
|
2014-05-19 20:43:39 +00:00
|
|
|
#define gfxExit() chSysHalt()
|
2015-06-19 17:55:40 +00:00
|
|
|
#define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); }
|
2018-07-07 07:05:18 +00:00
|
|
|
#else
|
2014-04-18 11:20:50 +00:00
|
|
|
#define gfxSystemTicks() chVTGetSystemTimeX()
|
|
|
|
#define gfxMutexInit(pmutex) chMtxObjectInit(pmutex)
|
|
|
|
#define gfxMutexExit(pmutex) chMtxUnlock(pmutex)
|
2014-05-19 20:43:39 +00:00
|
|
|
#define gfxExit() osalSysHalt("gfx_exit")
|
2018-07-07 07:05:18 +00:00
|
|
|
#define gfxHalt(msg) { chSysHalt(msg); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CH_KERNEL_MAJOR <= 4
|
|
|
|
#define gfxMillisecondsToTicks(ms) MS2ST(ms)
|
|
|
|
#else
|
|
|
|
#define gfxMillisecondsToTicks(ms) TIME_MS2I(ms)
|
2014-04-18 11:20:50 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-21 03:21:59 +00:00
|
|
|
#define gfxAlloc(sz) chHeapAlloc(0, sz)
|
2013-05-24 15:26:52 +00:00
|
|
|
#define gfxFree(ptr) chHeapFree(ptr)
|
2013-05-25 16:06:55 +00:00
|
|
|
#define gfxYield() chThdYield()
|
|
|
|
#define gfxSystemLock() chSysLock()
|
|
|
|
#define gfxSystemUnlock() chSysUnlock()
|
2013-11-17 10:23:41 +00:00
|
|
|
#define gfxMutexDestroy(pmutex) (void)pmutex
|
2013-05-25 16:06:55 +00:00
|
|
|
#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
|
2018-11-03 00:51:23 +00:00
|
|
|
void *gfxRealloc(void *ptr, gMemSize oldsz, gMemSize newsz);
|
2018-07-08 04:30:31 +00:00
|
|
|
void gfxSleepMilliseconds(gDelay ms);
|
|
|
|
void gfxSleepMicroseconds(gDelay ms);
|
2018-11-03 02:29:30 +00:00
|
|
|
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit);
|
|
|
|
void gfxSemDestroy(gSem *psem);
|
|
|
|
gBool gfxSemWait(gSem *psem, gDelay ms);
|
|
|
|
gBool gfxSemWaitI(gSem *psem);
|
|
|
|
void gfxSemSignal(gSem *psem);
|
|
|
|
void gfxSemSignalI(gSem *psem);
|
|
|
|
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param);
|
2013-06-02 08:57:22 +00:00
|
|
|
#define gfxThreadWait(thread) chThdWait(thread)
|
|
|
|
#define gfxThreadMe() chThdSelf()
|
2013-11-17 10:23:41 +00:00
|
|
|
#define gfxThreadClose(thread) (void)thread
|
2013-05-24 15:26:52 +00:00
|
|
|
|
|
|
|
#endif /* GFX_USE_OS_CHIBIOS */
|
|
|
|
#endif /* _GOS_CHIBIOS_H */
|