Deleted Added
sdiff udiff text old ( 13260:4d18f1d20093 ) new ( 13262:ef4b783f84f7 )
full compact
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 "systemc/core/sensitivity.hh"
31
32#include "systemc/core/event.hh"
33#include "systemc/core/port.hh"
34#include "systemc/core/process.hh"
35#include "systemc/core/scheduler.hh"
36#include "systemc/ext/channel/sc_in.hh"
37#include "systemc/ext/channel/sc_inout.hh"
38#include "systemc/ext/channel/sc_out.hh"
39#include "systemc/ext/core/sc_export.hh"
40#include "systemc/ext/core/sc_interface.hh"
41#include "systemc/ext/core/sc_port.hh"
42
43namespace sc_gem5
44{
45
46/*
47 * Common sensitivity interface.
48 */
49
50void
51Sensitivity::satisfy()
52{
53 process->satisfySensitivity(this);
54}
55
56bool
57Sensitivity::notify(Event *e)
58{
59 if (process->disabled())
60 return false;
61 satisfy();
62 return true;
63}
64
65bool
66Sensitivity::ofMethod()
67{
68 return process->procKind() == sc_core::SC_METHOD_PROC_;
69}
70
71
72/*
73 * Dynamic vs. static sensitivity.
74 */
75
76void
77DynamicSensitivity::addToEvent(const ::sc_core::sc_event *e)
78{
79 Event::getFromScEvent(e)->addSensitivity(this);
80}
81
82void
83DynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e)
84{
85 Event::getFromScEvent(e)->delSensitivity(this);
86}
87
88void
89StaticSensitivity::addToEvent(const ::sc_core::sc_event *e)
90{
91 Event::getFromScEvent(e)->addSensitivity(this);
92}
93
94void
95StaticSensitivity::delFromEvent(const ::sc_core::sc_event *e)
96{
97 Event::getFromScEvent(e)->delSensitivity(this);
98}
99
100void
101ResetSensitivity::addToEvent(const ::sc_core::sc_event *e)
102{
103 Event::getFromScEvent(e)->addSensitivity(this);
104}
105
106void
107ResetSensitivity::delFromEvent(const ::sc_core::sc_event *e)
108{
109 Event::getFromScEvent(e)->delSensitivity(this);
110}
111
112
113/*
114 * Static sensitivities.
115 */
116
117void
118newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
119{
120 auto s = new StaticSensitivityEvent(p, e);
121 s->addToEvent(s->event);
122 p->addStatic(s);
123}
124
125void
126newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
127{
128 auto s = new StaticSensitivityInterface(p, i);
129 s->addToEvent(s->event);
130 p->addStatic(s);
131}
132
133void
134newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
135{
136 auto s = new StaticSensitivityPort(p);
137 Port *port = Port::fromPort(pb);
138 port->sensitive(s);
139 p->addStatic(s);
140}
141
142void
143newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
144{
145 auto s = new StaticSensitivityExport(p, exp);
146 s->addToEvent(s->event);
147 p->addStatic(s);
148}
149
150void
151newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
152{
153 auto s = new StaticSensitivityFinder(p, f);
154 Port *port = Port::fromPort(f->port());
155 port->sensitive(s);
156 p->addStatic(s);
157}
158
159
160StaticSensitivityInterface::StaticSensitivityInterface(
161 Process *p, const sc_core::sc_interface *i) :
162 Sensitivity(p), StaticSensitivity(p),
163 SensitivityEvent(p, &i->default_event())
164{}
165
166StaticSensitivityExport::StaticSensitivityExport(
167 Process *p, const sc_core::sc_export_base *exp) :
168 Sensitivity(p), StaticSensitivity(p),
169 SensitivityEvent(p, &exp->get_interface()->default_event())
170{}
171
172const ::sc_core::sc_event &
173StaticSensitivityFinder::find(::sc_core::sc_interface *i)
174{
175 return finder->find_event(i);
176}
177
178
179/*
180 * Dynamic sensitivities.
181 */
182
183void
184newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
185{
186 auto s = new DynamicSensitivityEvent(p, e);
187 s->addToEvent(s->event);
188 p->setDynamic(s);
189}
190
191void
192newDynamicSensitivityEventOrList(
193 Process *p, const sc_core::sc_event_or_list *eol)
194{
195 auto s = new DynamicSensitivityEventOrList(p, eol);
196 for (auto event: s->events)
197 s->addToEvent(event);
198 p->setDynamic(s);
199}
200
201void newDynamicSensitivityEventAndList(
202 Process *p, const sc_core::sc_event_and_list *eal)
203{
204 auto s = new DynamicSensitivityEventAndList(p, eal);
205 for (auto event: s->events)
206 s->addToEvent(event);
207 p->setDynamic(s);
208}
209
210
211DynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
212 Process *p, const sc_core::sc_event_or_list *eol) :
213 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events)
214{}
215
216bool
217DynamicSensitivityEventOrList::notify(Event *e)
218{
219 if (process->disabled())
220 return false;
221
222 events.erase(e->sc_event());
223
224 // All the other events need this deleted from their lists since this
225 // sensitivity has been satisfied without them triggering.
226 for (auto le: events)
227 delFromEvent(le);
228
229 satisfy();
230 return true;
231}
232
233DynamicSensitivityEventAndList::DynamicSensitivityEventAndList(
234 Process *p, const sc_core::sc_event_and_list *eal) :
235 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events)
236{}
237
238bool
239DynamicSensitivityEventAndList::notify(Event *e)
240{
241 if (process->disabled())
242 return false;
243
244 events.erase(e->sc_event());
245
246 // This sensitivity is satisfied if all events have triggered.
247 if (events.empty())
248 satisfy();
249
250 return true;
251}
252
253/*
254 * Reset sensitivities.
255 */
256
257void
258newResetSensitivitySignal(
259 Process *p, const sc_core::sc_signal_in_if<bool> *signal,
260 bool val, bool sync)
261{
262 auto s = new ResetSensitivitySignal(p, signal, val, sync);
263 s->addToEvent(s->event);
264 p->addReset(s);
265}
266
267void
268newResetSensitivityPort(Process *p, const sc_core::sc_in<bool> *port,
269 bool val, bool sync)
270{
271 auto s = new ResetSensitivityPort(p, port, val, sync);
272 Port::fromPort(port)->sensitive(s);
273 p->addReset(s);
274}
275void
276newResetSensitivityPort(Process *p, const sc_core::sc_inout<bool> *port,
277 bool val, bool sync)
278{
279 auto s = new ResetSensitivityPort(p, port, val, sync);
280 Port::fromPort(port)->sensitive(s);
281 p->addReset(s);
282}
283void
284newResetSensitivityPort(Process *p, const sc_core::sc_out<bool> *port,
285 bool val, bool sync)
286{
287 auto s = new ResetSensitivityPort(p, port, val, sync);
288 Port::fromPort(port)->sensitive(s);
289 p->addReset(s);
290}
291
292ResetSensitivitySignal::ResetSensitivitySignal(
293 Process *p, const sc_core::sc_signal_in_if<bool> *signal,
294 bool _val, bool _sync) :
295 Sensitivity(p), ResetSensitivity(p, _val, _sync),
296 SensitivityEvent(p, signal ? &signal->value_changed_event() : nullptr),
297 _signal(signal)
298{
299 if (signal && signal->read() == val())
300 process->signalReset(true, sync());
301}
302
303bool
304ResetSensitivitySignal::notify(Event *e)
305{
306 process->signalReset(_signal->read() == val(), sync());
307 return true;
308}
309
310void
311ResetSensitivityPort::setSignal(const ::sc_core::sc_signal_in_if<bool> *signal)
312{
313 _signal = signal;
314 event = &_signal->value_changed_event();
315 addToEvent(event);
316 if (signal->read() == val())
317 process->signalReset(true, sync());
318}
319
320} // namespace sc_gem5