/* * fsm-wdt.c: WDT (Watch Dog Timer) functions for SpaghettiMonster. * * Copyright (C) 2017 Selene ToyKeeper * * 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 3 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. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef FSM_WDT_C #define FSM_WDT_C #include #include void WDT_on() { #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) // interrupt every 16ms //cli(); // Disable interrupts wdt_reset(); // Reset the WDT WDTCR |= (1<= HOLD_TIMEOUT) { ticks_since_last_event = 0; current_event |= B_HOLD; emit_current_event(0); } } } // event in progress, but button not currently down else if (current_event) { // "hold" event just ended // no timeout required when releasing a long-press if (current_event & B_HOLD) { //emit_current_event(ticks_since_last); // should have been emitted by PCINT_inner() empty_event_sequence(); } // end and clear event after release timeout else if (ticks_since_last >= RELEASE_TIMEOUT) { current_event |= B_TIMEOUT; emit_current_event(0); empty_event_sequence(); } } #ifdef TICK_DURING_STANDBY } #endif #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) // enable the deferred ADC handler once in a while if (! adc_trigger) { ADC_start_measurement(); adc_deferred_enable = 1; } // timing for the ADC handler is every 32 ticks (~2Hz) adc_trigger = (adc_trigger + 1) & 31; #endif } #endif