aboutsummaryrefslogtreecommitdiffstats
path: root/src/gos
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-02-19 00:36:52 +1000
committerinmarket <andrewh@inmarket.com.au>2014-02-19 00:36:52 +1000
commit37966ff16d923bbca53c9464815cb49cbd7fc3be (patch)
treed92db57067ffadd50cadf3ccf70efba3ac16e114 /src/gos
parent1e131851d6732e22f055c893face6b473a26f111 (diff)
downloaduGFX-37966ff16d923bbca53c9464815cb49cbd7fc3be.tar.gz
uGFX-37966ff16d923bbca53c9464815cb49cbd7fc3be.tar.bz2
uGFX-37966ff16d923bbca53c9464815cb49cbd7fc3be.zip
Integrate the include files with each module. Simplifies structure of code.
Diffstat (limited to 'src/gos')
-rw-r--r--src/gos/chibios.h100
-rw-r--r--src/gos/linux.h94
-rw-r--r--src/gos/osx.h94
-rw-r--r--src/gos/raw32.h125
-rw-r--r--src/gos/sys_defs.h445
-rw-r--r--src/gos/sys_make.mk (renamed from src/gos/gos.mk)0
-rw-r--r--src/gos/sys_options.h67
-rw-r--r--src/gos/sys_rules.h31
-rw-r--r--src/gos/win32.h106
9 files changed, 1062 insertions, 0 deletions
diff --git a/src/gos/chibios.h b/src/gos/chibios.h
new file mode 100644
index 00000000..6373aa43
--- /dev/null
+++ b/src/gos/chibios.h
@@ -0,0 +1,100 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file include/gos/chibios.h
+ * @brief GOS - Operating System Support header file for ChibiOS.
+ */
+
+#ifndef _GOS_CHIBIOS_H
+#define _GOS_CHIBIOS_H
+
+#if GFX_USE_OS_CHIBIOS
+
+#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
+ */
+
+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
+
+#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;
+
+typedef Mutex gfxMutex;
+typedef Thread * gfxThreadHandle;
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define gfxHalt(msg) { chDbgPanic(msg); chSysHalt(); }
+#define gfxExit() chSysHalt()
+#define gfxAlloc(sz) chHeapAlloc(0, sz)
+#define gfxFree(ptr) chHeapFree(ptr)
+#define gfxYield() chThdYield()
+#define gfxSystemTicks() chTimeNow()
+#define gfxMillisecondsToTicks(ms) MS2ST(ms)
+#define gfxSystemLock() chSysLock()
+#define gfxSystemUnlock() chSysUnlock()
+#define gfxMutexInit(pmutex) chMtxInit(pmutex)
+#define gfxMutexDestroy(pmutex) (void)pmutex
+#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
+#define gfxMutexExit(pmutex) chMtxUnlock()
+void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
+void gfxSleepMilliseconds(delaytime_t ms);
+void gfxSleepMicroseconds(delaytime_t ms);
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
+void gfxSemDestroy(gfxSem *psem);
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+void gfxSemSignal(gfxSem *psem);
+void gfxSemSignalI(gfxSem *psem);
+#define gfxSemCounterI(psem) ((psem)->sem.s_cnt)
+#define gfxSemCounter(psem) ((psem)->sem.s_cnt)
+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) (void)thread
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_OS_CHIBIOS */
+#endif /* _GOS_CHIBIOS_H */
+
diff --git a/src/gos/linux.h b/src/gos/linux.h
new file mode 100644
index 00000000..f8b049e9
--- /dev/null
+++ b/src/gos/linux.h
@@ -0,0 +1,94 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file include/gos/linux.h
+ * @brief GOS - Operating System Support header file for LINUX.
+ */
+
+#ifndef _GOS_LINUX_H
+#define _GOS_LINUX_H
+
+#if GFX_USE_OS_LINUX
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <pthread.h>
+
+/* Already defined int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, size_t */
+
+typedef int8_t bool_t;
+typedef unsigned long systemticks_t;
+typedef void * threadreturn_t;
+typedef unsigned long delaytime_t;
+typedef pthread_t gfxThreadHandle;
+typedef int threadpriority_t;
+typedef uint32_t semcount_t;
+typedef pthread_mutex_t gfxMutex;
+
+#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
+#define DECLARE_THREAD_STACK(name, sz) uint8_t name[0];
+
+#define gfxExit() exit(0)
+#define gfxAlloc(sz) malloc(sz)
+#define gfxRealloc(p,osz,nsz) realloc(p, nsz)
+#define gfxFree(ptr) free(ptr)
+#define gfxMillisecondsToTicks(ms) (ms)
+#define gfxYield() pthread_yield()
+#define gfxThreadMe() pthread_self()
+#define gfxThreadClose(th) (void)th
+#define gfxMutexInit(pmtx) pthread_mutex_init(pmtx, 0)
+#define gfxMutexDestroy(pmtx) pthread_mutex_destroy(pmtx)
+#define gfxMutexEnter(pmtx) pthread_mutex_lock(pmtx)
+#define gfxMutexExit(pmtx) pthread_mutex_unlock(pmtx)
+#define gfxSemSignalI(psem) gfxSemSignal(psem)
+#define gfxSemCounterI(pSem) ((pSem)->cnt)
+
+#define TIME_IMMEDIATE 0
+#define TIME_INFINITE ((delaytime_t)-1)
+#define MAX_SEMAPHORE_COUNT ((semcount_t)-1)
+#define LOW_PRIORITY 10
+#define NORMAL_PRIORITY 0
+#define HIGH_PRIORITY -10
+
+typedef struct gfxSem {
+ pthread_mutex_t mtx;
+ pthread_cond_t cond;
+ semcount_t cnt;
+ semcount_t max;
+} gfxSem;
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void gfxHalt(const char *msg);
+void gfxSleepMilliseconds(delaytime_t ms);
+void gfxSleepMicroseconds(delaytime_t ms);
+systemticks_t gfxSystemTicks(void);
+void gfxSystemLock(void);
+void gfxSystemUnlock(void);
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
+void gfxSemDestroy(gfxSem *psem);
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+void gfxSemSignal(gfxSem *psem);
+semcount_t gfxSemCounter(gfxSem *pSem);
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+threadreturn_t gfxThreadWait(gfxThreadHandle thread);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_OS_LINUX */
+
+#endif /* _GOS_LINUX_H */
diff --git a/src/gos/osx.h b/src/gos/osx.h
new file mode 100644
index 00000000..56e0551e
--- /dev/null
+++ b/src/gos/osx.h
@@ -0,0 +1,94 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file include/gos/osx.h
+ * @brief GOS - Operating System Support header file for Mac OS-X.
+ */
+
+#ifndef _GOS_OSX_H
+#define _GOS_OSX_H
+
+#if GFX_USE_OS_OSX
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <pthread.h>
+
+/* Already defined int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, size_t */
+
+typedef int8_t bool_t;
+typedef unsigned long systemticks_t;
+typedef void * threadreturn_t;
+typedef unsigned long delaytime_t;
+typedef pthread_t gfxThreadHandle;
+typedef int threadpriority_t;
+typedef uint32_t semcount_t;
+typedef pthread_mutex_t gfxMutex;
+
+#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
+#define DECLARE_THREAD_STACK(name, sz) uint8_t name[0];
+
+#define gfxExit() exit(0)
+#define gfxAlloc(sz) malloc(sz)
+#define gfxRealloc(p,osz,nsz) realloc(p, nsz)
+#define gfxFree(ptr) free(ptr)
+#define gfxMillisecondsToTicks(ms) (ms)
+#define gfxYield() sched_yield()
+#define gfxThreadMe() pthread_self()
+#define gfxThreadClose(th) (void)th
+#define gfxMutexInit(pmtx) pthread_mutex_init(pmtx, 0)
+#define gfxMutexDestroy(pmtx) pthread_mutex_destroy(pmtx)
+#define gfxMutexEnter(pmtx) pthread_mutex_lock(pmtx)
+#define gfxMutexExit(pmtx) pthread_mutex_unlock(pmtx)
+#define gfxSemSignalI(psem) gfxSemSignal(psem)
+#define gfxSemCounterI(pSem) ((pSem)->cnt)
+
+#define TIME_IMMEDIATE 0
+#define TIME_INFINITE ((delaytime_t)-1)
+#define MAX_SEMAPHORE_COUNT ((semcount_t)-1)
+#define LOW_PRIORITY 10
+#define NORMAL_PRIORITY 0
+#define HIGH_PRIORITY -10
+
+typedef struct gfxSem {
+ pthread_mutex_t mtx;
+ pthread_cond_t cond;
+ semcount_t cnt;
+ semcount_t max;
+} gfxSem;
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void gfxHalt(const char *msg);
+void gfxSleepMilliseconds(delaytime_t ms);
+void gfxSleepMicroseconds(delaytime_t ms);
+systemticks_t gfxSystemTicks(void);
+void gfxSystemLock(void);
+void gfxSystemUnlock(void);
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
+void gfxSemDestroy(gfxSem *psem);
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+void gfxSemSignal(gfxSem *psem);
+semcount_t gfxSemCounter(gfxSem *pSem);
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+threadreturn_t gfxThreadWait(gfxThreadHandle thread);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_OS_OSX */
+
+#endif /* _GOS_OSX_H */
+
diff --git a/src/gos/raw32.h b/src/gos/raw32.h
new file mode 100644
index 00000000..eb5b5e18
--- /dev/null
+++ b/src/gos/raw32.h
@@ -0,0 +1,125 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file include/gos/raw32.h
+ * @brief GOS - Operating System Support header file for any 32 bit processor in bare-metal mode
+ */
+
+/**
+ * The raw32 GOS implementation supports any 32 bit processor with or without an
+ * underlying operating system. It uses cooperative multi-tasking. Be careful
+ * when writing device drivers not to disturb the assumptions this creates by performing
+ * call-backs to uGFX code unless you define the INTERRUPTS_OFF() and INTERRUPTS_ON() macros.
+ * It still requires some C runtime library support...
+ * enough startup to initialise the stack, interrupts, static data etc and call main().
+ * setjmp() and longjmp() - for threading
+ * memcpy() - for heap and threading
+ * malloc(), realloc and free() - if GOS_RAW_HEAP_SIZE == 0
+ *
+ * You must also define the following routines in your own code so that timing functions will work...
+ * systemticks_t gfxSystemTicks(void);
+ * systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
+ */
+#ifndef _GOS_RAW32_H
+#define _GOS_RAW32_H
+
+#if GFX_USE_OS_RAW32
+
+/*===========================================================================*/
+/* Special Macros just for a Raw implementation */
+/*===========================================================================*/
+
+/**
+ * @brief Set the maximum size of the heap.
+ * @note If set to 0 then the C runtime library malloc() and free() are used.
+ */
+#ifndef GOS_RAW_HEAP_SIZE
+ #define GOS_RAW_HEAP_SIZE 0
+#endif
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+typedef unsigned char bool_t;
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
+typedef int int32_t;
+typedef unsigned int uint32_t;
+
+typedef uint32_t size_t;
+typedef uint32_t delaytime_t;
+typedef uint32_t systemticks_t;
+typedef short semcount_t;
+typedef int threadreturn_t;
+typedef int threadpriority_t;
+
+#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
+#define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz];
+
+#define TIME_IMMEDIATE 0
+#define TIME_INFINITE ((delaytime_t)-1)
+#define MAX_SEMAPHORE_COUNT 0x7FFF
+#define LOW_PRIORITY 0
+#define NORMAL_PRIORITY 1
+#define HIGH_PRIORITY 2
+
+typedef struct {
+ semcount_t cnt;
+ semcount_t limit;
+} gfxSem;
+
+typedef uint32_t gfxMutex;
+typedef void * gfxThreadHandle;
+
+#define gfxThreadClose(thread)
+#define gfxMutexDestroy(pmutex)
+#define gfxSemDestroy(psem)
+#define gfxSemCounter(psem) ((psem)->cnt)
+#define gfxSemCounterI(psem) ((psem)->cnt)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ #if GOS_RAW_HEAP_SIZE != 0
+ void gfxAddHeapBlock(void *ptr, size_t sz);
+ #endif
+
+ void gfxHalt(const char *msg);
+ void gfxExit(void);
+ void *gfxAlloc(size_t sz);
+ void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
+ void gfxFree(void *ptr);
+ void gfxYield(void);
+ void gfxSleepMilliseconds(delaytime_t ms);
+ void gfxSleepMicroseconds(delaytime_t ms);
+ systemticks_t gfxSystemTicks(void);
+ systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
+ void gfxSystemLock(void);
+ void gfxSystemUnlock(void);
+ void gfxMutexInit(gfxMutex *pmutex);
+ void gfxMutexEnter(gfxMutex *pmutex);
+ void gfxMutexExit(gfxMutex *pmutex);
+ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
+ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+ void gfxSemSignal(gfxSem *psem);
+ void gfxSemSignalI(gfxSem *psem);
+ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+ threadreturn_t gfxThreadWait(gfxThreadHandle thread);
+ gfxThreadHandle gfxThreadMe(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_OS_RAW32 */
+#endif /* _GOS_RAW32_H */
+
diff --git a/src/gos/sys_defs.h b/src/gos/sys_defs.h
new file mode 100644
index 00000000..b913fb66
--- /dev/null
+++ b/src/gos/sys_defs.h
@@ -0,0 +1,445 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gos/sys_defs.h
+ * @brief GOS - Operating System Support header file
+ *
+ * @addtogroup GOS
+ *
+ * @brief Module to build a uniform abstraction layer between uGFX and the underlying system
+ *
+ * @note Some of the routines specified below may be implemented simply as
+ * a macro to the real operating system call.
+ * @{
+ */
+
+#ifndef _GOS_H
+#define _GOS_H
+
+#if defined(__DOXYGEN__)
+ /*===========================================================================*/
+ /* Type definitions */
+ /*===========================================================================*/
+
+ /**
+ * @brief Various integer sizes
+ * @note Your platform may use slightly different definitions to these
+ * @{
+ */
+ typedef unsigned char bool_t;
+ typedef char int8_t;
+ typedef unsigned char uint8_t;
+ typedef short int16_t;
+ typedef unsigned short uint16_t;
+ typedef long int32_t;
+ typedef unsigned long uint32_t;
+ /**
+ * @}
+ *
+ * @brief Various platform (and operating system) dependent types
+ * @note Your platform may use slightly different definitions to these
+ * @{
+ */
+ typedef unsigned long size_t;
+ typedef unsigned long delaytime_t;
+ typedef unsigned long systemticks_t;
+ typedef short semcount_t;
+ typedef int threadreturn_t;
+ typedef int threadpriority_t;
+
+ /**
+ * @brief Declare a thread stack and function
+ * @{
+ */
+ #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
+ #define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz];
+ /* @} */
+
+ /**
+ * @}
+ *
+ * @brief Various platform (and operating system) constants
+ * @note Your platform may use slightly different definitions to these
+ * @{
+ */
+ #define FALSE 0
+ #define TRUE 1
+ #define TIME_IMMEDIATE 0
+ #define TIME_INFINITE ((delaytime_t)-1)
+ #define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
+ #define LOW_PRIORITY 0
+ #define NORMAL_PRIORITY 1
+ #define HIGH_PRIORITY 2
+ /* @} */
+
+ /**
+ * @brief A semaphore
+ * @note Your operating system will have a proper definition for this structure
+ */
+ typedef struct {} gfxSem;
+
+ /**
+ * @brief A mutex
+ * @note Your operating system will have a proper definition for this structure
+ */
+ typedef struct {} gfxMutex;
+
+ /**
+ * @brief A thread handle
+ * @note Your operating system will have a proper definition for this.
+ */
+ typedef void * gfxThreadHandle;
+
+ /*===========================================================================*/
+ /* Function declarations. */
+ /*===========================================================================*/
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+ /**
+ * @brief Halt the GFX application due to an error.
+ *
+ * @param[in] msg An optional debug message to show (Can be NULL)
+ *
+ * @api
+ */
+ void gfxHalt(const char *msg);
+
+ /**
+ * @brief Exit the GFX application.
+ *
+ * @api
+ */
+ void gfxExit(void);
+
+ /**
+ * @brief Allocate memory
+ * @return A pointer to the memory allocated or NULL if there is no more memory available
+ *
+ * @param[in] sz The size in bytes of the area to allocate
+ *
+ * @api
+ */
+ void *gfxAlloc(size_t sz);
+
+ /**
+ * @brief Re-allocate memory
+ * @return A pointer to the new memory area or NULL if there is no more memory available
+ *
+ * @param[in] ptr The old memory area to be increased/decreased in size
+ * @param[in] oldsz The size in bytes of the old memory area
+ * @param[in] newsz The size in bytes of the new memory area
+ *
+ * @note Some operating systems don't use the oldsz parameter as they implicitly know the size of
+ * old memory area. The parameter must always be supplied however for API compatibility.
+ * @note gfxRealloc() can make the area smaller or larger but may have to return a different pointer.
+ * If this occurs the new area contains a copy of the data from the old area. The old memory
+ * pointer should not be used after this routine as the original area may have been freed.
+ * @note If there is insufficient memory to create the new memory region, NULL is returned and the
+ * old memory area is left unchanged.
+ *
+ * @api
+ */
+ void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
+
+ /**
+ * @brief Free memory
+ *
+ * @param[in] ptr The memory to free
+ *
+ * @api
+ */
+ void gfxFree(void *ptr);
+
+ /**
+ * @brief Yield the current thread
+ * @details Give up the rest of the current time slice for this thread in order to give other threads
+ * a chance to run.
+ *
+ * @api
+ */
+ void gfxYield(void);
+
+ /**
+ * @brief Put the current thread to sleep for the specified period in milliseconds
+ *
+ * @param[in] ms The number milliseconds to sleep
+ *
+ * @note Specifying TIME_IMMEDIATE will yield the current thread but return
+ * on the next time slice.
+ * @note Specifying TIME_INFINITE will sleep forever.
+ *
+ * @api
+ */
+ void gfxSleepMilliseconds(delaytime_t ms);
+
+ /**
+ * @brief Put the current thread to sleep for the specified period in microseconds
+ *
+ * @param[in] ms The number microseconds to sleep
+ *
+ * @note Specifying TIME_IMMEDIATE will return immediately (no sleeping)
+ * @note Specifying TIME_INFINITE will sleep forever.
+ *
+ * @api
+ */
+ void gfxSleepMicroseconds(delaytime_t ms);
+
+ /**
+ * @brief Get the current operating system tick time
+ * @return The current tick time
+ *
+ * @note A "tick" is an arbitrary period of time that the operating
+ * system uses to mark time.
+ * @note The absolute value of this call is relatively meaningless. Its usefulness
+ * is in calculating periods between two calls to this function.
+ * @note As the value from this function can wrap it is important that any periods are calculated
+ * as t2 - t1 and then compared to the desired period rather than comparing
+ * t1 + period to t2
+ *
+ * @api
+ */
+ systemticks_t gfxSystemTicks(void);
+
+ /**
+ * @brief Convert a given number of millseconds to a number of operating system ticks
+ * @return The period in system ticks.
+ *
+ * @note A "tick" is an arbitrary period of time that the operating
+ * system uses to mark time.
+ *
+ * @param[in] ms The number of millseconds
+ *
+ * @api
+ */
+ systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
+
+ /**
+ * @brief Lock the operating system to protect a sequence of code
+ *
+ * @note Calling this will lock out all other threads from executing even at interrupt level
+ * within the GFX system. On hardware this may be implemented as a disabling of interrupts,
+ * however in an operating system which hides real interrupt level code it may simply use a
+ * mutex lock.
+ * @note The thread MUST NOT block whilst the system is locked. It must execute in this state for
+ * as short a period as possible as this can seriously affect interrupt latency on some
+ * platforms.
+ * @note While locked only interrupt level (iclass) GFX routines may be called.
+ *
+ * @api
+ */
+ void gfxSystemLock(void);
+
+ /**
+ * @brief Unlock the operating system previous locked by gfxSystemLock()
+ *
+ * @api
+ */
+ void gfxSystemUnlock(void);
+
+ /**
+ * @brief Initialise a mutex to protect a region of code from other threads.
+ *
+ * @param[in] pmutex A pointer to the mutex
+ *
+ * @note Whilst a counting semaphore with a limit of 1 can be used for similiar purposes
+ * on many operating systems using a seperate mutex structure is more efficient.
+ *
+ * @api
+ */
+ void gfxMutexInit(gfxMutex *pmutex);
+
+ /**
+ * @brief Destroy a Mutex.
+ *
+ * @param[in] pmutex A pointer to the mutex
+ *
+ * @api
+ */
+ void gfxMutexDestroy(gfxMutex *pmutex);
+
+ /**
+ * @brief Enter the critical code region protected by the mutex.
+ * @details Blocks until there is no other thread in the critical region.
+ *
+ * @param[in] pmutex A pointer to the mutex
+ *
+ * @api
+ */
+ void gfxMutexEnter(gfxMutex *pmutex);
+
+ /**
+ * @brief Exit the critical code region protected by the mutex.
+ * @details May cause another thread waiting on the mutex to now be placed into the run queue.
+ *
+ * @param[in] pmutex A pointer to the mutex
+ *
+ * @api
+ */
+ void gfxMutexExit(gfxMutex *pmutex);
+
+ /**
+ * @brief Initialise a Counted Semaphore
+ *
+ * @param[in] psem A pointer to the semaphore
+ * @param[in] val The initial value of the semaphore
+ * @param[in] limit The maxmimum value of the semaphore
+ *
+ * @note Operations defined for counted semaphores:
+ * Signal: The semaphore counter is increased and if the result is non-positive then a waiting thread
+ * is queued for execution. Note that once the thread reaches "limit", further signals are
+ * ignored.
+ * Wait: The semaphore counter is decreased and if the result becomes negative the thread is queued
+ * in the semaphore and suspended.
+ *
+ * @api
+ */
+ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
+
+ /**
+ * @brief Destroy a Counted Semaphore
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @note Any threads waiting on the semaphore will be released
+ *
+ * @api
+ */
+ void gfxSemDestroy(gfxSem *psem);
+
+ /**
+ * @brief Wait on a semaphore
+ * @details The semaphore counter is decreased and if the result becomes negative the thread waits for it to become
+ * non-negative again
+ * @return FALSE if the wait timeout occurred otherwise TRUE
+ *
+ * @param[in] psem A pointer to the semaphore
+ * @param[in] ms The maximum time to wait for the semaphore
+ *
+ * @api
+ */
+ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+
+ /**
+ * @brief Signal a semaphore
+ * @details The semaphore counter is increased and if the result is non-positive then a waiting thread
+ * is queued for execution. Note that once the thread reaches "limit", further signals are
+ * ignored.
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @api
+ */
+ void gfxSemSignal(gfxSem *psem);
+
+ /**
+ * @brief Signal a semaphore
+ * @details The semaphore counter is increased and if the result is non-positive then a waiting thread
+ * is queued for execution. Note that once the thread reaches "limit", further signals are
+ * ignored.
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @iclass
+ * @api
+ */
+ void gfxSemSignalI(gfxSem *psem);
+
+ /**
+ * @brief Get the current semaphore count
+ * @return The current semaphore count
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @api
+ */
+ semcount_t gfxSemCounter(gfxSem *psem);
+
+ /**
+ * @brief Get the current semaphore count
+ * @return The current semaphore count
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @iclass
+ * @api
+ */
+ semcount_t gfxSemCounterI(gfxSem *psem);
+
+ /**
+ * @brief Start a new thread.
+ * @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
+ * is only valid when stackarea is dynamically allocated.
+ * @param[in] prio The priority of the new thread
+ * @param[in] fn The function the new thread will run
+ * @param[in] param A parameter to pass the thread function.
+ *
+ * @api
+ */
+ 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
+ }
+ #endif
+
+/**
+ * All the above was just for the doxygen documentation. All the implementation of the above
+ * (without any of the documentation overheads) is in the files below.
+ */
+#elif GFX_USE_OS_CHIBIOS
+ #include "src/gos/chibios.h"
+#elif GFX_USE_OS_WIN32
+ #include "src/gos/win32.h"
+#elif GFX_USE_OS_LINUX
+ #include "src/gos/linux.h"
+#elif GFX_USE_OS_OSX
+ #include "src/gos/osx.h"
+#elif GFX_USE_OS_RAW32
+ #include "src/gos/raw32.h"
+#else
+ #error "Your operating system is not supported yet"
+#endif
+
+#endif /* _GOS_H */
+/** @} */
diff --git a/src/gos/gos.mk b/src/gos/sys_make.mk
index 9db29fe2..9db29fe2 100644
--- a/src/gos/gos.mk
+++ b/src/gos/sys_make.mk
diff --git a/src/gos/sys_options.h b/src/gos/sys_options.h
new file mode 100644
index 00000000..ae9916ad
--- /dev/null
+++ b/src/gos/sys_options.h
@@ -0,0 +1,67 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gos/sys_options.h
+ * @brief GOS - Operating System options header file.
+ *
+ * @addtogroup GOS
+ * @{
+ */
+
+#ifndef _GOS_OPTIONS_H
+#define _GOS_OPTIONS_H
+
+/**
+ * @name GOS The operating system to use. One (and only one) of these must be defined.
+ * @{
+ */
+ /**
+ * @brief Use ChibiOS
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_CHIBIOS
+ #define GFX_USE_OS_CHIBIOS FALSE
+ #endif
+ /**
+ * @brief Use Win32
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_WIN32
+ #define GFX_USE_OS_WIN32 FALSE
+ #endif
+ /**
+ * @brief Use a linux based system running X11
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_LINUX
+ #define GFX_USE_OS_LINUX FALSE
+ #endif
+ /**
+ * @brief Use a Mac OS-X based system
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_OSX
+ #define GFX_USE_OS_OSX FALSE
+ #endif
+ /**
+ * @brief Use a Raw 32 bit CPU based system
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_RAW32
+ #define GFX_USE_OS_RAW32 FALSE
+ #endif
+/**
+ * @}
+ *
+ * @name GOS Optional Sizing Parameters
+ * @{
+ */
+/** @} */
+
+#endif /* _GOS_OPTIONS_H */
+/** @} */
diff --git a/src/gos/sys_rules.h b/src/gos/sys_rules.h
new file mode 100644
index 00000000..390e8116
--- /dev/null
+++ b/src/gos/sys_rules.h
@@ -0,0 +1,31 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file src/gos/sys_rules.h
+ * @brief GOS safety rules header file.
+ *
+ * @addtogroup GOS
+ * @{
+ */
+
+#ifndef _GOS_RULES_H
+#define _GOS_RULES_H
+
+#if !GFX_USE_OS_CHIBIOS && !GFX_USE_OS_WIN32 && !GFX_USE_OS_LINUX && !GFX_USE_OS_OSX && !GFX_USE_OS_RAW32
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GOS: No Operating System has been defined. ChibiOS (GFX_USE_OS_CHIBIOS) has been turned on for you."
+ #endif
+ #undef GFX_USE_OS_CHIBIOS
+ #define GFX_USE_OS_CHIBIOS TRUE
+#endif
+#if GFX_USE_OS_CHIBIOS + GFX_USE_OS_WIN32 + GFX_USE_OS_LINUX + GFX_USE_OS_OSX + GFX_USE_OS_RAW32 != 1 * TRUE
+ #error "GOS: More than one operation system has been defined as TRUE."
+#endif
+
+#endif /* _GOS_RULES_H */
+/** @} */
diff --git a/src/gos/win32.h b/src/gos/win32.h
new file mode 100644
index 00000000..c704a288
--- /dev/null
+++ b/src/gos/win32.h
@@ -0,0 +1,106 @@
+/*
+ * 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:
+ *
+ * http://ugfx.org/license.html
+ */
+
+/**
+ * @file include/gos/win32.h
+ * @brief GOS - Operating System Support header file for WIN32.
+ */
+
+#ifndef _GOS_WIN32_H
+#define _GOS_WIN32_H
+
+#if GFX_USE_OS_WIN32
+
+#ifndef _WIN32_WINNT
+ #define _WIN32_WINNT 0x0501 // Windows XP and up
+#endif
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#undef WIN32_LEAN_AND_MEAN
+
+#include <malloc.h>
+
+/* Stop cygwin from defining these types */
+#define __int8_t_defined
+
+/**
+ * size_t
+ * TRUE, FALSE
+ * are already defined by Win32
+ */
+typedef __int8 bool_t;
+typedef __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef DWORD delaytime_t;
+typedef DWORD systemticks_t;
+typedef LONG semcount_t;
+typedef DWORD threadreturn_t;
+typedef int threadpriority_t;
+
+#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
+#define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
+#define LOW_PRIORITY THREAD_PRIORITY_BELOW_NORMAL
+#define NORMAL_PRIORITY THREAD_PRIORITY_NORMAL
+#define HIGH_PRIORITY THREAD_PRIORITY_ABOVE_NORMAL
+
+typedef HANDLE gfxSem;
+typedef HANDLE gfxMutex;
+typedef HANDLE gfxThreadHandle;
+
+#define gfxExit() ExitProcess(0)
+#define gfxAlloc(sz) malloc(sz)
+#define gfxRealloc(p,osz,nsz) realloc(p, nsz)
+#define gfxFree(ptr) free(ptr)
+#define gfxSleepMilliseconds(ms) Sleep(ms)
+#define gfxYield() Sleep(0)
+#define gfxSystemTicks() GetTickCount()
+#define gfxMillisecondsToTicks(ms) (ms)
+#define gfxMutexInit(pmutex) *(pmutex) = CreateMutex(0, FALSE, 0)
+#define gfxMutexDestroy(pmutex) CloseHandle(*(pmutex))
+#define gfxMutexEnter(pmutex) WaitForSingleObject(*(pmutex), INFINITE)
+#define gfxMutexExit(pmutex) ReleaseMutex(*(pmutex))
+#define gfxSemInit(psem, val, limit) *(psem) = CreateSemaphore(0, val, limit, 0)
+#define gfxSemDestroy(psem) CloseHandle(*(psem))
+#define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, 0)
+#define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, 0)
+#define gfxSemCounterI(psem) gfxSemCounter(psem)
+#define gfxThreadMe() GetCurrentThread()
+#define gfxThreadClose(thread) CloseHandle(thread)
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void gfxHalt(const char *msg);
+void gfxSleepMicroseconds(delaytime_t ms);
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+semcount_t gfxSemCounter(gfxSem *pSem);
+void gfxSystemLock(void);
+void gfxSystemUnlock(void);
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+threadreturn_t gfxThreadWait(gfxThreadHandle thread);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_OS_WIN32 */
+#endif /* _GOS_WIN32_H */
+