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___
29 typedef struct avr_watchdog_t {
32 avr_regbit_t wdrf; // watchdog reset flag (in MCU Status Register)
34 avr_regbit_t wdce; // watchdog change enable
35 avr_regbit_t wde; // watchdog enabled
36 avr_regbit_t wdp[4]; // watchdog Timer Prescaler
38 avr_int_vector_t watchdog; // watchdog interrupt
40 avr_cycle_count_t cycle_count;
43 /* takes no parameter */
44 #define AVR_IOCTL_WATCHDOG_RESET AVR_IOCTL_DEF('w','d','t','r')
46 void avr_watchdog_init(avr_t * avr, avr_watchdog_t * p);
50 * This helps declare a watchdog block into a core.
51 * No guarantee it will work with all, but it works
52 * with the one we have right now
54 #define AVR_WATCHDOG_DECLARE(_WDSR, _vec) \
56 .wdrf = AVR_IO_REGBIT(MCUSR, WDRF),\
57 .wdce = AVR_IO_REGBIT(_WDSR, WDCE),\
58 .wde = AVR_IO_REGBIT(_WDSR, WDE),\
59 .wdp = { AVR_IO_REGBIT(_WDSR, WDP0),AVR_IO_REGBIT(_WDSR, WDP1),\
60 AVR_IO_REGBIT(_WDSR, WDP2),AVR_IO_REGBIT(_WDSR, WDP3) },\
62 .enable = AVR_IO_REGBIT(_WDSR, WDIE),\
63 .raised = AVR_IO_REGBIT(_WDSR, WDIF),\
68 /* no WDP3, WDIE, WDIF in atmega128 */
69 #define AVR_WATCHDOG_DECLARE_128(_WDSR, _vec) \
71 .wdrf = AVR_IO_REGBIT(MCUSR, WDRF),\
72 .wdce = AVR_IO_REGBIT(_WDSR, WDCE),\
73 .wde = AVR_IO_REGBIT(_WDSR, WDE),\
74 .wdp = { AVR_IO_REGBIT(_WDSR, WDP0),AVR_IO_REGBIT(_WDSR, WDP1),\
75 AVR_IO_REGBIT(_WDSR, WDP2) },\
77 .enable = AVR_IO_REGBIT(_WDSR, 6),\
78 .raised = AVR_IO_REGBIT(_WDSR, 7),\
83 #endif /* __AVR_WATCHDOG_H___ */