gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_signal.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Authors: Gabe Black
28  */
29 
30 #include <sstream>
31 
36 
37 namespace sc_gem5
38 {
39 
41  sc_core::sc_prim_channel(name), _changeStamp(~0ULL),
42  _gem5WriterPort(nullptr)
43 {}
44 
46 
47 const sc_core::sc_event &
49 {
50  return valueChangedEvent();
51 }
52 
53 const sc_core::sc_event &
55 {
56  return _valueChangedEvent;
57 }
58 
59 bool
61 {
62  return _changeStamp == getChangeStamp();
63 }
64 
65 void
67 {
70 }
71 
72 void
74 {
75  _posStamp = getChangeStamp();
76  _posedgeEvent.notify(sc_core::SC_ZERO_TIME);
77 }
78 
79 void
81 {
82  _negStamp = getChangeStamp();
83  _negedgeEvent.notify(sc_core::SC_ZERO_TIME);
84 }
85 
86 namespace
87 {
88 
89 void
90 reportSignalError(ScSignalBase *sig, sc_core::sc_object *first,
91  sc_core::sc_object *second, bool delta_conflict=false)
92 {
93  std::ostringstream ss;
94  ss << "\n signal " << "`" << sig->name() << "' (" << sig->kind() << ")";
95  ss << "\n first driver `" << first->name() << "' (" <<
96  first->kind() << ")";
97  ss << "\n second driver `" << second->name() << "' (" <<
98  second->kind() << ")";
99  if (delta_conflict) {
100  ss << "\n conflicting write in delta cycle " <<
102  }
104  ss.str().c_str());
105 }
106 
107 } // anonymous namespace
108 
110  sig(_sig), firstPort(nullptr), proc(nullptr), writeStamp(~0ULL)
111 {}
112 
113 void
115  std::string iface_type_name, std::string out_name)
116 {
117  if (iface_type_name == out_name) {
118  if (firstPort)
119  reportSignalError(sig, firstPort, &port);
120  firstPort = &port;
121  }
122 }
123 
124 void
126 {
127  Process *p = scheduler.current();
128  if (!p)
129  return;
130  uint64_t stamp = getChangeStamp();
131  if (proc && proc != p)
132  reportSignalError(sig, proc, p);
133  proc = p;
134  writeStamp = stamp;
135 }
136 
138  sig(_sig), proc(nullptr), writeStamp(~0ULL)
139 {}
140 
141 void
143  std::string iface_type_name, std::string out_name)
144 {
145  return;
146 }
147 
148 void
150 {
151  Process *p = scheduler.current();
152  if (!p)
153  return;
154  uint64_t stamp = getChangeStamp();
155  if (writeStamp == stamp && proc && proc != p)
156  reportSignalError(sig, proc, p, writeStamp == stamp);
157  proc = p;
158  writeStamp = stamp;
159 }
160 
162  ScSignalBase(_name), _posStamp(~0ULL), _negStamp(~0ULL)
163 {}
164 
165 const sc_core::sc_event &
167 {
168  return _posedgeEvent;
169 }
170 
171 const sc_core::sc_event &
173 {
174  return _negedgeEvent;
175 }
176 
177 bool
179 {
180  return _posStamp == getChangeStamp();
181 }
182 
183 bool
185 {
186  return _negStamp == getChangeStamp();
187 }
188 
189 void
191 {
192  r->update();
193 }
194 
195 void
197 {
198  for (auto r: _resets)
199  _signalReset(r);
200 }
201 
202 } // namespace sc_gem5
const sc_core::sc_event & defaultEvent() const
Definition: sc_signal.cc:48
uint64_t getChangeStamp()
Definition: sc_prim.cc:39
const std::string & name()
Definition: trace.cc:54
const char * name() const
Definition: sc_object.cc:46
InternalScEvent _posedgeEvent
Definition: sc_signal.hh:94
const sc_core::sc_event & valueChangedEvent() const
Definition: sc_signal.cc:54
InternalScEvent _valueChangedEvent
Definition: sc_signal.hh:74
virtual const char * kind() const
Definition: sc_object.hh:58
virtual const char * kind() const
Definition: sc_signal.hh:59
Process * current()
Definition: scheduler.hh:172
bool event() const
Definition: sc_signal.cc:60
Bitfield< 21 > ss
Scheduler scheduler
Definition: scheduler.cc:491
void update()
Definition: process.hh:228
#define ULL(N)
uint64_t constant
Definition: types.hh:50
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:292
InternalScEvent _negedgeEvent
Definition: sc_signal.hh:95
std::vector< sc_gem5::Reset * > _resets
Definition: sc_signal.hh:84
#define SC_REPORT_ERROR(msg_type, msg)
ScSignalBaseBinary(const char *_name)
Definition: sc_signal.cc:161
const char SC_ID_MORE_THAN_ONE_SIGNAL_DRIVER_[]
Definition: messages.cc:54
ScSignalBase(const char *_name)
Definition: sc_signal.cc:40
sc_dt::uint64 sc_delta_count()
Definition: sc_main.cc:138
Bitfield< 0 > p
const sc_core::sc_event & negedgeEvent() const
Definition: sc_signal.cc:172
virtual ~ScSignalBase()
Definition: sc_signal.cc:45
const sc_core::sc_event & posedgeEvent() const
Definition: sc_signal.cc:166

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13