uGFX now works with ChibiOS/RT 2.x and 3.x out of the box.
This commit is contained in:
parent
1454d20f2e
commit
40cf9fff9f
2 changed files with 97 additions and 31 deletions
|
@ -8,6 +8,7 @@
|
||||||
/**
|
/**
|
||||||
* @file src/gos/chibios.c
|
* @file src/gos/chibios.c
|
||||||
* @brief GOS ChibiOS Operating System support.
|
* @brief GOS ChibiOS Operating System support.
|
||||||
|
* @details Supports both, ChibiOS/RT 2.x and 3.x
|
||||||
*/
|
*/
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
|
||||||
|
@ -15,20 +16,41 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if !CH_USE_MUTEXES
|
#if CH_KERNEL_MAJOR == 2
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#elif CH_KERNEL_MAJOR == 3
|
||||||
|
|
||||||
|
#if !CH_CFG_USE_MUTEXES
|
||||||
|
#error "GOS: CH_USE_MUTEXES must be defined in chconf.h"
|
||||||
|
#endif
|
||||||
|
#if !CH_CFG_USE_SEMAPHORES
|
||||||
|
#error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void _gosInit(void)
|
void _gosInit(void)
|
||||||
{
|
{
|
||||||
/* Don't initialise if the user already has */
|
/* Don't initialise if the user already has */
|
||||||
|
|
||||||
|
#if CH_KERNEL_MAJOR == 2
|
||||||
if (!chThdSelf()) {
|
if (!chThdSelf()) {
|
||||||
halInit();
|
halInit();
|
||||||
chSysInit();
|
chSysInit();
|
||||||
}
|
}
|
||||||
|
#elif CH_KERNEL_MAJOR == 3
|
||||||
|
if (!chThdGetSelfX()) {
|
||||||
|
halInit();
|
||||||
|
chSysInit();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void _gosDeinit(void)
|
void _gosDeinit(void)
|
||||||
|
@ -36,7 +58,8 @@ void _gosDeinit(void)
|
||||||
/* ToDo */
|
/* ToDo */
|
||||||
}
|
}
|
||||||
|
|
||||||
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz) {
|
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz)
|
||||||
|
{
|
||||||
void *np;
|
void *np;
|
||||||
|
|
||||||
if (newsz <= oldsz)
|
if (newsz <= oldsz)
|
||||||
|
@ -52,7 +75,8 @@ void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz) {
|
||||||
return np;
|
return np;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxSleepMilliseconds(delaytime_t ms) {
|
void gfxSleepMilliseconds(delaytime_t ms)
|
||||||
|
{
|
||||||
switch(ms) {
|
switch(ms) {
|
||||||
case TIME_IMMEDIATE: chThdYield(); return;
|
case TIME_IMMEDIATE: chThdYield(); return;
|
||||||
case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
|
case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
|
||||||
|
@ -60,7 +84,8 @@ void gfxSleepMilliseconds(delaytime_t ms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxSleepMicroseconds(delaytime_t ms) {
|
void gfxSleepMicroseconds(delaytime_t ms)
|
||||||
|
{
|
||||||
switch(ms) {
|
switch(ms) {
|
||||||
case TIME_IMMEDIATE: return;
|
case TIME_IMMEDIATE: return;
|
||||||
case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
|
case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
|
||||||
|
@ -68,34 +93,52 @@ void gfxSleepMicroseconds(delaytime_t ms) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit) {
|
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
|
||||||
|
{
|
||||||
if (val > limit)
|
if (val > limit)
|
||||||
val = limit;
|
val = limit;
|
||||||
|
|
||||||
psem->limit = limit;
|
psem->limit = limit;
|
||||||
|
|
||||||
|
#if CH_KERNEL_MAJOR == 2
|
||||||
chSemInit(&psem->sem, val);
|
chSemInit(&psem->sem, val);
|
||||||
|
#elif CH_KERNEL_MAJOR == 3
|
||||||
|
chSemObjectInit(&psem->sem, val);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxSemDestroy(gfxSem *psem) {
|
void gfxSemDestroy(gfxSem *psem)
|
||||||
|
{
|
||||||
chSemReset(&psem->sem, 1);
|
chSemReset(&psem->sem, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) {
|
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
|
||||||
|
{
|
||||||
|
#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 TRUE;
|
case TIME_INFINITE: chSemWait(&psem->sem); return TRUE;
|
||||||
default: return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != RDY_TIMEOUT;
|
default: return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != RDY_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
#elif CH_KERNEL_MAJOR == 3
|
||||||
|
switch(ms) {
|
||||||
|
case TIME_IMMEDIATE: return chSemWaitTimeout(&psem->sem, TIME_IMMEDIATE) != MSG_TIMEOUT;
|
||||||
|
case TIME_INFINITE: chSemWait(&psem->sem); return TRUE;
|
||||||
|
default: return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != MSG_TIMEOUT;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t gfxSemWaitI(gfxSem *psem) {
|
bool_t gfxSemWaitI(gfxSem *psem)
|
||||||
|
{
|
||||||
if (chSemGetCounterI(&psem->sem) <= 0)
|
if (chSemGetCounterI(&psem->sem) <= 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
chSemFastWaitI(&psem->sem);
|
chSemFastWaitI(&psem->sem);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxSemSignal(gfxSem *psem) {
|
void gfxSemSignal(gfxSem *psem)
|
||||||
|
{
|
||||||
chSysLock();
|
chSysLock();
|
||||||
|
|
||||||
if (gfxSemCounterI(psem) < psem->limit)
|
if (gfxSemCounterI(psem) < psem->limit)
|
||||||
|
@ -105,12 +148,14 @@ void gfxSemSignal(gfxSem *psem) {
|
||||||
chSysUnlock();
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfxSemSignalI(gfxSem *psem) {
|
void gfxSemSignalI(gfxSem *psem)
|
||||||
|
{
|
||||||
if (gfxSemCounterI(psem) < psem->limit)
|
if (gfxSemCounterI(psem) < psem->limit)
|
||||||
chSemSignalI(&psem->sem);
|
chSemSignalI(&psem->sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) {
|
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
|
||||||
|
{
|
||||||
if (!stackarea) {
|
if (!stackarea) {
|
||||||
if (!stacksz) stacksz = 256;
|
if (!stacksz) stacksz = 256;
|
||||||
return chThdCreateFromHeap(0, stacksz, prio, fn, param);
|
return chThdCreateFromHeap(0, stacksz, prio, fn, param);
|
||||||
|
@ -124,4 +169,3 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_
|
||||||
|
|
||||||
#endif /* GFX_USE_OS_CHIBIOS */
|
#endif /* GFX_USE_OS_CHIBIOS */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
/**
|
/**
|
||||||
* @file src/gos/chibios.h
|
* @file src/gos/chibios.h
|
||||||
* @brief GOS - Operating System Support header file for ChibiOS.
|
* @brief GOS - Operating System Support header file for ChibiOS.
|
||||||
|
* @details Supports both, ChibiOS/RT 2.x and 3.x
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _GOS_CHIBIOS_H
|
#ifndef _GOS_CHIBIOS_H
|
||||||
|
@ -47,13 +48,27 @@ typedef tprio_t threadpriority_t;
|
||||||
#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
|
#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
|
||||||
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
|
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
|
||||||
|
|
||||||
typedef struct {
|
#if CH_KERNEL_MAJOR == 2
|
||||||
|
typedef struct {
|
||||||
Semaphore sem;
|
Semaphore sem;
|
||||||
semcount_t limit;
|
semcount_t limit;
|
||||||
} gfxSem;
|
} gfxSem;
|
||||||
|
|
||||||
typedef Mutex gfxMutex;
|
typedef Mutex gfxMutex;
|
||||||
typedef Thread * gfxThreadHandle;
|
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. */
|
/* Function declarations. */
|
||||||
|
@ -63,19 +78,27 @@ typedef Thread * gfxThreadHandle;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// First the kernel version specific ones
|
||||||
|
#if CH_KERNEL_MAJOR == 2
|
||||||
|
#define gfxSystemTicks() chTimeNow()
|
||||||
|
#define gfxMutexInit(pmutex) chMtxInit(pmutex)
|
||||||
|
#define gfxMutexExit(pmutex) chMtxUnlock()
|
||||||
|
#elif CH_KERNEL_MAJOR == 3
|
||||||
|
#define gfxSystemTicks() chVTGetSystemTimeX()
|
||||||
|
#define gfxMutexInit(pmutex) chMtxObjectInit(pmutex)
|
||||||
|
#define gfxMutexExit(pmutex) chMtxUnlock(pmutex)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); }
|
#define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); }
|
||||||
#define gfxExit() chSysHalt()
|
#define gfxExit() chSysHalt()
|
||||||
#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 gfxSystemTicks() chTimeNow()
|
|
||||||
#define gfxMillisecondsToTicks(ms) MS2ST(ms)
|
#define gfxMillisecondsToTicks(ms) MS2ST(ms)
|
||||||
#define gfxSystemLock() chSysLock()
|
#define gfxSystemLock() chSysLock()
|
||||||
#define gfxSystemUnlock() chSysUnlock()
|
#define gfxSystemUnlock() chSysUnlock()
|
||||||
#define gfxMutexInit(pmutex) chMtxInit(pmutex)
|
|
||||||
#define gfxMutexDestroy(pmutex) (void)pmutex
|
#define gfxMutexDestroy(pmutex) (void)pmutex
|
||||||
#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
|
#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
|
||||||
#define gfxMutexExit(pmutex) chMtxUnlock()
|
|
||||||
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
|
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
|
||||||
void gfxSleepMilliseconds(delaytime_t ms);
|
void gfxSleepMilliseconds(delaytime_t ms);
|
||||||
void gfxSleepMicroseconds(delaytime_t ms);
|
void gfxSleepMicroseconds(delaytime_t ms);
|
||||||
|
@ -98,4 +121,3 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_
|
||||||
|
|
||||||
#endif /* GFX_USE_OS_CHIBIOS */
|
#endif /* GFX_USE_OS_CHIBIOS */
|
||||||
#endif /* _GOS_CHIBIOS_H */
|
#endif /* _GOS_CHIBIOS_H */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue