/* * 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 // TODO? move this logic to PCINT() and simplify things here? if (current_event & B_HOLD) { //emit_current_event(0); // should have been emitted by PCINT empty_event_sequence(); } // end and clear event after release timeout else if (ticks_since_last >= RELEASE_TIMEOUT) { current_event |= B_TIMEOUT; //ticks_since_last_event = 0; emit_current_event(0); empty_event_sequence(); } } #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) // start a new ADC measurement every 4 ticks adc_trigger ++; if (0 == (adc_trigger & 3)) { #if defined(TICK_DURING_STANDBY) && defined(USE_SLEEP_LVP) // we shouldn't be here unless it woke up for a LVP check... // so enable ADC voltage measurement functions temporarily if (go_to_standby) ADC_on(); #endif ADC_start_measurement(); adcint_enable = 1; } #endif } #endif