| Xmega IEC60730 Class B Library 1.0 |

All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Watchdog Timer Test

## Detailed Description

This test checks that the watchdog timer (WDT) is working. The WDT is a system function for monitoring correct program operation that allows recovering from error situations such as runaway or deadlocked code. The self-diagnostic test classb_wdt_test() is executed before the main application and it basically makes sure that:

- a system reset is issued after WDT timeout
- the WDT can be reset
- the device is reset upon untimely WDT reset in window mode

The test relies on the Real Time Counter (RTC) to check the timing of the WDT oscillator and, therefore, this library includes a basic RTC driver (see Real Time Counter Driver). Note that the RTC has a clock source independent from the CPU and the WDT. The RTC module is implicitly tested as well: if the frequency difference between RTC and WDT is more than 50%, the error state is set.

Errors are handled by CLASSB_ERROR_HANDLER_WDT() and there are two configurable actions:

1. CLASSB_ACTIONS_WDT_RUNTIME_FAILURE() processes systems resets caused by a working WDT.
2. CLASSB_ACTIONS_WDT_OTHER_FAILURE() deals with other reset causes, e.g. brown-out or software reset.

In addition to error handler and configurable actions, the user should configure the WDT periods CLASSB_WDT_WPER and CLASSB_WDT_PER.

Note:
  The WDT should be left enabled by this test and be active at all times. There are a number of Class B tests that can potentially take longer time than a WDT, see for example CRC Tests. If this was the case, a possible solution would be to increase the WDT period before the Class B test and decrease it again afterwards.

## Configuration settings
#define | CLASSB_WDT_WPER WDT_WPER_500CLK_gc
| This is the closed period, where WDT cannot be reset.
#define | CLASSB_WDT_PER WDT_PER_250CLK_gc
| This is the open period, where WDT has to be reset.

## Class B Test
void | classb_wdt_test (void)
| This is the watchdog timer (WDT) self-diagnostic test.

## Macro Definition Documentation

#define CLASSB_WDT_WPER WDT_WPER_500CLK_gc

This is the closed period, where WDT cannot be reset.

This should be given as one of the group configuration settings. The total timeout period is the sum of the open and closed periods. In order to comply with the standard, this should be at least 50% of the total period.

Definition at line 105 of file classb_wdt_test.h.

Referenced by classb_wdt_test().

#define CLASSB_WDT_PER WDT_PER_250CLK_gc

This is the open period, where WDT has to be reset.

This should be given as one of the group configuration settings. The total timeout period is the sum of the open and closed periods. In order to comply with the standard, this should be no greater than than 50% of the total period.

Definition at line 112 of file classb_wdt_test.h.

Referenced by classb_wdt_test().

## Function Documentation

void classb_wdt_test | ( | void |  | ) |

This is the watchdog timer (WDT) self-diagnostic test.

Basically this functions tests the following:

1. WDT issues a system reset after timeout.
2. WDT timing and that it can be reset.
3. WDT issues a system reset if it is untimely reset (WDT window mode). If any of these tests should fail, CLASSB_ERROR_HANDLER_WDT() would be called. By default the device will simply hang.

The expected (error-free) execution flow is as follows:

1. Power-on or external reset has occurred.
2. Check that WDT can issue a system reset. Set test state 1 and system reset.
3. Check that WDT can be reset. Set test state 2 and system reset.
4. Check that window mode works correctly. Set test state 3 and system reset.
5. Set up WDT in windows mode with periods CLASSB_WDT_WPER and CLASSB_WDT_PER. Set test state "ok" and continue to main().

The real time counter (RTC) is used as an independent clock source, which is used to check the timing of the oscillator used by the WDT.

The reset cause is used to decide which actions to take. The user can configure how to process a reset caused by the watchdog when the test is in the "ok" state, i.e. CLASSB_ACTIONS_WDT_RUNTIME_FAILURE(), or what to do for brown-out or software reset, i.e. CLASSB_ACTIONS_WDT_OTHER_FAILURE().

Note:
  This test is executed before the main function. The method to achieve this depends on the specific compiler that is used.

Definition at line 107 of file classb_wdt_test.c.

References CLASSB_ACTIONS_WDT_OTHER_FAILURE, CLASSB_ACTIONS_WDT_RUNTIME_FAILURE, classb_error, CLASSB_ERROR_HANDLER_WDT, CLASSB_WDT_PER, and CLASSB_WDT_WPER.