Skip to content

Commit

Permalink
Fix gtimer on freertos
Browse files Browse the repository at this point in the history
gtime tries to calculate from ticks to milliseconds by dividing by
`gfxMillisecondsToTicks(1)`. That'd be fine on systems where there's multiple
milliseconds per tick, but on freertos we count 10 ticks per millisecond, so
`gfxMillisecondsToTicks(1)` is 0, causing a division by zero later on.

For a 'proper' fix we'd need to implement gfxTicksToMilliseconds
on each backend, not just freertos
  • Loading branch information
raboof committed Jun 9, 2017
1 parent e6721f7 commit f20d419
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/gos/gos_freertos.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extern "C" {
#define gfxYield() taskYIELD()
#define gfxSystemTicks() xTaskGetTickCount()
#define gfxMillisecondsToTicks(ms) ((systemticks_t)((ms) / portTICK_PERIOD_MS))
#define gfxTicksToMilliseconds(ticks) (ticks * portTICK_PERIOD_MS)
#define gfxSystemLock() taskENTER_CRITICAL()
#define gfxSystemUnlock() taskEXIT_CRITICAL()

Expand Down
4 changes: 1 addition & 3 deletions src/gtimer/gtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ static gfxMutex mutex;
static gfxThreadHandle hThread = 0;
static GTimer *pTimerHead = 0;
static gfxSem waitsem;
static systemticks_t ticks2ms;
static DECLARE_THREAD_STACK(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);

/*===========================================================================*/
Expand Down Expand Up @@ -100,7 +99,7 @@ static DECLARE_THREAD_FUNCTION(GTimerThreadHandler, arg) {

// Find when we next need to wake up
if (!(pt->flags & GTIMER_FLG_INFINITE) && pt->when - tm < nxtTimeout)
nxtTimeout = (pt->when - tm)/ticks2ms;
nxtTimeout = gfxTicksToMilliseconds(pt->when - tm);
pt = pt->next;
} while(pt != pTimerHead);
}
Expand All @@ -116,7 +115,6 @@ void _gtimerInit(void)
{
gfxSemInit(&waitsem, 0, 1);
gfxMutexInit(&mutex);
ticks2ms = gfxMillisecondsToTicks(1);
}

void _gtimerDeinit(void)
Expand Down

0 comments on commit f20d419

Please sign in to comment.