gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_inout.hh
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
28#ifndef __SYSTEMC_EXT_CHANNEL_SC_INOUT_HH__
29#define __SYSTEMC_EXT_CHANNEL_SC_INOUT_HH__
30
31#include <string>
32
33#include "../core/sc_event.hh"
34#include "../core/sc_main.hh"
35#include "../core/sc_port.hh"
36#include "../dt/bit/sc_logic.hh"
38#include "sc_signal_inout_if.hh"
39
40namespace sc_dt
41{
42
43class sc_logic;
44
45} // namespace sc_dt
46
47namespace sc_core
48{
49
50class sc_event;
51class sc_trace_file;
52
53template <class T>
54class sc_inout : public sc_port<sc_signal_inout_if<T>, 1>
55{
56 public:
60 explicit sc_inout(const char *name) :
61 sc_port<sc_signal_inout_if<T>, 1>(name), initValue(nullptr),
63 {}
64 virtual ~sc_inout() { delete initValue; }
65
66 // Deprecated binding constructors.
67 explicit sc_inout(const sc_signal_inout_if<T> &interface) :
68 sc_port<sc_signal_inout_if<T>, 1>(interface), initValue(nullptr),
70 {}
71 sc_inout(const char *name, const sc_signal_inout_if<T> &interface) :
72 sc_port<sc_signal_inout_if<T>, 1>(name, interface), initValue(nullptr),
74 {}
87 sc_inout(const char *name, sc_port<sc_signal_inout_if<T>, 1> &parent) :
88 sc_port<sc_signal_inout_if<T>, 1>(name, parent), initValue(nullptr),
90 {}
91
92 void
93 initialize(const T &t)
94 {
95 if (this->size()) {
96 (*this)->write(t);
97 } else {
98 if (!initValue)
99 initValue = new T;
100 *initValue = t;
101 }
102 }
103 void initialize(const sc_signal_in_if<T> &i) { initialize(i.read()); }
104
105 virtual void
107 {
108 if (initValue) {
110 delete initValue;
111 initValue = nullptr;
112 }
113
114 for (auto params: traceParamsVec)
115 sc_trace(params->tf, (*this)->read(), params->name);
116
117 traceParamsVec.clear();
118 }
119
120 const T &read() const { return (*this)->read(); }
121 operator const T& () const { return (*this)->read(); }
122
123 void write(const T &t) { (*this)->write(t); }
125 operator = (const T &t)
126 {
127 (*this)->write(t);
128 return *this;
129 }
132 {
133 (*this)->write(i.read());
134 return *this;
135 }
138 {
139 (*this)->write(p->read());
140 return *this;
141 }
144 {
145 (*this)->write(p->read());
146 return *this;
147 }
150 {
151 (*this)->write(p->read());
152 return *this;
153 }
154
155 const sc_event &default_event() const { return (*this)->default_event(); }
156 const sc_event &
158 {
159 return (*this)->value_changed_event();
160 }
161 bool event() const { return (*this)->event(); }
163
164 virtual const char *kind() const { return "sc_inout"; }
165
166 void
167 add_trace(sc_trace_file *tf, const std::string &name) const
168 {
169 traceParamsVec.push_back(new sc_trace_params(tf, name));
170 }
171
172 private:
175
177
178 // Disabled
180};
181
182template <class T>
183inline void
184sc_trace(sc_trace_file *tf, const sc_inout<T> &i, const std::string &name)
185{
187 i.add_trace(tf, name);
188 else
189 sc_trace(tf, i->read(), name);
190}
191
192template <>
193class sc_inout<bool> : public sc_port<sc_signal_inout_if<bool>, 1>
194{
195 public:
196 sc_inout() : sc_port<sc_signal_inout_if<bool>, 1>(), initValue(nullptr),
199 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
200 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
201 {}
202 explicit sc_inout(const char *name) :
203 sc_port<sc_signal_inout_if<bool>, 1>(name), initValue(nullptr),
206 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
207 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
208 {}
209 virtual ~sc_inout() { delete initValue; }
210
211 // Deprecated binding constructors.
212 explicit sc_inout(const sc_signal_inout_if<bool> &interface) :
213 sc_port<sc_signal_inout_if<bool>, 1>(interface), initValue(nullptr),
216 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
217 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
218 {}
219 sc_inout(const char *name, const sc_signal_inout_if<bool> &interface) :
220 sc_port<sc_signal_inout_if<bool>, 1>(name, interface),
221 initValue(nullptr),
224 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
225 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
226 {}
228 sc_port<sc_signal_inout_if<bool>, 1>(parent), initValue(nullptr),
231 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
232 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
233 {}
235 sc_port<sc_signal_inout_if<bool>, 1>(name, parent), initValue(nullptr),
238 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
239 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
240 {}
242 sc_port<sc_signal_inout_if<bool>, 1>(parent), initValue(nullptr),
245 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
246 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
247 {}
248 sc_inout(const char *name, sc_port<sc_signal_inout_if<bool>, 1> &parent) :
249 sc_port<sc_signal_inout_if<bool>, 1>(name, parent), initValue(nullptr),
252 _posFinder(*this, &sc_signal_inout_if<bool>::posedge_event),
253 _negFinder(*this, &sc_signal_inout_if<bool>::negedge_event)
254 {}
255
256 void
257 initialize(const bool &b)
258 {
259 if (this->size()) {
260 (*this)->write(b);
261 } else {
262 if (!initValue)
263 initValue = new bool;
264 *initValue = b;
265 }
266 }
267 void initialize(const sc_signal_in_if<bool> &i) { initialize(i.read()); }
268
269 virtual void
271 {
272 if (initValue) {
274 delete initValue;
275 initValue = nullptr;
276 }
277
278 for (auto params: traceParamsVec)
279 sc_trace(params->tf, (*this)->read(), params->name);
280
281 traceParamsVec.clear();
282 }
283
284 const bool &read() const { return (*this)->read(); }
285 operator const bool& () const { return (*this)->read(); }
286
287 void write(const bool &b) { (*this)->write(b); }
289 operator = (const bool &b)
290 {
291 (*this)->write(b);
292 return *this;
293 }
296 {
297 (*this)->write(i.read());
298 return *this;
299 }
302 {
303 (*this)->write(p->read());
304 return *this;
305 }
308 {
309 (*this)->write(p->read());
310 return *this;
311 }
314 {
315 (*this)->write(p->read());
316 return *this;
317 }
318
319 const sc_event &default_event() const { return (*this)->default_event(); }
320 const sc_event &
322 {
323 return (*this)->value_changed_event();
324 }
325 const sc_event &posedge_event() const { return (*this)->posedge_event(); }
326 const sc_event &negedge_event() const { return (*this)->negedge_event(); }
327 bool event() const { return (*this)->event(); }
328 bool posedge() const { return (*this)->posedge(); }
329 bool negedge() const { return (*this)->negedge(); }
330
332 sc_event_finder &pos() const { return _posFinder; }
333 sc_event_finder &neg() const { return _negFinder; }
334
335 virtual const char *kind() const { return "sc_inout"; }
336
337 void
338 add_trace(sc_trace_file *tf, const std::string &name) const
339 {
340 traceParamsVec.push_back(new sc_trace_params(tf, name));
341 }
342
343 private:
348
350
351 // Disabled
353};
354
355template <>
356inline void sc_trace<bool>(
357 sc_trace_file *tf, const sc_inout<bool> &i, const std::string &name)
358{
360 i.add_trace(tf, name);
361 else
362 sc_trace(tf, i->read(), name);
363}
364
365template <>
366class sc_inout<sc_dt::sc_logic> :
367 public sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>
368{
369 public:
371 initValue(nullptr),
374 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
375 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
376 {}
377 explicit sc_inout(const char *name) :
378 sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>(name),
379 initValue(nullptr),
382 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
383 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
384 {}
385 virtual ~sc_inout() { delete initValue; }
386
387 // Deprecated binding constructors.
389 sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>(interface),
390 initValue(nullptr),
393 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
394 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
395 {}
396 sc_inout(const char *name,
397 const sc_signal_inout_if<sc_dt::sc_logic> &interface) :
398 sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>(name, interface),
399 initValue(nullptr),
402 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
403 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
404 {}
405 explicit sc_inout(
407 sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>(parent),
408 initValue(nullptr),
411 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
412 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
413 {}
414 sc_inout(const char *name,
416 sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>(name, parent),
417 initValue(nullptr),
420 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
421 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
422 {}
423 explicit sc_inout(
425 sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>(parent),
426 initValue(nullptr),
429 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
430 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
431 {}
432 sc_inout(const char *name,
434 sc_port<sc_signal_inout_if<sc_dt::sc_logic>, 1>(name, parent),
435 initValue(nullptr),
438 _posFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::posedge_event),
439 _negFinder(*this, &sc_signal_inout_if<sc_dt::sc_logic>::negedge_event)
440 {}
441
442 void
444 {
445 if (this->size()) {
446 (*this)->write(l);
447 } else {
448 if (!initValue)
450 *initValue = l;
451 }
452 }
453 void
455 {
456 initialize(i.read());
457 }
458
459 virtual void
461 {
462 if (initValue) {
464 delete initValue;
465 initValue = nullptr;
466 }
467
468 for (auto params: traceParamsVec)
469 sc_trace(params->tf, (*this)->read(), params->name);
470
471 traceParamsVec.clear();
472 }
473
474 const sc_dt::sc_logic &read() const { return (*this)->read(); }
475 operator const sc_dt::sc_logic& () const { return (*this)->read(); }
476
477 void write(const sc_dt::sc_logic &l) { (*this)->write(l); }
480 {
481 (*this)->write(l);
482 return *this;
483 }
486 {
487 (*this)->write(i.read());
488 return *this;
489 }
492 {
493 (*this)->write(p->read());
494 return *this;
495 }
498 {
499 (*this)->write(p->read());
500 return *this;
501 }
504 {
505 (*this)->write(p->read());
506 return *this;
507 }
508
509 const sc_event &default_event() const { return (*this)->default_event(); }
510 const sc_event &
512 {
513 return (*this)->value_changed_event();
514 }
515 const sc_event &posedge_event() const { return (*this)->posedge_event(); }
516 const sc_event &negedge_event() const { return (*this)->negedge_event(); }
517 bool event() const { return (*this)->event(); }
518 bool posedge() const { return (*this)->posedge(); }
519 bool negedge() const { return (*this)->negedge(); }
520
522 sc_event_finder &pos() const { return _posFinder; }
523 sc_event_finder &neg() const { return _negFinder; }
524
525 virtual const char *kind() const { return "sc_inout"; }
526
527 void
528 add_trace(sc_trace_file *tf, const std::string &name) const
529 {
530 traceParamsVec.push_back(new sc_trace_params(tf, name));
531 }
532
533 private:
535 mutable sc_event_finder_t<
539
541
542 // Disabled
544};
545
546template <>
547inline void
549 const sc_inout<sc_dt::sc_logic> &i, const std::string &name)
550{
552 i.add_trace(tf, name);
553 else
554 sc_trace(tf, i->read(), name);
555}
556
557} // namespace sc_core
558
559#endif //__SYSTEMC_EXT_CHANNEL_SC_INOUT_HH__
sc_trace_params_vec traceParamsVec
Definition sc_inout.hh:349
void add_trace(sc_trace_file *tf, const std::string &name) const
Definition sc_inout.hh:338
const sc_event & posedge_event() const
Definition sc_inout.hh:325
const sc_event & value_changed_event() const
Definition sc_inout.hh:321
const sc_event & negedge_event() const
Definition sc_inout.hh:326
sc_inout(const char *name, sc_port< sc_signal_inout_if< bool >, 1 > &parent)
Definition sc_inout.hh:248
sc_event_finder_t< sc_signal_inout_if< bool > > _valueChangedFinder
Definition sc_inout.hh:345
sc_event_finder_t< sc_signal_inout_if< bool > > _posFinder
Definition sc_inout.hh:346
void initialize(const sc_signal_in_if< bool > &i)
Definition sc_inout.hh:267
void initialize(const bool &b)
Definition sc_inout.hh:257
sc_event_finder & neg() const
Definition sc_inout.hh:333
sc_inout(const char *name)
Definition sc_inout.hh:202
const sc_event & default_event() const
Definition sc_inout.hh:319
sc_event_finder & pos() const
Definition sc_inout.hh:332
sc_event_finder & value_changed() const
Definition sc_inout.hh:331
sc_event_finder_t< sc_signal_inout_if< bool > > _negFinder
Definition sc_inout.hh:347
sc_inout(const char *name, const sc_signal_inout_if< bool > &interface)
Definition sc_inout.hh:219
sc_inout(const char *name, sc_port_b< sc_signal_inout_if< bool > > &parent)
Definition sc_inout.hh:234
sc_inout(const sc_inout< bool > &)
virtual const char * kind() const
Definition sc_inout.hh:335
sc_inout(const sc_signal_inout_if< bool > &interface)
Definition sc_inout.hh:212
void write(const bool &b)
Definition sc_inout.hh:287
virtual void end_of_elaboration()
Definition sc_inout.hh:270
const bool & read() const
Definition sc_inout.hh:284
sc_inout(sc_port< sc_signal_inout_if< bool >, 1 > &parent)
Definition sc_inout.hh:241
sc_inout(sc_port_b< sc_signal_inout_if< bool > > &parent)
Definition sc_inout.hh:227
sc_inout(const char *name, const sc_signal_inout_if< sc_dt::sc_logic > &interface)
Definition sc_inout.hh:396
virtual const char * kind() const
Definition sc_inout.hh:525
sc_event_finder & neg() const
Definition sc_inout.hh:523
const sc_event & default_event() const
Definition sc_inout.hh:509
sc_inout(const sc_signal_inout_if< sc_dt::sc_logic > &interface)
Definition sc_inout.hh:388
sc_event_finder_t< sc_signal_inout_if< sc_dt::sc_logic > > _posFinder
Definition sc_inout.hh:537
sc_event_finder & value_changed() const
Definition sc_inout.hh:521
void write(const sc_dt::sc_logic &l)
Definition sc_inout.hh:477
sc_inout(const sc_inout< sc_dt::sc_logic > &)
sc_event_finder_t< sc_signal_inout_if< sc_dt::sc_logic > > _negFinder
Definition sc_inout.hh:538
const sc_event & value_changed_event() const
Definition sc_inout.hh:511
void initialize(const sc_dt::sc_logic &l)
Definition sc_inout.hh:443
sc_inout(const char *name, sc_port_b< sc_signal_inout_if< sc_dt::sc_logic > > &parent)
Definition sc_inout.hh:414
sc_trace_params_vec traceParamsVec
Definition sc_inout.hh:540
sc_inout(const char *name, sc_port< sc_signal_inout_if< sc_dt::sc_logic >, 1 > &parent)
Definition sc_inout.hh:432
sc_inout(sc_port_b< sc_signal_inout_if< sc_dt::sc_logic > > &parent)
Definition sc_inout.hh:405
sc_event_finder & pos() const
Definition sc_inout.hh:522
const sc_event & negedge_event() const
Definition sc_inout.hh:516
const sc_dt::sc_logic & read() const
Definition sc_inout.hh:474
void initialize(const sc_signal_in_if< sc_dt::sc_logic > &i)
Definition sc_inout.hh:454
sc_inout(sc_port< sc_signal_inout_if< sc_dt::sc_logic >, 1 > &parent)
Definition sc_inout.hh:423
void add_trace(sc_trace_file *tf, const std::string &name) const
Definition sc_inout.hh:528
sc_event_finder_t< sc_signal_inout_if< sc_dt::sc_logic > > _valueChangedFinder
Definition sc_inout.hh:536
const sc_event & posedge_event() const
Definition sc_inout.hh:515
virtual const char * kind() const
Definition sc_inout.hh:164
void initialize(const T &t)
Definition sc_inout.hh:93
void add_trace(sc_trace_file *tf, const std::string &name) const
Definition sc_inout.hh:167
const sc_event & value_changed_event() const
Definition sc_inout.hh:157
sc_inout(const char *name, sc_port_b< sc_signal_inout_if< T > > &parent)
Definition sc_inout.hh:79
sc_event_finder & value_changed() const
Definition sc_inout.hh:162
sc_inout(const sc_signal_inout_if< T > &interface)
Definition sc_inout.hh:67
bool event() const
Definition sc_inout.hh:161
sc_inout(const char *name)
Definition sc_inout.hh:60
const sc_event & default_event() const
Definition sc_inout.hh:155
sc_inout(const char *name, sc_port< sc_signal_inout_if< T >, 1 > &parent)
Definition sc_inout.hh:87
virtual void end_of_elaboration()
Definition sc_inout.hh:106
void write(const T &t)
Definition sc_inout.hh:123
virtual ~sc_inout()
Definition sc_inout.hh:64
sc_event_finder_t< sc_signal_inout_if< T > > _valueChangedFinder
Definition sc_inout.hh:174
sc_inout< T > & operator=(const T &t)
Definition sc_inout.hh:125
sc_inout(sc_port_b< sc_signal_inout_if< T > > &parent)
Definition sc_inout.hh:75
void initialize(const sc_signal_in_if< T > &i)
Definition sc_inout.hh:103
sc_inout(const char *name, const sc_signal_inout_if< T > &interface)
Definition sc_inout.hh:71
const T & read() const
Definition sc_inout.hh:120
sc_trace_params_vec traceParamsVec
Definition sc_inout.hh:176
sc_inout(const sc_inout< T > &)
sc_inout(sc_port< sc_signal_inout_if< T >, 1 > &parent)
Definition sc_inout.hh:83
SwitchingFiber b
sc_status sc_get_status()
Definition sc_main.cc:172
@ SC_START_OF_SIMULATION
Definition sc_main.hh:86
void sc_trace< bool >(sc_trace_file *tf, const sc_in< bool > &i, const std::string &name)
Definition sc_in.hh:318
void sc_trace(sc_trace_file *tf, const sc_in< T > &i, const std::string &name)
Definition sc_in.hh:156
void sc_trace< sc_dt::sc_logic >(sc_trace_file *tf, const sc_in< sc_dt::sc_logic > &i, const std::string &name)
Definition sc_in.hh:479
const std::string & name()
Definition trace.cc:48

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