mc146818.hh (9235:5aa4896ed55a) mc146818.hh (9356:b279bad40aa3)
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ali Saidi
29 * Andrew Schultz
30 * Miguel Serrano
31 */
32
33#ifndef __DEV_MC146818_HH__
34#define __DEV_MC146818_HH__
35
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Ali Saidi
29 * Andrew Schultz
30 * Miguel Serrano
31 */
32
33#ifndef __DEV_MC146818_HH__
34#define __DEV_MC146818_HH__
35
36#include "sim/eventq.hh"
36#include "sim/eventq_impl.hh"
37
38/** Real-Time Clock (MC146818) */
39class MC146818 : public EventManager
40{
41 protected:
42 virtual void handleEvent()
43 {
44 warn("No RTC event handler defined.\n");
45 }
46
47 private:
48 /** Event for RTC periodic interrupt */
49 struct RTCEvent : public Event
50 {
51 MC146818 * parent;
52 Tick interval;
53
54 RTCEvent(MC146818 * _parent, Tick i);
55
56 /** Schedule the RTC periodic interrupt */
57 void scheduleIntr();
58
59 /** Event process to occur at interrupt*/
60 virtual void process();
61
62 /** Event description */
63 virtual const char *description() const;
64 };
65
66 /** Event for RTC periodic interrupt */
67 struct RTCTickEvent : public Event
68 {
69 MC146818 * parent;
70
71 RTCTickEvent(MC146818 * _parent) : parent(_parent)
72 {
73 parent->schedule(this, curTick() + SimClock::Int::s);
74 }
75
76 /** Event process to occur at interrupt*/
77 void process();
78
79 /** Event description */
80 const char *description() const;
81 };
82
83 private:
84 std::string _name;
85 const std::string &name() const { return _name; }
86
87 /** RTC periodic interrupt event */
88 RTCEvent event;
89
90 /** RTC tick event */
91 RTCTickEvent tickEvent;
92
93 /** Data for real-time clock function */
94 union {
95 uint8_t clock_data[10];
96
97 struct {
98 uint8_t sec;
99 uint8_t sec_alrm;
100 uint8_t min;
101 uint8_t min_alrm;
102 uint8_t hour;
103 uint8_t hour_alrm;
104 uint8_t wday;
105 uint8_t mday;
106 uint8_t mon;
107 uint8_t year;
108 };
109 };
110
111 struct tm curTime;
112
113 void setTime(const struct tm time);
114
115 /** RTC status register A */
116 uint8_t stat_regA;
117
118 /** RTC status register B */
119 uint8_t stat_regB;
120
121 public:
122 MC146818(EventManager *em, const std::string &name, const struct tm time,
123 bool bcd, Tick frequency);
124 virtual ~MC146818();
125
126 /** RTC write data */
127 void writeData(const uint8_t addr, const uint8_t data);
128
129 /** RTC read data */
130 uint8_t readData(const uint8_t addr);
131
132 void tickClock();
133
134 /**
135 * Serialize this object to the given output stream.
136 * @param base The base name of the counter object.
137 * @param os The stream to serialize to.
138 */
139 void serialize(const std::string &base, std::ostream &os);
140
141 /**
142 * Reconstruct the state of this object from a checkpoint.
143 * @param base The base name of the counter object.
144 * @param cp The checkpoint use.
145 * @param section The section name of this object
146 */
147 void unserialize(const std::string &base, Checkpoint *cp,
148 const std::string &section);
149};
150
151#endif // __DEV_MC146818_HH__
37
38/** Real-Time Clock (MC146818) */
39class MC146818 : public EventManager
40{
41 protected:
42 virtual void handleEvent()
43 {
44 warn("No RTC event handler defined.\n");
45 }
46
47 private:
48 /** Event for RTC periodic interrupt */
49 struct RTCEvent : public Event
50 {
51 MC146818 * parent;
52 Tick interval;
53
54 RTCEvent(MC146818 * _parent, Tick i);
55
56 /** Schedule the RTC periodic interrupt */
57 void scheduleIntr();
58
59 /** Event process to occur at interrupt*/
60 virtual void process();
61
62 /** Event description */
63 virtual const char *description() const;
64 };
65
66 /** Event for RTC periodic interrupt */
67 struct RTCTickEvent : public Event
68 {
69 MC146818 * parent;
70
71 RTCTickEvent(MC146818 * _parent) : parent(_parent)
72 {
73 parent->schedule(this, curTick() + SimClock::Int::s);
74 }
75
76 /** Event process to occur at interrupt*/
77 void process();
78
79 /** Event description */
80 const char *description() const;
81 };
82
83 private:
84 std::string _name;
85 const std::string &name() const { return _name; }
86
87 /** RTC periodic interrupt event */
88 RTCEvent event;
89
90 /** RTC tick event */
91 RTCTickEvent tickEvent;
92
93 /** Data for real-time clock function */
94 union {
95 uint8_t clock_data[10];
96
97 struct {
98 uint8_t sec;
99 uint8_t sec_alrm;
100 uint8_t min;
101 uint8_t min_alrm;
102 uint8_t hour;
103 uint8_t hour_alrm;
104 uint8_t wday;
105 uint8_t mday;
106 uint8_t mon;
107 uint8_t year;
108 };
109 };
110
111 struct tm curTime;
112
113 void setTime(const struct tm time);
114
115 /** RTC status register A */
116 uint8_t stat_regA;
117
118 /** RTC status register B */
119 uint8_t stat_regB;
120
121 public:
122 MC146818(EventManager *em, const std::string &name, const struct tm time,
123 bool bcd, Tick frequency);
124 virtual ~MC146818();
125
126 /** RTC write data */
127 void writeData(const uint8_t addr, const uint8_t data);
128
129 /** RTC read data */
130 uint8_t readData(const uint8_t addr);
131
132 void tickClock();
133
134 /**
135 * Serialize this object to the given output stream.
136 * @param base The base name of the counter object.
137 * @param os The stream to serialize to.
138 */
139 void serialize(const std::string &base, std::ostream &os);
140
141 /**
142 * Reconstruct the state of this object from a checkpoint.
143 * @param base The base name of the counter object.
144 * @param cp The checkpoint use.
145 * @param section The section name of this object
146 */
147 void unserialize(const std::string &base, Checkpoint *cp,
148 const std::string &section);
149};
150
151#endif // __DEV_MC146818_HH__