gem5 v24.0.0.0
Loading...
Searching...
No Matches
lupio_rtc.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 The Regents of the University of California
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
30
31#include "base/time.hh"
32#include "debug/LupioRTC.hh"
33#include "mem/packet_access.hh"
34#include "params/LupioRTC.hh"
35
36namespace gem5
37{
38
39LupioRTC::LupioRTC(const Params &params) :
40 BasicPioDevice(params, params.pio_size),
41 time(params.time)
42{
43 start = mktime(&time);
44}
45
46uint8_t
48{
49 uint8_t r = 0;
50 uint32_t time_sec;
51 time_t total_time;
52
56 time_sec = (curTick() / sim_clock::as_int::s);
57 total_time = (time_t) time_sec + start;
58
62 gmtime_r(&total_time, &time);
63
64 switch (addr) {
65 case LUPIO_RTC_SECD:
66 r = time.tm_sec; /* 0-60 (for leap seconds) */
67 break;
68 case LUPIO_RTC_MINT:
69 r = time.tm_min; /* 0-59 */
70 break;
71 case LUPIO_RTC_HOUR:
72 r = time.tm_hour; /* 0-23 */
73 break;
74 case LUPIO_RTC_DYMO:
75 r = time.tm_mday; /* 1-31 */
76 break;
77 case LUPIO_RTC_MNTH:
78 r = time.tm_mon + 1; /* 1-12 */
79 break;
80 case LUPIO_RTC_YEAR:
81 r = (time.tm_year + 1900) % 100; /* 0-99 */
82 break;
83 case LUPIO_RTC_CENT:
84 r = (time.tm_year + 1900) / 100; /* 0-99 */
85 break;
86 case LUPIO_RTC_DYWK:
87 r = 1 + (time.tm_wday + 6) % 7; /* 1-7 (Monday is 1) */
88 break;
89 case LUPIO_RTC_DYYR:
90 r = time.tm_yday + 1; /* 1-366 (for leap years) */
91 break;
92 }
93 return r;
94}
95
96Tick
98{
99 bool is_atomic = pkt->isAtomicOp() && pkt->cmd == MemCmd::SwapReq;
101 "Read request - addr: %#x, size: %#x, atomic:%d\n",
102 pkt->getAddr(), pkt->getSize(), is_atomic);
103
104 Addr rtc_addr = pkt->getAddr() - pioAddr;
105 uint8_t time_val = lupioRTCRead(rtc_addr);
106 DPRINTF(LupioRTC, "time value: %d\n", time_val);
107
108 pkt->setData(&time_val);
109
110 if (is_atomic) {
111 pkt->makeAtomicResponse();
112 } else {
113 pkt->makeResponse();
114 }
115
116 return pioDelay;
117}
118
119Tick
121{
122 panic("Unexpected write to the LupioRTC device!");
123 return pioDelay;
124}
125
126} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Addr pioAddr
Address that the device listens to.
Definition io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition io_device.hh:157
LupioRTC: A Real-Time Clock Virtual Device that returns the current date and time in ISO 8601 format.
Definition lupio_rtc.hh:46
struct tm time
Definition lupio_rtc.hh:49
LupioRTC(const Params &params)
Definition lupio_rtc.cc:39
Tick read(PacketPtr pkt) override
Implement BasicPioDevice virtual functions.
Definition lupio_rtc.cc:97
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition lupio_rtc.cc:120
uint8_t lupioRTCRead(const uint8_t addr)
Function to return current time and date using system's wall-clock time.
Definition lupio_rtc.cc:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
bool isAtomicOp() const
Definition packet.hh:846
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition packet.hh:1062
void setData(const uint8_t *p)
Copy data into the packet from the provided pointer.
Definition packet.hh:1293
unsigned getSize() const
Definition packet.hh:817
void makeAtomicResponse()
Definition packet.hh:1074
MemCmd cmd
The command field of the packet.
Definition packet.hh:372
PioDeviceParams Params
Definition io_device.hh:134
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0