Task switching

casperh wrote on Wednesday, October 06, 2010:

Hi all.
I’m using FreeRTOS on an Atmel 32bit controller and want to switch quickly between a few tasks. As far as I can see, the taskYIELD() function only sets a task to be “ready”, so if the task with the highest priority is calling taskYIELD(), it will take its turn again right away and not letting the other tasks have a go? Is there another function to call to let tasks with a lower priority have a go without using equal priorities, using vTaskDelay or changing priority and then use taskYIELD()?

/Casper

richard_damon wrote on Wednesday, October 06, 2010:

This sounds more like a program design issue, as you are excluding exactly the things to do what you want.

By the definition of Priority, a ready task of highest priority will be running. If your higher priority task to let a lower priority task run you need to ask is it really at the time a higher priority task? or is the issue that it really shouldn’t be ready now? If it isn’t the highest priority task, then some task needs it priority changed (either it or the other task that should be run now). If it really shouldn’t be ready now, how do you determine when it will be ready again? If it is after a period of time, then it should delay, if it need information for something then it should wait on a queue or semaphore, that will be set when that data is available either by an interrupt or another task.

casperh wrote on Thursday, October 07, 2010:

You are probably right. This isn’t going to be a problem if the priorities are thought through. Thank you for your quick reply!