2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef __DEV_MC146818_HH__
34 #define __DEV_MC146818_HH__
36 #include "base/range.hh"
37 #include "sim/eventq.hh"
39 /** Real-Time Clock (MC146818) */
40 class MC146818 : public EventManager
43 virtual void handleEvent()
45 warn("No RTC event handler defined.\n");
49 /** Event for RTC periodic interrupt */
50 struct RTCEvent : public Event
55 RTCEvent(MC146818 * _parent, Tick i);
57 /** Schedule the RTC periodic interrupt */
60 /** Event process to occur at interrupt*/
61 virtual void process();
63 /** Event description */
64 virtual const char *description() const;
67 /** Event for RTC periodic interrupt */
68 struct RTCTickEvent : public Event
72 RTCTickEvent(MC146818 * _parent) : parent(_parent)
74 parent->schedule(this, curTick() + SimClock::Int::s);
77 /** Event process to occur at interrupt*/
80 /** Event description */
81 const char *description() const;
86 const std::string &name() const { return _name; }
88 /** RTC periodic interrupt event */
92 RTCTickEvent tickEvent;
94 /** Data for real-time clock function */
96 uint8_t clock_data[10];
114 void setTime(const struct tm time);
116 /** RTC status register A */
119 /** RTC status register B */
123 MC146818(EventManager *em, const std::string &name, const struct tm time,
124 bool bcd, Tick frequency);
127 /** RTC write data */
128 void writeData(const uint8_t addr, const uint8_t data);
131 uint8_t readData(const uint8_t addr);
136 * Serialize this object to the given output stream.
137 * @param base The base name of the counter object.
138 * @param os The stream to serialize to.
140 void serialize(const std::string &base, std::ostream &os);
143 * Reconstruct the state of this object from a checkpoint.
144 * @param base The base name of the counter object.
145 * @param cp The checkpoint use.
146 * @param section The section name of this object
148 void unserialize(const std::string &base, Checkpoint *cp,
149 const std::string §ion);
152 #endif // __DEV_MC146818_HH__