From 1c258a82738e145953fc9cf40c68dcce6db87d92 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 2 Jun 2013 18:57:22 +1000 Subject: GOS updates --- include/gfx.h | 17 +++++++++++++-- include/ginput/lld/toggle.h | 2 +- include/gos/chibios.h | 15 +++++++------ include/gos/gos.h | 51 ++++++++++++++++++++++++++++++++++++++++----- include/gos/win32.h | 15 +++++++++---- include/gqueue/gqueue.h | 4 ++-- 6 files changed, 84 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/gfx.h b/include/gfx.h index b2c84daf..7c82243b 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -35,6 +35,19 @@ #define TRUE -1 #endif +/** + * @brief Mark a function as deprecated. + */ +#ifndef DEPRECATED + #if defined(__GNUC__) || defined(__MINGW32_) || defined(__CYGWIN__) + #define DEPRECATED(msg) __attribute__((deprecated(msg))) + #elif defined(_MSC_VER) + #define DEPRECATED(msg) __declspec(deprecated(msg)) + #else + #define DEPRECATED(msg) + #endif +#endif + /* gfxconf.h is the user's project configuration for the GFX system. */ #include "gfxconf.h" @@ -199,8 +212,8 @@ extern "C" { */ void gfxInit(void); - /* compatibility for old programs - throws a #warning */ - void gdispInit(void); + /* Compatibility for old programs */ + void DEPRECATED("Use gfxInit() instead") gdispInit(void); #ifdef __cplusplus } diff --git a/include/ginput/lld/toggle.h b/include/ginput/lld/toggle.h index 869b92f8..8db4bea6 100644 --- a/include/ginput/lld/toggle.h +++ b/include/ginput/lld/toggle.h @@ -24,7 +24,7 @@ typedef struct GToggleConfig_t { void *id; unsigned mask; unsigned invert; - iomode_t mode; + unsigned mode; } GToggleConfig; /*===========================================================================*/ diff --git a/include/gos/chibios.h b/include/gos/chibios.h index 1fa93141..280a9a45 100644 --- a/include/gos/chibios.h +++ b/include/gos/chibios.h @@ -51,21 +51,21 @@ typedef cnt_t semcount_t; typedef msg_t threadreturn_t; typedef tprio_t threadpriority_t; -typedef threadreturn_t (*gfxThreadFunction)(void *param); - #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 DECLARESTACK(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) typedef struct { Semaphore sem; semcount_t limit; } gfxSem; -#define gfxMutex Mutex +typedef Mutex gfxMutex; +typedef Thread * gfxThreadHandle; /*===========================================================================*/ /* Function declarations. */ @@ -85,7 +85,7 @@ extern "C" { #define gfxSystemLock() chSysLock() #define gfxSystemUnlock() chSysUnlock() #define gfxMutexInit(pmutex) chMtxInit(pmutex) -#define gfxMutexDestroy(pmutex) ; +#define gfxMutexDestroy(pmutex) {} #define gfxMutexEnter(pmutex) chMtxLock(pmutex) #define gfxMutexExit(pmutex) chMtxUnlock() void gfxSleepMilliseconds(delaytime_t ms); @@ -97,7 +97,10 @@ void gfxSemSignal(gfxSem *psem); void gfxSemSignalI(gfxSem *psem); #define gfxSemCounterI(psem) ((psem)->sem.s_cnt) #define gfxSemCounter(psem) ((psem)->sem.s_cnt) -bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param); +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) {} #ifdef __cplusplus } diff --git a/include/gos/gos.h b/include/gos/gos.h index d979cd27..177349cf 100644 --- a/include/gos/gos.h +++ b/include/gos/gos.h @@ -61,10 +61,15 @@ typedef short semcount_t; typedef int threadreturn_t; typedef int threadpriority_t; + /** - * @brief A function for a new thread to execute. + * @brief Declare a thread stack and function + * @{ */ - typedef threadreturn_t (*gfxThreadFunction)(void *param); + #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) + #define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz]; + /* @} */ + /** * @} * @@ -80,7 +85,6 @@ #define LOW_PRIORITY 0 #define NORMAL_PRIORITY 1 #define HIGH_PRIORITY 2 - #define DECLARESTACK(name, sz) uint8_t name[sz]; /* @} */ /** @@ -95,6 +99,12 @@ */ typedef struct {} gfxMutex; + /** + * @brief A thread handle + * @note Your operating system will have a proper definition for this. + */ + typedef void * gfxThreadHandle; + /*===========================================================================*/ /* Function declarations. */ /*===========================================================================*/ @@ -355,7 +365,7 @@ /** * @brief Start a new thread. - * @return Return TRUE if the thread was started, FALSE on an error + * @return Returns a thread handle if the thread was started, NULL on an error * * @param[in] stackarea A pointer to the area for the new threads stack or NULL to dynamically allocate it * @param[in] stacksz The size of the thread stack. 0 means the default operating system size although this @@ -366,7 +376,38 @@ * * @api */ - bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param); + gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); + + /** + * @brief Wait for a thread to finish. + * @return Returns the thread exit code. + * + * @param[in] thread The Thread Handle + * + * @note This will also close the thread handle as it is no longer useful + * once the thread has ended. + * @api + */ + threadreturn_t gfxThreadWait(gfxThreadHandle thread); + + /** + * @brief Get the current thread handle. + * @return A thread handle + * + * @api + */ + gfxThreadHandle gfxThreadMe(void); + + /** + * @brief Close the thread handle. + * + * @param[in] thread The Thread Handle + * + * @note This does not affect the thread, it just closes our handle to the thread. + * + * @api + */ + void gfxThreadClose(gfxThreadHandle thread); #ifdef __cplusplus } diff --git a/include/gos/win32.h b/include/gos/win32.h index 80a1f430..d61de187 100644 --- a/include/gos/win32.h +++ b/include/gos/win32.h @@ -30,6 +30,9 @@ //#define WIN32_LEAN_AND_MEAN #include +/* Stop cygwin from defining these types */ +#define __int8_t_defined + /** * size_t * TRUE, FALSE @@ -45,10 +48,11 @@ typedef unsigned __int32 uint32_t; typedef DWORD delaytime_t; typedef DWORD systemticks_t; typedef LONG semcount_t; -#define threadreturn_t DWORD WINAPI +typedef DWORD threadreturn_t; typedef int threadpriority_t; -typedef threadreturn_t (*gfxThreadFunction)(void *param); +#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t WINAPI fnName(void *param) +#define DECLARE_THREAD_STACK(name, sz) uint8_t name[0]; #define TIME_IMMEDIATE 0 #define TIME_INFINITE INFINITE @@ -56,10 +60,10 @@ typedef threadreturn_t (*gfxThreadFunction)(void *param); #define LOW_PRIORITY THREAD_PRIORITY_BELOW_NORMAL #define NORMAL_PRIORITY THREAD_PRIORITY_NORMAL #define HIGH_PRIORITY THREAD_PRIORITY_ABOVE_NORMAL -#define DECLARESTACK(name, sz) uint8_t name[0]; typedef HANDLE gfxSem; typedef HANDLE gfxMutex; +typedef HANDLE gfxThreadHandle; #define gfxExit() ExitProcess(0) #define gfxAlloc(sz) malloc(sz) @@ -77,6 +81,8 @@ typedef HANDLE gfxMutex; #define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, NULL) #define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, NULL) #define gfxSemCounterI(psem) gfxSemCounter(psem) +#define gfxThreadMe() GetCurrentThread() +#define gfxThreadClose(thread) CloseHandle(thread) /*===========================================================================*/ /* Function declarations. */ @@ -92,7 +98,8 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); semcount_t gfxSemCounter(gfxSem *pSem); void gfxSystemLock(void); void gfxSystemUnlock(void); -bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param); +gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); +threadreturn_t gfxThreadWait(gfxThreadHandle thread); #ifdef __cplusplus } diff --git a/include/gqueue/gqueue.h b/include/gqueue/gqueue.h index deeca93b..38c1908d 100644 --- a/include/gqueue/gqueue.h +++ b/include/gqueue/gqueue.h @@ -47,7 +47,7 @@ typedef struct gfxQueueASync { struct gfxQueueASyncItem *head; struct gfxQueueASyncItem *tail; - } gfxQueueAsync; + } gfxQueueASync; typedef struct gfxQueueGSync { struct gfxQueueGSyncItem *head; struct gfxQueueGSyncItem *tail; @@ -57,7 +57,7 @@ typedef struct gfxQueueFSync { struct gfxQueueFSyncItem *head; struct gfxQueueFSyncItem *tail; gfxSem sem; - } gfxQueueGSync; + } gfxQueueFSync; /* @} */ /** -- cgit v1.2.3