From 0bb6473f880e69c294f78972a04c286a088d15fb Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:06:20 +0100 Subject: [PATCH 01/11] initial public release of FreeRTOS port (does still need some cleanup) --- include/gos/freertos.h | 113 ++++++++++++++++++++++++++++++ src/gos/freertos.c | 151 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 264 insertions(+) create mode 100644 include/gos/freertos.h create mode 100644 src/gos/freertos.c diff --git a/include/gos/freertos.h b/include/gos/freertos.h new file mode 100644 index 00000000..3ceb279d --- /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/FreeRTOS.h" +#include "config/FreeRTOSConfig.h" +#include "freertos/semphr.h" +#include "freertos/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/src/gos/freertos.c b/src/gos/freertos.c new file mode 100644 index 00000000..9b22af1b --- /dev/null +++ b/src/gos/freertos.c @@ -0,0 +1,151 @@ +/* + * 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 "heivs/config.h" +#include "gfx.h" +#include "heivs/delay.h" +#include "freertos/FreeRTOS.h" +#include "config/FreeRTOSConfig.h" +#include + +#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) +{ + // IMPORTANT: Check for already started scheduler here!!! + vTaskStartScheduler(); +} + +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) +{ + if(ms == TIME_IMMEDIATE) { + taskYIELD(); + } else { + vTaskDelay(ms); + } +} + +void gfxSleepMicroseconds(delaytime_t ms) +{ + delay_wait_us(ms); +} + +portTickType MS2ST(portTickType ms) +{ + 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 */ +/** @} */ +#endif /* USE_UGFX */ From 6e893c7efd56a89b452e84421f5235e5cbaf6867 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:08:14 +0100 Subject: [PATCH 02/11] doc --- gfxconf.example.h | 1 + include/gos/options.h | 17 +++++++++++++++++ releases.txt | 1 + 3 files changed, 19 insertions(+) diff --git a/gfxconf.example.h b/gfxconf.example.h index e6a3381e..53aa187d 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -18,6 +18,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/options.h b/include/gos/options.h index 4edb35d8..864cb832 100644 --- a/include/gos/options.h +++ b/include/gos/options.h @@ -27,6 +27,23 @@ #ifndef GFX_USE_OS_CHIBIOS #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 2cf47a9a..ea3aa785 100644 --- a/releases.txt +++ b/releases.txt @@ -12,6 +12,7 @@ FIX: Console does not execute gwinPrintf() anymore if not visible 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: Added FreeRTOS port *** changes after 1.9 *** From 42f96a10c5eed41dcebc039e255dd8b8466a9a76 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:30:02 +0100 Subject: [PATCH 03/11] some cleanup --- include/gos/freertos.h | 8 ++++---- src/gos/freertos.c | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/gos/freertos.h b/include/gos/freertos.h index 3ceb279d..c9d63ec5 100644 --- a/include/gos/freertos.h +++ b/include/gos/freertos.h @@ -15,10 +15,10 @@ #if GFX_USE_OS_FREERTOS -#include "freertos/FreeRTOS.h" -#include "config/FreeRTOSConfig.h" -#include "freertos/semphr.h" -#include "freertos/task.h" +#include "FreeRTOS.h" +#include "FreeRTOSConfig.h" +#include "semphr.h" +#include "task.h" /*===========================================================================*/ /* Type definitions */ diff --git a/src/gos/freertos.c b/src/gos/freertos.c index 9b22af1b..25166f18 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -9,13 +9,13 @@ * @file src/gos/freertos.c * @brief GOS FreeRTOS Operating System support. */ -#include "heivs/config.h" #include "gfx.h" -#include "heivs/delay.h" -#include "freertos/FreeRTOS.h" -#include "config/FreeRTOSConfig.h" #include +#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 @@ -26,8 +26,7 @@ void _gosInit(void) { - // IMPORTANT: Check for already started scheduler here!!! - vTaskStartScheduler(); + // The user must call vTaskStartScheduler() himself before he calls gfxInit(). } void* gfxRealloc(void *ptr, size_t oldsz, size_t newsz) From 124c8da3ff135e32d31a8ebb587516e504129b05 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:39:11 +0100 Subject: [PATCH 04/11] update --- src/gos/freertos.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gos/freertos.c b/src/gos/freertos.c index 25166f18..3fb94d25 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -50,20 +50,18 @@ void* gfxRealloc(void *ptr, size_t oldsz, size_t newsz) void gfxSleepMilliseconds(delaytime_t ms) { - if(ms == TIME_IMMEDIATE) { - taskYIELD(); - } else { - vTaskDelay(ms); - } + // Implement this } void gfxSleepMicroseconds(delaytime_t ms) { - delay_wait_us(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 From fca893ab832c7316f39dae6cc332cef74e364380 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:40:30 +0100 Subject: [PATCH 05/11] whitespaces --- src/gos/freertos.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gos/freertos.c b/src/gos/freertos.c index 3fb94d25..77adf267 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -64,7 +64,7 @@ portTickType MS2ST(portTickType ms) uint64_t val; - if(configTICK_RATE_HZ == 1000) { // gain time because no test to do in most case + if (configTICK_RATE_HZ == 1000) { // gain time because no test to do in most case return ms; } @@ -97,7 +97,7 @@ bool_t gfxSemWait(gfxSem* psem, delaytime_t ms) { psem->counter--; - if(xSemaphoreTake(psem->sem, MS2ST(ms)) == pdPASS) + if (xSemaphoreTake(psem->sem, MS2ST(ms)) == pdPASS) return TRUE; psem->counter++; @@ -109,7 +109,7 @@ void gfxSemSignal(gfxSem* psem) { taskENTER_CRITICAL(); - if(psem->counter < psem->limit) { + if (psem->counter < psem->limit) { psem->counter++; xSemaphoreGive(psem->sem); } @@ -122,7 +122,7 @@ void gfxSemSignalI(gfxSem* psem) { portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; - if(psem->counter < psem->limit) { + if (psem->counter < psem->limit) { psem->counter++; xSemaphoreGiveFromISR(psem->sem,&xHigherPriorityTaskWoken); } @@ -146,3 +146,4 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_ #endif /* GFX_USE_OS_FREERTOS */ /** @} */ #endif /* USE_UGFX */ + From b6daaabf32bf2092689e0732ca4486f25e80317f Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 2 Feb 2014 19:31:33 +0100 Subject: [PATCH 06/11] fixed file inclusion --- include/gos/gos.h | 2 ++ src/gos/gos.mk | 1 + 2 files changed, 3 insertions(+) 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/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 \ From 9e66363817276214551079baba661d1daa449ff6 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 9 Feb 2014 20:21:08 +0100 Subject: [PATCH 07/11] fixed macros --- src/gos/freertos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gos/freertos.c b/src/gos/freertos.c index 77adf267..872807d1 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -12,6 +12,8 @@ #include "gfx.h" #include +#if GFX_USE_OS_FREERTOS + #if INCLUDE_vTaskDelay != 1 #error "GOS: INCLUDE_vTaskDelay must be defined in FreeRTOSConfig.h" #endif @@ -145,5 +147,4 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_ #endif /* GFX_USE_OS_FREERTOS */ /** @} */ -#endif /* USE_UGFX */ From 58cf2d2b35542166f1a4e50a83bcf28ff33574a5 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 14 Mar 2014 07:39:02 +1000 Subject: [PATCH 08/11] Add SemWaitI() to FreeRTOS --- src/gos/freertos.c | 14 ++++++++++++++ src/gos/freertos.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/gos/freertos.c b/src/gos/freertos.c index 872807d1..e3be4f28 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -107,6 +107,20 @@ bool_t gfxSemWait(gfxSem* psem, delaytime_t ms) return FALSE; } +bool_t gfxSemWaitI(gfxSem* psem) +{ + portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; + + psem->counter--; + + if (xSemaphoreTakeFromISR(psem->sem,&xHigherPriorityTaskWoken) == pdTRUE) + return TRUE; + + psem->counter++; + + return FALSE; +} + void gfxSemSignal(gfxSem* psem) { taskENTER_CRITICAL(); diff --git a/src/gos/freertos.h b/src/gos/freertos.h index dc98185f..f15ca910 100644 --- a/src/gos/freertos.h +++ b/src/gos/freertos.h @@ -94,6 +94,7 @@ 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); +bool_t gfxSemWaitI(gfxSem* psem); void gfxSemSignal(gfxSem* psem); void gfxSemSignalI(gfxSem* psem); #define gfxSemCounterI(psem) ((psem)->counter) From 2ef393d35b579325666797b67969c6dc94d161f9 Mon Sep 17 00:00:00 2001 From: Winfred Lu Date: Sun, 4 May 2014 22:52:58 +0800 Subject: [PATCH 09/11] Fix some typos and implement gfxSleepMilliseconds(). --- src/gos/freertos.c | 35 ++++++++++++++++------------------- src/gos/freertos.h | 3 +-- src/gos/sys_options.h | 12 +----------- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/gos/freertos.c b/src/gos/freertos.c index e3be4f28..ce831a4c 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -28,7 +28,11 @@ void _gosInit(void) { - // The user must call vTaskStartScheduler() himself before he calls gfxInit(). + // The user must call vTaskStartScheduler() himself before he calls gfxInit(). +} + +void _gosDeinit(void) +{ } void* gfxRealloc(void *ptr, size_t oldsz, size_t newsz) @@ -52,30 +56,24 @@ void* gfxRealloc(void *ptr, size_t oldsz, size_t newsz) void gfxSleepMilliseconds(delaytime_t ms) { - // Implement this + const portTickType ticks = ms / portTICK_PERIOD_MS; + vTaskDelay(ticks); } void gfxSleepMicroseconds(delaytime_t ms) { - // Implement this + const portTickType ticks = (ms / 1000) / portTICK_PERIOD_MS; + + // delay milli seconds + vTaskDelay(ticks); + + // microsecond resolution delay is not supported in FreeRTOS + // vUsDelay(ms%1000); } 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; + return (ms / portTICK_PERIOD_MS); } void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit) @@ -152,7 +150,7 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_ if (stacksz < configMINIMAL_STACK_SIZE) stacksz = configMINIMAL_STACK_SIZE; - if (xTaskCreate(fn, (signed char*)"uGFX_TASK", stacksz, param, prio, &task )!= pdPASS) { + if (xTaskCreate(fn, "uGFX_TASK", stacksz, param, prio, &task )!= pdPASS) { for (;;); } @@ -161,4 +159,3 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_ #endif /* GFX_USE_OS_FREERTOS */ /** @} */ - diff --git a/src/gos/freertos.h b/src/gos/freertos.h index f15ca910..7fa9ee4f 100644 --- a/src/gos/freertos.h +++ b/src/gos/freertos.h @@ -59,7 +59,7 @@ typedef struct { } gfxSem; typedef xSemaphoreHandle gfxMutex; -typedef xTaskHandl* gfxThreadHandle; +typedef xTaskHandle* gfxThreadHandle; /*===========================================================================*/ /* Function declarations. */ @@ -111,4 +111,3 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_ #endif /* GFX_USE_OS_FREERTOS */ #endif /* _GOS_CHIBIOS_H */ - diff --git a/src/gos/sys_options.h b/src/gos/sys_options.h index 9d2e735f..90a5bc91 100644 --- a/src/gos/sys_options.h +++ b/src/gos/sys_options.h @@ -42,17 +42,7 @@ #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 - */ - #ifndef GFX_USE_OS_WIN32 - #define GFX_USE_OS_WIN32 FALSE - #endif - /** - * @brief Use a linux based system running X11 + * @brief Use a linux based system running X11 * @details Defaults to FALSE */ #ifndef GFX_USE_OS_LINUX From cb825aa823f2b7ae687cdc4753a77baf6f24cb91 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 10 May 2014 18:13:51 +0200 Subject: [PATCH 10/11] Introducing GFX_FREERTOS_USE_TRACE --- gfxconf.example.h | 16 ++++++++++------ src/gos/freertos.c | 9 +++------ src/gos/freertos.h | 6 ++++-- src/gos/sys_options.h | 9 ++++++++- src/gos/sys_rules.h | 5 +++++ 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/gfxconf.example.h b/gfxconf.example.h index fe7814bf..22135ca0 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -18,12 +18,16 @@ #ifndef _GFXCONF_H #define _GFXCONF_H -/* 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 + +/////////////////////////////////////////////////////////////////////////// +// GOS - One of these must be defined, preferably in your Makefile // +/////////////////////////////////////////////////////////////////////////// +//#define GFX_USE_OS_CHIBIOS FALSE +//#define GFX_USE_OS_FREERTOS FALSE + #define GFX_FREERTOS_USE_TRACE FALSE +//#define GFX_USE_OS_WIN32 FALSE +//#define GFX_USE_OS_LINUX FALSE +//#define GFX_USE_OS_OSX FALSE /////////////////////////////////////////////////////////////////////////// diff --git a/src/gos/freertos.c b/src/gos/freertos.c index ce831a4c..a61914c0 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -5,10 +5,6 @@ * http://ugfx.org/license.html */ -/** - * @file src/gos/freertos.c - * @brief GOS FreeRTOS Operating System support. - */ #include "gfx.h" #include @@ -85,7 +81,9 @@ void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit) psem->limit = limit; psem->sem = xSemaphoreCreateCounting(limit,val); - vTraceSetSemaphoreName(psem->sem, "uGFXSema"); // for FreeRTOS+Trace debug + #if GFX_FREERTOS_USE_TRACE + vTraceSetSemaphoreName(psem->sem, "uGFXSema"); // for FreeRTOS+Trace debug + #endif } void gfxSemDestroy(gfxSem* psem) @@ -158,4 +156,3 @@ gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_ } #endif /* GFX_USE_OS_FREERTOS */ -/** @} */ diff --git a/src/gos/freertos.h b/src/gos/freertos.h index 7fa9ee4f..db1c427b 100644 --- a/src/gos/freertos.h +++ b/src/gos/freertos.h @@ -39,7 +39,7 @@ typedef int8_t bool_t; typedef uint32_t delaytime_t; typedef portTickType systemticks_t; typedef int32_t semcount_t; -typedef void threadreturn_t; +typedef void threadreturn_t; typedef portBASE_TYPE threadpriority_t; #define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1)) @@ -81,7 +81,9 @@ extern "C" { static inline void gfxMutexInit(xSemaphoreHandle *s) { *s = xSemaphoreCreateMutex(); - vTraceSetMutexName(*s,"uGFXMutex"); // for FreeRTOS+Trace debug + #if GFX_FREERTOS_USE_TRACE + vTraceSetMutexName(*s,"uGFXMutex"); // for FreeRTOS+Trace debug + #endif } #define gfxMutexDestroy(pmutex) vSemaphoreDelete(*pmutex) #define gfxMutexEnter(pmutex) xSemaphoreTake(*pmutex,portMAX_DELAY) diff --git a/src/gos/sys_options.h b/src/gos/sys_options.h index 90a5bc91..cfbed057 100644 --- a/src/gos/sys_options.h +++ b/src/gos/sys_options.h @@ -65,9 +65,16 @@ /** * @} * - * @name GOS Optional Sizing Parameters + * @name GOS Optional Parameters * @{ */ + /** + * @brief Should uGFX stuff be added to the FreeRTOS+Tracer + * @details Defaults to FALSE + */ + #ifndef GFX_FREERTOS_USE_TRACE + #define GFX_FREERTOS_USE_TRACE FALSE + #endif /** @} */ #endif /* _GOS_OPTIONS_H */ diff --git a/src/gos/sys_rules.h b/src/gos/sys_rules.h index ff4a1ecb..f23d330b 100644 --- a/src/gos/sys_rules.h +++ b/src/gos/sys_rules.h @@ -23,9 +23,14 @@ #undef GFX_USE_OS_CHIBIOS #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 != 1 * TRUE #error "GOS: More than one operation system has been defined as TRUE." #endif +#if GFX_FREERTOS_USE_TRACE && !GFX_USE_OS_FREERTOS + #error "GOS: GFX_FREERTOS_USE_TRACE is only available for the FreeRTOS port." +#endif + #endif /* _GOS_RULES_H */ /** @} */ From 33a037b81c5d974d1cf419ecc87e91a74b8c9406 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 10 May 2014 18:26:44 +0200 Subject: [PATCH 11/11] freertos port cleanup --- src/gos/freertos.c | 8 ++++++++ src/gos/freertos.h | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/gos/freertos.c b/src/gos/freertos.c index a61914c0..f2c03eec 100644 --- a/src/gos/freertos.c +++ b/src/gos/freertos.c @@ -72,6 +72,14 @@ portTickType MS2ST(portTickType ms) return (ms / portTICK_PERIOD_MS); } +void gfxMutexInit(xSemaphoreHandle *s) +{ + *s = xSemaphoreCreateMutex(); + #if GFX_FREERTOS_USE_TRACE + vTraceSetMutexName(*s,"uGFXMutex"); // for FreeRTOS+Trace debug + #endif +} + void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit) { if (val > limit) diff --git a/src/gos/freertos.h b/src/gos/freertos.h index db1c427b..ccda4cbd 100644 --- a/src/gos/freertos.h +++ b/src/gos/freertos.h @@ -78,13 +78,8 @@ extern "C" { #define gfxMillisecondsToTicks(ms) MS2ST(ms) #define gfxSystemLock() {} #define gfxSystemUnlock() {} -static inline void gfxMutexInit(xSemaphoreHandle *s) -{ - *s = xSemaphoreCreateMutex(); - #if GFX_FREERTOS_USE_TRACE - vTraceSetMutexName(*s,"uGFXMutex"); // for FreeRTOS+Trace debug - #endif -} + +void gfxMutexInit(xSemaphoreHandle* s); #define gfxMutexDestroy(pmutex) vSemaphoreDelete(*pmutex) #define gfxMutexEnter(pmutex) xSemaphoreTake(*pmutex,portMAX_DELAY) #define gfxMutexExit(pmutex) xSemaphoreGive(*pmutex)