gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
intel_8254_timer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004, 2005
3  * The Regents of The University of Michigan
4  * All Rights Reserved
5  *
6  * This code is part of the M5 simulator.
7  *
8  * Permission is granted to use, copy, create derivative works and
9  * redistribute this software and such derivative works for any
10  * purpose, so long as the copyright notice above, this grant of
11  * permission, and the disclaimer below appear in all copies made; and
12  * so long as the name of The University of Michigan is not used in
13  * any advertising or publicity pertaining to the use or distribution
14  * of this software without specific, written prior authorization.
15  *
16  * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE
17  * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND
18  * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER
19  * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE
22  * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT,
23  * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM
24  * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
25  * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH
26  * DAMAGES.
27  */
28 
29 #ifndef __DEV_8254_HH__
30 #define __DEV_8254_HH__
31 
32 #include <iostream>
33 #include <string>
34 
35 #include "base/bitunion.hh"
36 #include "base/types.hh"
37 #include "base/trace.hh"
38 #include "debug/Intel8254Timer.hh"
39 #include "sim/eventq_impl.hh"
40 #include "sim/serialize.hh"
41 
44 {
45  protected:
46  BitUnion8(CtrlReg)
47  Bitfield<7, 6> sel;
48  Bitfield<5, 4> rw;
49  Bitfield<3, 1> mode;
50  Bitfield<0> bcd;
51  EndBitUnion(CtrlReg)
52 
53  enum SelectVal {
54  SelectCounter0,
55  SelectCounter1,
56  SelectCounter2,
57  ReadBackCommand
58  };
59 
60  enum ReadWriteVal {
65  };
66 
67  enum ModeVal {
74  };
75 
77  class Counter
78  {
80  class CounterEvent : public Event
81  {
82  private:
86 
87  public:
89 
91  void process();
92 
94  virtual const char *description() const;
95 
96  friend class Counter;
97 
98  void setTo(int clocks);
99 
100  int clocksLeft();
101 
102  Tick getInterval();
103  };
104 
105  private:
106  std::string _name;
107  const std::string &name() const { return _name; }
108 
109  unsigned int num;
110 
112 
114  bool running;
115 
117  uint16_t initial_count;
118 
120  uint16_t latched_count;
121 
123  uint16_t period;
124 
127 
129  uint8_t mode;
130 
133 
135  bool latch_on;
136 
138  enum {LSB, MSB};
139 
142 
145 
146  public:
147  Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
148 
150  void latchCount();
151 
153  int currentCount();
154 
156  void setRW(int rw_val);
157 
159  void setMode(int mode_val);
160 
162  void setBCD(int bcd_val);
163 
165  uint8_t read();
166 
168  void write(const uint8_t data);
169 
171  bool outputHigh();
172 
178  void serialize(const std::string &base, CheckpointOut &cp) const;
179 
186  void unserialize(const std::string &base, CheckpointIn &cp);
187 
189  void startup();
190  };
191 
192  protected:
193  std::string _name;
194  const std::string &name() const { return _name; }
195 
198 
199  virtual void
200  counterInterrupt(unsigned int num)
201  {
202  DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
203  }
204 
205  public:
206 
207  virtual
209  {}
210 
211  Intel8254Timer(EventManager *em, const std::string &name,
212  Counter *counter0, Counter *counter1, Counter *counter2);
213 
214  Intel8254Timer(EventManager *em, const std::string &name);
215 
217  void writeControl(const CtrlReg data);
218 
219  uint8_t
220  readCounter(unsigned int num)
221  {
222  assert(num < 3);
223  return counter[num]->read();
224  }
225 
226  void
227  writeCounter(unsigned int num, const uint8_t data)
228  {
229  assert(num < 3);
230  counter[num]->write(data);
231  }
232 
233  bool
234  outputHigh(unsigned int num)
235  {
236  assert(num < 3);
237  return counter[num]->outputHigh();
238  }
239 
245  void serialize(const std::string &base, CheckpointOut &cp) const;
246 
253  void unserialize(const std::string &base, CheckpointIn &cp);
254 
256  void startup();
257 };
258 
259 #endif // __DEV_8254_HH__
#define DPRINTF(x,...)
Definition: trace.hh:225
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: eventq.cc:237
void setBCD(int bcd_val)
Set count encoding.
EndBitUnion(CtrlReg) enum SelectVal
virtual ~Intel8254Timer()
void writeControl(const CtrlReg data)
Write control word.
uint16_t initial_count
Initial count value.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: eventq.cc:246
Programmable Interval Timer (Intel 8254)
Counter element for PIT.
Intel8254Timer * parent
Pointer to container.
BitUnion8(CtrlReg) Bitfield< 7
Bitfield< 2 > em
Definition: misc.hh:602
friend class Counter
All counters are of 64-bit values.
Intel8254Timer(EventManager *em, const std::string &name, Counter *counter0, Counter *counter1, Counter *counter2)
Counter * counter
Pointer back to Counter.
void latchCount()
Latch the current count (if one is not already latched)
Definition: cprintf.cc:40
uint8_t readCounter(unsigned int num)
void setRW(int rw_val)
Set the read/write mode.
void writeCounter(unsigned int num, const uint8_t data)
virtual const char * description() const
Event description.
void startup()
Start ticking.
Bitfield< 0 > bcd
bool outputHigh(unsigned int num)
Bitfield< 5, 4 > rw
bool running
True after startup is called.
virtual const std::string name() const
Definition: eventq.cc:82
virtual void counterInterrupt(unsigned int num)
uint8_t mode
Current mode of operation.
bool output_high
Output goes high when the counter reaches zero.
uint64_t Tick
Tick count type.
Definition: types.hh:61
const std::string & name() const
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
uint8_t read_byte
Determine which byte of a 16-bit count value to read/write.
Bitfield< 3, 1 > mode
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
void setMode(int mode_val)
Set operational mode.
bool latch_on
State of the count latch.
bool outputHigh()
Is the output high?
std::ostream CheckpointOut
Definition: serialize.hh:63
Definition: eventq.hh:245
int currentCount()
Get the current count for this counter.
const std::string & name() const
Event for counter interrupt.
uint16_t latched_count
Latched count.
Bitfield< 0 > p
const char data[]
uint8_t read()
Read a count byte.
void write(const uint8_t data)
Write a count byte.
uint16_t period
Interrupt period.
Tick offset
When to start ticking.

Generated on Thu May 28 2020 16:21:32 for gem5 by doxygen 1.8.13