simulavr  1.1.0
prescalermux.cpp
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #include "hwtimer/prescalermux.h"
27 #include "avrerror.h"
28 
30  prescaler(ps) {}
31 
32 bool PrescalerMultiplexer::isClock(unsigned int cs) {
33  unsigned short pv = prescaler->GetValue();
34 
35  switch(cs) {
36  case 0: // no clock, counter stop
37  return false;
38 
39  case 1: // every clock
40  return true;
41 
42  case 2: // CKx8
43  return (bool)((pv % 8) == 0);
44 
45  case 3: // CKx32
46  return (bool)((pv % 32) == 0);
47 
48  case 4: // CKx64
49  return (bool)((pv % 64) == 0);
50 
51  case 5: // CKx128
52  return (bool)((pv % 128) == 0);
53 
54  case 6: // CKx256
55  return (bool)((pv % 256) == 0);
56 
57  case 7: // CKx1024
58  return (bool)((pv % 1024) == 0);
59 
60  default:
61  avr_error("wrong prescaler multiplex value: %d", cs);
62  }
63 }
64 
67  clkpin(pi) {
68  clkpin_old = (bool)(clkpin == 1);
69 }
70 
71 bool PrescalerMultiplexerExt::isClock(unsigned int cs) {
72  bool current = (bool)(clkpin == 1);
73 
74  switch(cs) {
75  case 0: // no clock, counter stop
76  return false;
77 
78  case 1: // every clock
79  return true;
80 
81  case 2: // CKx8
82  return (bool)((prescaler->GetValue() % 8) == 0);
83 
84  case 3: // CKx64
85  return (bool)((prescaler->GetValue() % 64) == 0);
86 
87  case 4: // CKx256
88  return (bool)((prescaler->GetValue() % 256) == 0);
89 
90  case 5: // CKx1024
91  return (bool)((prescaler->GetValue() % 1024) == 0);
92 
93  case 6: // pin falling edge
94  if(current == clkpin_old) return false; // no change
95  clkpin_old = current;
96  return (bool)(current == false); // old = true, current = false
97 
98  case 7: // pin rising edge
99  if(current == clkpin_old) return false; // no change
100  clkpin_old = current;
101  return (bool)(current == true); // old = false, current = true
102 
103  default:
104  avr_error("wrong prescaler multiplex value: %d", cs);
105  }
106 }
107 
109  PrescalerMultiplexer(ps) {}
110 
111 bool PrescalerMultiplexerT15::isClock(unsigned int cs) {
112  avr_warning("method not implemented");
113  return false;
114 }
115 
PrescalerMultiplexer(HWPrescaler *ps)
Creates a multiplexer instance, connected with prescaler.
PrescalerMultiplexerT15(HWPrescaler *ps)
Creates a multiplexer instance for timer 1 on ATTiny15, connected with prescaler. ...
virtual bool isClock(unsigned int cs)
#define avr_error(...)
Definition: avrerror.h:135
#define avr_warning(...)
Definition: avrerror.h:133
virtual bool isClock(unsigned int cs)
Prescaler unit for support timers with clock.
PrescalerMultiplexerExt(HWPrescaler *ps, PinAtPort pi)
Creates a multiplexer instance with a count input pin, connected with prescaler.
unsigned short GetValue()
Get method for current prescaler counter value.
PrescalerMultiplexer without external count pin.
Definition: prescalermux.h:35
virtual bool isClock(unsigned int cs)
HWPrescaler * prescaler
pointer to prescaler
Definition: prescalermux.h:38