1 | |
---|
2 | #include "systemc.h" |
---|
3 | #include "test.h" |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | using namespace std; |
---|
8 | |
---|
9 | |
---|
10 | struct test : sc_module { |
---|
11 | sc_in_clk clk; |
---|
12 | sc_in<bool> i1; |
---|
13 | sc_in<int> i2; |
---|
14 | sc_in<int> i3; |
---|
15 | sc_out<bool> o1; |
---|
16 | sc_out<int> o2; |
---|
17 | sc_out<int> o3; |
---|
18 | sc_inout< sc_uint<32> > io4; |
---|
19 | sc_out<int> mealy1; |
---|
20 | sc_out<int> mealy2; |
---|
21 | |
---|
22 | sc_signal<bool> reg1; |
---|
23 | sc_signal<int> reg2; |
---|
24 | sc_signal<int> reg3; |
---|
25 | sc_signal<sc_uint<32> > reg9; |
---|
26 | sc_signal<int> reg10; |
---|
27 | |
---|
28 | void fmealy1() { |
---|
29 | mealy1 = i2.read(); |
---|
30 | } |
---|
31 | |
---|
32 | void fmealy2() { |
---|
33 | mealy2 = i2.read() + reg2.read(); |
---|
34 | } |
---|
35 | |
---|
36 | void gen() { |
---|
37 | o1 = reg1.read() ^ true; |
---|
38 | o2 = reg2.read() + 1; |
---|
39 | o3 = reg3.read() + 1; |
---|
40 | io4 = reg9.read() + 1; |
---|
41 | } |
---|
42 | |
---|
43 | void trans() { |
---|
44 | reg1 = reg1.read() ^ 1; |
---|
45 | reg2 = reg2.read() + 1; |
---|
46 | reg3 = reg3.read() + 1; |
---|
47 | reg9 = reg9.read() + 2; |
---|
48 | reg10 = reg10.read() + i2.read(); |
---|
49 | } |
---|
50 | |
---|
51 | SC_HAS_PROCESS(test); |
---|
52 | test(sc_module_name n) : sc_module(n), |
---|
53 | clk("clk"), |
---|
54 | i1("i1"), i2("i2"), i3("i3"), |
---|
55 | o1("o1"), o2("o2"), o3("o3"), |
---|
56 | io4("io4"), |
---|
57 | mealy1("mealy1_equivalent_to_i2"), |
---|
58 | mealy2("mealy2_equivalent_to_i2_plus_reg2"), |
---|
59 | reg1("reg1_cycle_number_not_parity"), |
---|
60 | reg2("reg2_cycle_number"), |
---|
61 | reg3("reg3_cycle_number"), |
---|
62 | reg9("reg9_cycle_number_x2"), |
---|
63 | reg10("reg10_sum_cycle_number") { |
---|
64 | SC_METHOD(trans); |
---|
65 | sensitive << clk.pos(); |
---|
66 | dont_initialize(); |
---|
67 | |
---|
68 | SC_METHOD(gen); |
---|
69 | sensitive << clk.neg(); |
---|
70 | dont_initialize(); |
---|
71 | |
---|
72 | SC_METHOD(fmealy1); |
---|
73 | sensitive << i2; |
---|
74 | dont_initialize(); |
---|
75 | |
---|
76 | SC_METHOD(fmealy2); |
---|
77 | sensitive << i2 << clk.neg(); |
---|
78 | dont_initialize(); |
---|
79 | } |
---|
80 | }; |
---|
81 | |
---|
82 | |
---|
83 | int usage (const char * com) { |
---|
84 | cout << "Usage :\n" << com << " [#cycles]\n"; |
---|
85 | return EXIT_FAILURE; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | sc_signal<bool> s01("i1_cycle_number_not_parity"), s02("o2_not_reg1"); |
---|
90 | sc_signal<int> s03("i2_cycle_number_x2"), s04("o2_reg2_plus_one"); |
---|
91 | sc_signal<int> s05("i3_cycle_number_x3"), s06("o3_reg3_plus_one"); |
---|
92 | sc_signal< sc_uint<32> > s16("io4_reg9_plus_one"); |
---|
93 | sc_signal<int> s17("mealy1_equivalent_to_i2"); |
---|
94 | sc_signal<int> s18("mealy2_i2_plus_reg2"); |
---|
95 | |
---|
96 | |
---|
97 | int s(int i) { |
---|
98 | int val = 0; |
---|
99 | while (i) { |
---|
100 | val += i--; |
---|
101 | } |
---|
102 | return val; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | void * func() { |
---|
107 | cerr << "func () at #" << sc_time_stamp() << endl; |
---|
108 | int i = (int) (sc_time_stamp().to_double()) / 1000; |
---|
109 | s01 = (i & 1) > 0; |
---|
110 | s03 = i * 2; |
---|
111 | s05 = i * 3; |
---|
112 | ++i; |
---|
113 | return 0; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | void save() { |
---|
118 | #ifdef SYSTEMCASS_SPECIFIC |
---|
119 | char name[256]; |
---|
120 | sprintf(name, "test_systemcass_%d.dat", ((int) sc_time_stamp().to_double() / 1000)); |
---|
121 | sc_save_simulation(name); |
---|
122 | #endif |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | int sc_main (int argc, char * argv[]) { |
---|
127 | sc_clock signal_clk("my_clock", 1, 0.5); |
---|
128 | |
---|
129 | // Setup number of threads open-mp to 1 with the macro threads_omp() |
---|
130 | threads_omp(); |
---|
131 | |
---|
132 | test test1("test1"); |
---|
133 | test1.clk(signal_clk); |
---|
134 | test1.i1(s01); |
---|
135 | test1.o1(s02); |
---|
136 | test1.i2(s03); |
---|
137 | test1.o2(s04); |
---|
138 | test1.i3(s05); |
---|
139 | test1.o3(s06); |
---|
140 | test1.io4(s16); |
---|
141 | test1.mealy1(s17); |
---|
142 | test1.mealy2(s18); |
---|
143 | |
---|
144 | // Init & run |
---|
145 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
146 | |
---|
147 | #ifndef SOCVIEW |
---|
148 | if (argc != 2) { |
---|
149 | return usage(argv[0]); |
---|
150 | } |
---|
151 | |
---|
152 | int nb = atoi(argv[1]); |
---|
153 | |
---|
154 | if (nb == 0) { |
---|
155 | return usage(argv[0]); |
---|
156 | } |
---|
157 | |
---|
158 | int i = 0; |
---|
159 | save(); |
---|
160 | while (i++ < nb) { |
---|
161 | func(); |
---|
162 | sc_start(sc_time(1, sc_core::SC_NS)); |
---|
163 | save(); |
---|
164 | } |
---|
165 | #else |
---|
166 | debug(&func); |
---|
167 | #endif |
---|
168 | |
---|
169 | return EXIT_SUCCESS; |
---|
170 | } |
---|
171 | |
---|
172 | #undef sc_inout |
---|
173 | |
---|
174 | /* |
---|
175 | # Local Variables: |
---|
176 | # tab-width: 4; |
---|
177 | # c-basic-offset: 4; |
---|
178 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
179 | # indent-tabs-mode: nil; |
---|
180 | # End: |
---|
181 | # |
---|
182 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
183 | */ |
---|
184 | |
---|