Вы находитесь на странице: 1из 12

Microprocessor based embedded systems

Lecture 33 34: The Time Triggered Cooperative


Scheduler (TTC)

Dr Musharraf A Hanif

Overview of the Lecture

by Dr. Musharraf A Hanif

The Time-Triggered Cooperative


scheduler

The time-triggered cooperative scheduler can


be used to run tasks periodically.
The tasks are added to the scheduler along
with their periods and initial offsets.
The scheduler then runs these tasks according
to the programmed timing characteristics.

by Dr. Musharraf A Hanif

Using the TTC scheduler


int main(void)
{
SCH_Init(1000); //tick period in micro seconds
Initialization tasks. // call the initialization functions here.
SCH_Add_Task(Taks_1, 0, 1);
SCH_Add_Task(Task_2, 1, 1);
SCH_Add_Task(Task_3, 500, 500);
SCH_Start();
while(1)
{
SCH_Dispatch_Tasks();
}
return(1);
}
4

by Dr. Musharraf A Hanif

The variables and data structures

The TTC uses the task array to keep track of


the tasks that need to run by the scheduler
In addition to this, the Tick_count_G is used to
keep track of time even during transient
overloads.

* Review the code of the TTC project for details


on the variables and data structures

by Dr. Musharraf A Hanif

The functions
* Review the code of the TTC project for details
on the schedulers functions.

by Dr. Musharraf A Hanif

Behaviour of TTC

The Time-Triggered Cooperative scheduler controls


execution of user tasks.
Tasks are run cooperatively based on supplied timing
criteria.
A task array is used to store the function pointer and
the timing criteria (period and initial delay only).
The Scheduler works as follows:

The timer ISR / SCH_Update is used to keep track of time


(i.e. increment Tick_count_G).
The SCH_Dispatch_Tasks goes through the task array each
time the Tick_count_G is greater than 0, first decrementing
it and then updating the status of each task added in the
task array and run any that are due to run in response to
the tick being processed.
by Dr. Musharraf A Hanif

Behaviour of TTC (Cont.)

Splitting the track of time and the task execution


to separate levels allows the system to work
even under transient overloads.
All the due tasks in a tick are run in the sequence
in which their entries are in the task array.
While tasks are run cooperatively, there is still
pre-emption in the system.

The Timer ISR / SCH_Update interrupts the


dispatcher / tasks running at the default level.
Care has to be taken with the Tick_count_G variable
as it is a shared resource accessed by both the ISR
and the default priority level (SCH_Dispatch_Tasks).
by Dr. Musharraf A Hanif

Anatomy of the tasks

Tasks have to be time-triggered.

Tasks have to be void-void functions (no input


or return parameters).

Event triggered actions have to be polled in a


time-triggered task.

Any data that has to be shared between tasks


should use global variables.
While global variables are shared resources, if
there is cooperative task execution, there is no
risk of corruption.

by Dr. Musharraf A Hanif

Converting time cyclic code to TTC.


main()

System has a tick period of 10ms.

uint16_t Count = 50;


#Initialization of user code

Cyclic_Start(10); //Tick period of 10ms


while(1)

There are three tasks in the system:

{
if(++Count >= 100)
{
Count = 0;
Task_A();
}

Task_B();
if(Event == TRUE)
{
Task_C();
}
Cyclic_Wait();
}

i.e. The loop repeats every 10


ms.

Task A which runs for the first


time after (100 50) * 10ms
(because of the initial value of
the count) and then repeats
every 100 cycles after that (1
s).
Task B runs every cycle starting
from the first cycle.
Task C runs only if an event
associated with it occurs. The
system checks for this event
once every 10 ms (or every
cycle).

10

by Dr. Musharraf A Hanif

Converting time cyclic code to TTC


(Cont.)
main()

System has a tick period of 10000 s.

SCH_Init(10000);
#Initialization of user code
SCH_Add_Task(Task_A, (100-50), 100);
SCH_Add_Task(Task_B, 0, 1);

There are three tasks in the system:

SCH_Add_Task(Task_C_Polling, 0, 1);
SCH_Start();
while(1)
{
SCH_Dispatch_Tasks();

}
}
void Task_C_Polling(void)
{

if(Event == TRUE)
{
Task_C();
}

i.e. The loop repeats every


10 ms.
Task A which runs for the
first time after 50 * 10ms
and then repeats every
second after that.
Task B runs every cycle
starting from the first
cycle.
Task C is called from inside
Task_C_Polling only if the
event associated with it
occurs.

11

by Dr. Musharraf A Hanif

Practice

Draw the time lines of the proposed solution


and the TTC for the examples given in the
previous lecture.
Try to run the example transient overload task
in the TTC sample code in sEOS and timed
cyclic executive. What are the results.

12

by Dr. Musharraf A Hanif

Вам также может понравиться