aboutsummaryrefslogtreecommitdiffstats
path: root/src/gos
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-10-19 22:22:13 +0200
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-10-19 22:22:13 +0200
commit4b31f87fc8bde205ce1d331234dee768bac36af5 (patch)
tree4cf1983194fffaadb9fe69fcaaaa00d9f4437670 /src/gos
parent73b39a7d36504d33e04309a359beeb027b854c5a (diff)
downloaduGFX-4b31f87fc8bde205ce1d331234dee768bac36af5.tar.gz
uGFX-4b31f87fc8bde205ce1d331234dee768bac36af5.tar.bz2
uGFX-4b31f87fc8bde205ce1d331234dee768bac36af5.zip
Adding dedicated support for generic CMSIS RTOS and specific KEIL RTX
Diffstat (limited to 'src/gos')
-rw-r--r--src/gos/gos.h12
-rw-r--r--src/gos/gos.mk2
-rw-r--r--src/gos/gos_cmsis.c89
-rw-r--r--src/gos/gos_cmsis.h105
-rw-r--r--src/gos/gos_keil.h92
-rw-r--r--src/gos/gos_mk.c2
-rw-r--r--src/gos/gos_options.h9
-rw-r--r--src/gos/gos_rules.h4
8 files changed, 225 insertions, 90 deletions
diff --git a/src/gos/gos.h b/src/gos/gos.h
index 9d32867a..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,8 @@
#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
diff --git a/src/gos/gos.mk b/src/gos/gos.mk
index 8e8eb907..048e687f 100644
--- a/src/gos/gos.mk
+++ b/src/gos/gos.mk
@@ -12,7 +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_keil.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_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_keil.h b/src/gos/gos_keil.h
index f3f60113..84530d16 100644
--- a/src/gos/gos_keil.h
+++ b/src/gos/gos_keil.h
@@ -7,7 +7,7 @@
/**
* @file src/gos/gos_keil.h
- * @brief GOS - Operating System Support header file for Keil RTX.
+ * @brief GOS - Operating System Support header file for Keil RTX
*/
#ifndef _GOS_KEIL_H
@@ -15,91 +15,13 @@
#if GFX_USE_OS_KEIL
-#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 */
-/*===========================================================================*/
+/*
+ * Keil RTX uses the CMSIS RTOS interface. Therefore, just use the CMSIS RTOS port
+ */
+#define GFX_USE_OS_KEIL FALSE // Disable KEIL to avoid error: "GOS: More than one operation system has been defined as TRUE."
+#define GFX_USE_OS_CMSIS TRUE
-#define GOS_NEED_X_HEAP TRUE
-#include "gos_x_heap.h"
+#include "gos_cmsis.h"
#endif /* GFX_USE_OS_KEIL */
#endif /* _GOS_KEIL_H */
diff --git a/src/gos/gos_mk.c b/src/gos/gos_mk.c
index 13808791..49d6efb9 100644
--- a/src/gos/gos_mk.c
+++ b/src/gos/gos_mk.c
@@ -14,6 +14,6 @@
#include "gos_raw32.c"
#include "gos_rawrtos.c"
#include "gos_win32.c"
-#include "gos_keil.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 1521a123..37007650 100644
--- a/src/gos/gos_options.h
+++ b/src/gos/gos_options.h
@@ -77,11 +77,18 @@
#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
+ #define GFX_USE_OS_KEIL FALSE
#endif
/**
* @}
diff --git a/src/gos/gos_rules.h b/src/gos/gos_rules.h
index 49d32b1d..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 && !GFX_USE_OS_KEIL
+#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 + GFX_USE_OS_KEIL != 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