/* * OpenPSU firmware * Utility functions * * Copyright (C) 2007 Michael Buesch * * This program 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 2 * of the License, or (at your option) any later version. * * This program 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. */ #include "util.h" #include "calibration.h" #include "main.h" #include "lcd.h" #include #include #include #include void panic(const char PROGPTR *msg) { irq_disable(); wdt_disable(); emergency_shutdown(); lcd_clear_buffer(); lcd_put_str("Whee! PANIC :(\n"); lcd_put_pstr(msg); lcd_commit(); infinite_sleep(); } void reboot(void) { irq_disable(); /* Enable the WDT in system reset mode. */ wdt_enable(WDTO_15MS); while (1); } void infinite_sleep(void) { irq_disable(); wdt_disable(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); while (1) sleep_mode(); } ISR(WDT_vect) { panic(PSTR("watchdog")); } void wdt_enable_irq_mode(uint8_t timeout) { uint8_t sreg; sreg = irq_disable_save(); wdt_reset(); __asm__ __volatile__( "sts %0, %1 \n\t" "sts %0, %2 \n\t" : /* none */ : "M" (_SFR_MEM_ADDR(WDTCSR)) , "r" (1 << WDCE) , "r" ((1 << WDIE) | (1 << WDIF) | timeout) ); irq_restore(sreg); }