simulavr  1.1.0
timerprescaler.h
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 #ifndef TIMERPRESCALER
27 #define TIMERPRESCALER
28 
29 #include "../hardware.h"
30 #include "../avrdevice.h"
31 #include "../rwmem.h"
32 #include "../pinatport.h"
33 
35 
37 class HWPrescaler: public Hardware, public IOSpecialRegClient {
38 
39  private:
40  int _resetBit;
42 
43  protected:
45  unsigned short preScaleValue;
46  bool countEnable;
47  unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv);
50  unsigned char get_from_client(const IOSpecialReg *reg, unsigned char v) { return v; }
51 
52  public:
54  HWPrescaler(AvrDevice *core, const std::string &tracename);
56  HWPrescaler(AvrDevice *core,
57  const std::string &tracename,
58  IOSpecialReg *ioreg,
59  int resetBit);
61  HWPrescaler(AvrDevice *core,
62  const std::string &tracename,
63  IOSpecialReg *ioreg,
64  int resetBit,
65  int resetSyncBit);
67  virtual unsigned int CpuCycle() {
68  if(countEnable) {
69  preScaleValue++;
70  if(preScaleValue > 1023) preScaleValue = 0;
71  }
72  return 0;
73  }
75  unsigned short GetValue() { return preScaleValue; }
77  void Reset(){ preScaleValue = 0; }
78 };
79 
81 
84 
85  public:
88  const std::string &tracename,
89  PinAtPort tosc_pin,
90  IOSpecialReg *asyreg,
91  int clockSelBit,
92  IOSpecialReg *resreg,
93  int resetBit);
96  const std::string &tracename,
97  PinAtPort tosc_pin,
98  IOSpecialReg *asyreg,
99  int clockSelBit,
100  IOSpecialReg *resreg,
101  int resetBit,
102  int resetSyncBit);
104  virtual unsigned int CpuCycle();
105 
106  protected:
108  unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv);
109 
110  private:
113  bool pinstate;
114  bool clockselect;
116 };
117 
118 #endif // TIMERPRESCALER
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
bool pinstate
saved pin status of osc. pin
PinAtPort tosc_pin
input pin for external timer oscillator
Extends HWPrescaler with a external clock oszillator pin.
IOSpecialReg * resetRegister
instance of IO register with reset bits
int _resetBit
holds bit position for reset bit on IO register
Interface class to connect hardware units to control registers.
Definition: rwmem.h:398
unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv)
IO register interface set method, see IOSpecialRegClient.
IOSpecialReg * asyncRegister
instance of IO register with assr bits
int clockSelectBit
holds bit position of counter clock select
bool clockselect
holds the clock select state, true is external clock
void Reset()
Reset method, sets prescaler counter to 0.
int _resetSyncBit
holds sync bit position for prescaler reset synchronisation
Prescaler unit for support timers with clock.
unsigned short preScaleValue
prescaler counter value
unsigned short GetValue()
Get method for current prescaler counter value.
HWPrescaler(AvrDevice *core, const std::string &tracename)
Creates HWPrescaler instance without reset feature.
virtual unsigned int CpuCycle()
Count functionality for prescaler.
unsigned char get_from_client(const IOSpecialReg *reg, unsigned char v)
IO register interface get method, see IOSpecialRegClient.