00001 /* 00002 **************************************************************************** 00003 * 00004 * simulavr - A simulator for the Atmel AVR family of microcontrollers. 00005 * Copyright (C) 2001, 2002, 2003 Klaus Rudolph 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 **************************************************************************** 00022 * 00023 * $Id$ 00024 */ 00025 00026 #include "prescalermux.h" 00027 #include "avrerror.h" 00028 00029 PrescalerMultiplexer::PrescalerMultiplexer(HWPrescaler *ps): 00030 prescaler(ps) {} 00031 00032 bool PrescalerMultiplexer::isClock(unsigned int cs) { 00033 unsigned short pv = prescaler->GetValue(); 00034 00035 switch(cs) { 00036 case 0: // no clock, counter stop 00037 return false; 00038 00039 case 1: // every clock 00040 return true; 00041 00042 case 2: // CKx8 00043 return (bool)((pv % 8) == 0); 00044 00045 case 3: // CKx32 00046 return (bool)((pv % 32) == 0); 00047 00048 case 4: // CKx64 00049 return (bool)((pv % 64) == 0); 00050 00051 case 5: // CKx128 00052 return (bool)((pv % 128) == 0); 00053 00054 case 6: // CKx256 00055 return (bool)((pv % 256) == 0); 00056 00057 case 7: // CKx1024 00058 return (bool)((pv % 1024) == 0); 00059 00060 default: 00061 avr_error("wrong prescaler multiplex value: %d", cs); 00062 } 00063 } 00064 00065 PrescalerMultiplexerExt::PrescalerMultiplexerExt(HWPrescaler *ps, PinAtPort pi): 00066 PrescalerMultiplexer(ps), 00067 clkpin(pi) { 00068 clkpin_old = (bool)(clkpin == 1); 00069 } 00070 00071 bool PrescalerMultiplexerExt::isClock(unsigned int cs) { 00072 unsigned short pv = prescaler->GetValue(); 00073 bool current = (bool)(clkpin == 1); 00074 00075 switch(cs) { 00076 case 0: // no clock, counter stop 00077 return false; 00078 00079 case 1: // every clock 00080 return true; 00081 00082 case 2: // CKx8 00083 return (bool)((prescaler->GetValue() % 8) == 0); 00084 00085 case 3: // CKx64 00086 return (bool)((prescaler->GetValue() % 64) == 0); 00087 00088 case 4: // CKx256 00089 return (bool)((prescaler->GetValue() % 256) == 0); 00090 00091 case 5: // CKx1024 00092 return (bool)((prescaler->GetValue() % 1024) == 0); 00093 00094 case 6: // pin falling edge 00095 if(current == clkpin_old) return false; // no change 00096 clkpin_old = current; 00097 return (bool)(current == false); // old = true, current = false 00098 00099 case 7: // pin rising edge 00100 if(current == clkpin_old) return false; // no change 00101 clkpin_old = current; 00102 return (bool)(current == true); // old = false, current = true 00103 00104 default: 00105 avr_error("wrong prescaler multiplex value: %d", cs); 00106 } 00107 } 00108 00109 PrescalerMultiplexerT15::PrescalerMultiplexerT15(HWPrescaler *ps): 00110 PrescalerMultiplexer(ps) {} 00111 00112 bool PrescalerMultiplexerT15::isClock(unsigned int cs) { 00113 avr_warning("method not implemented"); 00114 return false; 00115 } 00116