aboutsummaryrefslogtreecommitdiffstats
path: root/src/gos
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-05-25 01:26:52 +1000
committerinmarket <andrewh@inmarket.com.au>2013-05-25 01:26:52 +1000
commit7fbfde42aabbcd30cffba2fba35158236c0a6c6c (patch)
treee85c90a4f21974b706315d64209021e0b2bde764 /src/gos
parent42006a67b5ccfd86f30d8a91cc474681c437eaf6 (diff)
downloaduGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.tar.gz
uGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.tar.bz2
uGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.zip
GOS module, for operating system independance
GMISC fast floating point trig GMISC fast fixed point trig
Diffstat (limited to 'src/gos')
-rw-r--r--src/gos/chibios.c207
-rw-r--r--src/gos/gos.mk3
-rw-r--r--src/gos/posix.c32
-rw-r--r--src/gos/win32.c32
4 files changed, 274 insertions, 0 deletions
diff --git a/src/gos/chibios.c b/src/gos/chibios.c
new file mode 100644
index 00000000..6e63a2a4
--- /dev/null
+++ b/src/gos/chibios.c
@@ -0,0 +1,207 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS/GFX.
+
+ ChibiOS/GFX is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/GFX is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file src/gos/chibios.c
+ * @brief GOS ChibiOS Operating System support.
+ */
+#include "gfx.h"
+
+#if GFX_USE_OS_CHIBIOS
+
+#if !CH_USE_MUTEXES
+ #error "GOS: CH_USE_MUTEXES must be defined in chconf.h"
+#endif
+#if !CH_USE_SEMAPHORES
+ #error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h"
+#endif
+
+/* Our module initialiser */
+void _gosInit(void) {
+ /* Don't initialise if the user already has */
+ if (!chThdSelf()) {
+ halInit();
+ chSysInit();
+ }
+}
+
+void gfxSleepMilliseconds(delaytime_t ms) {
+ switch(ms) {
+ case TIME_IMMEDIATE: chThdYield(); return;
+ case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
+ default: chThdSleepMilliseconds(ms); return;
+ }
+}
+
+void gfxSleepMicroseconds(delaytime_t ms) {
+ switch(ms) {
+ case TIME_IMMEDIATE: return;
+ case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
+ default: chThdSleepMicroseconds(ms); return;
+ }
+}
+
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit) {
+ if (val > limit) val = limit;
+ psem->limit = limit;
+ chSemInit(&psem->sem, val);
+}
+
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) {
+ if (ms == TIME_INFINITE) {
+ chSemWait(&psem->sem);
+ return TRUE;
+ }
+ return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != RDY_TIMEOUT;
+}
+
+void gfxSemSignal(gfxSem *psem) {
+ chSysLock();
+ if (gfxSemCounterI(psem) < psem->limit)
+ chSemSignalI(&psem->sem);
+ chSchRescheduleS();
+ chSysUnlock();
+}
+
+void gfxSemSignalI(gfxSem *psem) {
+ if (gfxSemCounterI(psem) < psem->limit)
+ chSemSignalI(&psem->sem);
+}
+
+void gfxQueueInit(gfxQueue *pqueue) {
+ pqueue->head = pqueue->tail = 0;
+ chSemInit(&pqueue->sem, 0);
+}
+
+gfxQueueItem * gfxQueueGet(gfxQueue *pqueue, delaytime_t ms) {
+ gfxQueueItem *pi;
+
+ chSysLock();
+ /* If someone else is waiting or if the queue is empty - wait ourselves */
+ if (pqueue->sem.s_cnt < 0 || !pqueue->head) {
+ if (chSemWaitTimeoutS(&pqueue->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) == RDY_TIMEOUT) {
+ chSysUnlock();
+ return NULL;
+ }
+ }
+ /* We can now get the head element */
+ pi = pqueue->head;
+ pqueue->head = pi;
+ chSemSignalI(&pi->sem);
+ chSysUnlock();
+ return pi;
+}
+
+bool_t gfxQueuePut(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms) {
+ chSemInit(&pitem->sem, 0);
+ chSysLock();
+ pitem->next = 0;
+ if (!pqueue->head) {
+ pqueue->head = pqueue->tail = pitem;
+ } else {
+ pqueue->tail->next = pitem;
+ pqueue->tail = pitem;
+ }
+ /* Wake up someone who is waiting */
+ if (chSemGetCounterI(&pqueue->sem) < 0)
+ chSemSignalI(&pqueue->sem);
+ chSysUnlock();
+ return chSemWaitTimeout(&pitem->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) != RDY_TIMEOUT;
+}
+
+bool_t gfxQueuePush(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms) {
+ chSemInit(&pitem->sem, 0);
+ chSysLock();
+ pitem->next = pqueue->head;
+ pqueue->head = pitem;
+ if (!pitem->next)
+ pqueue->tail = pitem;
+ /* Wake up someone who is waiting */
+ if (chSemGetCounterI(&pqueue->sem) < 0)
+ chSemSignalI(&pqueue->sem);
+ chSysUnlock();
+ return chSemWaitTimeout(&pitem->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) != RDY_TIMEOUT;
+}
+
+void gfxQueueRemove(gfxQueue *pqueue, gfxQueueItem *pitem) {
+ gfxQueueItem *pi;
+
+ chSysLock();
+ if (pqueue->head) {
+ if (pqueue->head == pitem) {
+ pqueue->head = pitem->next;
+ chSemSignalI(&pitem->sem);
+ } else {
+ for(pi = pqueue->head; pi->next; pi = pi->next) {
+ if (pi->next == pitem) {
+ pi->next = pitem->next;
+ if (pqueue->tail == pitem)
+ pqueue->tail = pi;
+ chSemSignalI(&pitem->sem);
+ break;
+ }
+ }
+ }
+ }
+ chSysUnlock();
+}
+
+bool_t gfxQueueIsEmpty(gfxQueue *pqueue) {
+ return pqueue->head == NULL;
+}
+
+bool_t gfxQueueIsIn(gfxQueue *pqueue, gfxQueueItem *pitem) {
+ gfxQueueItem *pi;
+
+ chSysLock();
+ for(pi = pqueue->head; pi; pi = pi->next) {
+ if (pi == pitem) {
+ chSysUnlock();
+ return TRUE;
+ }
+ }
+ chSysUnlock();
+ return FALSE;
+}
+
+/**
+ * @brief Start a new thread.
+ * @return Return TRUE if the thread was started, FALSE 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
+ */
+bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param) {
+ if (!stackarea) {
+ if (!stacksz) stacksz = 256;
+ return chThdCreateFromHeap(0, stacksz, prio, fn, param) != 0;
+ }
+
+ return stacksz && chThdCreateStatic(stackarea, stacksz, prio, fn, param) != NULL;
+}
+
+#endif /* GFX_USE_OS_CHIBIOS */
+/** @} */
diff --git a/src/gos/gos.mk b/src/gos/gos.mk
new file mode 100644
index 00000000..d963eea8
--- /dev/null
+++ b/src/gos/gos.mk
@@ -0,0 +1,3 @@
+GFXSRC += $(GFXLIB)/src/gos/chibios.c \
+ $(GFXLIB)/src/gos/win32.c \
+ $(GFXLIB)/src/gos/posix.c
diff --git a/src/gos/posix.c b/src/gos/posix.c
new file mode 100644
index 00000000..9f6fe430
--- /dev/null
+++ b/src/gos/posix.c
@@ -0,0 +1,32 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS/GFX.
+
+ ChibiOS/GFX is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/GFX is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file src/gos/chibios.c
+ * @brief GOS ChibiOS Operating System support.
+ */
+#include "gfx.h"
+
+#if GFX_USE_OS_POSIX
+
+#error "GOS: POSIX not supported yet"
+
+#endif /* GFX_USE_OS_POSIX */
+/** @} */
diff --git a/src/gos/win32.c b/src/gos/win32.c
new file mode 100644
index 00000000..6cf803a2
--- /dev/null
+++ b/src/gos/win32.c
@@ -0,0 +1,32 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS/GFX.
+
+ ChibiOS/GFX is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/GFX is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file src/gos/chibios.c
+ * @brief GOS ChibiOS Operating System support.
+ */
+#include "gfx.h"
+
+#if GFX_USE_OS_WIN32
+
+#error "GOS: WIN32 not supported yet"
+
+#endif /* GFX_USE_OS_WIN32 */
+/** @} */