User`s manual

66 digi.com Multitasking with Dynamic C
Example
5.5.6 Types of Cofunction Calls
A wfd statement makes one of three types of calls to a cofunction.
5.5.6.1 First Time Call
A first time call happens when a wfd statement calls a cofunction for the first time in that statement. After
the first time, only the original wfd statement can give this cofunction instance continuation calls until
either the instance is complete or until the instance is given another first time call from a different state-
ment. The lifetime of a cofunction instance stretches from a first time call until its terminal call or until its
next first time call.
5.5.6.2 Continuation Call
A continuation call is when a cofunction that has previously yielded is given another chance to run by the
enclosing wfd statement. These statements can only call the cofunction if it was the last statement to give
the cofunction a first time call or a continuation call.
5.5.6.3 Terminal Call
A terminal call ends with a cofunction returning to its wfd statement without yielding to another cofunc-
tion. This can happen when it reaches the end of the cofunction and does an implicit return, when the
cofunction does an explicit return, or when the cofunction aborts.
// echoes characters
main() {
int c;
serAopen(19200);
loopinit();
while (1) {
loophead();
costate {
wfd c = cof_serAgetc();
wfd cof_serAputc(c);
}
}
serAclose();
}