chinamaykumar wrote on Tuesday, April 29, 2008:

Hi all,

After a long time I am able to run multiple task at same priority. But not able to do multitasking for different priorities.

So can anybody tell me to do multitaking at different priorities or i have to do some changes in kernal.
here i am mentioning a situation…

Let us assume  we have two tasks task1 and task2.Task1 has higher priority than task2.Initially my task1 is running but a delay call come and than i want to execute my task2.

At the same priority i am able to execute task2 but not at different prorities.

Please reply soon.


neilbradley wrote on Tuesday, April 29, 2008:

You’ll need to make sure that Task1 blocks on a kernel object (semaphore, mutex, event flag, queue, etc…) so Task1 will go to sleep, otherwise Task2 will never execute.

incrediball wrote on Tuesday, April 29, 2008:

You certainly do not need to change the kernel. Task2 will run when task1 is suspended, e.g. by a delay, when waiting for a semaphore or an item to appear in a queue, etc. What does not work is if task1 only calls taskYIELD since the yield will only allow a switch to other tasks of equal or higher priority.

chinamaykumar wrote on Tuesday, April 29, 2008:

check my application part in which i made two task …and try to run…

int main( void )
xTaskCreate( MyTask1, ( signed portCHAR * ) "MyTask1",
xTaskCreate( MyTask2, ( signed portCHAR * ) "MyTask2", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
    /* Now all the tasks have been started - start the scheduler.
    /* Will only get here if there was insufficient memory to   create the idle
       task. */
    return 0;
static void MyTask1( void  )
printf("Chinmay Task 1\n\r");
//vTaskDelay( 10 );
printf("Chinmay Task 1 end\n\r");
static void MyTask2( void )
printf("Chinmay Task 2\n\r");
void SleepMs(uint32_t ms)
     //Actual clock speed 14.745 MHz 
     //One sec = 14745,000 Cycles
     //One msec = 14745 Cycles

    uint32_t i;
    ms *= 14745;
    for(i=0; i<ms; i++) nop();

Here printf is used through uart0 in polling mode and my tick int occure after every 3 ms.

I want to execute my task 2 when task 1 is in sleep mode.
So sseing above can you suggest me anything.

Many thanks in advance

rtel wrote on Tuesday, April 29, 2008:

SleepMs() never blocks, it stays within the function for the requested amount of time, but during this time it uses maximum CPU processing time to execute your null loop.  As it does not block it is ready to run, and as the highest priority task it will always be the task that is selected to run.  In other words you are seeing the expected behaviour whereby the low priority task is starved of processing time by a higher priority task that never leaves the Ready/Running state.

If the higher priority task blocked then it would not consume CPU time and the lower priority task would execute.  This is achieved by replacing the null loop with vTaskDelay() or vTaskDelayUntil().


chinamaykumar wrote on Tuesday, April 29, 2008:

I realised that and try vtaskdelay()function as u can see in my code but after using that no prints available.
So please u also check that code with vtaskdelay().

Many thanks in advance.

incrediball wrote on Tuesday, April 29, 2008:

If you are using vTaskDelay then task2 will run. However was the delay really only for 10 ticks as shown by the commented out line in your program? Try a longer delay as this might not be enough time for the printf and its rs232 transmission to complete. Another possibility is that your configuration (see your FreeRTOSConfig.h) is not setting up enough heap space for the two tasks (try reversing the creation order of the two tasks and see if it makes any difference) or enough priority levels. Also try selecting pre-emptive multitasking if you haven’t done so already.

chinamaykumar wrote on Wednesday, April 30, 2008:

when i am not using vtaskdelay() i am able to run both tasks at same priority but when i use vtaskdelay() it m task2 is not executing.I also increase tick and reversing the task creation as u suggest but getting same result as earlier.
If Heap memory is less than last task will not create and i am using premptive scheduling.

I observe that when i call vtaskdelay() it will not go beyond portyield() which is  a macro asm("SWI").

chinamaykumar wrote on Thursday, May 01, 2008:

Hi All,

I am trying to execute my low priority task by halting high priority task.
For that i tried vtaskdelay and vtasksuspend  functions but after calling them no task is working.

so plz tell me to suspend a task we have to only call vtasksuspend and ou next low priority task starts resume without any modification?

Reply as soon as possible.

chinamaykumar wrote on Thursday, May 01, 2008:

NOw i am able to run low priority task by delaying high priority task using vtaskdelay but my high priority task is not resuming after expire of delay period and after delay period my low priority task also not running.

What can be the problem…

picmeup wrote on Thursday, May 01, 2008:

sound like your tick interrupt not running. Verify that the tick is working.

chinamaykumar wrote on Friday, May 02, 2008:

My tick interrupt is working.
Any other suggestion>
Can u tell me after expire of delay time how dealyed task is resume?