User guide

146 Additional Features
The Scheduler
Chapter 2,
Focusing on a Single Device
, on page 15, introduced the basic
functioning of the Neuron firmware scheduler, shown in
Figure 14 on page 147.
Priority when clauses are executed in the order specified every time the
scheduler runs. If any priority when clause evaluates to TRUE, its task is run
and the scheduler starts over. If none of the priority when clauses evaluates to
TRUE, then a nonpriority when clause is evaluated, selected in a round-robin
fashion. If the when clause is TRUE, its task is executed. If the nonpriority
when clause is FALSE, its task is ignored. In either case, the scheduler returns
to the top of the loop.
Interrupt tasks do not use the scheduler; see
Interrupts
on page 153 for more
information.
Scheduler Reset Mechanism
The scheduler reset mechanism is normally disabled. When the reset mechanism
is enabled, the round-robin part of the scheduler is reset to the first regular when
clause whenever one of the following conditions is detected:
A new network variable update is at the head of the queue.
A new timer has expired.
A new message is at the head of the queue.
Although these events can occur at any time, the scheduler recognizes them only
when it is at the beginning of the scheduling loop (labeled “Top of Scheduling
Loop” in
Figure 14).
If you disable the reset mechanism, nonpriority when
clauses are evaluated in
the order in which they appear. When the last nonpriority when
clause is
reached, the scheduling loop returns to the first nonpriority when clause.
If ordering of when
clauses is desired, you can turn on the reset mechanism with
the following compiler directive:
#pragma scheduler_reset
Important: If the scheduler reset mechanism is enabled, then there is a risk that
when clauses later in the program might never execute if the scheduler is reset
too frequently. This can lead to application buffer starvation, because network
variable and message processing tasks can only process buffers in the order in
which they arrive. Thus, if the scheduler reset mechanism is enabled, you must
ensure that the when clauses and tasks of your program are ordered such that
the most frequently executed ones are last, or the rare ones are declared using
the priority keyword.