TC1796
System Units (Vol. 1 of 2)
Watchdog Timer
User’s Manual
16-27
V2.0, 2007-07
WDT, V2.0
16.5.5
Determining the Required Values for a WDT Access
As described on
and
, the values required for the password and
Modify Accesses to register WDT_CON0 are designed such that they can be derived
from the values read from registers WDT_CON0 and WDT_CON1. However, at least
some bits have to be modified in order to get the correct write value. This makes it very
unlikely that a false operation derives values from reading these registers that
inadvertently affect the WDT operation when written back to WDT_CON0. Even if a false
write operation would have written the correct password to WDT_CON0, one further,
different correct value needs to be written to this register in order to have an effect. In
addition, the WDT switches to Time-Out Mode after the Valid Password Access,
providing only a time-limited window for the second access.
Although computing the required values from the current contents of the Watchdog
registers is one option, using predetermined values that are set at compile-time of the
program, may be the better approach in many cases. Usually, handling the WDT is
performed by one and only one task. Thus, the problem will not occur that another task
might have changed some of the parameters which must not be modified (which would
require reading the contents, modifying the value appropriately, and then writing it back).
The one task handling the Watchdog Timer function would always “know” how it has
programmed the WDT last time, and would therefore also “know” the next password
value for opening WDT_CON0. In fact, this method would actually detect the case if
another task had illegally modified the Watchdog registers, since the predetermined
password might not work anymore, and a Watchdog error condition would thus be
generated.
In addition, accessing the WDT with predetermined values has the obvious benefit of
shorter code, as no computing steps need to be performed.