Scheduler example – Echelon Neuron C User Manual
Page 160

148 Additional
Features
Outgoing messages, network variable updates, and network variable polls use
application output buffers. If you check for completion events with any of the
following tasks, then the application output buffers are automatically processed
and freed by the scheduler in correspondence with these completion event tasks:
when (nv_update_completes)
when (nv_update_succeeds)
when (nv_update_fails)
when (msg_completes)
when (msg_succeeds)
when (msg_fails)
If there is no corresponding completion event task, then the output buffer is freed
automatically by the scheduler when its corresponding event is discarded.
In either case, failure to reach the when clause that processes the application
buffer at the head of the incoming or completion event queues (because of too
frequent resets of the scheduler) lead to that queue’s becoming blocked (or
stuck
)
because the application buffer is never processed and freed.
Therefore, when using the scheduler reset mechanism, it is
important
to order
the when clauses in a program such that events that occur frequently (such as
I/O events that occur constantly, or short-interval timer events that expire
continually) not lock out processing of messaging events.
Scheduler Example
Turning on the reset mechanism ensures that events are processed in the order
intended. For example, you might want ensure that specific events are checked
first, followed by a
catch-all
event, as illustrated in this code fragment:
#pragma scheduler_reset
network input SNVT_switch nviSwitch1;
network input SNVT_switch nviSwitch2;
network input SNVT_switch nviSwitch3;
network input SNVT_switch nviSwitch4;
when (nv_update_occurs(nviSwitch1))
{
...
}
when (nv_update_occurs(nviSwitch2))
{
...
}
when (nv_update_occurs)
{
// provides a generic check
...
// for all network variable
// updates
}
Updates received for nviSwitch1 cause both the first and third events to become
TRUE. Similarly, updates for nviSwitch2 cause the second and third events to