simulavr  1.1.0
hwpinchange.h
Go to the documentation of this file.
1 #ifndef _hwpinchangeh_
2 #define _hwpinchangeh_
3 #include "avrdevice.h"
4 #include "pin.h"
5 #include "pinnotify.h"
6 #include "net.h"
7 #include "rwmem.h"
8 #include "hardware.h"
9 
10 class HWPcifrApi {
11  public:
12  virtual ~HWPcifrApi() {}
13  virtual bool getPcifr(unsigned bit) throw() = 0;
14  virtual void setPcifr(unsigned bit) throw() = 0;
15 
16 };
17 
18 class HWPcicrApi {
19  public:
20  virtual ~HWPcicrApi() {}
21  virtual bool getPcicr(unsigned bit) throw() = 0;
22  virtual void setPcicr(unsigned bit) throw() = 0;
23 
24 };
25 
26 class HWPcmskApi {
27  public:
28  virtual ~HWPcmskApi() {}
29  virtual void setPcmskMask(unsigned char val) throw() = 0;
30  virtual unsigned char getPcmskMask() throw() = 0;
31 
32 };
33 
35  public:
36  virtual ~HWPcmskPinApi() {}
37  virtual void pinChanged(unsigned bit) throw() = 0;
38 
39 };
40 
42  public: // HWPcirMaskApi
43  virtual void setPcifrMask(unsigned char val) throw() = 0;
44  virtual unsigned char getPcifrMask() throw() = 0;
45 
46  virtual void setPcicrMask(unsigned char val) throw() = 0;
47  virtual unsigned char getPcicrMask() throw() = 0;
48 
49 };
50 
52 class HWPcir : public HWPcifrApi , public HWPcirMaskApi , public Hardware {
53  private:
54  unsigned char _pcifr;
55  unsigned char _pcicr;
57 
58  const unsigned _vector0;
59  const unsigned _vector1;
60  const unsigned _vector2;
61  const unsigned _vector3;
62  const unsigned _vector4;
63  const unsigned _vector5;
64  const unsigned _vector6;
65  const unsigned _vector7;
66 
67  public:
68  // Unimplemented vectors are set
69  // to a value of all ones (i.e. ~0).
70  HWPcir( AvrDevice* avr,
71  HWIrqSystem& irqSystem,
72  unsigned vector0 = ~0,
73  unsigned vector1 = ~0,
74  unsigned vector2 = ~0,
75  unsigned vector3 = ~0,
76  unsigned vector4 = ~0,
77  unsigned vector5 = ~0,
78  unsigned vector6 = ~0,
79  unsigned vector7 = ~0
80  ) throw();
81 
82  private:
83  unsigned convertBitToVector(unsigned bit) const throw();
84 
85  public: // HWPcifrApi
86  bool getPcifr(unsigned pcifrBit) throw();
87  void setPcifr(unsigned pcifrBit) throw();
88 
89  public: // HWPcirMaskApi
90  void setPcifrMask(unsigned char val) throw();
91  unsigned char getPcifrMask() throw();
92 
93  void setPcicrMask(unsigned char val) throw();
94  unsigned char getPcicrMask() throw();
95 
96 
97  IOReg<HWPcir>
98  pcicr_reg,
99  pcifr_reg;
100 
101  private: // Hardware
102  void Reset();
103  void ClearIrqFlag(unsigned int vector);
104 
105 
106 };
107 
109 class HWPcmsk : public HWPcmskApi , public HWPcmskPinApi {
110  private:
112  unsigned char _pcmsk;
113  const unsigned _pcifrBit;
114 
115  public:
116  // constructor
117  HWPcmsk(
118  AvrDevice *core,
119  HWPcifrApi& pcifrApi,
120  unsigned pcifrBit
121  ) throw();
122 
123  public: // HWPcmskApi
124  void setPcmskMask(unsigned char val) throw();
125  unsigned char getPcmskMask() throw();
126 
127  public: // HWPcmskPinApi
128  void pinChanged(unsigned bit) throw();
129 
130  IOReg<HWPcmsk> pcmsk_reg;
131 
132 };
133 
134 // This class monitors a single pin for changes
135 // an reports an interrupt if the pin chages.
138  private:
139  HWPcmskPinApi& _pcmskPinApi;
140  const unsigned _pcmskBit;
141 
142  // Previous state of pin since change callback doesn't *really*
143  // mean "change"!
145 
146  public:
147  PinChange( Pin& pin,
148  HWPcmskPinApi& pcmskPinApi,
149  unsigned pcmskBit
150  ) throw();
151 
152 
153  private: // HasPinNotifyFunction
154  void PinStateHasChanged(Pin*);
155 
156 };
157 
158 #endif
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
This class is never used.
Definition: hwpinchange.h:52
This class is never used.
Definition: hwpinchange.h:109
const unsigned _vector5
Definition: hwpinchange.h:63
unsigned char _pcifr
Definition: hwpinchange.h:54
const unsigned _pcifrBit
Definition: hwpinchange.h:113
HWIrqSystem & _irqSystem
Definition: hwpinchange.h:56
Pin class, handles input and output to external parts.
Definition: pin.h:98
virtual ~HWPcicrApi()
Definition: hwpinchange.h:20
const unsigned _vector2
Definition: hwpinchange.h:60
unsigned char _pcmsk
Definition: hwpinchange.h:112
unsigned char _pcicr
Definition: hwpinchange.h:55
This class is never used. Delete? (Pin-change interrupt is done by ExternalIRQPort.)
Definition: hwpinchange.h:137
const unsigned _vector7
Definition: hwpinchange.h:65
const unsigned _vector1
Definition: hwpinchange.h:59
const unsigned _vector4
Definition: hwpinchange.h:62
const unsigned _vector6
Definition: hwpinchange.h:64
const unsigned _vector3
Definition: hwpinchange.h:61
virtual ~HWPcmskApi()
Definition: hwpinchange.h:28
virtual ~HWPcmskPinApi()
Definition: hwpinchange.h:36
IO register to be specialized for a certain class/hardware.
Definition: pin.h:35
HWPcmskPinApi & _pcmskPinApi
Definition: hwpinchange.h:139
const unsigned _pcmskBit
Definition: hwpinchange.h:140
virtual ~HWPcifrApi()
Definition: hwpinchange.h:12
const unsigned _vector0
Definition: hwpinchange.h:58
virtual bool getPcifr(unsigned bit)=0
bool _prevState
Definition: hwpinchange.h:144
HWPcifrApi & _pcifrApi
Definition: hwpinchange.h:111
virtual void setPcifr(unsigned bit)=0