kivie wrote on Monday, August 24, 2015:
I need to schedule and run tasks at certain intervals each hour. To get correct calendar time the clock is synchronized with GPS. I am using Giant Gecko from Sililabs and need to use tickless mode. I’m using the FreeRTOS version (v7.4.2) that comes with Simplicity Studio. I need millisecond precision.
My first idea was to use the vTaskDelay function with a calculated value when to run the task. The problem with this method was that the time drifted. I just couldn’t get it right with the RTC. It worked quite well (within approx 10ms) when I only got one task and I redefined portTICK_PERIOD_MS to 9.94875.
Currently the application is running without FreeRTOS and the wake-ups for the tasks is done with the BURTC and this works really good (but it seemed simplier to use a RTOS to enable multitasking then extend current application). The way the calender time is kept on the mcu is by letting the BURTC count 1024 ticks per second. So I thought I could use the BURTC, but to be able to keep the calendar time I could not reset the the tick counter. The tick counter is reset by the GPS synchronization (each hour, no overflow). The problem here was that I had to set ISR to run each tick and this made the same task run multiple times for some reason.
So my third idea was to rewrite some parts of the FreeRTOS to get things working. The idea is to make some changes to tasks.c.
Redefine xTickCount to BURTC->CNT. Also remove everything that updates xTickCount. This way the xTickCount is always correct.
#define xTickCount BURTC->CNT
Whenever the BURTC->CNT is reset a loop goes through the list with tasks and reduces the time for each task.
vTaskDelay (chould be renamed) is supplied with a calculated value from BURTC->CNT and the value supplied is not subracted with xTickCount.
With these changes the vPortSuppressTicksAndSleep (there are changes in this function as well, e.g. the vTaskSetTick is not called since task.c get the tick count directly from BURTC->CNT) function sleeps to exactly the correct time. When it wakes up it starts to tick again but the task does not get executed.
The xTaskResumeAll is called when it is woken up and xYieldPending is set to pdTRUE.
I’m sure it can be unsafe to define xTickCount as I have done but I still think the task should be running after the cup have slept.
For some reason I can’t debug after the prvPortStartFirstTask is executed which makes it hard to see what goes wrong. I’m using eclipse and gdb for debugging.
Anyone have any suggestion why my Task isn’t running after sleep?
How I can use the RTC with a resolution of 1ms and no drift?
How I can use the BURTC with a resolution of 1ms and no drift (without reset the counter)?
Any idea why I can’t debug after prvPortStartFirstTask?