gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mc146818.hh
Go to the documentation of this file.
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 "base/bitunion.hh"
37 #include "base/misc.hh"
38 #include "sim/eventq_impl.hh"
39 
41 class MC146818 : public EventManager
42 {
43  protected:
44  virtual void handleEvent()
45  {
46  warn("No RTC event handler defined.\n");
47  }
48 
49  private:
51  struct RTCEvent : public Event
52  {
56 
57  RTCEvent(MC146818 * _parent, Tick i);
58 
60  void scheduleIntr();
61 
63  virtual void process();
64 
66  virtual const char *description() const;
67  };
68 
70  struct RTCTickEvent : public Event
71  {
74 
75  RTCTickEvent(MC146818 * _parent) :
76  parent(_parent), offset(SimClock::Int::s)
77  {}
78 
80  void process();
81 
83  const char *description() const;
84  };
85 
86  private:
87  std::string _name;
88  const std::string &name() const { return _name; }
89 
92 
95 
97  union {
98  uint8_t clock_data[10];
99 
100  struct {
101  uint8_t sec;
102  uint8_t sec_alrm;
103  uint8_t min;
104  uint8_t min_alrm;
105  uint8_t hour;
106  uint8_t hour_alrm;
107  uint8_t wday;
108  uint8_t mday;
109  uint8_t mon;
110  uint8_t year;
111  };
112  };
113 
114  struct tm curTime;
115 
116  void setTime(const struct tm time);
117 
118  BitUnion8(RtcRegA)
119  Bitfield<7> uip;
120  Bitfield<6, 4> dv;
121 
130  Bitfield<3, 0> rs;
131  EndBitUnion(RtcRegA)
132 
134  static inline bool rega_dv_disabled(const RtcRegA &reg);
135 
136  BitUnion8(RtcRegB)
137  Bitfield<7> set;
138  Bitfield<6> pie;
139  Bitfield<5> aie;
140  Bitfield<4> uie;
141  Bitfield<3> sqwe;
142  Bitfield<2> dm;
143  Bitfield<1> format24h;
144  Bitfield<0> dse;
145  EndBitUnion(RtcRegB)
146 
148  RtcRegA stat_regA;
149 
151  RtcRegB stat_regB;
152 
153  public:
154  MC146818(EventManager *em, const std::string &name, const struct tm time,
155  bool bcd, Tick frequency);
156  virtual ~MC146818();
157 
159  virtual void startup();
160 
162  void writeData(const uint8_t addr, const uint8_t data);
163 
165  uint8_t readData(const uint8_t addr);
166 
167  void tickClock();
168 
174  void serialize(const std::string &base, CheckpointOut &cp) const;
175 
182  void unserialize(const std::string &base, CheckpointIn &cp);
183 };
184 
185 #endif // __DEV_MC146818_HH__
void tickClock()
Definition: mc146818.cc:257
Bitfield< 5, 3 > reg
Definition: types.hh:89
uint8_t readData(const uint8_t addr)
RTC read data.
Definition: mc146818.cc:232
Bitfield< 7 > i
Definition: miscregs.hh:1378
Real-Time Clock (MC146818)
Definition: mc146818.hh:41
uint8_t mon
Definition: mc146818.hh:109
void writeData(const uint8_t addr, const uint8_t data)
RTC write data.
Definition: mc146818.cc:139
std::string _name
Definition: mc146818.hh:87
Bitfield< 4 > uie
1 = enable alarm interrupt
Definition: mc146818.hh:140
ip6_addr_t addr
Definition: inet.hh:335
Bitfield< 2 > em
Definition: misc.hh:603
MC146818 * parent
Definition: mc146818.hh:53
uint8_t sec
Definition: mc146818.hh:101
const char * description() const
Event description.
Definition: mc146818.cc:347
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
Definition: mc146818.cc:269
BitUnion8(RtcRegA) Bitfield< 7 > uip
Bitfield< 2 > dm
1 = output sqare wave at SQW pin
Definition: mc146818.hh:142
const char data[]
Definition: circlebuf.cc:43
#define warn(...)
Definition: misc.hh:219
Bitfield< 5 > aie
1 = enable periodic clock interrupt
Definition: mc146818.hh:139
Bitfield< 6 > pie
stop clock updates
Definition: mc146818.hh:138
RtcRegB stat_regB
RTC status register B.
Definition: mc146818.hh:151
Bitfield< 0 > dse
0 = 12 hours, 1 = 24 hours
Definition: mc146818.hh:144
RTCEvent(MC146818 *_parent, Tick i)
Definition: mc146818.cc:312
RTCEvent event
RTC periodic interrupt event.
Definition: mc146818.hh:91
Bitfield< 4 > s
Definition: miscregs.hh:1738
virtual void process()
Event process to occur at interrupt.
Definition: mc146818.cc:325
const std::string & name() const
Definition: mc146818.hh:88
RTCTickEvent tickEvent
RTC tick event.
Definition: mc146818.hh:94
uint64_t Tick
Tick count type.
Definition: types.hh:63
void scheduleIntr()
Schedule the RTC periodic interrupt.
Definition: mc146818.cc:319
uint8_t clock_data[10]
Definition: mc146818.hh:98
uint8_t mday
Definition: mc146818.hh:108
Bitfield< 51, 12 > base
Definition: pagetable.hh:85
Event for RTC periodic interrupt.
Definition: mc146818.hh:51
uint8_t wday
Definition: mc146818.hh:107
Bitfield< 3, 0 > rs
Divider configuration.
Definition: mc146818.hh:130
virtual void handleEvent()
Definition: mc146818.hh:44
void setTime(const struct tm time)
Definition: mc146818.cc:67
virtual const char * description() const
Event description.
Definition: mc146818.cc:333
struct tm curTime
Definition: mc146818.hh:114
RTCTickEvent(MC146818 *_parent)
Definition: mc146818.hh:75
Event for RTC periodic interrupt.
Definition: mc146818.hh:70
std::ostream CheckpointOut
Definition: serialize.hh:67
uint8_t hour_alrm
Definition: mc146818.hh:106
virtual void startup()
Start ticking.
Definition: mc146818.cc:127
Definition: eventq.hh:185
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
Definition: mc146818.cc:289
uint8_t sec_alrm
Definition: mc146818.hh:102
uint8_t hour
Definition: mc146818.hh:105
Bitfield< 3 > sqwe
1 = enable update-ended interrupt
Definition: mc146818.hh:141
uint8_t min_alrm
Definition: mc146818.hh:104
Bitfield< 6, 4 > dv
1 = date and time update in progress
Definition: mc146818.hh:120
void process()
Event process to occur at interrupt.
Definition: mc146818.cc:339
Bitfield< 1 > format24h
0 = BCD, 1 = Binary coded time
Definition: mc146818.hh:143
EndBitUnion(RtcRegA) static inline bool rega_dv_disabled(const RtcRegA &reg)
Is the DV field in regA set to disabled?
uint8_t min
Definition: mc146818.hh:103
uint8_t year
Definition: mc146818.hh:110

Generated on Fri Jun 9 2017 13:03:46 for gem5 by doxygen 1.8.6