hsk-libs-dev  270
High Speed Karlsruhe XC878 library collection
hsk_wdt.h
Go to the documentation of this file.
1 /** \file
2  * HSK Watchdog Timer headers
3  *
4  * Provides access to the Watchdog Timer (WDT) of the XC878.
5  *
6  * Depending on the configured window time the µC reset is delayed for
7  * 1.024ms (window < 5460µs) or 65.536ms (window >= 5460µs).
8  *
9  * This time can be used by assigning a callback function to
10  * \ref hsk_isr14 member \ref hsk_isr14_callback::NMIWDT and setting
11  * the NMICON.NMIWDT bit.
12  *
13  * @warning
14  * The WDT should be set up at the end of the boot procedure. Setting
15  * the WDT up at the beginning of the boot process can trigger all kinds
16  * of erratic behaviour like reset races or a complete lockup.
17  * @author
18  * kami
19  *
20  * \section hazards Hazards
21  *
22  * The WDT has proven a useful tool in hazardous EMI conditions. Severe EMI
23  * may freeze the µC without causing a proper reboot. In most cases the WDT
24  * can mitigate this issue by reactivating the system.
25  *
26  * However the WDT is trigger happy. A series of refresh time interval
27  * measurements shows that the WDT resets the µC long before the end of
28  * its interval shortly after boot. The best mitigation is to refresh
29  * the WDT with the hsk_wdt_service() function unconditionally. Instead
30  * of using fixed timings (e.g. for 20ms watchdog time a 5ms refresh interval
31  * should have been quite safe).
32  *
33  * That however does not solve the problem with NMIs. Any non-maskable
34  * interrupt may cause the WDT to reset the µC. This means it is incopatible
35  * to the hsk_flash library, which requires precise timings with only a couple
36  * of µs tolerance. To meet this requirement the library uses the Flash Timer
37  * of the XC878, which triggers NMIs.
38  */
39 
40 #ifndef _HSK_WDT_H_
41 #define _HSK_WDT_H_
42 
43 /**
44  * Sets up the watchdog timer.
45  *
46  * The window time specifies the time available to call hsk_wdt_service()
47  * before a reset is triggered. Possible times range from 21.3µs to 350ms.
48  *
49  * The window time is rounded up to the next higher possible value.
50  * Exceeding the value range causes an overflow that results in shorter
51  * window times.
52  *
53  * @param window
54  * The time window in multiples of 10µs
55  */
56 void hsk_wdt_init(const uword window);
57 
58 /**
59  * Activates the Watchdog Timer.
60  */
61 void hsk_wdt_enable(void);
62 
63 /**
64  * Disables the Watchdog Timer.
65  */
66 void hsk_wdt_disable(void);
67 
68 /**
69  * Resets the watchdog timer.
70  *
71  * This function needs to be called to prevent the WDT from resetting the
72  * device.
73  */
74 void hsk_wdt_service(void);
75 
76 #endif /* _HSK_WDT_H_ */
void hsk_wdt_service(void)
Resets the watchdog timer.
Definition: hsk_wdt.c:98
void hsk_wdt_disable(void)
Disables the Watchdog Timer.
Definition: hsk_wdt.c:80
void hsk_wdt_enable(void)
Activates the Watchdog Timer.
Definition: hsk_wdt.c:67
void hsk_wdt_init(const uword window)
Sets up the watchdog timer.
Definition: hsk_wdt.c:30