gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_signal.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_SIGNAL_HH__
29#define __SYSTEMC_EXT_CHANNEL_SC_SIGNAL_HH__
30
31#include <iostream>
32#include <string>
33#include <vector>
34
35#include "../core/sc_event.hh"
36#include "../core/sc_module.hh" // for sc_gen_unique_name
37#include "../core/sc_prim.hh"
38#include "../dt/bit/sc_logic.hh"
39#include "sc_signal_inout_if.hh"
40
41namespace sc_core
42{
43
44class sc_port_base;
45
46} // namespace sc_core
47
48namespace sc_gem5
49{
50
51class Process;
52class Reset;
53
55{
56 public:
57 virtual const char *kind() const { return "sc_signal"; }
58
59 protected:
60 ScSignalBase(const char *_name);
61 virtual ~ScSignalBase();
62
63 const sc_core::sc_event &defaultEvent() const;
65
66 bool event() const;
67
68 void _signalChange();
69
71
73 uint64_t _changeStamp;
75};
76
78{
79 protected:
80 ScSignalBaseBinary(const char *_name);
81
83 void _signalReset(sc_gem5::Reset *reset);
84 void _signalReset();
85
86 const sc_core::sc_event &posedgeEvent() const;
87 const sc_core::sc_event &negedgeEvent() const;
88
89 bool posedge() const;
90 bool negedge() const;
91
94
95 uint64_t _posStamp;
96 uint64_t _negStamp;
97
98 void _signalPosedge();
99 void _signalNegedge();
100};
101
102template <class T>
104{
105 protected:
106 ScSignalBasePicker(const char *_name) : ScSignalBase(_name) {}
107};
108
109template <>
111{
112 protected:
113 ScSignalBasePicker(const char *_name) : ScSignalBaseBinary(_name) {}
114};
115
116template <>
118{
119 protected:
120 ScSignalBasePicker(const char *_name) : ScSignalBaseBinary(_name) {}
121};
122
123template <sc_core::sc_writer_policy WRITER_POLICY>
125
126template <>
127class WriteChecker<sc_core::SC_ONE_WRITER>
128{
129 public:
131
132 void checkPort(sc_core::sc_port_base &port,
133 std::string iface_type_name, std::string out_name);
134 void checkWriter();
135
136 private:
140 uint64_t writeStamp;
141};
142
143template <>
144class WriteChecker<sc_core::SC_MANY_WRITERS>
145{
146 public:
148
149 void checkPort(sc_core::sc_port_base &port,
150 std::string iface_type_name, std::string out_name);
151 void checkWriter();
152
153 private:
156 uint64_t writeStamp;
157};
158
159template <class T, sc_core::sc_writer_policy WRITER_POLICY>
162{
163 public:
164 ScSignalBaseT(const char *_name) :
165 ScSignalBasePicker<T>(_name), m_cur_val(T()), m_new_val(T()),
166 _checker(this)
167 {}
168 ScSignalBaseT(const char *_name, const T &initial_value) :
169 ScSignalBasePicker<T>(_name), m_cur_val(initial_value),
170 m_new_val(initial_value), _checker(this)
171 {}
172 virtual ~ScSignalBaseT() {}
173
174 virtual void
175 register_port(sc_core::sc_port_base &port, const char *iface_type_name)
176 {
177# if !defined(SC_NO_WRITE_CHECK)
178 {
179 _checker.checkPort(port, iface_type_name,
181 }
182# endif
183 }
184
185 virtual const T &read() const { return m_cur_val; }
186 operator const T&() const { return read(); }
187
188 virtual void
189 write(const T &t)
190 {
191# if !defined(SC_NO_WRITE_CHECK)
192 {
193 _checker.checkWriter();
194 }
195# endif
196 m_new_val = t;
197 bool changed = !(m_cur_val == m_new_val);
198 if (changed)
199 this->request_update();
200 }
201
202 virtual const sc_core::sc_event &
204 {
206 }
207
208 virtual const sc_core::sc_event &
210 {
212 }
213
214 virtual void print(std::ostream &os=std::cout) const { os << m_cur_val; }
215 virtual void
216 dump(std::ostream &os=std::cout) const
217 {
218 os << " name = " << this->name() << ::std::endl;
219 os << " value = " << m_cur_val << ::std::endl;
220 os << "new value = " << m_new_val << ::std::endl;
221 }
222
223 virtual bool event() const { return ScSignalBase::event(); }
224
227 {
228 return WRITER_POLICY;
229 }
230
231 protected:
232 // These members which store the current and future value of the signal
233 // are not specified in the standard but are referred to directly by one
234 // of the tests.
237
239};
240
241template <typename T, sc_core::sc_writer_policy WRITER_POLICY>
242class ScSignalBinary : public ScSignalBaseT<T, WRITER_POLICY>
243{
244 public:
245 ScSignalBinary(const char *_name) : ScSignalBaseT<T, WRITER_POLICY>(_name)
246 {}
247 ScSignalBinary(const char *_name, const T& initial_value) :
248 ScSignalBaseT<T, WRITER_POLICY>(_name, initial_value)
249 {}
250
251 const sc_core::sc_event &
253 {
255 }
256 const sc_core::sc_event &
258 {
260 }
261
262 bool posedge() const { return ScSignalBaseBinary::posedge(); }
263 bool negedge() const { return ScSignalBaseBinary::negedge(); }
264};
265
266} // namespace sc_gem5
267
268namespace sc_core
269{
270
271template <class T, sc_writer_policy WRITER_POLICY=SC_ONE_WRITER>
272class sc_signal : public sc_gem5::ScSignalBaseT<T, WRITER_POLICY>
273{
274 public:
275 sc_signal() : sc_gem5::ScSignalBaseT<T, WRITER_POLICY>(
276 sc_gen_unique_name("signal"))
277 {}
278 explicit sc_signal(const char *name) :
279 sc_gem5::ScSignalBaseT<T, WRITER_POLICY>(name)
280 {}
281 explicit sc_signal(const char *name, const T &initial_value) :
282 sc_gem5::ScSignalBaseT<T, WRITER_POLICY>(name, initial_value)
283 {}
284 virtual ~sc_signal() {}
285
287 operator = (const T &t)
288 {
289 this->write(t);
290 return *this;
291 }
294 {
295 this->write(s.read());
296 return *this;
297 }
298
299 protected:
300 virtual void
302 {
303 if (this->m_new_val == this->m_cur_val)
304 return;
305
306 this->m_cur_val = this->m_new_val;
307 this->_signalChange();
308 }
309
310 private:
311 // Disabled
313};
314
315template <class T, sc_writer_policy WRITER_POLICY>
316inline std::ostream &
317operator << (std::ostream &os, const sc_signal<T, WRITER_POLICY> &s)
318{
319 os << s.read();
320 return os;
321}
322
323template <sc_writer_policy WRITER_POLICY>
324class sc_signal<bool, WRITER_POLICY> :
325 public sc_gem5::ScSignalBinary<bool, WRITER_POLICY>
326{
327 public:
329 sc_gem5::ScSignalBinary<bool, WRITER_POLICY>(
330 sc_gen_unique_name("signal"))
331 {}
332 explicit sc_signal(const char *name) :
333 sc_gem5::ScSignalBinary<bool, WRITER_POLICY>(name)
334 {}
335 explicit sc_signal(const char *name, const bool &initial_value) :
336 sc_gem5::ScSignalBinary<bool, WRITER_POLICY>(name, initial_value)
337 {}
338 virtual ~sc_signal() {}
339
341 operator = (const bool &b)
342 {
343 this->write(b);
344 return *this;
345 }
348 {
349 this->write(s.read());
350 return *this;
351 }
352
353 protected:
354 virtual void
356 {
357 if (this->m_new_val == this->m_cur_val)
358 return;
359
360 this->m_cur_val = this->m_new_val;
361 this->_signalChange();
362 }
363
364 void
366 {
368 this->_signalReset();
369 if (this->m_cur_val)
370 this->_signalPosedge();
371 else
372 this->_signalNegedge();
373 }
374
375 private:
376 bool
378 {
379 this->_resets.push_back(reset);
380 return true;
381 }
382
383 // Disabled
385};
386
387template <sc_writer_policy WRITER_POLICY>
388class sc_signal<sc_dt::sc_logic, WRITER_POLICY> :
389 public sc_gem5::ScSignalBinary<sc_dt::sc_logic, WRITER_POLICY>
390{
391 public:
393 sc_gem5::ScSignalBinary<sc_dt::sc_logic, WRITER_POLICY>(
394 sc_gen_unique_name("signal"))
395 {}
396 explicit sc_signal(const char *name) :
397 sc_gem5::ScSignalBinary<sc_dt::sc_logic, WRITER_POLICY>(name)
398 {}
399 explicit sc_signal(const char *name,
400 const sc_dt::sc_logic &initial_value) :
401 sc_gem5::ScSignalBinary<sc_dt::sc_logic, WRITER_POLICY>(
402 name, initial_value)
403 {}
404 virtual ~sc_signal() {}
405
408 {
409 this->write(l);
410 return *this;
411 }
414 {
415 this->write(s.read());
416 return *this;
417 }
418
419 protected:
420 virtual void
422 {
423 if (this->m_new_val == this->m_cur_val)
424 return;
425
426 this->m_cur_val = this->m_new_val;
427 this->_signalChange();
428 }
429
430 void
432 {
435 if (this->m_cur_val == sc_dt::SC_LOGIC_1)
436 this->_signalPosedge();
437 else if (this->m_cur_val == sc_dt::SC_LOGIC_0)
438 this->_signalNegedge();
439 }
440
441 private:
442 // Disabled
444};
445
446} // namespace sc_core
447
448#endif //__SYSTEMC_EXT_CHANNEL_SC_SIGNAL_HH__
sc_signal(const sc_signal< bool, WRITER_POLICY > &)
bool _addReset(sc_gem5::Reset *reset) const
Definition sc_signal.hh:377
sc_signal(const char *name, const bool &initial_value)
Definition sc_signal.hh:335
sc_signal(const char *name, const sc_dt::sc_logic &initial_value)
Definition sc_signal.hh:399
sc_signal(const sc_signal< sc_dt::sc_logic, WRITER_POLICY > &)
sc_signal(const sc_signal< T, WRITER_POLICY > &)
virtual ~sc_signal()
Definition sc_signal.hh:284
virtual void update()
Definition sc_signal.hh:301
sc_signal< T, WRITER_POLICY > & operator=(const T &t)
Definition sc_signal.hh:287
sc_signal(const char *name, const T &initial_value)
Definition sc_signal.hh:281
sc_signal(const char *name)
Definition sc_signal.hh:278
InternalScEvent _negedgeEvent
Definition sc_signal.hh:93
InternalScEvent _posedgeEvent
Definition sc_signal.hh:92
const sc_core::sc_event & negedgeEvent() const
Definition sc_signal.cc:170
ScSignalBaseBinary(const char *_name)
Definition sc_signal.cc:159
const sc_core::sc_event & posedgeEvent() const
Definition sc_signal.cc:164
std::vector< sc_gem5::Reset * > _resets
Definition sc_signal.hh:82
ScSignalBasePicker(const char *_name)
Definition sc_signal.hh:113
ScSignalBasePicker(const char *_name)
Definition sc_signal.hh:106
virtual const sc_core::sc_event & default_event() const
Definition sc_signal.hh:203
virtual const T & read() const
Definition sc_signal.hh:185
virtual void dump(std::ostream &os=std::cout) const
Definition sc_signal.hh:216
virtual const sc_core::sc_event & value_changed_event() const
Definition sc_signal.hh:209
ScSignalBaseT(const char *_name)
Definition sc_signal.hh:164
WriteChecker< WRITER_POLICY > _checker
Definition sc_signal.hh:238
virtual void register_port(sc_core::sc_port_base &port, const char *iface_type_name)
Definition sc_signal.hh:175
virtual bool event() const
Definition sc_signal.hh:223
ScSignalBaseT(const char *_name, const T &initial_value)
Definition sc_signal.hh:168
virtual sc_core::sc_writer_policy get_writer_policy() const
Definition sc_signal.hh:226
virtual void print(std::ostream &os=std::cout) const
Definition sc_signal.hh:214
virtual void write(const T &t)
Definition sc_signal.hh:189
virtual sc_core::sc_writer_policy get_writer_policy() const =0
InternalScEvent _valueChangedEvent
Definition sc_signal.hh:72
const sc_core::sc_event & valueChangedEvent() const
Definition sc_signal.cc:52
virtual const char * kind() const
Definition sc_signal.hh:57
bool event() const
Definition sc_signal.cc:58
virtual ~ScSignalBase()
Definition sc_signal.cc:43
const sc_core::sc_event & defaultEvent() const
Definition sc_signal.cc:46
ScSignalBase(const char *_name)
Definition sc_signal.cc:38
sc_core::sc_port_base * _gem5WriterPort
Definition sc_signal.hh:74
const sc_core::sc_event & posedge_event() const
Definition sc_signal.hh:252
const sc_core::sc_event & negedge_event() const
Definition sc_signal.hh:257
ScSignalBinary(const char *_name, const T &initial_value)
Definition sc_signal.hh:247
ScSignalBinary(const char *_name)
Definition sc_signal.hh:245
STL vector class.
Definition stl.hh:37
SwitchingFiber b
@ Reset
Definition types.hh:69
std::ostream & operator<<(std::ostream &os, sc_status s)
Definition sc_main.cc:178
const sc_logic SC_LOGIC_0(Log_0)
Definition sc_logic.hh:367
const sc_logic SC_LOGIC_1(Log_1)
Definition sc_logic.hh:368
const std::string & name()
Definition trace.cc:48

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