4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef __AVR_WATCHDOG_H___
24 #define __AVR_WATCHDOG_H___
32 typedef struct avr_watchdog_t {
35 avr_regbit_t wdrf; // watchdog reset flag (in MCU Status Register)
37 avr_regbit_t wdce; // watchdog change enable
38 avr_regbit_t wde; // watchdog enabled
39 avr_regbit_t wdp[4]; // watchdog Timer Prescaler
41 avr_int_vector_t watchdog; // watchdog interrupt
43 avr_cycle_count_t cycle_count;
46 /* takes no parameter */
47 #define AVR_IOCTL_WATCHDOG_RESET AVR_IOCTL_DEF('w','d','t','r')
49 void avr_watchdog_init(avr_t * avr, avr_watchdog_t * p);
53 * This helps declare a watchdog block into a core.
54 * No guarantee it will work with all, but it works
55 * with the one we have right now
57 #define AVR_WATCHDOG_DECLARE(_WDSR, _vec) \
59 .wdrf = AVR_IO_REGBIT(MCUSR, WDRF),\
60 .wdce = AVR_IO_REGBIT(_WDSR, WDCE),\
61 .wde = AVR_IO_REGBIT(_WDSR, WDE),\
62 .wdp = { AVR_IO_REGBIT(_WDSR, WDP0),AVR_IO_REGBIT(_WDSR, WDP1),\
63 AVR_IO_REGBIT(_WDSR, WDP2),AVR_IO_REGBIT(_WDSR, WDP3) },\
65 .enable = AVR_IO_REGBIT(_WDSR, WDIE),\
66 .raised = AVR_IO_REGBIT(_WDSR, WDIF),\
71 /* no WDP3, WDIE, WDIF in atmega128 */
72 #define AVR_WATCHDOG_DECLARE_128(_WDSR, _vec) \
74 .wdrf = AVR_IO_REGBIT(MCUSR, WDRF),\
75 .wdce = AVR_IO_REGBIT(_WDSR, WDCE),\
76 .wde = AVR_IO_REGBIT(_WDSR, WDE),\
77 .wdp = { AVR_IO_REGBIT(_WDSR, WDP0),AVR_IO_REGBIT(_WDSR, WDP1),\
78 AVR_IO_REGBIT(_WDSR, WDP2) },\
80 .enable = AVR_IO_REGBIT(_WDSR, 6),\
81 .raised = AVR_IO_REGBIT(_WDSR, 7),\
90 #endif /* __AVR_WATCHDOG_H___ */