diff options
-rw-r--r-- | gfxconf.example.h | 1 | ||||
-rw-r--r-- | include/gos/freertos.h | 113 | ||||
-rw-r--r-- | include/gos/gos.h | 2 | ||||
-rw-r--r-- | include/gos/options.h | 17 | ||||
-rw-r--r-- | releases.txt | 1 | ||||
-rw-r--r-- | src/gos/freertos.c | 150 | ||||
-rw-r--r-- | src/gos/gos.mk | 1 |
7 files changed, 285 insertions, 0 deletions
diff --git a/gfxconf.example.h b/gfxconf.example.h index d9dcf88b..4f7ffb8b 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -20,6 +20,7 @@ /* The operating system to use. One of these must be defined - preferably in your Makefile */ //#define GFX_USE_OS_CHIBIOS TRUE +//#define GFX_USE_OS_FREERTOS TRUE //#define GFX_USE_OS_WIN32 TRUE //#define GFX_USE_OS_LINUX TRUE //#define GFX_USE_OS_OSX TRUE diff --git a/include/gos/freertos.h b/include/gos/freertos.h new file mode 100644 index 00000000..c9d63ec5 --- /dev/null +++ b/include/gos/freertos.h @@ -0,0 +1,113 @@ +/*
+ * 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 include/gos/freertos.h
+ * @brief GOS - Operating System Support header file for FreeRTOS.
+ */
+
+#ifndef _GOS_FREERTOS_H
+#define _GOS_FREERTOS_H
+
+#if GFX_USE_OS_FREERTOS
+
+#include "FreeRTOS.h"
+#include "FreeRTOSConfig.h"
+#include "semphr.h"
+#include "task.h"
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+/**
+ * bool_t,
+ * int8_t, uint8_t,
+ * int16_t, uint16_t,
+ * int32_t, uint32_t,
+ * size_t
+ * TRUE, FALSE
+ * are already defined by FreeRTOS
+ */
+#define TIME_IMMEDIATE 0
+#define TIME_INFINITE ((delaytime_t)-1)
+typedef int8_t bool_t;
+typedef uint32_t delaytime_t;
+typedef portTickType systemticks_t;
+typedef int32_t semcount_t;
+typedef void threadreturn_t;
+typedef portBASE_TYPE threadpriority_t;
+
+#define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
+#define LOW_PRIORITY 0
+#define NORMAL_PRIORITY configMAX_PRIORITIES/2
+#define HIGH_PRIORITY configMAX_PRIORITIES-1
+
+/* 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)
+portTickType MS2ST(portTickType ms);
+
+typedef struct {
+ xSemaphoreHandle sem;
+ semcount_t limit;
+ semcount_t counter;
+} gfxSem;
+
+typedef xSemaphoreHandle gfxMutex;
+typedef xTaskHandl* gfxThreadHandle;
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define gfxHalt(msg) {}
+#define gfxExit() {}
+#define gfxAlloc(sz) pvPortMalloc(sz)
+#define gfxFree(ptr) vPortFree(ptr)
+#define gfxYield() taskYIELD()
+#define gfxSystemTicks() xTaskGetTickCount()
+#define gfxMillisecondsToTicks(ms) MS2ST(ms)
+#define gfxSystemLock() {}
+#define gfxSystemUnlock() {}
+static inline void gfxMutexInit(xSemaphoreHandle *s)
+{
+ *s = xSemaphoreCreateMutex();
+ vTraceSetMutexName(*s,"uGFXMutex"); // for FreeRTOS+Trace debug
+}
+#define gfxMutexDestroy(pmutex) vSemaphoreDelete(*pmutex)
+#define gfxMutexEnter(pmutex) xSemaphoreTake(*pmutex,portMAX_DELAY)
+#define gfxMutexExit(pmutex) xSemaphoreGive(*pmutex)
+
+void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
+void gfxSleepMilliseconds(delaytime_t ms);
+void gfxSleepMicroseconds(delaytime_t ms);
+
+void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit);
+void gfxSemDestroy(gfxSem* psem);
+bool_t gfxSemWait(gfxSem* psem, delaytime_t ms);
+void gfxSemSignal(gfxSem* psem);
+void gfxSemSignalI(gfxSem* psem);
+#define gfxSemCounterI(psem) ((psem)->counter)
+#define gfxSemCounter(psem) ((psem)->counter)
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
+
+#define gfxThreadWait(thread) {} // never used, not imlpemented
+#define gfxThreadMe() {} // never used, not implemented
+#define gfxThreadClose(thread) {}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_OS_FREERTOS */
+#endif /* _GOS_CHIBIOS_H */
+
diff --git a/include/gos/gos.h b/include/gos/gos.h index 37335fbb..54529016 100644 --- a/include/gos/gos.h +++ b/include/gos/gos.h @@ -429,6 +429,8 @@ */ #elif GFX_USE_OS_CHIBIOS #include "gos/chibios.h" +#elif GFX_USE_OS_FREERTOS + #include "gos/freertos.h" #elif GFX_USE_OS_WIN32 #include "gos/win32.h" #elif GFX_USE_OS_LINUX diff --git a/include/gos/options.h b/include/gos/options.h index 4edb35d8..864cb832 100644 --- a/include/gos/options.h +++ b/include/gos/options.h @@ -28,6 +28,23 @@ #define GFX_USE_OS_CHIBIOS FALSE #endif /** + * @brief Use FreeRTOS + * @details Defaults to FALSE + */ + #ifndef GFX_USE_OS_FREERTOS + #define GFX_USE_OS_FREERTOS FALSE + #endif + /** + * @brief Use Win32 + * @details Defaults to FALSE + */ + #ifndef GFX_USE_OS_WIN32 + #define GFX_USE_OS_WIN32 FALSE + #endif + /** + * @brief Use a linux based system running X11 + * @details Defaults to FALSE + /** * @brief Use Win32 * @details Defaults to FALSE */ diff --git a/releases.txt b/releases.txt index f2cb77d5..f1b1ca83 100644 --- a/releases.txt +++ b/releases.txt @@ -13,6 +13,7 @@ FEATURE: Added gwinGetColor() and gwinGetBgColor() FEATURE: Console does now have an optional buffer (GWIN_CONSOLE_USE_HISTORY) FEATURE: Added smooth scrolling to list widget FEATURE: Increased performance of gwinListAddItem() +FEATURE: Added FreeRTOS port FEATURE: Added gfxDeinit() diff --git a/src/gos/freertos.c b/src/gos/freertos.c new file mode 100644 index 00000000..872807d1 --- /dev/null +++ b/src/gos/freertos.c @@ -0,0 +1,150 @@ +/* + * 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/freertos.c + * @brief GOS FreeRTOS Operating System support. + */ +#include "gfx.h" +#include <string.h> + +#if GFX_USE_OS_FREERTOS + +#if INCLUDE_vTaskDelay != 1 + #error "GOS: INCLUDE_vTaskDelay must be defined in FreeRTOSConfig.h" +#endif + +#if configUSE_MUTEXES != 1 + #error "GOS: configUSE_MUTEXES must be defined in FreeRTOSConfig.h" +#endif + +#if configUSE_COUNTING_SEMAPHORES != 1 + #error "GOS: configUSE_COUNTING_SEMAPHORES must be defined in FreeRTOSConfig.h" +#endif + +void _gosInit(void) +{ + // The user must call vTaskStartScheduler() himself before he calls gfxInit(). +} + +void* gfxRealloc(void *ptr, size_t oldsz, size_t newsz) +{ + void *np; + + if (newsz <= oldsz) + return ptr; + + np = gfxAlloc(newsz); + if (!np) + return 0; + + if (oldsz) { + memcpy(np, ptr, oldsz); + vPortFree(ptr); + } + + return np; +} + +void gfxSleepMilliseconds(delaytime_t ms) +{ + // Implement this +} + +void gfxSleepMicroseconds(delaytime_t ms) +{ + // Implement this +} + +portTickType MS2ST(portTickType ms) +{ + // Verify this + + uint64_t val; + + if (configTICK_RATE_HZ == 1000) { // gain time because no test to do in most case + return ms; + } + + val = ms; + val *= configTICK_RATE_HZ; + val += 999; + val /= 1000; + + return val; +} + +void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit) +{ + if (val > limit) + val = limit; + + psem->counter = val; + psem->limit = limit; + psem->sem = xSemaphoreCreateCounting(limit,val); + + vTraceSetSemaphoreName(psem->sem, "uGFXSema"); // for FreeRTOS+Trace debug +} + +void gfxSemDestroy(gfxSem* psem) +{ + vSemaphoreDelete(psem->sem); +} + +bool_t gfxSemWait(gfxSem* psem, delaytime_t ms) +{ + psem->counter--; + + if (xSemaphoreTake(psem->sem, MS2ST(ms)) == pdPASS) + return TRUE; + + psem->counter++; + + return FALSE; +} + +void gfxSemSignal(gfxSem* psem) +{ + taskENTER_CRITICAL(); + + if (psem->counter < psem->limit) { + psem->counter++; + xSemaphoreGive(psem->sem); + } + + taskYIELD(); + taskEXIT_CRITICAL(); +} + +void gfxSemSignalI(gfxSem* psem) +{ + portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; + + if (psem->counter < psem->limit) { + psem->counter++; + xSemaphoreGiveFromISR(psem->sem,&xHigherPriorityTaskWoken); + } +} + +gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) +{ + xTaskHandle task = NULL; + stacksz = (size_t)stackarea; + + if (stacksz < configMINIMAL_STACK_SIZE) + stacksz = configMINIMAL_STACK_SIZE; + + if (xTaskCreate(fn, (signed char*)"uGFX_TASK", stacksz, param, prio, &task )!= pdPASS) { + for (;;); + } + + return task; +} + +#endif /* GFX_USE_OS_FREERTOS */ +/** @} */ + diff --git a/src/gos/gos.mk b/src/gos/gos.mk index 9db29fe2..8ef22121 100644 --- a/src/gos/gos.mk +++ b/src/gos/gos.mk @@ -1,4 +1,5 @@ GFXSRC += $(GFXLIB)/src/gos/chibios.c \ + $(GFXLIB)/src/gos/freertos.c \ $(GFXLIB)/src/gos/win32.c \ $(GFXLIB)/src/gos/linux.c \ $(GFXLIB)/src/gos/osx.c \ |