simulavr  1.1.0
hwacomp.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 HWACOMP
27 #define HWACOMP
28 
29 #include "hardware.h"
30 #include "rwmem.h"
31 #include "irqsystem.h"
32 #include "pinatport.h"
33 #include "pinnotify.h"
34 #include "traceval.h"
35 
36 // support input configuration for analog comparator and input capture event for timer,
37 // if it's possible by hardware
38 class HWAd;
39 class BasicTimerUnit;
40 
42 class HWAcomp: public Hardware,
43  public HasPinNotifyFunction,
44  public TraceValueRegister,
45  public IOSpecialRegClient,
46  public AnalogSignalChange {
47 
48  protected:
52  Pin *v_bg;
53  Pin *v_cc;
54  bool useBG;
55  bool acme_sfior;
56  bool enabled;
57  unsigned char acsr;
58  unsigned int irqVec;
61  HWAd *ad;
63 
64  unsigned char set_from_reg(const IOSpecialReg* reg, unsigned char nv);
65  unsigned char get_from_client(const IOSpecialReg* reg, unsigned char v) { return v; }
66 
68  bool isSetACME(void);
69 
70  public:
71  enum {
72  ACD = 0x80,
73  ACBG = 0x40,
74  ACO = 0x20,
75  ACI = 0x10,
76  ACIE = 0x08,
77  ACIC = 0x04,
78  ACIS1 = 0x02,
79  ACIS0 = 0x01
80  };
81 
83 
85  HWAcomp(AvrDevice *core,
86  HWIrqSystem *irqsys,
87  PinAtPort ain0,
88  PinAtPort ain1,
89  unsigned int irqVec,
90  HWAd *_ad,
91  BasicTimerUnit *_timerA,
92  IOSpecialReg *_sfior = NULL,
93  BasicTimerUnit *_timerB = NULL,
94  bool _useBG = true);
95  ~HWAcomp();
96 
98  unsigned char GetAcsr() { return acsr; }
100  void SetAcsr(unsigned char val);
102  void Reset();
104  void ClearIrqFlag(unsigned int vec);
106  void PinStateHasChanged(Pin *);
108  float GetIn0(void);
110  float GetIn1(void);
112  bool GetACO(void) { return ((acsr & ACO) == ACO); }
113  // Interface for notify signal change in ADC multiplexer
114  void NotifySignalChanged(void);
115 
116 };
117 
118 #endif
119 
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
HWIrqSystem * irqSystem
connection to IRQ controller
Definition: hwacomp.h:49
bool useBG
has ADBG register bit and can switch In0 to bandgap ref
Definition: hwacomp.h:54
Pin * v_cc
get access to voltage supply level
Definition: hwacomp.h:53
unsigned char get_from_client(const IOSpecialReg *reg, unsigned char v)
Definition: hwacomp.h:65
BasicTimerUnit * timerB
connection to timerB for input capture event. NULL, if not available
Definition: hwacomp.h:60
float GetIn0(void)
Get analog value for comparator input 0.
Definition: hwacomp.cpp:126
Pin class, handles input and output to external parts.
Definition: pin.h:98
bool enabled
analog comparator is enabled
Definition: hwacomp.h:56
float GetIn1(void)
Get analog value for comparator input 1.
Definition: hwacomp.cpp:133
IOReg< HWAcomp > acsr_reg
ACSR IO register.
Definition: hwacomp.h:82
void SetAcsr(unsigned char val)
Set method for ACSR register.
Definition: hwacomp.cpp:93
unsigned char acsr
ACSR register value.
Definition: hwacomp.h:57
Interface class to connect hardware units to control registers.
Definition: rwmem.h:398
void PinStateHasChanged(Pin *)
Get informed about input pin change.
Definition: hwacomp.cpp:141
void ClearIrqFlag(unsigned int vec)
Reflect irq processing, reset interrupt source.
Definition: hwacomp.cpp:182
BasicTimerUnit * timerA
connection to timerA for input capture event. NULL, if not available
Definition: hwacomp.h:59
Basic timer unit.
Definition: hwtimer.h:48
void Reset()
Reset the unit.
Definition: hwacomp.cpp:85
unsigned char GetAcsr()
Get method for ACSR register.
Definition: hwacomp.h:98
Build a register for TraceValue&#39;s.
Definition: traceval.h:442
PinAtPort pinAin1
port pin AIN1
Definition: hwacomp.h:51
bool acme_sfior
ACME flag in SFIOR register is set.
Definition: hwacomp.h:55
unsigned int irqVec
stores the IRQ vector number
Definition: hwacomp.h:58
bool GetACO(void)
Return last state of analog comparator (assume, that this is correct, if unit is disabled) ...
Definition: hwacomp.h:112
HWAd * ad
connection to ADC for analog input mux. NULL, if not available
Definition: hwacomp.h:61
unsigned char set_from_reg(const IOSpecialReg *reg, unsigned char nv)
Definition: hwacomp.cpp:189
Pin * v_bg
get access to bandgap reference
Definition: hwacomp.h:52
bool isSetACME(void)
Check, if ACME flag is set (from ADC or SFIOR register)
Definition: hwacomp.cpp:197
~HWAcomp()
Definition: hwacomp.cpp:80
IOSpecialReg * sfior
connection to SFIOR register, if necessary. NULL, if not used
Definition: hwacomp.h:62
HWAcomp(AvrDevice *core, HWIrqSystem *irqsys, PinAtPort ain0, PinAtPort ain1, unsigned int irqVec, HWAd *_ad, BasicTimerUnit *_timerA, IOSpecialReg *_sfior=NULL, BasicTimerUnit *_timerB=NULL, bool _useBG=true)
constructor to instantiate a analog comparator peripheral
Definition: hwacomp.cpp:32
void NotifySignalChanged(void)
Definition: hwacomp.cpp:176
Definition: hwad.h:204
PinAtPort pinAin0
port pin AIN0
Definition: hwacomp.h:50
Analog comparator peripheral.
Definition: hwacomp.h:42