Intel8254Timer::Counter::Counter(Intel8254Timer *p,
const string &name, unsigned int _num)
- : _name(name), num(_num), event(this), count(0),
+ : _name(name), num(_num), event(this), initial_count(0),
latched_count(0), period(0), mode(0), output_high(false),
latch_on(false), read_byte(LSB), write_byte(LSB), parent(p)
{
if(!latch_on) {
latch_on = true;
read_byte = LSB;
- latched_count = count;
+ latched_count = currentCount();
}
}
+int
+Intel8254Timer::Counter::currentCount()
+{
+ int clocks = event.clocksLeft();
+ if (clocks == -1) {
+ warn_once("Reading current count from inactive timer.\n");
+ return 0;
+ }
+ if (mode == RateGen || mode == SquareWave)
+ return clocks + 1;
+ else
+ return clocks;
+}
+
uint8_t
Intel8254Timer::Counter::read()
{
panic("Shouldn't be here");
}
} else {
+ uint16_t count = currentCount();
switch (read_byte) {
case LSB:
read_byte = MSB;
{
switch (write_byte) {
case LSB:
- count = (count & 0xFF00) | data;
+ initial_count = (initial_count & 0xFF00) | data;
if (event.scheduled())
parent->deschedule(event);
break;
case MSB:
- count = (count & 0x00FF) | (data << 8);
+ initial_count = (initial_count & 0x00FF) | (data << 8);
// In the RateGen or SquareWave modes, the timer wraps around and
// triggers on a value of 1, not 0.
if (mode == RateGen || mode == SquareWave)
- period = count - 1;
+ period = initial_count - 1;
else
- period = count;
+ period = initial_count;
if (period > 0)
event.setTo(period);
void
Intel8254Timer::Counter::serialize(const string &base, ostream &os)
{
- paramOut(os, base + ".count", count);
+ paramOut(os, base + ".initial_count", initial_count);
paramOut(os, base + ".latched_count", latched_count);
paramOut(os, base + ".period", period);
paramOut(os, base + ".mode", mode);
Intel8254Timer::Counter::unserialize(const string &base, Checkpoint *cp,
const string §ion)
{
- paramIn(cp, section, base + ".count", count);
+ paramIn(cp, section, base + ".initial_count", initial_count);
paramIn(cp, section, base + ".latched_count", latched_count);
paramIn(cp, section, base + ".period", period);
paramIn(cp, section, base + ".mode", mode);
counter->parent->schedule(this, curTick + clocks * interval);
}
+int
+Intel8254Timer::Counter::CounterEvent::clocksLeft()
+{
+ if (!scheduled())
+ return -1;
+ return (when() - curTick + interval - 1) / interval;
+}
+
const char *
Intel8254Timer::Counter::CounterEvent::description() const
{