/* Copyright (c) 2002, 2004 Marek Michalkiewicz Copyright (c) 2005, 2006, 2007 Eric B. Weddington Copyright (c) 2015 Matthijs Kooijman All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This file provides a variant on the wdt_enable() macro (taken from avr/wdt.h) that can enable the watchdog timer interrupt, but not the timer itself. This file only provides the Atmega version, ideally avr-libc would provide a version for all supported devices. A request for this was filed at https://savannah.nongnu.org/bugs/?45420 The name of the macro below is intentionally not wdt_enable_interrupt, to prevent conflicts later if avr-libc adds this macro as well. This macro uses inline assembly, since this is the only way to really guarantee the correct timed sequence needed to change the watchdog register. Using plain C with things in the right order will _usually_ work, but sometimes the compiler gets smart and reorders some instructions or control flow, breaking things. */ #ifndef _AVR_WDT_INTERRUPT_H_ #define _AVR_WDT_INTERRUPT_H_ #include #include #define enable_wdt_interrupt(value) \ __asm__ __volatile__ ( \ "in __tmp_reg__,__SREG__" "\n\t" \ "cli" "\n\t" \ "wdr" "\n\t" \ "sts %0,%1" "\n\t" \ "out __SREG__,__tmp_reg__" "\n\t" \ "sts %0,%2" "\n\t" \ : /* no outputs */ \ : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ _BV(WDIE) | (value & 0x07)) ) \ : "r0" \ ) #endif // _AVR_WDT_INTERRUPT_H_