User`s manual

60 digi.com Multitasking with Dynamic C
5.4.2 CoData Fields
This section describes the fields of the CoData structure.
CSState
The CSState field contains two flags, STOPPED and INIT. The possible flag values and their meaning
are in the table below.
The function isCoDone() returns true (1) if both the STOPPED and INIT flags are set. The function
isCoRunning() returns true (1) if the STOPPED flag is not set.
The CSState field applies only if the costatement has a name. The CSState flag has no meaning for
unnamed costatements or cofunctions.
Last Location
The two fields lastlocADDR and lastlocCBR represent the 24-bit address of the location at which to
resume execution of the costatement. If lastlocADDR is zero (as it is when initialized), the costatement
executes from the beginning, subject to the CSState flag. If lastlocADDR is nonzero, the costatement
resumes at the 24-bit address represented by lastlocADDR and lastlocCBR.
These fields are zeroed whenever one of the following is true:
the CoData structure is initialized by a call to _GLOBAL_INIT, CoBegin or CoReset
the costatement is executed to completion
the costatement is aborted.
Check Sum
The ChkSum
field is a one-byte check sum of the address. (It is the exclusive-or result of the bytes in
lastlocADDR
and lastlocCBR.) If ChkSum is not consistent with the address, the program will
generate a run-time error and reset. The check sum is maintained automatically. It is initialized by
_GLOBAL_INIT, CoBegin
and CoReset.
First Time
The firsttime field is a flag that is used by a waitfor, or waitfordone statement. It is set to 1
before the statement is evaluated the first time. This aids in calculating elapsed time for the functions
DelayMs, DelaySec, DelayTicks, IntervalTick, IntervalMs, and IntervalSec.
Table 5-1. Flags that Specify the Run Status of a Costatement
STOPPED INIT State of Costatement
yes yes
Done, or has been initialized to run, but set to
inactive. Set by CoReset().
yes no Paused, waiting to resume. Set by CoPause().
no yes Initialized to run. Set by CoBegin().
no no
Running. CoResume() will return the flags to
this state.