aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gos/gos.h14
-rw-r--r--src/gos/gos.mk1
-rw-r--r--src/gos/gos_chibios.h1
-rw-r--r--src/gos/gos_cmsis.c89
-rw-r--r--src/gos/gos_cmsis.h105
-rw-r--r--src/gos/gos_ecos.h1
-rw-r--r--src/gos/gos_freertos.h1
-rw-r--r--src/gos/gos_keil.c89
-rw-r--r--src/gos/gos_keil.h32
-rw-r--r--src/gos/gos_linux.h1
-rw-r--r--src/gos/gos_mk.c1
-rw-r--r--src/gos/gos_options.h14
-rw-r--r--src/gos/gos_osx.h1
-rw-r--r--src/gos/gos_rawrtos.h1
-rw-r--r--src/gos/gos_rules.h4
-rw-r--r--src/gos/gos_win32.h1
-rw-r--r--src/gos/gos_x_threads.h1
-rw-r--r--src/gtimer/gtimer.c3
18 files changed, 357 insertions, 3 deletions
diff --git a/src/gos/gos.h b/src/gos/gos.h
index 82ad9d1c..af9486f8 100644
--- a/src/gos/gos.h
+++ b/src/gos/gos.h
@@ -69,6 +69,16 @@
*/
#define DECLARE_THREAD_STACK(name, sz) uint8_t name[sz];
+ /*
+ * @brief Return from a thread
+ *
+ * @details Some underlying operating systems allow to return a value from a thread while others don't.
+ * For systems that don't allow to return a value from a thread function this call is simply ignored.
+ *
+ * @param[in] reval The value which should be returned
+ */
+ #define THREAD_RETURN(retval);
+
/**
* @name Various platform (and operating system) constants
* @note Your platform may use slightly different definitions to these
@@ -464,6 +474,10 @@
#include "src/gos/gos_ecos.h"
#elif GFX_USE_OS_ARDUINO
#include "src/gos/gos_arduino.h"
+#elif GFX_USE_OS_CMSIS
+ #include "src/gos/gos_cmsis.h"
+#elif GFX_USE_OS_KEIL
+ #include "src/gos/gos_keil.h"
#else
#error "Your operating system is not supported yet"
#endif
diff --git a/src/gos/gos.mk b/src/gos/gos.mk
index 1c3a86a5..048e687f 100644
--- a/src/gos/gos.mk
+++ b/src/gos/gos.mk
@@ -12,6 +12,7 @@ GFXSRC += $(GFXLIB)/src/gos/gos_chibios.c \
$(GFXLIB)/src/gos/gos_ecos.c \
$(GFXLIB)/src/gos/gos_rawrtos.c \
$(GFXLIB)/src/gos/gos_arduino.c \
+ $(GFXLIB)/src/gos/gos_cmsis.c \
$(GFXLIB)/src/gos/gos_x_threads.c \
$(GFXLIB)/src/gos/gos_x_heap.c
diff --git a/src/gos/gos_chibios.h b/src/gos/gos_chibios.h
index c4755020..30a65423 100644
--- a/src/gos/gos_chibios.h
+++ b/src/gos/gos_chibios.h
@@ -56,6 +56,7 @@ typedef tprio_t threadpriority_t;
#define DECLARE_THREAD_STACK(name, sz) WORKING_AREA(name, sz)
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
+#define THREAD_RETURN(retval) return retval
#if CH_KERNEL_MAJOR == 2
typedef struct {
diff --git a/src/gos/gos_cmsis.c b/src/gos/gos_cmsis.c
new file mode 100644
index 00000000..26a3f7f0
--- /dev/null
+++ b/src/gos/gos_cmsis.c
@@ -0,0 +1,89 @@
+/*
+ * 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
+ */
+
+#include "gfx.h"
+#include <string.h>
+
+#if GFX_USE_OS_CMSIS
+
+void _gosHeapInit(void);
+
+void _gosInit(void)
+{
+ #if !GFX_OS_NO_INIT
+ osKernelInitialize();
+ if (!osKernelRunning())
+ osKernelStart();
+ #elif !GFX_OS_INIT_NO_WARNING
+ #warning "GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize() and osKernelStart() before gfxInit() in your application!"
+ #endif
+
+ // Set up the heap allocator
+ _gosHeapInit();
+}
+
+void _gosDeinit(void)
+{
+}
+
+void gfxMutexInit(gfxMutex* pmutex)
+{
+ pmutex->id = osMutexCreate(&(pmutex->def));
+}
+
+void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit)
+{
+ psem->id = osSemaphoreCreate(&(psem->def), limit);
+ while(val--)
+ osSemaphoreRelease(psem->id);
+}
+
+void gfxSemDestroy(gfxSem* psem)
+{
+ osSemaphoreDelete(psem->id);
+}
+
+bool_t gfxSemWait(gfxSem* psem, delaytime_t ms)
+{
+ return osSemaphoreWait(psem->id, ms) > 0;
+}
+
+bool_t gfxSemWaitI(gfxSem* psem)
+{
+ return osSemaphoreWait(psem->id, 0) > 0;
+}
+
+void gfxSemSignal(gfxSem* psem)
+{
+ osSemaphoreRelease(psem->id);
+}
+
+void gfxSemSignalI(gfxSem* psem)
+{
+ osSemaphoreRelease(psem->id);
+}
+
+gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param)
+{
+ osThreadDef_t def;
+
+ (void)stackarea;
+
+ def.pthread = (os_pthread)fn;
+ def.tpriority = prio;
+ def.instances = 1;
+ def.stacksize = stacksz;
+
+ return osThreadCreate(&def, param);
+}
+
+threadreturn_t gfxThreadWait(gfxThreadHandle thread) {
+ while(osThreadGetPriority(thread) == osPriorityError)
+ gfxYield();
+}
+
+#endif /* GFX_USE_OS_CMSIS */
diff --git a/src/gos/gos_cmsis.h b/src/gos/gos_cmsis.h
new file mode 100644
index 00000000..a0833c07
--- /dev/null
+++ b/src/gos/gos_cmsis.h
@@ -0,0 +1,105 @@
+/*
+ * 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/gos_cmsis.h
+ * @brief GOS - Operating System Support header file for CMSIS RTOS.
+ */
+
+#ifndef _GOS_CMSIS_H
+#define _GOS_CMSIS_H
+
+#if GFX_USE_OS_CMSIS
+
+#include <stdbool.h>
+#include "cmsis_os.h"
+
+#ifndef GFX_OS_HEAP_SIZE
+ #define GFX_OS_HEAP_SIZE 10240
+#endif
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+typedef bool bool_t;
+
+#define TIME_IMMEDIATE 0
+#define TIME_INFINITE osWaitForever
+typedef uint32_t delaytime_t;
+typedef uint32_t systemticks_t;
+typedef uint16_t semcount_t;
+typedef void threadreturn_t;
+typedef osPriority threadpriority_t;
+
+#define MAX_SEMAPHORE_COUNT osFeature_Semaphore
+#define LOW_PRIORITY osPriorityLow
+#define NORMAL_PRIORITY osPriorityNormal
+#define HIGH_PRIORITY osPriorityHigh
+
+typedef struct gfxSem {
+ osSemaphoreDef_t def;
+ osSemaphoreId id;
+} gfxSem;
+
+typedef struct gfxMutex {
+ osMutexDef_t def;
+ osMutexId id;
+} gfxMutex;
+
+typedef osThreadId gfxThreadHandle;
+
+#define DECLARE_THREAD_STACK(name, sz) uint8_t name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte
+#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void* param)
+#define THREAD_RETURN(retval)
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define gfxExit() os_error(0)
+#define gfxHalt(msg) os_error(1)
+#define gfxSystemTicks() osKernelSysTick()
+#define gfxMillisecondsToTicks(ms) osKernelSysTickMicroSec(1000*ms)
+#define gfxSystemLock() osKernelInitialize()
+#define gfxSystemUnlock() osKernelStart()
+#define gfxSleepMilliseconds(ms) osDelay(ms)
+
+void gfxMutexInit(gfxMutex* pmutex);
+#define gfxMutexDestroy(pmutex) osMutexDelete((pmutex)->id)
+#define gfxMutexEnter(pmutex) osMutexWait((pmutex)->id, TIME_INFINITE)
+#define gfxMutexExit(pmutex) osMutexRelease((pmutex)->id)
+
+void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit);
+void gfxSemDestroy(gfxSem* psem);
+bool_t gfxSemWait(gfxSem* psem, delaytime_t ms);
+bool_t gfxSemWaitI(gfxSem* psem);
+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);
+#define gfxYield() osThreadYield()
+#define gfxThreadMe() osThreadGetId()
+#define gfxThreadClose(thread) {}
+
+#ifdef __cplusplus
+}
+#endif
+
+/*===========================================================================*/
+/* Use the generic heap handling */
+/*===========================================================================*/
+
+#define GOS_NEED_X_HEAP TRUE
+#include "gos_x_heap.h"
+
+#endif /* GFX_USE_OS_CMSIS */
+#endif /* _GOS_CMSIS_H */
diff --git a/src/gos/gos_ecos.h b/src/gos/gos_ecos.h
index be9037b6..cd5678df 100644
--- a/src/gos/gos_ecos.h
+++ b/src/gos/gos_ecos.h
@@ -46,6 +46,7 @@ typedef cyg_handle_t gfxThreadHandle;
#define DECLARE_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[sz]; } name[1]
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(cyg_addrword_t param)
+#define THREAD_RETURN(retval)
typedef struct {
cyg_sem_t sem;
diff --git a/src/gos/gos_freertos.h b/src/gos/gos_freertos.h
index d6dcf5c5..574e13ae 100644
--- a/src/gos/gos_freertos.h
+++ b/src/gos/gos_freertos.h
@@ -62,6 +62,7 @@ typedef portBASE_TYPE threadpriority_t;
/* FreeRTOS will allocate the stack when creating the thread, so pass the size instead of a working area */
#define DECLARE_THREAD_STACK(name, sz) size_t *name = (size_t *)sz
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
+#define THREAD_RETURN(retval)
portTickType MS2ST(portTickType ms);
typedef struct {
diff --git a/src/gos/gos_keil.c b/src/gos/gos_keil.c
new file mode 100644
index 00000000..e8eef7b8
--- /dev/null
+++ b/src/gos/gos_keil.c
@@ -0,0 +1,89 @@
+/*
+ * 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
+ */
+
+#include "gfx.h"
+#include <string.h>
+
+#if GFX_USE_OS_KEIL
+
+void _gosHeapInit(void);
+
+void _gosInit(void)
+{
+ #if !GFX_OS_NO_INIT
+ osKernelInitialize();
+ if (!osKernelRunning())
+ osKernelStart();
+ #elif !GFX_OS_INIT_NO_WARNING
+ #warning "GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize() and osKernelStart() before gfxInit() in your application!"
+ #endif
+
+ // Set up the heap allocator
+ _gosHeapInit();
+}
+
+void _gosDeinit(void)
+{
+}
+
+void gfxMutexInit(gfxMutex* pmutex)
+{
+ pmutex->id = osMutexCreate(&(pmutex->def));
+}
+
+void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit)
+{
+ psem->id = osSemaphoreCreate(&(psem->def), limit);
+ while(val--)
+ osSemaphoreRelease(psem->id);
+}
+
+void gfxSemDestroy(gfxSem* psem)
+{
+ osSemaphoreDelete(psem->id);
+}
+
+bool_t gfxSemWait(gfxSem* psem, delaytime_t ms)
+{
+ return osSemaphoreWait(psem->id, ms) > 0;
+}
+
+bool_t gfxSemWaitI(gfxSem* psem)
+{
+ return osSemaphoreWait(psem->id, 0) > 0;
+}
+
+void gfxSemSignal(gfxSem* psem)
+{
+ osSemaphoreRelease(psem->id);
+}
+
+void gfxSemSignalI(gfxSem* psem)
+{
+ osSemaphoreRelease(psem->id);
+}
+
+gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param)
+{
+ osThreadDef_t def;
+
+ (void)stackarea;
+
+ def.pthread = (os_pthread)fn;
+ def.tpriority = prio;
+ def.instances = 1;
+ def.stacksize = stacksz;
+
+ return osThreadCreate(&def, param);
+}
+
+threadreturn_t gfxThreadWait(gfxThreadHandle thread) {
+ while(osThreadGetPriority(thread) == osPriorityError)
+ gfxYield();
+}
+
+#endif /* GFX_USE_OS_KEIL */
diff --git a/src/gos/gos_keil.h b/src/gos/gos_keil.h
new file mode 100644
index 00000000..863986d4
--- /dev/null
+++ b/src/gos/gos_keil.h
@@ -0,0 +1,32 @@
+/*
+ * 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/gos_keil.h
+ * @brief GOS - Operating System Support header file for Keil RTX
+ */
+
+#ifndef _GOS_KEIL_H
+#define _GOS_KEIL_H
+
+#if GFX_USE_OS_KEIL
+
+/*
+ * Keil RTX uses the CMSIS RTOS interface. Therefore, just use the CMSIS RTOS port
+ */
+
+// Disable KEIL to avoid error: "GOS: More than one operation system has been defined as TRUE."
+#undef GFX_USE_OS_KEIL
+#define GFX_USE_OS_KEIL FALSE
+
+// Enable generic CMSIS RTOS implementation
+#undef GFX_USE_OS_CMSIS
+#define GFX_USE_OS_CMSIS TRUE
+#include "gos_cmsis.h"
+
+#endif /* GFX_USE_OS_KEIL */
+#endif /* _GOS_KEIL_H */
diff --git a/src/gos/gos_linux.h b/src/gos/gos_linux.h
index 39cfbc85..fe406cb6 100644
--- a/src/gos/gos_linux.h
+++ b/src/gos/gos_linux.h
@@ -37,6 +37,7 @@ 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 THREAD_RETURN(retval) return retval
#define gfxExit() exit(0)
#define gfxAlloc(sz) malloc(sz)
diff --git a/src/gos/gos_mk.c b/src/gos/gos_mk.c
index 1b033206..49d6efb9 100644
--- a/src/gos/gos_mk.c
+++ b/src/gos/gos_mk.c
@@ -14,5 +14,6 @@
#include "gos_raw32.c"
#include "gos_rawrtos.c"
#include "gos_win32.c"
+#include "gos_cmsis.c"
#include "gos_x_threads.c"
#include "gos_x_heap.c"
diff --git a/src/gos/gos_options.h b/src/gos/gos_options.h
index c80a9f39..37007650 100644
--- a/src/gos/gos_options.h
+++ b/src/gos/gos_options.h
@@ -76,6 +76,20 @@
#ifndef GFX_USE_OS_ARDUINO
#define GFX_USE_OS_ARDUINO FALSE
#endif
+ /**
+ * @brief Use CMSIS RTOS compatible OS
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_CMSIS
+ #define GFX_USE_OS_CMSIS FALSE
+ #endif
+ /**
+ * @brief Use Keil CMSIS
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_KEIL
+ #define GFX_USE_OS_KEIL FALSE
+ #endif
/**
* @}
*
diff --git a/src/gos/gos_osx.h b/src/gos/gos_osx.h
index 635a8934..e5764b81 100644
--- a/src/gos/gos_osx.h
+++ b/src/gos/gos_osx.h
@@ -27,6 +27,7 @@ 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 THREAD_RETURN(retval) return reval
#define gfxExit() exit(0)
#define gfxAlloc(sz) malloc(sz)
diff --git a/src/gos/gos_rawrtos.h b/src/gos/gos_rawrtos.h
index eeb5119d..f352d681 100644
--- a/src/gos/gos_rawrtos.h
+++ b/src/gos/gos_rawrtos.h
@@ -27,6 +27,7 @@ typedef RAW_TASK_OBJ* gfxThreadHandle;
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
#define DECLARE_THREAD_STACK(name, sz) PORT_STACK name[sz];
+#define THREAD_RETURN(retval) return retval
#define gfxHalt(msg) for(;;)
#define gfxExit() for(;;)
diff --git a/src/gos/gos_rules.h b/src/gos/gos_rules.h
index 6eea98c9..0f0f6596 100644
--- a/src/gos/gos_rules.h
+++ b/src/gos/gos_rules.h
@@ -16,7 +16,7 @@
#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 && !GFX_USE_OS_FREERTOS && !GFX_USE_OS_ECOS && !GFX_USE_OS_RAWRTOS && !GFX_USE_OS_ARDUINO
+#if !GFX_USE_OS_CHIBIOS && !GFX_USE_OS_WIN32 && !GFX_USE_OS_LINUX && !GFX_USE_OS_OSX && !GFX_USE_OS_RAW32 && !GFX_USE_OS_FREERTOS && !GFX_USE_OS_ECOS && !GFX_USE_OS_RAWRTOS && !GFX_USE_OS_ARDUINO && !GFX_USE_OS_CMSIS && !GFX_USE_OS_KEIL
#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
@@ -24,7 +24,7 @@
#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 + GFX_USE_OS_FREERTOS + GFX_USE_OS_ECOS + GFX_USE_OS_RAWRTOS + GFX_USE_OS_ARDUINO != 1 * TRUE
+#if GFX_USE_OS_CHIBIOS + GFX_USE_OS_WIN32 + GFX_USE_OS_LINUX + GFX_USE_OS_OSX + GFX_USE_OS_RAW32 + GFX_USE_OS_FREERTOS + GFX_USE_OS_ECOS + GFX_USE_OS_RAWRTOS + GFX_USE_OS_ARDUINO + GFX_USE_OS_CMSIS + GFX_USE_OS_KEIL != 1 * TRUE
#error "GOS: More than one operation system has been defined as TRUE."
#endif
diff --git a/src/gos/gos_win32.h b/src/gos/gos_win32.h
index 7e4f051b..bac74d46 100644
--- a/src/gos/gos_win32.h
+++ b/src/gos/gos_win32.h
@@ -48,6 +48,7 @@ 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 THREAD_RETURN(retval) return retval
#define TIME_IMMEDIATE 0
#define TIME_INFINITE INFINITE
diff --git a/src/gos/gos_x_threads.h b/src/gos/gos_x_threads.h
index 78c30ac4..ee7a9cd0 100644
--- a/src/gos/gos_x_threads.h
+++ b/src/gos/gos_x_threads.h
@@ -32,6 +32,7 @@ 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 THREAD_RETURN(retval) return retval
#define TIME_IMMEDIATE 0
#define TIME_INFINITE ((delaytime_t)-1)
diff --git a/src/gtimer/gtimer.c b/src/gtimer/gtimer.c
index f84cad22..6a4705d2 100644
--- a/src/gtimer/gtimer.c
+++ b/src/gtimer/gtimer.c
@@ -29,13 +29,14 @@ static DECLARE_THREAD_STACK(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
/*===========================================================================*/
static DECLARE_THREAD_FUNCTION(GTimerThreadHandler, arg) {
- (void)arg;
GTimer *pt;
systemticks_t tm;
systemticks_t nxtTimeout;
systemticks_t lastTime;
GTimerFunction fn;
void *param;
+
+ (void)arg;
nxtTimeout = TIME_INFINITE;
lastTime = 0;