using vTaskDelayUntil questions

Posted by Brian Carver on November 4, 2009
I am trying a simple delay into my simple program so I can control the rate of delay to flash an LED on/off. Here is the code:

int i;
portTickType xLastWakeTime;
const portTickType xFrequency = 10000;

LATBbits.LATB2 = 1;// Set LAT register to turn on LED
xLastWakeTime = xTaskGetTickCount();

for(;;)
{
vTaskDelayUntil(&xLastWakeTime, xFrequency);
//for(i=0; i<0xFFFF; i++);
//for(i=0; i<0xFFFF; i++);
//for(i=0; i<0xFFFF; i++);

taskENTER_CRITICAL();
LATBbits.LATB3 = ~LATBbits.LATB3;// Set LAT register bit 3 to turn on LED
taskEXIT_CRITICAL();

When I use the function vTaskDelayUntil the code does not work, but If I comment out my busy wait loops, those work well. I know the delayUntil function is a better way to go, as the processor might go to sleep in the idle task (hopefully a correct assumption)

I followed the debugger into the code, I can see the task get placed into the wait queue, but it's really hard to see when the task is released from the wait queue.

Any suggestion?

RE: using vTaskDelayUntil questions

Posted by MEdwards on November 4, 2009
Check the tick interrupt is running. If not then the task will never leave the delay.

10000 is potentially a long delay too, 10 seconds if the tick frequency is 1KHz, 100 seconds if the tick frequency is 100Hz.

RE: using vTaskDelayUntil questions

Posted by Brian Carver on November 4, 2009
You are correct, the tick interrupt is not running. I changed my code to this:
xLastWakeTime = xTaskGetTickCount();
vTaskDelayUntil(&xLastWakeTime, xFrequency);

I set a debug break on the vTaskDelayUntil line to read the value xLastWakeTime. The value read zero every time, i looped through the application.

Thinking I had the right option I turned on

#define configUSE_TICK_HOOK1

That resulted into a compile error:
Source\tasks.c:1362: undefined reference to `vApplicationTickHook'

I am using a PIC24F16KA102 for my chip. So I know the scheduler is started as I call vTaskStartScheduler(); and that starts the task interrupt.

The suggestion was spot on, but I really don't know how to make sure the tick interrupt is really working.

RE: using vTaskDelayUntil questions

Posted by Brian Carver on November 5, 2009
I really now know that the scheduler is giving control to my function but the interrupt tick is not working. I added an extra task to send a character on the UART. The uartTask and my ledTask (flasher) does not work together. At least I am not seeing a context switch between the two. So I have a configuration issue with my code, any more suggestions?