Browse Source

Updates to the FreeRTOS GOS port

remotes/origin_old/release/v2.9
inmarket 5 years ago
parent
commit
8b4ca12a2d
  1. 73
      src/gos/gos_freertos.c
  2. 37
      src/gos/gos_freertos.h

73
src/gos/gos_freertos.c

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

37
src/gos/gos_freertos.h

@ -59,21 +59,14 @@ typedef portBASE_TYPE threadpriority_t;
#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)
/* FreeRTOS will allocate the stack when creating the thread */
#define DECLARE_THREAD_STACK(name, sz)
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
#define THREAD_RETURN(retval)
portTickType MS2ST(portTickType ms);
typedef struct {
xSemaphoreHandle sem;
semcount_t limit;
semcount_t counter;
} gfxSem;
typedef xSemaphoreHandle gfxSem;
typedef xSemaphoreHandle gfxMutex;
typedef xTaskHandle* gfxThreadHandle;
typedef xTaskHandle gfxThreadHandle;
/*===========================================================================*/
/* Function declarations. */
@ -83,33 +76,31 @@ typedef xTaskHandle* gfxThreadHandle;
extern "C" {
#endif
#define gfxHalt(msg) {}
#define gfxExit() {}
#define gfxHalt(msg) {while(1);}
#define gfxExit() {while(1);}
#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() {}
#define gfxMillisecondsToTicks(ms) ((systemticks_t)((ms) / portTICK_PERIOD_MS))
#define gfxSystemLock() taskENTER_CRITICAL()
#define gfxSystemUnlock() taskEXIT_CRITICAL()
void gfxMutexInit(xSemaphoreHandle* s);
#define gfxMutexDestroy(pmutex) vSemaphoreDelete(*pmutex)
#define gfxMutexEnter(pmutex) xSemaphoreTake(*pmutex,portMAX_DELAY)
#define gfxMutexExit(pmutex) xSemaphoreGive(*pmutex)
void gfxMutexInit(gfxMutex* s);
#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);
#define gfxSemDestroy(psem) vSemaphoreDelete(*(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)
#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

Loading…
Cancel
Save