Timeslice and task scheduler timing – Maxim Integrated High-Speed Microcontroller Users Guide: Network Microcontroller Supplement User Manual

Page 220

Advertising
background image

High-Speed Microcontroller User’s

Guide: Network Microcontroller

Supplement

TIMESLICE AND TASK SCHEDULER TIMING

The task scheduler is primarily driven by the timer 0. The exported ROM function

tick_init handles the initial timer 0 configuration. The

tick_init routine configures timer 0 as a 16-bit timer running from an (oscillator frequency / 12) input clock, with an initial start value of
TH0:TL0 = FA00h. Timer 0 is then enabled as a high-priority interrupt source and started (TR0 = 1). Once running, the timer 0 interrupt

is triggered at a periodic interval so that it can be determined whether the scheduler needs to be run and whether it should be run

given the current CPU activity. This periodic interval is equal to (65,536d – FA00h)

1 / (crystal frequency)

12 and is defined as the

basic timeslice. The exported ROM function

WOS_tick is the default timer 0 interrupt service routine that is executed each timeslice.

The

WOS_tick routine updates its millisecond counter and signals that the task scheduler should be run, once the fourth timeslice has

elapsed. At this point, the task scheduler is run unless other interrupts are in progress, in which case the task scheduler is deferred. If

the scheduler is deferred, its ability to run is reassessed on each of the following (timer 0 interrupt) timeslices or whenever a task is

suspended or put to sleep. Note that the

tick_init function is automatically called by the rom_init function. Figure 23-1 illustrates the

general flow that occurs on each (timer 0 interrupt) timeslice.

Figure 23-1. Timer 0 Interrupt Routine (WOS_tick) Flow

220

Stop TIMER 0

Software reload of TH0:TL0

Restart TIMER 0

Increment millisecond counter (ms_count_4:0)

Already know that task scheduler is required?

(need sched = 1) from previous deferral?

Millisecond counter = 4?

Low-priority interrupt

currently in progress?

--OR

Critical task currently in

progress? (wos_crit_count > 0)

Set bit need_sched = 1.

TASK SCHEDULER

Return to application

Y

N

N

Y

Y

N

Maxim Integrated

Advertising