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;
|
|
|
|
typedef msg_t gThreadreturn;
|
|
|
|
typedef tprio_t gThreadpriority;
|
2013-05-24 15:26:52 +00:00
|
|
|
|
2018-07-08 04:30:31 +00:00
|
|
|
#define MAX_SEMAPHORE_COUNT ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1))
|
2018-07-08 05:32:26 +00:00
|
|
|
#define gThreadpriorityLow LOWPRIO
|
|
|
|
#define gThreadpriorityNormal NORMALPRIO
|
|
|
|
#define gThreadpriorityHigh HIGHPRIO
|
2013-05-24 15:26:52 +00:00
|
|
|
|
2013-06-02 08:57:22 +00:00
|
|
|
#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
|
2018-07-08 04:30:31 +00:00
|
|
|
#define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn fnName(void *param)
|
2015-10-19 20:29:35 +00:00
|
|
|
#define THREAD_RETURN(retval) return retval
|
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;
|
2013-05-24 15:26:52 +00:00
|
|
|
} gfxSem;
|
|
|
|
|
2014-04-18 11:20:50 +00:00
|
|
|
typedef Mutex gfxMutex;
|
2018-07-08 05:40:27 +00:00
|
|
|
typedef Thread* gThread;
|
2018-07-07 07:05:18 +00:00
|
|
|
#else
|
2014-04-18 11:20:50 +00:00
|
|
|
#undef DECLARE_THREAD_STACK
|
|
|
|
#define DECLARE_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;
|
2014-04-18 11:20:50 +00:00
|
|
|
} gfxSem;
|
|
|
|
|
|
|
|
typedef mutex_t gfxMutex;
|
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)
|
2013-07-20 11:57:01 +00:00
|
|
|
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
|
2018-07-08 04:30:31 +00:00
|
|
|
void gfxSleepMilliseconds(gDelay ms);
|
|
|
|
void gfxSleepMicroseconds(gDelay ms);
|
|
|
|
void gfxSemInit(gfxSem *psem, gSemcount val, gSemcount limit);
|
2013-05-25 16:06:55 +00:00
|
|
|
void gfxSemDestroy(gfxSem *psem);
|
2018-07-08 04:30:31 +00:00
|
|
|
gBool gfxSemWait(gfxSem *psem, gDelay ms);
|
2018-06-23 03:02:07 +00:00
|
|
|
gBool gfxSemWaitI(gfxSem *psem);
|
2013-05-24 15:26:52 +00:00
|
|
|
void gfxSemSignal(gfxSem *psem);
|
|
|
|
void gfxSemSignalI(gfxSem *psem);
|
2018-07-08 05:40:27 +00:00
|
|
|
gThread gfxThreadCreate(void *stackarea, size_t stacksz, gThreadpriority prio, DECLARE_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 */
|