gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  * Authors: Ali G. Saidi
29  * Andrew L. Schultz
30  * Miguel J. Serrano
31  */
32 
33 #ifndef __DEV_8254_HH__
34 #define __DEV_8254_HH__
35 
36 #include <iostream>
37 #include <string>
38 
39 #include "base/bitunion.hh"
40 #include "base/types.hh"
41 #include "base/trace.hh"
42 #include "debug/Intel8254Timer.hh"
43 #include "sim/eventq_impl.hh"
44 #include "sim/serialize.hh"
45 
48 {
49  protected:
50  BitUnion8(CtrlReg)
51  Bitfield<7, 6> sel;
52  Bitfield<5, 4> rw;
53  Bitfield<3, 1> mode;
54  Bitfield<0> bcd;
55  EndBitUnion(CtrlReg)
56 
57  enum SelectVal {
58  SelectCounter0,
59  SelectCounter1,
60  SelectCounter2,
61  ReadBackCommand
62  };
63 
64  enum ReadWriteVal {
69  };
70 
71  enum ModeVal {
78  };
79 
81  class Counter
82  {
84  class CounterEvent : public Event
85  {
86  private:
90 
91  public:
93 
95  void process();
96 
98  virtual const char *description() const;
99 
100  friend class Counter;
101 
102  void setTo(int clocks);
103 
104  int clocksLeft();
105 
106  Tick getInterval();
107  };
108 
109  private:
110  std::string _name;
111  const std::string &name() const { return _name; }
112 
113  unsigned int num;
114 
116 
118  bool running;
119 
121  uint16_t initial_count;
122 
124  uint16_t latched_count;
125 
127  uint16_t period;
128 
131 
133  uint8_t mode;
134 
137 
139  bool latch_on;
140 
142  enum {LSB, MSB};
143 
146 
149 
150  public:
151  Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
152 
154  void latchCount();
155 
157  int currentCount();
158 
160  void setRW(int rw_val);
161 
163  void setMode(int mode_val);
164 
166  void setBCD(int bcd_val);
167 
169  uint8_t read();
170 
172  void write(const uint8_t data);
173 
175  bool outputHigh();
176 
182  void serialize(const std::string &base, CheckpointOut &cp) const;
183 
190  void unserialize(const std::string &base, CheckpointIn &cp);
191 
193  void startup();
194  };
195 
196  protected:
197  std::string _name;
198  const std::string &name() const { return _name; }
199 
202 
203  virtual void
204  counterInterrupt(unsigned int num)
205  {
206  DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
207  }
208 
209  public:
210 
211  virtual
213  {}
214 
215  Intel8254Timer(EventManager *em, const std::string &name,
216  Counter *counter0, Counter *counter1, Counter *counter2);
217 
218  Intel8254Timer(EventManager *em, const std::string &name);
219 
221  void writeControl(const CtrlReg data);
222 
223  uint8_t
224  readCounter(unsigned int num)
225  {
226  assert(num < 3);
227  return counter[num]->read();
228  }
229 
230  void
231  writeCounter(unsigned int num, const uint8_t data)
232  {
233  assert(num < 3);
234  counter[num]->write(data);
235  }
236 
237  bool
238  outputHigh(unsigned int num)
239  {
240  assert(num < 3);
241  return counter[num]->outputHigh();
242  }
243 
249  void serialize(const std::string &base, CheckpointOut &cp) const;
250 
257  void unserialize(const std::string &base, CheckpointIn &cp);
258 
260  void startup();
261 };
262 
263 #endif // __DEV_8254_HH__
#define DPRINTF(x,...)
Definition: trace.hh:212
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.
const std::string & name() const
Programmable Interval Timer (Intel 8254)
Counter element for PIT.
Intel8254Timer * parent
Pointer to container.
Bitfield< 2 > em
Definition: misc.hh:603
Intel8254Timer(EventManager *em, const std::string &name, Counter *counter0, Counter *counter1, Counter *counter2)
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Counter * counter
Pointer back to Counter.
void latchCount()
Latch the current count (if one is not already latched)
uint8_t readCounter(unsigned int num)
void setRW(int rw_val)
Set the read/write mode.
BitUnion8(CtrlReg) Bitfield<7
void writeCounter(unsigned int num, const uint8_t data)
void startup()
Start ticking.
const char data[]
Definition: circlebuf.cc:43
void startup()
Start ticking.
Bitfield< 0 > bcd
bool outputHigh(unsigned int num)
Bitfield< 5, 4 > rw
bool running
True after startup is called.
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:63
Bitfield< 51, 12 > base
Definition: pagetable.hh:85
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.
virtual const char * description() const
Event description.
int64_t Counter
Statistics counter type.
Definition: types.hh:58
void setMode(int mode_val)
Set operational mode.
bool latch_on
State of the count latch.
Counter(Intel8254Timer *p, const std::string &name, unsigned int num)
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
bool outputHigh()
Is the output high?
const std::string & name() const
std::ostream CheckpointOut
Definition: serialize.hh:67
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Definition: eventq.hh:185
Counter * counter[3]
PIT has three seperate counters.
int currentCount()
Get the current count for this counter.
Event for counter interrupt.
uint16_t latched_count
Latched count.
Bitfield< 0 > p
uint8_t read()
Read a count byte.
void write(const uint8_t data)
Write a count byte.
uint16_t period
Interrupt period.
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
Tick offset
When to start ticking.

Generated on Fri Jun 9 2017 13:03:46 for gem5 by doxygen 1.8.6