Operation of RTOS

nobody wrote on Friday, April 28, 2006:

I’m studing your rtos code for Atmel AVR.

But I’ve some question about priority and task execution time.

This is my problem :

suppose we have 3 task (A, B, C)

I want to be sure that each task is executed every 1 mSec independently from their time of elaboration.

But the important thing is that the scheduler must stops task A  , task B or task C and start the other tasks independently from their work.

I explain : if task A (in reponse to an user input…a stupid example…an user has entered to calc the sqr from 1 to 25000000) needs about 10 mSec for his work, I want that the kernel stops task A and executes task B.

Same thing for the other task. Task B must be stopped (if not finished) after max 1 msec because another task needs starting

Is it possible with freertos ???

Another question:

In the article about context switching you write "TaskB has a higher priority than TaskA so vTaskSwitchContext() selects TaskB as the task to be given processing time when the ISR completes" (http://www.techonline.com/static/feature_articles/barry/step4.html)

But if I have only two task (A and B) in my program and the task B has low priority then task A, the context switch will never happens ???

Excuse me, but I’m a primer with rtos.

Thank you

Best regards

rtel wrote on Friday, April 28, 2006:

I’m not sure I follow your questions fully, but I think they are both referring to the scheduling policy.

FreeRTOS is a preemptive priority based kernel.  A task will never execute if there is a task of higher priority that is ready to execute (not blocked).  In other words, the scheduler will always choose to run the highest priority task that is able to run at the expense of any lower priority tasks.

If the preemptive scheduler is being used then task can be given the same priority.  When there are more than one task of the same priority a context switch will occur each kernel tick.  So I think the answer to your first question is that if each of the three tasks are given the same priority they will share the processing time, provided there are no tasks of higher priority that are able to run.