Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RTOS mechanics when there is a main task and a second task

Status
Not open for further replies.

GrandAlf

Advanced Member level 2
Advanced Member level 2
Joined
Mar 9, 2002
Messages
520
Helped
47
Reputation
92
Reaction score
6
Trophy points
1,298
Location
UK
Activity points
4,730
Assuming that you have a main task and a second task thus.


main task 0
start task 1
do something
time delay 20 ticks

Task 1
x=getkey or some loop waiting for input
time delay 5 ticks

Now the question is, in task1 as it is in effect in a loop waiting for input, it may never get to the delay tick routine. Does this mean that it is switched in every 5 ticks, or in fact only when it gets an input. Or indeed is it switched at the rtos default setting, and the 5 ticks has no effect until reached. Not really sure about the mechanics of operation. anyone clued up on this?
 

Re: RTOS question

Whenever any task call delay ticks, it will be blocked and relinguish CPU to other task.

main task 0
start task 1
do something
time delay 20 ticks // relinquish CPU, task1 will get executed

Task 1
x=getkey or some input // loop waiting is not good pratice in RTOS
time delay 5 ticks // task 1 blocked for 5 ticks, task 0 will get executed
 

Re: RTOS question

When Task 1 begins executions and i made to wait for any resources like input from user and delay , Scheduler pre empts or pends that task which i wating for any resources other then CPU so the executions to task ) or what ever task and resumes when task 1 is ready
 

RTOS question

I agree with Epegic

main task 0
start task 1
do something
time delay 20 ticks // relinquish CPU, task1 will get executed

Task 1
x=getkey or some input // loop waiting is not good pratice in RTOS
time delay 5 ticks // task 1 blocked for 5 ticks, task 0 will get executed
 

Re: RTOS question

Yes, you are correct when you state that Task 1 will not reach the delay tick routine until it gets an input. Therefore, the "delay 5 ticks" statement has no effect until it is reached.

If the "getkey" routine suspends waiting for a key, Task 1 will of course be switched out when it calls getkey. When it receives a key, it will be switched in.

If Task 1 is in a loop waiting for a key, it will not be switched out....unless Main Task 0 is higher priority. Then, Main Task 0 will pre-empt Task 1 every 20 ticks.
 

Re: RTOS question

GrandAlf said:
Assuming that you have a main task and a second task thus.


main task 0
start task 1
do something
time delay 20 ticks

Task 1
x=getkey or some loop waiting for input
time delay 5 ticks

Now the question is, in task1 as it is in effect in a loop waiting for input, it may never get to the delay tick routine. Does this mean that it is switched in every 5 ticks, or in fact only when it gets an input. Or indeed is it switched at the rtos default setting, and the 5 ticks has no effect until reached. Not really sure about the mechanics of operation. anyone clued up on this?

To me it looks like algo of main_task_0. So main_task_0 spawns task_1. When it does this, the RTOS scheduler will create a new task called task_1 and it will become ready for execution. Now we have three cases:

Case 1:
if the priority of main_task_0 is greater than task_1, then it will continue to execute. If "do something" does not cause it to block or pend, then it shall reach time_delay statement where it shall be switched out and task_1 shall start executing. In task_1, input is detecte in busy-waiting loop. So it shall continue to execute till either it gets the input or main_task_0 wakes up. Supposing task_1 gets input first, then it shall again pend due to time_delay statement. At this point, system idle task shall be running and system shall be doing no useful work.

Case 2:
Assuming that priority of the task_1 is greater than main_task_0, then in this case the main_task_0 won't be able to complete the "do-something" part of its work and task_1 shall take over. The system shall continue to wait for input in a busy loop and once input is received, the task_1 executes time_delay to hand over CPU back to main_task_0 which continues with "do something". If this "do something" part is completed before 5 ticks, then the main_task_0 surrenders CPU via time_delay and system becomes idle.

Case 3:
Assuming both tasks have same priority, then it depends. Most likely, RTOS shall allow the current executing task to continue. If Round-Robin scheduling for equal priority task is enabled then probably both tasks shall execute for roughly equal amount of the time - task_1 executing the busy loop while main_task_0 executing the "do something" portion of its task.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top