FREE RTOS - task switch

kpraveen4488 wrote on Wednesday, June 19, 2019:

Is it possible to immediately switch tasks from one to another irrespective of its task priorities?
I have been trying this since a week and what I found so far with

  1. task notifications is
    • it acts as a flag set and data transmission wrt priorities
      2)Event handler
  • This sets bits of event and in a group as well

in this regard,please guide me if there is any way to switch the tasks irrespective of its proirities…
**RTOS ver- 10.0.1
Board - ti-CC3200

heinbali01 wrote on Wednesday, June 19, 2019:

Priorities are priorities: you can not tell the kernel to disregard them. When there is another higher-priority task in the running state, that task will get priority.

If you want a lower-priority task to become active immediately, make sure that all higher-priority tasks are in some blocking function, or you temporarily raise the priority of the task that you want to become active.

kpraveen4488 wrote on Wednesday, June 19, 2019:

Hi Hein Tibosch,
Thanks for the response …

What are the best methods to block all higher priority tasks in order to active a lower priority task immediately?

richarddamon wrote on Wednesday, June 19, 2019:

Task generally should block themselves, not be blocked by some outside agent. You can block them by using vTaskSuspend, but I would really not suggest using it for this.

If a task has suddenly been given a responsibility that means it is high priority, then change its priority, don’t try to play with suspending/resuming tasks yourself to force it to run.

I would say that needing to do this is also a likely sign that priorities/responsibilities weren’t well assigned to begin with (but will admit there could be cases where a priority change can make sense).

rtel wrote on Wednesday, June 19, 2019:

Make the task the highest priority, then it will run.

kpraveen4488 wrote on Wednesday, June 19, 2019:

I don’t want to reallocate priorities which are set initially…
If you are suggesting me to make the task highest priority temporarily as Hein Tibosch said,
I am definitily gonna try that…

heinbali01 wrote on Wednesday, June 19, 2019:

Praveen, it looks like you’re still missing some basic understanding of FreeRTOS.
Richard Barry suggests that when you want task X to run, give it the highest priority. There are API’s that let you change a task’s priority.

Richard Damon is trying to tell you that tasks should not run constantly, they do their thing and then block somehow, waiting for a queue, for a semaphore, for a task notification, or whatever. While being blocked, they allow lower-priotity tasks to run.

If you look around on freertos.org, I am sure that you will find some good tutorials about FreeRTOS and it’s possibilities.

kpraveen4488 wrote on Wednesday, June 19, 2019:

Yes Hein,definitely…
I am going through freertos.org as I have started to implement free rtos in my project recently & so is this querry…
Hope vTaskPrioritySet( ) will work in this regard…

Thank you for your time…

heinbali01 wrote on Thursday, June 20, 2019:

Hope vTaskPrioritySet( ) must be used in this regard…

That is correct.

There are 4 macro’s that may be interesting for you, regarding tasks and priorities:

#define configUSE_PREEMPTION       1  // or 0
#define configUSE_TIME_SLICING     1  // or 0 ( default 1 )
#define configIDLE_SHOULD_YIELD    1  // or 0 ( default 1 )
#define configMAX_PRIORITIES       5  // 1 or more

You can look them up here

In every FreeRTOS project there must be one ( and no more ) file called FreeRTOSConfig.h. You maintain that file, and it belongs to the project. It is there where you can configure the behaviour of the kernel.