125
CPU System Functions
Chapter 3
Preliminary User’s Manual U17566EE1V2UM00
Example
Start the Watchdog Timer
The following example shows how to write to the write protected register
WDTM. The example starts the Watchdog Timer.
do {
_WPR
E
RR = 0;
DI();
WCMD = 0
x
5A;
WDTM = 0
x
80;
E
I();
} while (_WPR
E
RR != 0)
Note
1.
Make sure that the compiler generates two consecutive assembler “store”
instructions to WCMD and WDTM from the associated C statements.
2.
Special care must be taken when writing to registers PCS and PRCMD.
Please refer to
“Clock Generator“ on page 129
for details.
Since any action between writing to a write enable register and writing to a
protected register destroys this sequence, the effects of interrupts and DMA
transfers have to be considered:
• Interrupts:
In order to prevent any maskable interrupt to be acknowledged between the
two write instructions in question, shield this sequence by DI - EI (disable
interrupt - enable interrupt).
However, any non-maskable interrupt can still be acknowledged.
• DMA:
In the above example, DMA transfers can still take place. They may destroy
the sequence.
If appropriate, you may disable DMA transfers in advance. Otherwise you
must check whether writing to the protected register was successful. To do
so, check the status via the status register, if available, or by reading back
the protected register.
The above examples checks WPHS.WPRERR for that purposes and repeats
the sequence until the write to WDTM was successful.
electronic components distributor