39#include "debug/MC146818.hh"
50 result += (
val / 10) << 4;
59 result += (
val >> 4) * 10;
69 mon = time.tm_mon + 1;
76 wday = time.tm_wday + 1;
92 const struct tm time,
bool bcd,
Tick frequency)
107 DPRINTFN(
"Real-time clock set to %s", asctime(&time));
117MC146818::rega_dv_disabled(
const RtcRegA &
reg)
131 if (!rega_dv_disabled(stat_regA))
138 bool panic_unsupported(
false);
152 RtcRegA old_rega(stat_regA);
155 stat_regA.uip = old_rega;
157 if (!rega_dv_disabled(stat_regA) &&
159 inform(
"RTC: Unimplemented divider configuration: %i\n",
161 panic_unsupported =
true;
165 inform(
"RTC: Unimplemented interrupt rate: %i\n",
167 panic_unsupported =
true;
170 if (rega_dv_disabled(stat_regA)) {
175 }
else if (rega_dv_disabled(old_rega)) {
187 inform(
"RTC: Unimplemented interrupt configuration: %s %s\n",
190 panic_unsupported =
true;
194 inform(
"RTC: The binary interface is not fully implemented.\n");
195 panic_unsupported =
true;
199 inform(
"RTC: The 12h time format not supported.\n");
200 panic_unsupported =
true;
204 inform(
"RTC: Automatic daylight saving time not supported.\n");
205 panic_unsupported =
true;
210 event.scheduleIntr();
218 panic(
"RTC status registers C and D are not implemented.\n");
223 if (panic_unsupported)
224 panic(
"Unimplemented RTC configuration!\n");
249 panic(
"Shouldn't be here");
257 assert(!rega_dv_disabled(stat_regA));
269 uint8_t regA_serial(stat_regA);
273 paramOut(cp,
base +
".stat_regA", (uint8_t)regA_serial);
274 paramOut(cp,
base +
".stat_regB", (uint8_t)regB_serial);
280 Tick rtcTimerInterruptTickOffset =
event.when() -
curTick();
302 Tick rtcTimerInterruptTickOffset;
304 event.offset = rtcTimerInterruptTickOffset;
305 Tick rtcClockTickOffset;
311 : parent(_parent), interval(
i),
offset(
i)
319 parent->schedule(
this,
curTick() + interval);
326 parent->schedule(
this,
curTick() + interval);
327 parent->handleEvent();
333 return "RTC interrupt";
347 return "RTC clock tick";
Real-Time Clock (MC146818)
void setTime(const struct tm time)
MC146818(EventManager *em, const std::string &name, const struct tm time, bool bcd, Tick frequency)
RTCTickEvent tickEvent
RTC tick event.
virtual void startup()
Start ticking.
RtcRegB stat_regB
RTC status register B.
void serialize(const std::string &base, CheckpointOut &cp) const
Serialize this object to the given output stream.
void unserialize(const std::string &base, CheckpointIn &cp)
Reconstruct the state of this object from a checkpoint.
RTCEvent event
RTC periodic interrupt event.
uint8_t readData(const uint8_t addr)
RTC read data.
void writeData(const uint8_t addr, const uint8_t data)
RTC write data.
void deschedule(Event &event)
bool scheduled() const
Determine if the current event is scheduled.
void schedule(Event &event, Tick when)
Tick when() const
Get the time that the event is scheduled.
#define panic(...)
This implements a cprintf based panic() function.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Tick curTick()
The universal simulation clock.
std::ostream CheckpointOut
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
time_t mkutctime(struct tm *time)
static uint8_t unbcdize(uint8_t val)
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
void arrayParamOut(CheckpointOut &cp, const std::string &name, const CircleBuf< T > ¶m)
uint64_t Tick
Tick count type.
static uint8_t bcdize(uint8_t val)
void arrayParamIn(CheckpointIn &cp, const std::string &name, CircleBuf< T > ¶m)
static const int RTCA_RS_1024HZ
static const int RTCA_DV_DISABLED0
static const int RTC_STAT_REGA
static const int RTC_STAT_REGB
static const int RTC_STAT_REGD
static const int RTC_STAT_REGC
static const int RTCA_DV_DISABLED1
static const int RTCA_DV_32768HZ
#define UNSERIALIZE_SCALAR(scalar)
#define SERIALIZE_SCALAR(scalar)
virtual const char * description() const
Event description.
RTCEvent(MC146818 *_parent, Tick i)
virtual void process()
Event process to occur at interrupt.
void scheduleIntr()
Schedule the RTC periodic interrupt.
const char * description() const
Event description.
void process()
Event process to occur at interrupt.