36 #include "debug/Intel8254Timer.hh"
44 counter[0] = counter0;
45 counter[1] = counter1;
46 counter[2] = counter2;
52 counter[0] =
new Counter(
this, name +
".counter0", 0);
53 counter[1] =
new Counter(
this, name +
".counter1", 1);
54 counter[2] =
new Counter(
this, name +
".counter2", 2);
62 if (sel == ReadBackCommand)
63 panic(
"PITimer Read-Back Command is not implemented.\n");
101 const string &
name,
unsigned int _num)
102 : _name(name), num(_num),
event(this), running(false),
103 initial_count(0), latched_count(0), period(0),
mode(0),
104 output_high(false), latch_on(false), read_byte(LSB),
105 write_byte(LSB), parent(p)
117 latched_count = currentCount();
124 int clocks =
event.clocksLeft();
126 warn_once(
"Reading current count from inactive timer.\n");
142 return (uint8_t)latched_count;
147 return latched_count >> 8;
150 panic(
"Shouldn't be here");
153 uint16_t
count = currentCount();
157 return (uint8_t)
count;
164 panic(
"Shouldn't be here");
172 switch (write_byte) {
174 initial_count = (initial_count & 0xFF00) | data;
176 if (
event.scheduled())
177 parent->deschedule(
event);
183 initial_count = (initial_count & 0x00FF) | (data << 8);
187 period = initial_count - 1;
189 period = initial_count;
191 offset = period *
event.getInterval();
193 if (running && (period > 0))
205 panic(
"Only LSB/MSB read/write is implemented.\n");
213 panic(
"PIT mode %#x is not implemented: \n", mode_val);
222 panic(
"PITimer does not implement BCD counts.\n");
234 paramOut(cp, base +
".initial_count", initial_count);
235 paramOut(cp, base +
".latched_count", latched_count);
236 paramOut(cp, base +
".period", period);
238 paramOut(cp, base +
".output_high", output_high);
239 paramOut(cp, base +
".latch_on", latch_on);
240 paramOut(cp, base +
".read_byte", read_byte);
241 paramOut(cp, base +
".write_byte", write_byte);
243 Tick event_tick_offset = 0;
244 if (
event.scheduled())
246 paramOut(cp, base +
".event_tick_offset", event_tick_offset);
252 paramIn(cp, base +
".initial_count", initial_count);
253 paramIn(cp, base +
".latched_count", latched_count);
254 paramIn(cp, base +
".period", period);
256 paramIn(cp, base +
".output_high", output_high);
257 paramIn(cp, base +
".latch_on", latch_on);
258 paramIn(cp, base +
".read_byte", read_byte);
259 paramIn(cp, base +
".write_byte", write_byte);
261 Tick event_tick_offset = 0;
262 assert(!
event.scheduled());
263 paramIn(cp, base +
".event_tick_offset", event_tick_offset);
264 offset = event_tick_offset;
271 if ((period > 0) && (
offset > 0))
295 panic(
"Unimplemented PITimer mode.\n");
304 panic(
"Timer can't be set to go off instantly.\n");
315 return (when() -
curTick() + interval - 1) / interval;
321 return "Intel 8254 Interval timer";
void setBCD(int bcd_val)
Set count encoding.
void writeControl(const CtrlReg data)
Write control word.
const std::string & name()
Programmable Interval Timer (Intel 8254)
Intel8254Timer * parent
Pointer to container.
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.
double s
These variables equal the number of ticks in the unit of time they're named after in a double...
void latchCount()
Latch the current count (if one is not already latched)
void setRW(int rw_val)
Set the read/write mode.
void startup()
Start ticking.
void startup()
Start ticking.
Tick curTick()
The current simulated tick.
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.
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
virtual const char * description() const
Event description.
int64_t Counter
Statistics counter type.
void setMode(int mode_val)
Set operational mode.
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?
void process()
Event process.
std::ostream CheckpointOut
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Counter * counter[3]
PIT has three seperate counters.
int currentCount()
Get the current count for this counter.
void schedule(Event &event, Tick when)
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
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.