User`s manual

210 digi.com Keywords
protected
An important feature of Dynamic C is the ability to declare variables as protected. Such a variable is pro-
tected against loss in case of a power failure or other system reset because the compiler generates code that
creates a backup copy of a protected variable before the variable is modified. If the system resets while the
protected variable is being modified, the variable’s value can be restored when the system restarts. This
operation requires battery-backed RAM and the use of the main system clock. If you are using the 32 kHz
clock you must switch back to the main system clock to use protected variables because the atomicity of
the write cannot be ensured when using the 32 kHz clock.
main(){
protected int state1, state2, state3;
...
_sysIsSoftReset(); // restore any protected variables
}
The call to _sysIsSoftReset checks to see if the previous board reset was due to the compiler restart-
ing the program (i.e., a soft reset). If so, then it initializes the protected variable flags and calls
sysResetChain(), a function chain that can be used to initialize any protected variables or do other
initialization. If the reset was due to a power failure or watchdog time-out, then any protected variables
that were being written when the reset occurred are restored.
A system that shares data among different tasks or among interrupt routines can find its shared data cor-
rupted if an interrupt occurs in the middle of a write to a multi-byte variable (such as type int or float).
The variable might be only partially written at its next use. Declaring a multi-byte variable shared means
that changes to the variable are atomic, i.e., interrupts are disabled while the variable is being changed.
You may declare a multi-byte variable as both shared and protected.
register
The register keyword is not currently implemented in Dynamic C, but is reserved for possible future
implementation. It is currently synonymous with the keyword auto.