Updates to the FreeRTOS GOS port

release/v2.9
inmarket 2017-03-01 10:46:14 +10:00
parent 29ccac5efc
commit 8b4ca12a2d
2 changed files with 32 additions and 78 deletions

View File

@ -49,7 +49,7 @@ void* gfxRealloc(void *ptr, size_t oldsz, size_t newsz)
if (oldsz) { if (oldsz) {
memcpy(np, ptr, oldsz); memcpy(np, ptr, oldsz);
vPortFree(ptr); gfxFree(ptr);
} }
return np; return np;
@ -57,31 +57,22 @@ void* gfxRealloc(void *ptr, size_t oldsz, size_t newsz)
void gfxSleepMilliseconds(delaytime_t ms) void gfxSleepMilliseconds(delaytime_t ms)
{ {
const portTickType ticks = ms / portTICK_PERIOD_MS; vTaskDelay(gfxMillisecondsToTicks(ms));
vTaskDelay(ticks);
} }
void gfxSleepMicroseconds(delaytime_t ms) void gfxSleepMicroseconds(delaytime_t ms)
{ {
const portTickType ticks = (ms / 1000) / portTICK_PERIOD_MS;
// delay milli seconds // delay milli seconds - microsecond resolution delay is not supported in FreeRTOS
vTaskDelay(ticks); vTaskDelay(gfxMillisecondsToTicks(ms/1000));
// microsecond resolution delay is not supported in FreeRTOS
// vUsDelay(ms%1000); // vUsDelay(ms%1000);
} }
portTickType MS2ST(portTickType ms) void gfxMutexInit(gfxMutex *pmutex)
{ {
return (ms / portTICK_PERIOD_MS); *pmutex = xSemaphoreCreateMutex();
}
void gfxMutexInit(xSemaphoreHandle *s)
{
*s = xSemaphoreCreateMutex();
#if GFX_FREERTOS_USE_TRACE #if GFX_FREERTOS_USE_TRACE
vTraceSetMutexName(*s,"uGFXMutex"); // for FreeRTOS+Trace debug vTraceSetMutexName(*pmutex,"uGFXMutex");
#endif #endif
} }
@ -90,29 +81,16 @@ void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit)
if (val > limit) if (val > limit)
val = limit; val = limit;
psem->counter = val; *psem = xSemaphoreCreateCounting(limit,val);
psem->limit = limit;
psem->sem = xSemaphoreCreateCounting(limit,val);
#if GFX_FREERTOS_USE_TRACE #if GFX_FREERTOS_USE_TRACE
vTraceSetSemaphoreName(psem->sem, "uGFXSema"); // for FreeRTOS+Trace debug vTraceSetSemaphoreName(*psem, "uGFXSema");
#endif #endif
} }
void gfxSemDestroy(gfxSem* psem)
{
vSemaphoreDelete(psem->sem);
}
bool_t gfxSemWait(gfxSem* psem, delaytime_t ms) bool_t gfxSemWait(gfxSem* psem, delaytime_t ms)
{ {
psem->counter--; if (xSemaphoreTake(*psem, gfxMillisecondsToTicks(ms)) == pdPASS)
if (xSemaphoreTake(psem->sem, MS2ST(ms)) == pdPASS)
return TRUE; return TRUE;
psem->counter++;
return FALSE; return FALSE;
} }
@ -120,50 +98,35 @@ bool_t gfxSemWaitI(gfxSem* psem)
{ {
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
psem->counter--; if (xSemaphoreTakeFromISR(*psem, &xHigherPriorityTaskWoken) == pdTRUE)
if (xSemaphoreTakeFromISR(psem->sem,&xHigherPriorityTaskWoken) == pdTRUE)
return TRUE; return TRUE;
psem->counter++;
return FALSE; return FALSE;
} }
void gfxSemSignal(gfxSem* psem) void gfxSemSignal(gfxSem* psem)
{ {
taskENTER_CRITICAL(); xSemaphoreGive(*psem);
if (psem->counter < psem->limit) {
psem->counter++;
xSemaphoreGive(psem->sem);
}
taskYIELD(); taskYIELD();
taskEXIT_CRITICAL();
} }
void gfxSemSignalI(gfxSem* psem) void gfxSemSignalI(gfxSem* psem)
{ {
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
if (psem->counter < psem->limit) { xSemaphoreGiveFromISR(*psem,&xHigherPriorityTaskWoken);
psem->counter++;
xSemaphoreGiveFromISR(psem->sem,&xHigherPriorityTaskWoken);
}
} }
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
{ {
xTaskHandle task = NULL; gfxThreadHandle task;
stacksz = (size_t)stackarea; (void) stackarea;
if (stacksz < configMINIMAL_STACK_SIZE) if (stacksz < configMINIMAL_STACK_SIZE)
stacksz = configMINIMAL_STACK_SIZE; stacksz = configMINIMAL_STACK_SIZE;
if (xTaskCreate(fn, "uGFX_TASK", stacksz, param, prio, &task )!= pdPASS) { task = 0;
for (;;); if (xTaskCreate(fn, "uGFX_TASK", stacksz, param, prio, &task) != pdPASS)
} return 0;
return task; return task;
} }

View File

@ -59,21 +59,14 @@ typedef portBASE_TYPE threadpriority_t;
#define NORMAL_PRIORITY configMAX_PRIORITIES/2 #define NORMAL_PRIORITY configMAX_PRIORITIES/2
#define HIGH_PRIORITY configMAX_PRIORITIES-1 #define HIGH_PRIORITY configMAX_PRIORITIES-1
/* FreeRTOS will allocate the stack when creating the thread, so pass the size instead of a working area */ /* FreeRTOS will allocate the stack when creating the thread */
#define DECLARE_THREAD_STACK(name, sz) size_t *name = (size_t *)(sz) #define DECLARE_THREAD_STACK(name, sz)
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param) #define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
#define THREAD_RETURN(retval) #define THREAD_RETURN(retval)
portTickType MS2ST(portTickType ms); typedef xSemaphoreHandle gfxSem;
typedef struct {
xSemaphoreHandle sem;
semcount_t limit;
semcount_t counter;
} gfxSem;
typedef xSemaphoreHandle gfxMutex; typedef xSemaphoreHandle gfxMutex;
typedef xTaskHandle* gfxThreadHandle; typedef xTaskHandle gfxThreadHandle;
/*===========================================================================*/ /*===========================================================================*/
/* Function declarations. */ /* Function declarations. */
@ -83,33 +76,31 @@ typedef xTaskHandle* gfxThreadHandle;
extern "C" { extern "C" {
#endif #endif
#define gfxHalt(msg) {} #define gfxHalt(msg) {while(1);}
#define gfxExit() {} #define gfxExit() {while(1);}
#define gfxAlloc(sz) pvPortMalloc(sz) #define gfxAlloc(sz) pvPortMalloc(sz)
#define gfxFree(ptr) vPortFree(ptr) #define gfxFree(ptr) vPortFree(ptr)
#define gfxYield() taskYIELD() #define gfxYield() taskYIELD()
#define gfxSystemTicks() xTaskGetTickCount() #define gfxSystemTicks() xTaskGetTickCount()
#define gfxMillisecondsToTicks(ms) MS2ST(ms) #define gfxMillisecondsToTicks(ms) ((systemticks_t)((ms) / portTICK_PERIOD_MS))
#define gfxSystemLock() {} #define gfxSystemLock() taskENTER_CRITICAL()
#define gfxSystemUnlock() {} #define gfxSystemUnlock() taskEXIT_CRITICAL()
void gfxMutexInit(xSemaphoreHandle* s); void gfxMutexInit(gfxMutex* s);
#define gfxMutexDestroy(pmutex) vSemaphoreDelete(*pmutex) #define gfxMutexDestroy(pmutex) vSemaphoreDelete(*(pmutex))
#define gfxMutexEnter(pmutex) xSemaphoreTake(*pmutex,portMAX_DELAY) #define gfxMutexEnter(pmutex) xSemaphoreTake(*(pmutex),portMAX_DELAY)
#define gfxMutexExit(pmutex) xSemaphoreGive(*pmutex) #define gfxMutexExit(pmutex) xSemaphoreGive(*(pmutex))
void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz); void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz);
void gfxSleepMilliseconds(delaytime_t ms); void gfxSleepMilliseconds(delaytime_t ms);
void gfxSleepMicroseconds(delaytime_t ms); void gfxSleepMicroseconds(delaytime_t ms);
void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit); void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit);
void gfxSemDestroy(gfxSem* psem); #define gfxSemDestroy(psem) vSemaphoreDelete(*(psem))
bool_t gfxSemWait(gfxSem* psem, delaytime_t ms); bool_t gfxSemWait(gfxSem* psem, delaytime_t ms);
bool_t gfxSemWaitI(gfxSem* psem); bool_t gfxSemWaitI(gfxSem* psem);
void gfxSemSignal(gfxSem* psem); void gfxSemSignal(gfxSem* psem);
void gfxSemSignalI(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); 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 gfxThreadWait(thread) {} // never used, not imlpemented