aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2015-10-12 20:52:42 +1000
committerinmarket <andrewh@inmarket.com.au>2015-10-12 20:52:42 +1000
commit92b000291826ca78c30f205c104ac330484b82c9 (patch)
tree35afef7fd58342c22e6de006f3ff23d5ec0b5d76
parentddf79cd411e2cbdb58c485851b16be496109ab3b (diff)
downloaduGFX-92b000291826ca78c30f205c104ac330484b82c9.tar.gz
uGFX-92b000291826ca78c30f205c104ac330484b82c9.tar.bz2
uGFX-92b000291826ca78c30f205c104ac330484b82c9.zip
First attempt at Keil CMSIS support
-rw-r--r--gfxconf.example.h2
-rw-r--r--src/gos/gos.h2
-rw-r--r--src/gos/gos.mk1
-rw-r--r--src/gos/gos_keil.c80
-rw-r--r--src/gos/gos_keil.h99
-rw-r--r--src/gos/gos_mk.c1
-rw-r--r--src/gos/gos_options.h7
-rw-r--r--src/gos/gos_rules.h4
8 files changed, 194 insertions, 2 deletions
diff --git a/gfxconf.example.h b/gfxconf.example.h
index 27c55a2a..0753cf64 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.h b/src/gos/gos.h
index 82ad9d1c..9d32867a 100644
--- a/src/gos/gos.h
+++ b/src/gos/gos.h
@@ -464,6 +464,8 @@
#include "src/gos/gos_ecos.h"
#elif GFX_USE_OS_ARDUINO
#include "src/gos/gos_arduino.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..8e8eb907 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_keil.c \
$(GFXLIB)/src/gos/gos_x_threads.c \
$(GFXLIB)/src/gos/gos_x_heap.c
diff --git a/src/gos/gos_keil.c b/src/gos/gos_keil.c
new file mode 100644
index 00000000..72b37404
--- /dev/null
+++ b/src/gos/gos_keil.c
@@ -0,0 +1,80 @@
+/*
+ * 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 _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->osMutex(id));
+}
+
+void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit)
+{
+ psem->id = osSemaphoreCreate(psem->osSemaphore(id), 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(ugfx_thread, prio, 1, stacksz);
+
+ return osThreadCreate(osThread(ugfx_thread), 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..df2db720
--- /dev/null
+++ b/src/gos/gos_keil.h
@@ -0,0 +1,99 @@
+/*
+ * 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
+
+#ifndef GFX_OS_HEAP_SIZE
+ #define GFX_OS_HEAP_SIZE 10240
+#endif
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+#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 {
+ osSemaphoreId id;
+ osSemaphoreDef(id);
+ } gfxSem;
+
+typedef struct gfxMutex {
+ osMutexId id;
+ osMutexDef(id);
+ } gfxMutex;
+
+typedef osThreadId gfxThreadHandle;
+
+#define DECLARE_THREAD_STACK(name, sz)
+#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void* params)
+
+/*===========================================================================*/
+/* 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 thread handling and heap handling */
+/*===========================================================================*/
+
+#define GOS_NEED_X_HEAP TRUE
+#include "gos_x_heap.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..13808791 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_keil.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..1521a123 100644
--- a/src/gos/gos_options.h
+++ b/src/gos/gos_options.h
@@ -76,6 +76,13 @@
#ifndef GFX_USE_OS_ARDUINO
#define GFX_USE_OS_ARDUINO 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..49d32b1d 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_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_KEIL != 1 * TRUE
#error "GOS: More than one operation system has been defined as TRUE."
#endif