aboutsummaryrefslogtreecommitdiffstats
path: root/include/gos
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-05-26 02:06:55 +1000
committerinmarket <andrewh@inmarket.com.au>2013-05-26 02:06:55 +1000
commit8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a (patch)
treec52d7733525727320d2de00acedb42bc18124471 /include/gos
parent7fbfde42aabbcd30cffba2fba35158236c0a6c6c (diff)
downloaduGFX-8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a.tar.gz
uGFX-8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a.tar.bz2
uGFX-8fcbf4e5d5cc88d52f4e6e67ebead27fc856ff4a.zip
More GOS module changes
GQUEUE as a seperate module GOS changes including basic Win32 O/S support
Diffstat (limited to 'include/gos')
-rw-r--r--include/gos/chibios.h37
-rw-r--r--include/gos/gos.h227
-rw-r--r--include/gos/win32.h74
3 files changed, 151 insertions, 187 deletions
diff --git a/include/gos/chibios.h b/include/gos/chibios.h
index 37bf93ee..1fa93141 100644
--- a/include/gos/chibios.h
+++ b/include/gos/chibios.h
@@ -67,17 +67,6 @@ typedef struct {
#define gfxMutex Mutex
-typedef struct gfxQueue {
- struct gfxQueueItem *head;
- struct gfxQueueItem *tail;
- Semaphore sem;
- } gfxQueue;
-
-typedef struct gfxQueueItem {
- struct gfxQueueItem *next;
- Semaphore sem;
- } gfxQueueItem;
-
/*===========================================================================*/
/* Function declarations. */
/*===========================================================================*/
@@ -90,30 +79,24 @@ extern "C" {
#define gfxExit() chSysHalt()
#define gfxAlloc(sz) chHeapAlloc(NULL, 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) ;
+#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
+#define gfxMutexExit(pmutex) chMtxUnlock()
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)
-#define gfxSystemTicks() chTimeNow()
-#define gfxMillisecondsToTicks(ms) MS2ST(ms)
-#define gfxYield() chThdYield()
-#define gfxSystemLock() chSysLock()
-#define gfxSystemUnlock() chSysUnlock()
-#define gfxMutexInit(pmutex) chMtxInit(pmutex)
-#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
-#define gfxMutexExit(pmutex) chMtxUnlock()
-void gfxQueueInit(gfxQueue *pqueue);
-gfxQueueItem * gfxQueueGet(gfxQueue *pqueue, delaytime_t ms);
-bool_t gfxQueuePut(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
-#define gfxQueuePop(q) gfxQueueGet(q)
-bool_t gfxQueuePush(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
-void gfxQueueRemove(gfxQueue *pqueue, gfxQueueItem *pitem);
-bool_t gfxQueueIsEmpty(gfxQueue *pqueue);
-bool_t gfxQueueIsIn(gfxQueue *pqueue, gfxQueueItem *pitem);
bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
#ifdef __cplusplus
diff --git a/include/gos/gos.h b/include/gos/gos.h
index 04799540..d979cd27 100644
--- a/include/gos/gos.h
+++ b/include/gos/gos.h
@@ -37,11 +37,6 @@
/*===========================================================================*/
/**
- * @brief A function for a new thread to execute.
- */
- typedef threadreturn_t (*gfxThreadFunction)(void *param);
-
- /**
* @brief Various integer sizes
* @note Your platform may use slightly different definitions to these
* @{
@@ -67,6 +62,10 @@
typedef int threadreturn_t;
typedef int threadpriority_t;
/**
+ * @brief A function for a new thread to execute.
+ */
+ typedef threadreturn_t (*gfxThreadFunction)(void *param);
+ /**
* @}
*
* @brief Various platform (and operating system) constants
@@ -77,7 +76,7 @@
#define TRUE 1
#define TIME_IMMEDIATE 0
#define TIME_INFINITE ((delaytime_t)-1)
- #define MAX_SEMAPHORE_COUNT ((semcount_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
@@ -96,18 +95,6 @@
*/
typedef struct {} gfxMutex;
- /**
- * @brief A queue
- * @note Your operating system will have a proper definition for this structure
- */
- typedef struct {} gfxQueue;
-
- /**
- * @brief A queue item
- * @note Your operating system will have a proper definition for this structure
- */
- typedef struct {} gfxQueueItem;
-
/*===========================================================================*/
/* Function declarations. */
/*===========================================================================*/
@@ -152,6 +139,15 @@
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
@@ -177,83 +173,6 @@
void gfxSleepMicroseconds(delaytime_t ms);
/**
- * @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 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 maxmimum 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 Get the current operating system tick time
* @return The current tick time
*
@@ -283,15 +202,6 @@
systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
/**
- * @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 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
@@ -327,6 +237,15 @@
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.
*
@@ -347,104 +266,92 @@
void gfxMutexExit(gfxMutex *pmutex);
/**
- * @brief Initialise a queue.
- *
- * @param[in] pqueue A pointer to the queue
- *
- * @note Whilst queues are normally FIFO, a GFX queue also supports push and pop operations.
- * A pop operation is the same as normal get from the queue but a push places the item
- * at the head of the queue instead of the tail (as a put would).
+ * @brief Initialise a Counted Semaphore
*
- * @api
- */
- void gfxQueueInit(gfxQueue *pqueue);
-
- /**
- * @brief Get an item from the head of the queue.
- * @return NULL if the timeout expires before an item is available
+ * @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
*
- * @param[in] pqueue A pointer to the queue
- * @param[in] ms The maxmimum time to wait for an item
+ * @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
*/
- gfxQueueItem * gfxQueueGet(gfxQueue *pqueue, delaytime_t ms);
+ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
/**
- * @brief Put an item on the end of the queue.
- * @return FALSE on timeout, otherwise TRUE
+ * @brief Destroy a Counted Semaphore
*
- * @param[in] pqueue A pointer to the queue
- * @param[in] pitem A pointer to the queue item
- * @param[in] ms The maxmimum time to wait for an item to be removed from the queue
+ * @param[in] psem A pointer to the semaphore
*
- * @note Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
- * item is removed from the queue
+ * @note Any threads waiting on the semaphore will be released
*
* @api
*/
- bool_t gfxQueuePut(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
+ void gfxSemDestroy(gfxSem *psem);
/**
- * @brief Pop an item from the head of the queue.
- * @return NULL if there are no more items on the queue
+ * @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] pqueue A pointer to the queue
+ * @param[in] psem A pointer to the semaphore
+ * @param[in] ms The maxmimum time to wait for the semaphore
*
* @api
*/
- #define gfxQueuePop(pqueue, ms) gfxQueueGet(pqueue, ms)
+ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
/**
- * @brief Push an item into the start of the queue.
- * @return FALSE on timeout, otherwise TRUE
- *
- * @param[in] pqueue A pointer to the queue
- * @param[in] pitem A pointer to the queue item
- * @param[in] ms The maxmimum time to wait for an item to be popped
+ * @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.
*
- * @note Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
- * item is removed from the queue
+ * @param[in] psem A pointer to the semaphore
*
* @api
*/
- bool_t gfxQueuePush(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
+ void gfxSemSignal(gfxSem *psem);
/**
- * @brief Remove an item from the queue.
- * @note Removes the specified item from the queue whereever it is in the queue
- *
- * @param[in] pqueue A pointer to the queue
- * @param[in] pitem A pointer to the queue item
+ * @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.
*
- * @note If the item isn't in the queue the routine just returns.
+ * @param[in] psem A pointer to the semaphore
*
+ * @iclass
* @api
*/
- void gfxQueueRemove(gfxQueue *pqueue, gfxQueueItem *pitem);
+ void gfxSemSignalI(gfxSem *psem);
/**
- * @brief Is the queue empty?
- * @return TRUE if the queue is empty
+ * @brief Get the current semaphore count
+ * @return The current semaphore count
*
- * @param[in] pqueue A pointer to the queue
+ * @param[in] psem A pointer to the semaphore
*
* @api
*/
- bool_t gfxQueueIsEmpty(gfxQueue *pqueue);
+ semcount_t gfxSemCounter(gfxSem *pSem);
/**
- * @brief Is an item in the queue?
- * @return TRUE if the item is in the queue?
- *
- * @param[in] pqueue A pointer to the queue
- * @param[in] pitem A pointer to the queue item
+ * @brief Get the current semaphore count
+ * @return The current semaphore count
*
- * @note This operation may be expensive.
+ * @param[in] psem A pointer to the semaphore
*
+ * @iclass
* @api
*/
- bool_t gfxQueueIsIn(gfxQueue *pqueue, gfxQueueItem *pitem);
+ semcount_t gfxSemCounterI(gfxSem *pSem);
/**
* @brief Start a new thread.
diff --git a/include/gos/win32.h b/include/gos/win32.h
index a6f28865..80a1f430 100644
--- a/include/gos/win32.h
+++ b/include/gos/win32.h
@@ -26,6 +26,80 @@
#define _GOS_WIN32_H
#if GFX_USE_OS_WIN32
+
+//#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+/**
+ * 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;
+#define threadreturn_t DWORD WINAPI
+typedef int threadpriority_t;
+
+typedef threadreturn_t (*gfxThreadFunction)(void *param);
+
+#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
+#define DECLARESTACK(name, sz) uint8_t name[0];
+
+typedef HANDLE gfxSem;
+typedef HANDLE gfxMutex;
+
+#define gfxExit() ExitProcess(0)
+#define gfxAlloc(sz) malloc(sz)
+#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(NULL, FALSE, NULL)
+#define gfxMutexDestory(pmutex) CloseHandle(*(pmutex))
+#define gfxMutexEnter(pmutex) WaitForSingleObject(*(pmutex), INFINITE)
+#define gfxMutexExit(pmutex) ReleaseMutex(*(pmutex))
+#define gfxSemInit(psem, val, limit) *(psem) = CreateSemaphore(NULL, val, limit, NULL)
+#define gfxSemDestory(psem) CloseHandle(*(psem))
+#define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, NULL)
+#define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, NULL)
+#define gfxSemCounterI(psem) gfxSemCounter(psem)
+
+/*===========================================================================*/
+/* 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);
+bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
#endif /* GFX_USE_OS_WIN32 */
#endif /* _GOS_WIN32_H */