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:
|
|
|
|
*
|
2013-07-21 20:20:37 +00:00
|
|
|
* http://ugfx.org/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
|
|
|
|
|
2014-12-31 02:27:04 +00:00
|
|
|
// This shouldn't be needed but some people are complaining
|
|
|
|
// about TRUE/FALSE redefinition so we fix it here.
|
|
|
|
#undef TRUE
|
|
|
|
#undef FALSE
|
|
|
|
|
2013-05-24 15:26:52 +00:00
|
|
|
#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
|
|
|
|
*/
|
|
|
|
|
2014-12-31 02:27:04 +00:00
|
|
|
#if !defined(FALSE)
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
#if !defined(TRUE)
|
|
|
|
#define TRUE -1
|
|
|
|
#endif
|
2016-06-01 10:09:34 +00:00
|
|
|
#if (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
|
2014-10-06 05:50:19 +00:00
|
|
|
typedef char bool_t;
|
|
|
|
#endif
|
|
|
|
|
2013-05-24 15:26:52 +00:00
|
|
|
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
|
|
|
|
|
2013-06-02 08:57:22 +00:00
|
|
|
#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
|
|
|
|
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t 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
|
|
|
|
2014-04-18 11:20:50 +00:00
|
|
|
#if CH_KERNEL_MAJOR == 2
|
|
|
|
typedef struct {
|
|
|
|
Semaphore sem;
|
|
|
|
semcount_t limit;
|
2013-05-24 15:26:52 +00:00
|
|
|
} gfxSem;
|
|
|
|
|
2014-04-18 11:20:50 +00:00
|
|
|
typedef Mutex gfxMutex;
|
|
|
|
typedef Thread* gfxThreadHandle;
|
2016-06-01 10:09:34 +00:00
|
|
|
#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
|
2014-04-18 11:20:50 +00:00
|
|
|
#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
|
|
|
|
|
2013-05-24 15:26:52 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Function declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-04-18 11:20:50 +00:00
|
|
|
// First the kernel version specific ones
|
|
|
|
#if CH_KERNEL_MAJOR == 2
|
|
|
|
#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(); }
|
2016-06-01 10:09:34 +00:00
|
|
|
#elif (CH_KERNEL_MAJOR == 3) || (CH_KERNEL_MAJOR == 4)
|
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")
|
2015-06-19 17:55:40 +00:00
|
|
|
#define gfxHalt(msg) { chSysHalt(msg); }
|
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 gfxMillisecondsToTicks(ms) MS2ST(ms)
|
|
|
|
#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);
|
2013-05-24 15:26:52 +00:00
|
|
|
void gfxSleepMilliseconds(delaytime_t ms);
|
|
|
|
void gfxSleepMicroseconds(delaytime_t ms);
|
|
|
|
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
|
2013-05-25 16:06:55 +00:00
|
|
|
void gfxSemDestroy(gfxSem *psem);
|
2013-05-24 15:26:52 +00:00
|
|
|
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
|
2014-03-11 07:10:11 +00:00
|
|
|
bool_t gfxSemWaitI(gfxSem *psem);
|
2013-05-24 15:26:52 +00:00
|
|
|
void gfxSemSignal(gfxSem *psem);
|
|
|
|
void gfxSemSignalI(gfxSem *psem);
|
2016-06-01 10:09:34 +00:00
|
|
|
#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3)
|
2013-05-24 15:26:52 +00:00
|
|
|
#define gfxSemCounterI(psem) ((psem)->sem.s_cnt)
|
|
|
|
#define gfxSemCounter(psem) ((psem)->sem.s_cnt)
|
2016-06-01 10:09:34 +00:00
|
|
|
#elif (CH_KERNEL_MAJOR == 4)
|
|
|
|
#define gfxSemCounterI(psem) ((psem)->sem.cnt)
|
|
|
|
#define gfxSemCounter(psem) ((psem)->sem.cnt)
|
|
|
|
#endif
|
2013-06-02 08:57:22 +00:00
|
|
|
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()
|
2013-11-17 10:23:41 +00:00
|
|
|
#define gfxThreadClose(thread) (void)thread
|
2013-05-24 15:26:52 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* GFX_USE_OS_CHIBIOS */
|
|
|
|
#endif /* _GOS_CHIBIOS_H */
|