From 0bb6473f880e69c294f78972a04c286a088d15fb Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:06:20 +0100 Subject: initial public release of FreeRTOS port (does still need some cleanup) --- src/gos/freertos.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/gos/freertos.c (limited to 'src/gos') 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 */ -- cgit v1.2.3 From 42f96a10c5eed41dcebc039e255dd8b8466a9a76 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:30:02 +0100 Subject: some cleanup --- src/gos/freertos.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/gos') 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) -- cgit v1.2.3 From 124c8da3ff135e32d31a8ebb587516e504129b05 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:39:11 +0100 Subject: update --- src/gos/freertos.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/gos') 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 -- cgit v1.2.3 From fca893ab832c7316f39dae6cc332cef74e364380 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 1 Feb 2014 17:40:30 +0100 Subject: whitespaces --- src/gos/freertos.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/gos') 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 */ + -- cgit v1.2.3 From b6daaabf32bf2092689e0732ca4486f25e80317f Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 2 Feb 2014 19:31:33 +0100 Subject: fixed file inclusion --- src/gos/gos.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gos') 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 \ -- cgit v1.2.3 From 9e66363817276214551079baba661d1daa449ff6 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 9 Feb 2014 20:21:08 +0100 Subject: fixed macros --- src/gos/freertos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gos') 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 */ -- cgit v1.2.3 From 58cf2d2b35542166f1a4e50a83bcf28ff33574a5 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 14 Mar 2014 07:39:02 +1000 Subject: Add SemWaitI() to FreeRTOS --- src/gos/freertos.c | 14 ++++++++++++++ src/gos/freertos.h | 1 + 2 files changed, 15 insertions(+) (limited to 'src/gos') 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) -- cgit v1.2.3 From 2ef393d35b579325666797b67969c6dc94d161f9 Mon Sep 17 00:00:00 2001 From: Winfred Lu Date: Sun, 4 May 2014 22:52:58 +0800 Subject: 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(-) (limited to 'src/gos') 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 -- cgit v1.2.3 From cb825aa823f2b7ae687cdc4753a77baf6f24cb91 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 10 May 2014 18:13:51 +0200 Subject: Introducing GFX_FREERTOS_USE_TRACE --- src/gos/freertos.c | 9 +++------ src/gos/freertos.h | 6 ++++-- src/gos/sys_options.h | 9 ++++++++- src/gos/sys_rules.h | 5 +++++ 4 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src/gos') 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 */ /** @} */ -- cgit v1.2.3 From 33a037b81c5d974d1cf419ecc87e91a74b8c9406 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 10 May 2014 18:26:44 +0200 Subject: freertos port cleanup --- src/gos/freertos.c | 8 ++++++++ src/gos/freertos.h | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/gos') 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) -- cgit v1.2.3