aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/releases.txt3
-rw-r--r--gfxconf.example.h2
-rw-r--r--src/gos/gos.mk1
-rw-r--r--src/gos/gos_cmsis.c89
-rw-r--r--src/gos/gos_cmsis.h105
-rw-r--r--src/gos/gos_keil.c89
-rw-r--r--src/gos/gos_keil.h32
-rw-r--r--src/gos/gos_mk.c1
-rw-r--r--src/gos/gos_options.h14
-rw-r--r--src/gos/gos_rules.h4
10 files changed, 338 insertions, 2 deletions
diff --git a/docs/releases.txt b/docs/releases.txt
index 15c0a8bf..764799ca 100644
--- a/docs/releases.txt
+++ b/docs/releases.txt
@@ -17,9 +17,12 @@ FEATURE: Implementing widget focusing. See gwinSetFocus() and gwinGetFocus()
FEATURE: Adding TextEdit widget
FEATURE: Added color to widget style for focused widgets
FEATURE: Added GWIN_FOCUS_HIGHLIGHT_WIDTH as an option in the configuration file
+FEATURE: Added support for CMSIS RTOS
+FEATURE: Added support for KEIL RTX
FEATURE: Replace all references to inline with a reference to GFXINLINE
FEATURE: Added config option GFX_NO_INLINE to run off inlining of ugfx functions.
+
*** Release 2.3 ***
FEATURE: Added more events to the slider widget
FIX: Clean up visibility issues
diff --git a/gfxconf.example.h b/gfxconf.example.h
index edcb0d02..de4ed230 100644
--- a/gfxconf.example.h
+++ b/gfxconf.example.h
@@ -34,6 +34,8 @@
//#define GFX_USE_OS_OSX FALSE
//#define GFX_USE_OS_ECOS FALSE
//#define GFX_USE_OS_RAWRTOS FALSE
+//#define GFX_USE_OS_ARDUINO FALSE
+//#define GFX_USE_OS_KEIL FALSE
//#define GFX_USE_OS_RAW32 FALSE
// #define INTERRUPTS_OFF() optional_code
// #define INTERRUPTS_ON() optional_code
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_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.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_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_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