gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
29 #ifndef __DEV_MC146818_HH__
30 #define __DEV_MC146818_HH__
31 
32 #include "base/bitunion.hh"
33 #include "base/logging.hh"
34 #include "sim/core.hh"
35 #include "sim/eventq.hh"
36 
38 class MC146818 : public EventManager
39 {
40  protected:
41  virtual void handleEvent()
42  {
43  warn("No RTC event handler defined.\n");
44  }
45 
46  private:
48  struct RTCEvent : public Event
49  {
53 
54  RTCEvent(MC146818 * _parent, Tick i);
55 
57  void scheduleIntr();
58 
60  virtual void process();
61 
63  virtual const char *description() const;
64  };
65 
67  struct RTCTickEvent : public Event
68  {
71 
72  RTCTickEvent(MC146818 * _parent) :
73  parent(_parent), offset(SimClock::Int::s)
74  {}
75 
77  void process();
78 
80  const char *description() const;
81  };
82 
83  private:
84  std::string _name;
85  const std::string &name() const { return _name; }
86 
89 
92 
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  BitUnion8(RtcRegA)
116  Bitfield<7> uip;
117  Bitfield<6, 4> dv;
118 
127  Bitfield<3, 0> rs;
128  EndBitUnion(RtcRegA)
129 
130 
131  static inline bool rega_dv_disabled(const RtcRegA &reg);
132 
133  BitUnion8(RtcRegB)
134  Bitfield<7> set;
135  Bitfield<6> pie;
136  Bitfield<5> aie;
137  Bitfield<4> uie;
138  Bitfield<3> sqwe;
139  Bitfield<2> dm;
140  Bitfield<1> format24h;
141  Bitfield<0> dse;
142  EndBitUnion(RtcRegB)
143 
144 
145  RtcRegA stat_regA;
146 
148  RtcRegB stat_regB;
149 
150  public:
151  MC146818(EventManager *em, const std::string &name, const struct tm time,
152  bool bcd, Tick frequency);
153  virtual ~MC146818();
154 
156  virtual void startup();
157 
159  void writeData(const uint8_t addr, const uint8_t data);
160 
162  uint8_t readData(const uint8_t addr);
163 
164  void tickClock();
165 
171  void serialize(const std::string &base, CheckpointOut &cp) const;
172 
179  void unserialize(const std::string &base, CheckpointIn &cp);
180 };
181 
182 #endif // __DEV_MC146818_HH__
void tickClock()
Definition: mc146818.cc:253
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: eventq.cc:238
Bitfield< 5, 3 > reg
Definition: types.hh:87
uint8_t readData(const uint8_t addr)
RTC read data.
Definition: mc146818.cc:228
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: eventq.cc:247
Bitfield< 7 > i
Real-Time Clock (MC146818)
Definition: mc146818.hh:38
uint8_t mon
Definition: mc146818.hh:106
void writeData(const uint8_t addr, const uint8_t data)
RTC write data.
Definition: mc146818.cc:135
std::string _name
Definition: mc146818.hh:84
MC146818(EventManager *em, const std::string &name, const struct tm time, bool bcd, Tick frequency)
Definition: mc146818.cc:90
Bitfield< 4 > uie
1 = enable alarm interrupt
Definition: mc146818.hh:137
ip6_addr_t addr
Definition: inet.hh:330
Bitfield< 2 > em
Definition: misc.hh:602
MC146818 * parent
Definition: mc146818.hh:50
uint8_t sec
Definition: mc146818.hh:98
Definition: cprintf.cc:40
virtual const char * description() const
Event description.
Definition: mc146818.cc:329
BitUnion8(RtcRegA) Bitfield< 7 > uip
Bitfield< 2 > dm
1 = output sqare wave at SQW pin
Definition: mc146818.hh:139
Bitfield< 5 > aie
1 = enable periodic clock interrupt
Definition: mc146818.hh:136
Bitfield< 6 > pie
stop clock updates
Definition: mc146818.hh:135
RtcRegB stat_regB
RTC status register B.
Definition: mc146818.hh:148
These are variables that are set based on the simulator frequency.
Definition: core.cc:44
Bitfield< 0 > dse
0 = 12 hours, 1 = 24 hours
Definition: mc146818.hh:141
virtual const std::string name() const
Definition: eventq.cc:83
RTCEvent(MC146818 *_parent, Tick i)
Definition: mc146818.cc:308
RTCEvent event
RTC periodic interrupt event.
Definition: mc146818.hh:88
Bitfield< 4 > s
virtual void process()
Event process to occur at interrupt.
Definition: mc146818.cc:321
RTCTickEvent tickEvent
RTC tick event.
Definition: mc146818.hh:91
virtual ~MC146818()
Definition: mc146818.cc:109
uint64_t Tick
Tick count type.
Definition: types.hh:61
void scheduleIntr()
Schedule the RTC periodic interrupt.
Definition: mc146818.cc:315
uint8_t clock_data[10]
Definition: mc146818.hh:95
uint8_t mday
Definition: mc146818.hh:105
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Event for RTC periodic interrupt.
Definition: mc146818.hh:48
uint8_t wday
Definition: mc146818.hh:104
Bitfield< 3, 0 > rs
Divider configuration.
Definition: mc146818.hh:127
virtual void handleEvent()
Definition: mc146818.hh:41
void setTime(const struct tm time)
Definition: mc146818.cc:63
struct tm curTime
Definition: mc146818.hh:111
RTCTickEvent(MC146818 *_parent)
Definition: mc146818.hh:72
Event for RTC periodic interrupt.
Definition: mc146818.hh:67
std::ostream CheckpointOut
Definition: serialize.hh:63
uint8_t hour_alrm
Definition: mc146818.hh:103
virtual void startup()
Start ticking.
Definition: mc146818.cc:123
Definition: eventq.hh:246
uint8_t sec_alrm
Definition: mc146818.hh:99
uint8_t hour
Definition: mc146818.hh:102
Bitfield< 3 > sqwe
1 = enable update-ended interrupt
Definition: mc146818.hh:138
#define warn(...)
Definition: logging.hh:208
uint8_t min_alrm
Definition: mc146818.hh:101
Bitfield< 6, 4 > dv
1 = date and time update in progress
Definition: mc146818.hh:117
const std::string & name() const
Definition: mc146818.hh:85
const char data[]
Bitfield< 1 > format24h
0 = BCD, 1 = Binary coded time
Definition: mc146818.hh:140
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:100
uint8_t year
Definition: mc146818.hh:107

Generated on Mon Jun 8 2020 15:45:10 for gem5 by doxygen 1.8.13