Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Yasminkhaled22
Level 1
Level 1
First like given 5 sign-ins First reply posted

If a higher priority task is blocked, a lower priority one is running and before the time slice ends the higher priority became ready, how to switch between them without waiting for stm to fire an interrupt?

0 Likes
1 Solution
David_R
Moderator
Moderator
Moderator
100 replies posted 25 solutions authored 10 likes given

Hello @Yasminkhaled22 

That's correct, as described in the documentation (assuming ) you're using FreeRTOS

A periodic interrupt, called the 'tick interrupt', is used for this purpose.

Regarding to you question

"if there is a scenario where a higher priority task is ready before system timer fires the interrupt how to switch between the two tasks without waiting for the system timer as my application needed to be RTOS ? "

The FreeRTOS provides different scheduling algorithms, it depends of you application which one will be use, otherwise you will need to modify it to be able to achieve you goals.

David_R_0-1707749833769.png

It seems to me that the cooperative its what you need,

David_R_2-1707751063907.png

Finally, you could also made use of a mail boxes, so in this way you won't have to wait till the system timer interrupt occur. 

Please take a look at the official guide provided by FreeRTOS for further information about how the scheduler algo works, this explain the differences between the two schedulers schemes and how to control the flow execution.

time-measurement-and-the-tick-interrupt 

scheduling-algorithms

Regards! :1

View solution in original post

0 Likes
3 Replies
David_R
Moderator
Moderator
Moderator
100 replies posted 25 solutions authored 10 likes given

Hi @Yasminkhaled22 

Could you please tell which RTOS are you using?, if you could provide the code it will be very handful, so lets assume you're using FreeRTOS, if you enable the time slicing 

#define configUSE_TIME_SLICING                  1

Every task will have the same CPU time, of course the one with higher priority will be the first served, 

Regarding to you question, you put an example, so the CPU time is own by a lower priority task then an interruption occurs as the interrupt has a higher priority the CPU must leave the lower task and attend the interrupt, so once the interruption was attended it will go back to the lower task, 

So as far as i can understand you want to switch between tasks without the need of an interruption?, If so, the scheduler do this work automatically, you don't need to do anything, all you can control is which task will have the higher priority,

Or you can change the scheme from preemptive to cooperative, in this way you can have control of when a task must release (yield) the CPU.

Regards! :1

0 Likes

So I think there is a misunderstanding, according to my latest knowledge to switch between two tasks system timer must fire an interrupt first then switch between the tasks. so my question if there is a scenario where a higher priority task is ready before system timer fires the interrupt how to switch between the two tasks without waiting for the system timer as my application needed to be RTOS ? 

0 Likes
David_R
Moderator
Moderator
Moderator
100 replies posted 25 solutions authored 10 likes given

Hello @Yasminkhaled22 

That's correct, as described in the documentation (assuming ) you're using FreeRTOS

A periodic interrupt, called the 'tick interrupt', is used for this purpose.

Regarding to you question

"if there is a scenario where a higher priority task is ready before system timer fires the interrupt how to switch between the two tasks without waiting for the system timer as my application needed to be RTOS ? "

The FreeRTOS provides different scheduling algorithms, it depends of you application which one will be use, otherwise you will need to modify it to be able to achieve you goals.

David_R_0-1707749833769.png

It seems to me that the cooperative its what you need,

David_R_2-1707751063907.png

Finally, you could also made use of a mail boxes, so in this way you won't have to wait till the system timer interrupt occur. 

Please take a look at the official guide provided by FreeRTOS for further information about how the scheduler algo works, this explain the differences between the two schedulers schemes and how to control the flow execution.

time-measurement-and-the-tick-interrupt 

scheduling-algorithms

Regards! :1

0 Likes