-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathsct_prim_signal.h
118 lines (93 loc) · 2.64 KB
/
sct_prim_signal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/******************************************************************************
* Copyright (c) 2023, Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
*
*****************************************************************************/
/*
* Single Source library. Signal channel with multiple drivers.
*
* Used in sct_prim_fifo implementation.
* Not intended to be used in user code.
*
* Author: Mikhail Moiseev
*/
#ifndef SCT_PRIM_SIGNAL_H
#define SCT_PRIM_SIGNAL_H
#include "sct_ipc_if.h"
#include <systemc.h>
namespace sct {
template <class T>
class sct_prim_signal :
public sc_prim_channel,
public sct_inout_if<T>
{
public:
using this_type = sct_prim_signal<T>;
SC_HAS_PROCESS(sct_prim_signal);
explicit sct_prim_signal(const sc_module_name& name) :
sc_prim_channel(name),
event(std::string(std::string(name)+"_event").c_str())
{}
protected:
T curr_val = T{};
T next_val = T{};
sc_event event;
/// Channel update, run at DC 0
void update() override
{
if (!(curr_val == next_val)) {
curr_val = next_val;
event.notify(SC_ZERO_TIME);
}
}
public:
void write(const T& val) override {
if (!(next_val == val)) {
request_update();
}
next_val = val;
}
this_type& operator = (const this_type& other) {
write(other.read());
return *this;
}
this_type& operator = (const T& val) {
write(val);
return *this;
}
const T& read() const override {
return curr_val;
}
operator const T& () const {
return curr_val;
}
public:
const sc_event& default_event() const override {
return event;
}
inline void print(::std::ostream& os) const override {
os << "sct_prim_signal " << name() << " = " << curr_val << ::std::endl;
}
const char* kind() const override {
return "sct_prim_signal";
}
};
template<class T>
bool operator == (const sct_prim_signal<T>& a, const sct_prim_signal<T>& b) {
return (a.read() == b.read());
}
template<class T>
bool operator == (const sct_prim_signal<T>& a, const sc_signal<T>& b) {
return (a.read() == b.read());
}
template<class T>
bool operator != (const sct_prim_signal<T>& a, const sct_prim_signal<T>& b) {
return (!(a.read() == b.read()));
}
template<class T>
bool operator != (const sct_prim_signal<T>& a, const sc_signal<T>& b) {
return (!(a.read() == b.read()));
}
} // namespace sct
#endif /* SCT_PRIM_SIGNAL_H */