2 * Copyright (c) 2004, 2005
3 * The Regents of The University of Michigan
6 * This code is part of the M5 simulator.
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.
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
28 * Authors: Ali G. Saidi
33 #ifndef __DEV_8254_HH__
34 #define __DEV_8254_HH__
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"
46 /** Programmable Interval Timer (Intel 8254) */
47 class Intel8254Timer : public EventManager
80 /** Counter element for PIT */
83 /** Event for counter interrupt */
84 class CounterEvent : public Event
87 /** Pointer back to Counter */
92 CounterEvent(Counter*);
97 /** Event description */
98 virtual const char *description() const;
100 friend class Counter;
102 void setTo(int clocks);
111 const std::string &name() const { return _name; }
117 /** True after startup is called. */
120 /** Initial count value */
121 uint16_t initial_count;
124 uint16_t latched_count;
126 /** Interrupt period */
129 /** When to start ticking */
132 /** Current mode of operation */
135 /** Output goes high when the counter reaches zero */
138 /** State of the count latch */
141 /** Set of values for read_byte and write_byte */
144 /** Determine which byte of a 16-bit count value to read/write */
145 uint8_t read_byte, write_byte;
147 /** Pointer to container */
148 Intel8254Timer *parent;
151 Counter(Intel8254Timer *p, const std::string &name, unsigned int num);
153 /** Latch the current count (if one is not already latched) */
156 /** Get the current count for this counter */
159 /** Set the read/write mode */
160 void setRW(int rw_val);
162 /** Set operational mode */
163 void setMode(int mode_val);
165 /** Set count encoding */
166 void setBCD(int bcd_val);
168 /** Read a count byte */
171 /** Write a count byte */
172 void write(const uint8_t data);
174 /** Is the output high? */
178 * Serialize this object to the given output stream.
179 * @param base The base name of the counter object.
180 * @param os The stream to serialize to.
182 void serialize(const std::string &base, std::ostream &os);
185 * Reconstruct the state of this object from a checkpoint.
186 * @param base The base name of the counter object.
187 * @param cp The checkpoint use.
188 * @param section The section name of this object
190 void unserialize(const std::string &base, Checkpoint *cp,
191 const std::string §ion);
199 const std::string &name() const { return _name; }
201 /** PIT has three seperate counters */
205 counterInterrupt(unsigned int num)
207 DPRINTF(Intel8254Timer, "Timer interrupt from counter %d.\n", num);
216 Intel8254Timer(EventManager *em, const std::string &name,
217 Counter *counter0, Counter *counter1, Counter *counter2);
219 Intel8254Timer(EventManager *em, const std::string &name);
221 /** Write control word */
222 void writeControl(const CtrlReg data);
225 readCounter(unsigned int num)
228 return counter[num]->read();
232 writeCounter(unsigned int num, const uint8_t data)
235 counter[num]->write(data);
239 outputHigh(unsigned int num)
242 return counter[num]->outputHigh();
246 * Serialize this object to the given output stream.
247 * @param base The base name of the counter object.
248 * @param os The stream to serialize to.
250 void serialize(const std::string &base, std::ostream &os);
253 * Reconstruct the state of this object from a checkpoint.
254 * @param base The base name of the counter object.
255 * @param cp The checkpoint use.
256 * @param section The section name of this object
258 void unserialize(const std::string &base, Checkpoint *cp,
259 const std::string §ion);
265 #endif // __DEV_8254_HH__