Problems with xTaskDelay()

nobody wrote on Thursday, March 01, 2007:


I’ve some mysterious problems with the xTaskDelay function. I start a task an everything runs until the xTaskDelay()-function is called and never returns.
But if I create a “do-only-i++”-task with a priority set to tskIDLE_PRIORITY+1 and set the other task to tskIDLE_PRIORITY+2, everything runs normal.

I don’t know, that isn’t the way it should work, is it?
By the way, I use a LPC2106 Board, GCC4.1.1 and FreeRTOS V3.2.3.

So, if someone have a good guess, what might be wrong, all answers are welcome.

nobody wrote on Thursday, March 01, 2007:

I don’t understand your explanation.  Can you try rewording or giving an example simple bit of code.

If xTaskDelay() does not return are you sure the tick interrupt is running correctly?

Are you using an idle hook that calls a blocking function?

nobody wrote on Thursday, March 01, 2007:

I hope this time it is more understandable:

I create a task:
-> xTaskCreate(v_task_Heartbeat,(const signed portCHAR * const) "heartbeat", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &x_task_Heartbeat_Handle);
which should do:
->void v_task_Heartbeat(void *pvParameters)
    pvParameters = 0;
    HEARTBEAT_LED_PORT = HEARTBEAT_LED;        // set to output
    // endless loop
        vTaskDelay(HEARTBEAT_LED_DELAY);    // wait for 500 ticks (0.5s)
        vTaskDelay(HEARTBEAT_LED_DELAY);    // wait for 500 ticks (0.5s)

I use openocd to debug the program and when i reach the line: vTaskDelay(…), the programm jumps into the function. My task get delayed, but never wake up. When i step further the programm calls the Idle-Task an check if there are other task ready to run. Then i let the programm continue and after a short time i hold it. The programm now has reached an abort-error-loop.
Now i increase the Task-Priority to 2 and create a new task:
->void v_task_idle_2(void *pvParameters)
    pvParameters = 0;
    u32 i;

    // endless loop
with a Priotity of tskIDLE_PRIRITY+1. If i run this programm, everything seems to run normal an my LED is blinking.
I don’t use an idle hook.

Some more settings:
#define configUSE_PREEMPTION        1
#define configUSE_IDLE_HOOK            0
#define configCPU_CLOCK_HZ            ( ( unsigned portLONG ) 58982400 )    /* =12Mhz xtal multiplied by 4 using the PLL. */
#define configTICK_RATE_HZ            ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES        ( ( unsigned portBASE_TYPE ) 8 )
#define configMINIMAL_STACK_SIZE    ( ( unsigned portSHORT ) 150 )
#define configTOTAL_HEAP_SIZE        ( ( size_t ) ( 10 * 1024 ) )
#define configMAX_TASK_NAME_LEN        ( 16 )
#define configUSE_TRACE_FACILITY    0
#define configUSE_16_BIT_TICKS        0
#define configIDLE_SHOULD_YIELD        1

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

#define INCLUDE_vTaskPrioritySet        1
#define INCLUDE_uxTaskPriorityGet        1
#define INCLUDE_vTaskDelete                0
#define INCLUDE_vTaskCleanUpResources    0
#define INCLUDE_vTaskSuspend            1
#define INCLUDE_vTaskDelayUntil            1
#define INCLUDE_vTaskDelay                1

nobody wrote on Thursday, March 01, 2007:

By creating a second idle task that never blocks, you are soaking up all the available CPU so prvIdleTask is never executed.  That seems to make it work.  So I would then guess that the problem lies in prvIdleTask.

But in your configuration the prvIdleTask in tasks.c will do nothing at all if you create no tasks at tskIDLE_PRIORITY - are you sure you don’t have such tasks also defined?

It all sounds like either an interrupt going astray or perhaps your SWI handler not being setup properly and thus you’re getting aborts when trying to execute garbage?


nobody wrote on Thursday, March 01, 2007:

Hello Robin,
thanks for your answer. I checked the tasks.c, the interrupt routines and a few other functions, and there was nothing. While searching the code, i found a bug in my own code. (Actually i searched my own code a few times but didn’t saw it before). Now everything seems to work fine. (until the next bug :slight_smile: )

Again, thanks to all for helping me out.