/* interrupt.c - replacement for the avr library of the same name to provide dummy register variables Part of Grbl Simulator Copyright (c) 2012 Jens Geisler Grbl 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. Grbl 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 Grbl. If not, see . */ #include "interrupt.h" #include "io.h" #include "wdt.h" //pseudo-Interrupt vector table isr_fp compa_vect[6]={0}; isr_fp compb_vect[6]={0}; isr_fp ovf_vect[6]={0}; isr_fp wdt_vect = 0; isr_fp pc_vect = 0; void sei() {io.sreg|=SEI;} void cli() {io.sreg&=~SEI;} int16_t sim_scaling[8]={0,1,8,64,256,1024,1,1}; //clock scalars //Timer/Counter modes: these are incomplete, but enough for this application enum sim_wgm_mode { wgm_NORMAL, wgm_CTC, wgm_FAST_PWM, wgm_PHASE_PWM, wgm_PH_F_PWM, wgm_RESERVED }; //3-bit wgm table for 8-bit timers enum sim_wgm_mode sim_wgm_3[] = {wgm_NORMAL,wgm_PHASE_PWM,wgm_CTC,wgm_FAST_PWM, wgm_RESERVED,wgm_PHASE_PWM, wgm_RESERVED, wgm_FAST_PWM}; //4-bit wgm modes for 16-bit timers enum sim_wgm_mode sim_wgm_4[16] = {wgm_NORMAL,wgm_PHASE_PWM,wgm_PHASE_PWM,wgm_PHASE_PWM, wgm_CTC, wgm_FAST_PWM, wgm_FAST_PWM, wgm_FAST_PWM, wgm_PH_F_PWM, wgm_PH_F_PWM, wgm_PHASE_PWM, wgm_PHASE_PWM, wgm_CTC, wgm_RESERVED, wgm_FAST_PWM, wgm_FAST_PWM}; static const uint16_t timer_bitdepth[SIM_N_TIMERS] = { 0xFF,0xFFFF,0xFF, //0xFFFF,0xFFFF,0xFFFF 3 more for mega }; void timer_interrupts() { int i; uint8_t ien = io.sreg&SEI; //interrupts enabled? io.prescaler++; //all clocks for (i=0;i>1) | (io.tccra[i]&3); mode = sim_wgm_3[wgm]; } else { uint8_t wgm = ((io.tccrb[i]&0x18)>>1) | (io.tccra[i]&3); //4 wgm bits mode = sim_wgm_4[wgm]; } //tick if (io.tifr[i]&(1<