Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions common/wdt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is part of arduino-headers.
*
* arduino-headers is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or(at your option) any later version.
*
* arduino-headers is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with arduino-headers. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _ARDUINO_WDT_H
#define _ARDUINO_WDT_H

#include <avr/wdt.h>
#include <avr/interrupt.h>

#if defined(WDTCSR)
# define _WDT_REG WDTCSR
#else
# define _WDT_REG WDTCR
#endif

static inline void wdt_interrupt_enable() { _WDT_REG |= _BV(WDIE); }
static inline void wdt_interrupt_disable() { _WDT_REG &= ~_BV(WDIE); }

#define wdt_interrupt() ISR(WDT_vect)

#endif
31 changes: 31 additions & 0 deletions wdt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of arduino-headers.
*
* arduino-headers is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or(at your option) any later version.
*
* arduino-headers is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with arduino-headers. If not, see <http://www.gnu.org/licenses/>.
*/

#if defined(__AVR_ATmega8__)
# error "arduino/wdt.h: Not implemented for ATmega8 chips yet"
#elif defined(__AVR_ATmega168__) \
|| defined(__AVR_ATmega328P__)
# include <arduino/common/wdt.h>
#elif defined(__AVR_ATmega1280__)
# error "arduino/wdt.h: Not implemented for ATmega1280 chips yet"
#elif defined(__AVR_ATtiny25__) \
|| defined(__AVR_ATtiny45__) \
|| defined(__AVR_ATtiny85__)
# include <arduino/common/wdt.h>
#else
# error "arduino/wdt.h: Unknown chip type"
#endif