mattbudd wrote on Friday, June 06, 2008:
I have a problem with vTaskDelay. What I want to do is perform an action on a regular task once every tick, and then every say 100 ticks (1 second in my config) have a periodic task wake up and report on the status of the regular task. Here is my code:
//--------------------------------------------------------------
portTASK_FUNCTION_PROTO(regularTask, ppvParameters);
portTASK_FUNCTION_PROTO(periodicTask, ppvParameters);
static volatile unsigned int m_iCounter = 0;
void CreateTasks(void)
{
xTaskCreate(regularTask, "reg", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
xTaskCreate(periodicTask, "per", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
}
portTASK_FUNCTION(regularTask, ppvParameters)
{
while (1)
{
m_iCounter++;
vTaskDelay(1);
}
}
portTASK_FUNCTION(periodicTask, ppvParameters)
{
while (1)
{
vTaskDelay(1000 / portTICK_RATE_MS);
CSLog("counter = %d, tickcount = %d", m_iCounter, xTaskGetTickCount()); //This just logs to the debug window
}
}
//--------------------------------------------------------------
So the periodic task is a higher priority, but it doesn’t seem to fire off every 1 second…it takes about 3 or 4 second to fire off. If I take out the “vTaskDelay(1)” in the regular task, it will fire off at the correct speed, but then m_iCounter gets updated more than once per tick. How do I yield the regular task to the next tick…taskYield() seems have the same issue.
Any ideas?