I have a problem with vTaskDelayUntil() function not making a delay but finishing immediately. Here is the code:
TickType_t xLastWakeTime = xTaskGetTickCount();
while(1){
if (xSemaphoreTake(xSemaphoreRS485, portMAX_DELAY) == pdTRUE) {
printf("S display data %d\n", xTaskGetTickCount());
sendDisplayData();
printf("E display data %d\n", xTaskGetTickCount());
xSemaphoreGive(xSemaphoreRS485);
printf("W display data %d\n", xLastWakeTime);
vTaskDelayUntil(&xLastWakeTime, 2000);
}
}
From this I get following output:
S display data 29928
E display data 30534
W display data 3919
S display data 30534
E display data 31140
W display data 5919
S display data 31140
E display data 31746
W display data 7919
S display data 31746
E display data 32352
W display data 9919
The function sendDisplayData() takes about 670 ms to execute and xTaskGetTickCount() confirms it. Then the task should wait around 1230 ms so the whole iteration could take 2000 ms. But vTaskDelayUntil() finishes immediately. First execution ended at 30534 and the second one starts at 30534 too. Value returned by xTaskGetTickCount() proves there was no delay introduced by vTaskDelayUntil(). I can also see it by frequency of output of sendDisplayData().
The second funny thing is that xLastWakeTime shows totally different values and those values are in fact incremented by 2000. Shouldn't it store similar value as returned by xTaskGetTickCount()?