AVR-LibC  2.3.0
Standard C library for AVR-GCC
 

AVR-LibC Manual

AVR-LibC Sources

Main Page

User Manual

Lib­rary Refe­rence

FAQ

Exam­ple Pro­jects

Index

Loading...
Searching...
No Matches
wdt.h
Go to the documentation of this file.
1/* Copyright (c) 2002, 2004 Marek Michalkiewicz
2 Copyright (c) 2005, 2006, 2007 Eric B. Weddington
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
14 distribution.
15
16 * Neither the name of the copyright holders nor the names of
17 contributors may be used to endorse or promote products derived
18 from this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE. */
31
32/*
33 avr/wdt.h - macros for AVR watchdog timer
34*/
35
36#ifndef _AVR_WDT_H_
37#define _AVR_WDT_H_
38
39#include <avr/io.h>
40#include <stdint.h>
41
42/** \file */
43/** \defgroup avr_watchdog <avr/wdt.h>: Watchdog timer handling
44 \code #include <avr/wdt.h> \endcode
45
46 This header file declares the interface to some inline macros
47 handling the watchdog timer present in many AVR devices. In order
48 to prevent the watchdog timer configuration from being
49 accidentally altered by a crashing application, a special timed
50 sequence is required in order to change it. The macros within
51 this header file handle the required sequence automatically
52 before changing any value. Interrupts will be disabled during
53 the manipulation.
54
55 \note Depending on the fuse configuration of the particular
56 device, further restrictions might apply, in particular it might
57 be disallowed to turn off the watchdog timer.
58
59 Note that for newer devices (ATmega88 and newer, effectively any
60 AVR that has the option to also generate interrupts), the watchdog
61 timer remains active even after a system reset (except a power-on
62 condition), using the fastest prescaler value (approximately 15
63 ms). It is therefore required to turn off the watchdog early
64 during program startup, the datasheet recommends a sequence like
65 the following:
66
67 \code
68 #include <stdint.h>
69 #include <avr/wdt.h>
70
71 uint8_t mcusr_mirror __attribute__((section (".noinit")));
72
73 __attribute__((used, unused, naked, section(".init3")))
74 static void get_mcusr (void)
75 {
76 mcusr_mirror = MCUSR;
77 MCUSR = 0;
78 wdt_disable();
79 }
80 \endcode
81
82 Saving the value of MCUSR in \c mcusr_mirror is only needed if the
83 application later wants to examine the reset source, but in particular,
84 clearing the watchdog reset flag before disabling the
85 watchdog is required, according to the datasheet.
86*/
87
88/**
89 \ingroup avr_watchdog
90 Reset the watchdog timer. When the watchdog timer is enabled,
91 a call to this instruction is required before the timer expires,
92 otherwise a watchdog-initiated device reset will occur. */
93#define wdt_reset() __asm__ __volatile__ ("wdr")
94
95#ifndef __DOXYGEN__
96
97#include <bits/attribs.h>
98
99#if defined(WDP3)
100# define _WD_PS3_MASK _BV(WDP3)
101#else
102# define _WD_PS3_MASK 0x00
103#endif
104
105#if defined(WDTCSR)
106# define _WD_CONTROL_REG WDTCSR
107#elif defined(WDTCR)
108# define _WD_CONTROL_REG WDTCR
109#else
110# define _WD_CONTROL_REG WDT
111#endif
112
113#if defined(WDTOE)
114#define _WD_CHANGE_BIT WDTOE
115#else
116#define _WD_CHANGE_BIT WDCE
117#endif
118
119#endif /* !__DOXYGEN__ */
120
121#ifdef __DOXYGEN__
122/**
123 \ingroup avr_watchdog
124 Enable the watchdog timer, configuring it for expiry after
125 \c timeout (which is a combination of the \c WDP0 through
126 \c WDP2 bits to write into the \c WDTCR register; For those devices
127 that have a \c WDTCSR register, it uses the combination of the \c WDP0
128 through \c WDP3 bits).
129
130 See also the symbolic constants \c WDTO_15MS et al. */
131#define wdt_enable(timeout)
132#endif /* __DOXYGEN__ */
133
134
135#if defined(__AVR_XMEGA__)
136
137#if defined (WDT_CTRLA) && !defined(RAMPD)
138
139#define wdt_enable(timeout) \
140 do { \
141 uint8_t __temp; \
142 __asm__ __volatile__ ( \
143 "wdr" "\n\t" \
144 "out %i[ccp_reg], %[ioreg_cen_mask]" "\n\t" \
145 "lds %[tmp], %[wdt_reg]" "\n\t" \
146 "sbr %[tmp], %[wdt_enable_timeout]" "\n\t" \
147 "sts %[wdt_reg], %[tmp]" "\n\t" \
148 "1:lds %[tmp], %[wdt_status_reg]" "\n\t" \
149 "sbrc %[tmp], %[wdt_syncbusy_bit]" "\n\t" \
150 "rjmp 1b" \
151 : [tmp] "=d" (__temp) \
152 : [ccp_reg] "n" (& CCP), \
153 [ioreg_cen_mask] "r" ((uint8_t)CCP_IOREG_gc), \
154 [wdt_reg] "n" (& WDT_CTRLA), \
155 [wdt_enable_timeout] "M" (timeout), \
156 [wdt_status_reg] "n" (& WDT_STATUS), \
157 [wdt_syncbusy_bit] "I" (WDT_SYNCBUSY_bm) \
158 : "memory"); \
159 } while(0)
160
161static __ATTR_ALWAYS_INLINE__
162void wdt_disable (void)
163{
164 uint8_t __temp;
165 __asm__ __volatile__ (
166 "wdr" "\n\t"
167 "out %i[ccp_reg], %[ioreg_cen_mask]" "\n\t"
168 "lds %[tmp], %[wdt_reg]" "\n\t"
169 "cbr %[tmp], %[timeout_mask]" "\n\t"
170 "sts %[wdt_reg], %[tmp]"
171 : [tmp] "=d" (__temp)
172 : [ccp_reg] "n" (& CCP),
173 [ioreg_cen_mask] "r" ((uint8_t)CCP_IOREG_gc),
174 [wdt_reg] "n" (& WDT_CTRLA),
175 [timeout_mask] "I" (WDT_PERIOD_gm)
176 : "memory");
177}
178
179#else // defined (WDT_CTRLA) && !defined(RAMPD)
180
181/*
182 wdt_enable(timeout) for xmega devices
183 - write signature (CCP_IOREG_gc) that enables change of protected I/O
184 registers to the CCP register
185 - At the same time,
186 1) set WDT change enable (WDT_CEN_bm)
187 2) enable WDT (WDT_ENABLE_bm)
188 3) set timeout (timeout)
189 - Synchronization starts when ENABLE bit of WDT is set. So, wait till it
190 finishes (SYNCBUSY of STATUS register is automatically cleared after the
191 sync is finished). */
192#define wdt_enable(timeout) \
193 do { \
194 uint8_t __temp; \
195 __asm__ __volatile__ ( \
196 "in __tmp_reg__, %i[rampd]" "\n\t" \
197 "out %i[rampd], __zero_reg__" "\n\t" \
198 "out %i[ccp_reg], %[ioreg_cen_mask]" "\n\t" \
199 "sts %[wdt_reg], %[wdt_enable_timeout]" "\n\t" \
200 "1:lds %[tmp], %[wdt_status_reg]" "\n\t" \
201 "sbrc %[tmp], %[wdt_syncbusy_bit]" "\n\t" \
202 "rjmp 1b" "\n\t" \
203 "out %i[rampd], __tmp_reg__" \
204 : [tmp] "=r" (__temp) \
205 : [rampd] "n" (& RAMPD), \
206 [ccp_reg] "n" (& CCP), \
207 [ioreg_cen_mask] "r" ((uint8_t)CCP_IOREG_gc), \
208 [wdt_reg] "n" (& WDT_CTRL), \
209 [wdt_enable_timeout] "r" ((uint8_t)(WDT_CEN_bm \
210 | WDT_ENABLE_bm \
211 | ((timeout + 1) << 2))), \
212 [wdt_status_reg] "n" (& WDT_STATUS), \
213 [wdt_syncbusy_bit] "I" (WDT_SYNCBUSY_bm) \
214 : "memory"); \
215 } while(0)
216
217static __ATTR_ALWAYS_INLINE__
218void wdt_disable (void)
219{
220 __asm__ __volatile__ (
221 "in __tmp_reg__, %i[rampd]" "\n\t"
222 "out %i[rampd], __zero_reg__" "\n\t"
223 "out %i[ccp_reg], %[ioreg_cen_mask]" "\n\t"
224 "sts %[wdt_reg], %[disable_mask]" "\n\t"
225 "out %i[rampd], __tmp_reg__"
226 : /* no outputs */
227 : [rampd] "n" (& RAMPD),
228 [ccp_reg] "n" (& CCP),
229 [ioreg_cen_mask] "r" ((uint8_t)CCP_IOREG_gc),
230 [wdt_reg] "n" (& WDT_CTRL),
231 [disable_mask] "r" ((uint8_t)((~WDT_ENABLE_bm) | WDT_CEN_bm))
232 : "memory");
233}
234
235#endif // defined (WDT_CTRLA) && !defined(RAMPD)
236
237#elif defined(__AVR_TINY__)
238
239#define wdt_enable(value) \
240 __asm__ __volatile__ ( \
241 "in __tmp_reg__,__SREG__" "\n\t" \
242 "cli" "\n\t" \
243 "wdr" "\n\t" \
244 "out %i[CCPADDRESS],%[SIGNATURE]" "\n\t" \
245 "out %i[WDTREG],%[WDVALUE]" "\n\t" \
246 "out __SREG__,__tmp_reg__" \
247 : /* no outputs */ \
248 : [CCPADDRESS] "n" (& CCP), \
249 [SIGNATURE] "r" ((uint8_t)0xD8), \
250 [WDTREG] "n" (& _WD_CONTROL_REG), \
251 [WDVALUE] "r" ((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00) \
252 | _BV(WDE) | (value & 0x07) )) \
253 : "memory")
254
255static __ATTR_ALWAYS_INLINE__
256void wdt_disable (void)
257{
258 uint8_t __temp_wd;
259 __asm__ __volatile__ (
260 "in __tmp_reg__,__SREG__" "\n\t"
261 "cli" "\n\t"
262 "wdr" "\n\t"
263 "out %i[CCPADDRESS],%[SIGNATURE]" "\n\t"
264 "in %[TEMP_WD],%i[WDTREG]" "\n\t"
265 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t"
266 "out %i[WDTREG],%[TEMP_WD]" "\n\t"
267 "out __SREG__,__tmp_reg__"
268 : [TEMP_WD] "=d" (__temp_wd)
269 : [CCPADDRESS] "n" (& CCP),
270 [SIGNATURE] "r" ((uint8_t)0xD8),
271 [WDTREG] "n" (& _WD_CONTROL_REG),
272 [WDVALUE] "n" (1 << WDE)
273 : "memory");
274}
275
276#elif defined(CCP)
277
278static __ATTR_ALWAYS_INLINE__
279void wdt_enable (const uint8_t value)
280{
281 if (!_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P (_WD_CONTROL_REG))
282 {
283 __asm__ __volatile__ (
284 "in __tmp_reg__,__SREG__" "\n\t"
285 "cli" "\n\t"
286 "wdr" "\n\t"
287 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t"
288 "sts %[WDTREG],%[WDVALUE]" "\n\t"
289 "out __SREG__,__tmp_reg__"
290 : /* no outputs */
291 : [CCPADDRESS] "n" (& CCP),
292 [SIGNATURE] "r" ((uint8_t)0xD8),
293 [WDTREG] "n" (& _WD_CONTROL_REG),
294 [WDVALUE] "r" ((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
295 | _BV(WDE) | (value & 0x07) ))
296 : "memory");
297 }
298 else if (!_SFR_IO_REG_P (CCP) && _SFR_IO_REG_P (_WD_CONTROL_REG))
299 {
300 __asm__ __volatile__ (
301 "in __tmp_reg__,__SREG__" "\n\t"
302 "cli" "\n\t"
303 "wdr" "\n\t"
304 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t"
305 "out %i[WDTREG],%[WDVALUE]" "\n\t"
306 "out __SREG__,__tmp_reg__"
307 : /* no outputs */
308 : [CCPADDRESS] "n" (& CCP),
309 [SIGNATURE] "r" ((uint8_t)0xD8),
310 [WDTREG] "n" (& _WD_CONTROL_REG),
311 [WDVALUE] "r" ((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
312 | _BV(WDE) | (value & 0x07) ))
313 : "memory");
314 }
315 else if (_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P (_WD_CONTROL_REG))
316 {
317 __asm__ __volatile__ (
318 "in __tmp_reg__,__SREG__" "\n\t"
319 "cli" "\n\t"
320 "wdr" "\n\t"
321 "out %i[CCPADDRESS],%[SIGNATURE]" "\n\t"
322 "sts %[WDTREG],%[WDVALUE]" "\n\t"
323 "out __SREG__,__tmp_reg__"
324 : /* no outputs */
325 : [CCPADDRESS] "n" (& CCP),
326 [SIGNATURE] "r" ((uint8_t)0xD8),
327 [WDTREG] "n" (& _WD_CONTROL_REG),
328 [WDVALUE] "r" ((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
329 | _BV(WDE) | (value & 0x07) ))
330 : "memory");
331 }
332 else
333 {
334 __asm__ __volatile__ (
335 "in __tmp_reg__,__SREG__" "\n\t"
336 "cli" "\n\t"
337 "wdr" "\n\t"
338 "out %i[CCPADDRESS],%[SIGNATURE]" "\n\t"
339 "out %i[WDTREG],%[WDVALUE]" "\n\t"
340 "out __SREG__,__tmp_reg__"
341 : /* no outputs */
342 : [CCPADDRESS] "n" (& CCP),
343 [SIGNATURE] "r" ((uint8_t)0xD8),
344 [WDTREG] "n" (& _WD_CONTROL_REG),
345 [WDVALUE] "r" ((uint8_t)((value & 0x08 ? _WD_PS3_MASK : 0x00)
346 | _BV(WDE) | (value & 0x07) ))
347 : "memory");
348 }
349}
350
351static __ATTR_ALWAYS_INLINE__
352void wdt_disable (void)
353{
354 if (!_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P(_WD_CONTROL_REG))
355 {
356 uint8_t __temp_wd;
357 __asm__ __volatile__ (
358 "in __tmp_reg__,__SREG__" "\n\t"
359 "cli" "\n\t"
360 "wdr" "\n\t"
361 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t"
362 "lds %[TEMP_WD],%[WDTREG]" "\n\t"
363 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t"
364 "sts %[WDTREG],%[TEMP_WD]" "\n\t"
365 "out __SREG__,__tmp_reg__"
366 : [TEMP_WD] "=d" (__temp_wd)
367 : [CCPADDRESS] "n" (& CCP),
368 [SIGNATURE] "r" ((uint8_t)0xD8),
369 [WDTREG] "n" (& _WD_CONTROL_REG),
370 [WDVALUE] "n" (1 << WDE)
371 : "memory");
372 }
373 else if (!_SFR_IO_REG_P (CCP) && _SFR_IO_REG_P(_WD_CONTROL_REG))
374 {
375 uint8_t __temp_wd;
376 __asm__ __volatile__ (
377 "in __tmp_reg__,__SREG__" "\n\t"
378 "cli" "\n\t"
379 "wdr" "\n\t"
380 "sts %[CCPADDRESS],%[SIGNATURE]" "\n\t"
381 "in %[TEMP_WD],%i[WDTREG]" "\n\t"
382 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t"
383 "out %i[WDTREG],%[TEMP_WD]" "\n\t"
384 "out __SREG__,__tmp_reg__"
385 : [TEMP_WD] "=d" (__temp_wd)
386 : [CCPADDRESS] "n" (& CCP),
387 [SIGNATURE] "r" ((uint8_t)0xD8),
388 [WDTREG] "n" (& _WD_CONTROL_REG),
389 [WDVALUE] "n" (1 << WDE)
390 : "memory");
391 }
392 else if (_SFR_IO_REG_P (CCP) && !_SFR_IO_REG_P(_WD_CONTROL_REG))
393 {
394 uint8_t __temp_wd;
395 __asm__ __volatile__ (
396 "in __tmp_reg__,__SREG__" "\n\t"
397 "cli" "\n\t"
398 "wdr" "\n\t"
399 "out %i[CCPADDRESS],%[SIGNATURE]" "\n\t"
400 "lds %[TEMP_WD],%[WDTREG]" "\n\t"
401 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t"
402 "sts %[WDTREG],%[TEMP_WD]" "\n\t"
403 "out __SREG__,__tmp_reg__"
404 : [TEMP_WD] "=d" (__temp_wd)
405 : [CCPADDRESS] "n" (& CCP),
406 [SIGNATURE] "r" ((uint8_t)0xD8),
407 [WDTREG] "n" (& _WD_CONTROL_REG),
408 [WDVALUE] "n" (1 << WDE)
409 : "memory");
410 }
411 else
412 {
413 uint8_t __temp_wd;
414 __asm__ __volatile__ (
415 "in __tmp_reg__,__SREG__" "\n\t"
416 "cli" "\n\t"
417 "wdr" "\n\t"
418 "out %i[CCPADDRESS],%[SIGNATURE]" "\n\t"
419 "in %[TEMP_WD],%i[WDTREG]" "\n\t"
420 "cbr %[TEMP_WD],%[WDVALUE]" "\n\t"
421 "out %i[WDTREG],%[TEMP_WD]" "\n\t"
422 "out __SREG__,__tmp_reg__"
423 : [TEMP_WD] "=d" (__temp_wd)
424 : [CCPADDRESS] "n" (& CCP),
425 [SIGNATURE] "r" ((uint8_t)0xD8),
426 [WDTREG] "n" (& _WD_CONTROL_REG),
427 [WDVALUE] "n" (1 << WDE)
428 : "memory");
429 }
430}
431
432#else
433
434/** \ingroup avr_watchdog
435 Enable the watchdog timer, configuring it for expiry after
436 \c timeout (which is a combination of the \c WDP0 through
437 \c WDP2 bits to write into the \c WDTCR register; For those devices
438 that have a \c WDTCSR register, it uses the combination of the \c WDP0
439 through \c WDP3 bits).
440
441 See also the symbolic constants \c WDTO_15MS et al. */
442static __ATTR_ALWAYS_INLINE__
443void wdt_enable(const uint8_t value)
444{
445 if (_SFR_IO_REG_P (_WD_CONTROL_REG))
446 {
447 __asm__ __volatile__ (
448 "in __tmp_reg__,__SREG__" "\n\t"
449 "cli" "\n\t"
450 "wdr" "\n\t"
451 "out %i0, %1" "\n\t"
452 "out __SREG__,__tmp_reg__" "\n\t"
453 "out %i0, %2"
454 : /* no outputs */
455 : "n" (& _WD_CONTROL_REG),
456 "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),
457 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00)
458 | _BV(WDE) | (value & 0x07)) )
459 : "memory");
460 }
461 else
462 {
463 __asm__ __volatile__ (
464 "in __tmp_reg__,__SREG__" "\n\t"
465 "cli" "\n\t"
466 "wdr" "\n\t"
467 "sts %0, %1" "\n\t"
468 "out __SREG__,__tmp_reg__" "\n\t"
469 "sts %0, %2"
470 : /* no outputs */
471 : "n" (& _WD_CONTROL_REG),
472 "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),
473 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00)
474 | _BV(WDE) | (value & 0x07)) )
475 : "memory");
476 }
477}
478
479/** \ingroup avr_watchdog
480 Disable the watchdog timer.
481*/
482static __ATTR_ALWAYS_INLINE__
483void wdt_disable (void)
484{
485 if (_SFR_IO_REG_P (_WD_CONTROL_REG))
486 {
487 uint8_t __temp_reg;
488 __asm__ __volatile__ (
489 "in __tmp_reg__,__SREG__" "\n\t"
490 "cli" "\n\t"
491 "wdr" "\n\t"
492 "in %[TEMPREG],%i[WDTREG]" "\n\t"
493 "ori %[TEMPREG],%[WDCE_WDE]" "\n\t"
494 "out %i[WDTREG],%[TEMPREG]" "\n\t"
495 "out %i[WDTREG],__zero_reg__" "\n\t"
496 "out __SREG__,__tmp_reg__"
497 : [TEMPREG] "=d" (__temp_reg)
498 : [WDTREG] "n" (& _WD_CONTROL_REG),
499 [WDCE_WDE] "n" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE)))
500 : "memory");
501 }
502 else
503 {
504 uint8_t __temp_reg;
505 __asm__ __volatile__ (
506 "in __tmp_reg__,__SREG__" "\n\t"
507 "cli" "\n\t"
508 "wdr" "\n\t"
509 "lds %[TEMPREG],%[WDTREG]" "\n\t"
510 "ori %[TEMPREG],%[WDCE_WDE]" "\n\t"
511 "sts %[WDTREG],%[TEMPREG]" "\n\t"
512 "sts %[WDTREG],__zero_reg__" "\n\t"
513 "out __SREG__,__tmp_reg__"
514 : [TEMPREG] "=d" (__temp_reg)
515 : [WDTREG] "n" (& _WD_CONTROL_REG),
516 [WDCE_WDE] "n" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE)))
517 : "memory");
518 }
519}
520
521#endif
522
523
524/**
525 \ingroup avr_watchdog
526 Symbolic constants for the watchdog timeout. Since the watchdog
527 timer is based on a free-running RC oscillator, the times are
528 approximate only and apply to a supply voltage of 5 V. At lower
529 supply voltages, the times will increase. For older devices, the
530 times will be as large as three times when operating at Vcc = 3 V,
531 while the newer devices (e. g. ATmega128, ATmega8) only experience
532 a negligible change.
533
534 Possible timeout values are: 15 ms, 30 ms, 60 ms, 120 ms, 250 ms,
535 500 ms, 1 s, 2 s. (Some devices also allow for 4 s and 8 s.)
536 Symbolic constants are formed by the prefix
537 \c WDTO_, followed by the time.
538
539 Example that would select a watchdog timer expiry of approximately
540 500 ms:
541 \code
542 wdt_enable(WDTO_500MS);
543 \endcode
544*/
545#if defined(__DOXYGEN__) || defined(__AVR_XMEGA__)
546#define WDTO_8MS -1
547#endif
548
549/** \ingroup avr_watchdog
550 A value to be passed to wdt_enable() for the specified watchdog
551 timeout duration. */
552#define WDTO_15MS 0
553
554/** \ingroup avr_watchdog
555 See \c #WDTO_15MS */
556#define WDTO_30MS 1
557
558/** \ingroup avr_watchdog
559 See \c #WDTO_15MS */
560#define WDTO_60MS 2
561
562/** \ingroup avr_watchdog
563 See \c #WDTO_15MS */
564#define WDTO_120MS 3
565
566/** \ingroup avr_watchdog
567 See \c #WDTO_15MS */
568#define WDTO_250MS 4
569
570/** \ingroup avr_watchdog
571 See \c #WDTO_15MS */
572#define WDTO_500MS 5
573
574/** \ingroup avr_watchdog
575 See \c #WDTO_15MS */
576#define WDTO_1S 6
577
578/** \ingroup avr_watchdog
579 See \c #WDTO_15MS */
580#define WDTO_2S 7
581
582#if defined(__DOXYGEN__) || defined(WDP3) || defined(__AVR_XMEGA__)
583
584/** \ingroup avr_watchdog
585 See \c WDTO_15MS
586 Note: This is only available on the
587 ATtiny2313,
588 ATtiny24, ATtiny44, ATtiny84, ATtiny84A,
589 ATtiny25, ATtiny45, ATtiny85,
590 ATtiny261, ATtiny461, ATtiny861,
591 ATmega48*, ATmega88*, ATmega168*, ATmega328*,
592 ATmega164P, ATmega324P, ATmega324PB, ATmega644P, ATmega644,
593 ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561,
594 ATmega8HVA, ATmega16HVA, ATmega32HVB,
595 ATmega406, ATmega1284P,
596 AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316,
597 AT90PWM81, AT90PWM161,
598 AT90USB82, AT90USB162,
599 AT90USB646, AT90USB647, AT90USB1286, AT90USB1287,
600 ATtiny48, ATtiny88.
601
602 Note: This value does <em>not</em> match the bit pattern of the
603 respective control register. It is solely meant to be used together
604 with wdt_enable().
605*/
606#define WDTO_4S 8
607
608/** \ingroup avr_watchdog
609 See \c WDTO_15MS
610 Note: This is only available on the
611 ATtiny2313,
612 ATtiny24, ATtiny44, ATtiny84, ATtiny84A,
613 ATtiny25, ATtiny45, ATtiny85,
614 ATtiny261, ATtiny461, ATtiny861,
615 ATmega48*, ATmega88*, ATmega168*, ATmega328*,
616 ATmega164P, ATmega324P, ATmega324PB, ATmega644P, ATmega644,
617 ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561,
618 ATmega8HVA, ATmega16HVA, ATmega32HVB,
619 ATmega406, ATmega1284P,
620 ATmega2564RFR2, ATmega256RFR2, ATmega1284RFR2, ATmega128RFR2, ATmega644RFR2, ATmega64RFR2
621 AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316,
622 AT90PWM81, AT90PWM161,
623 AT90USB82, AT90USB162,
624 AT90USB646, AT90USB647, AT90USB1286, AT90USB1287,
625 ATtiny48, ATtiny88,
626 ATxmega16a4u, ATxmega32a4u,
627 ATxmega16c4, ATxmega32c4,
628 ATxmega128c3, ATxmega192c3, ATxmega256c3.
629
630 Note: This value does <em>not</em> match the bit pattern of the
631 respective control register. It is solely meant to be used together
632 with wdt_enable().
633*/
634#define WDTO_8S 9
635
636#endif /* defined(__DOXYGEN__) || defined(WDP3) */
637
638#endif /* _AVR_WDT_H_ */
#define _BV(bit)
Definition: sfr_defs.h:206
unsigned char uint8_t
Definition: stdint.h:88
static void wdt_disable(void)
Definition: wdt.h:483
#define wdt_enable(timeout)
Definition: wdt.h:131