1 | #include <signal.h> |
---|
2 | #include <iostream> |
---|
3 | #include <fstream> |
---|
4 | #include <cstdlib> //exit |
---|
5 | |
---|
6 | #include "systemc.h" |
---|
7 | #include "test.h" |
---|
8 | |
---|
9 | using namespace std; |
---|
10 | |
---|
11 | struct sc_test : public sc_module { |
---|
12 | sc_in<bool> clk; |
---|
13 | sc_in<bool> resetn; |
---|
14 | sc_signal<sc_uint<6> > ui6; |
---|
15 | sc_signal<sc_uint<16> > ui16; |
---|
16 | sc_signal<sc_uint<31> > ui31; |
---|
17 | sc_signal<sc_uint<32> > ui32; |
---|
18 | sc_signal<sc_uint<64> > ui64; |
---|
19 | sc_signal<sc_int<6> > i6; |
---|
20 | sc_signal<sc_int<16> > i16; |
---|
21 | sc_signal<sc_int<31> > i31; |
---|
22 | sc_signal<sc_int<32> > i32; |
---|
23 | sc_signal<sc_int<64> > i64; |
---|
24 | |
---|
25 | unsigned int ui6_c_type : 6; |
---|
26 | sc_uint<6> ui6_sc_uint; |
---|
27 | |
---|
28 | void eval() { |
---|
29 | if (resetn == false) { |
---|
30 | ui6 = 0xF; ui6_c_type = 0xF; |
---|
31 | ui6_sc_uint = 0xF; |
---|
32 | ui16 = 0x3F; |
---|
33 | ui31 = 0x100; |
---|
34 | ui32 = 0x211; |
---|
35 | ui64 = 0xABCF1234ULL; |
---|
36 | i6 = 0xF; |
---|
37 | i16 = 0x3F; |
---|
38 | i31 = 0x11112222; |
---|
39 | i32 = 0x43214321; |
---|
40 | i64 = 0x4444abcdULL; |
---|
41 | } |
---|
42 | else { |
---|
43 | cout << hex << ui6.read() << " " |
---|
44 | << ui6_c_type << " " |
---|
45 | << ui6_sc_uint << endl; |
---|
46 | ASSERT(ui6.read() == ui6_c_type); |
---|
47 | ui6 = (ui6.read() * 2) + 1; |
---|
48 | ui6_c_type = (ui6_c_type * 2) + 1; |
---|
49 | ui6_sc_uint = (ui6_sc_uint * 2) + 1; |
---|
50 | ui16 = (ui16.read() * 2) + 1; |
---|
51 | ui31 = (ui31.read() * 2) + 1; |
---|
52 | ui32 = (ui32.read() * 2) + 1; |
---|
53 | ui64 = (ui64.read() * 2) + 1; |
---|
54 | i6 = (i6.read() * 2) + 1; |
---|
55 | i16 = (i16.read() * 2) + 1; |
---|
56 | i31 = (i31.read() * 2) + 1; |
---|
57 | i32 = (i32.read() * 2) + 1; |
---|
58 | i64 = (i64.read() * 2) + 1; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | SC_CTOR(sc_test) { |
---|
63 | SC_METHOD(eval); |
---|
64 | sensitive << clk.pos(); |
---|
65 | dont_initialize(); |
---|
66 | } |
---|
67 | |
---|
68 | }; |
---|
69 | |
---|
70 | |
---|
71 | int sc_main(int argc, char * argv[]) { |
---|
72 | sc_clock clk("clk"); |
---|
73 | sc_signal<bool> resetn("resetn"); |
---|
74 | |
---|
75 | sc_test test("test"); |
---|
76 | test.clk(clk); |
---|
77 | test.resetn(resetn); |
---|
78 | |
---|
79 | sc_trace_file * tf; |
---|
80 | |
---|
81 | tf = sc_create_vcd_trace_file("trace_file"); |
---|
82 | sc_trace(tf, test.ui6 , "ui6"); |
---|
83 | sc_trace(tf, test.ui16, "ui16"); |
---|
84 | sc_trace(tf, test.ui31, "ui31"); |
---|
85 | sc_trace(tf, test.ui32, "ui32"); |
---|
86 | sc_trace(tf, test.ui64, "ui64"); |
---|
87 | sc_trace(tf, test.i6, "i6"); |
---|
88 | sc_trace(tf, test.i16, "i16"); |
---|
89 | sc_trace(tf, test.i31, "i31"); |
---|
90 | sc_trace(tf, test.i32, "i32"); |
---|
91 | sc_trace(tf, test.i64, "i64"); |
---|
92 | sc_trace(tf, clk, "clk"); |
---|
93 | |
---|
94 | ASSERT(test.ui6.read() == 0); |
---|
95 | ASSERT(test.ui31.read() == 0); |
---|
96 | ASSERT(test.ui32.read() == 0); |
---|
97 | ASSERT(test.ui64.read() == 0); |
---|
98 | ASSERT(test.i6.read() == 0); |
---|
99 | ASSERT(test.i64.read() == 0); |
---|
100 | |
---|
101 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
102 | |
---|
103 | resetn = false; |
---|
104 | |
---|
105 | sc_start(sc_time(3, sc_core::SC_NS)); |
---|
106 | resetn = true; |
---|
107 | sc_start(sc_time(20, sc_core::SC_NS)); |
---|
108 | |
---|
109 | #if 0 |
---|
110 | cout << "0x3f" << " 0x" << hex << (unsigned int) (sc_uint<6> )test.ui6 << endl; |
---|
111 | cout << "0x100fffff" << " 0x" << hex << (unsigned int) (sc_uint<31>)test.ui31 << endl; |
---|
112 | cout << "0x211fffff" << " 0x" << hex << (unsigned int) (sc_uint<32>)test.ui32 << endl; |
---|
113 | cout << "0xabcf1234fffff" << " 0x" << hex << (long long unsigned int) (sc_uint<64>)test.ui64 << endl; |
---|
114 | #endif |
---|
115 | cout << test.ui6.read() << endl; |
---|
116 | |
---|
117 | |
---|
118 | union t { |
---|
119 | int v1:3; |
---|
120 | int v2; |
---|
121 | }; |
---|
122 | |
---|
123 | |
---|
124 | t t1, t2; |
---|
125 | t1.v1 = 7; |
---|
126 | cout << t1.v1 << " " << t1.v2 << endl; |
---|
127 | t2.v2 = 7; |
---|
128 | cout << t2.v1 << " " << t2.v2 << endl; |
---|
129 | |
---|
130 | ASSERT(test.ui6.read() == 0x3f); |
---|
131 | ASSERT(test.ui31.read() == 0x100fffff); |
---|
132 | ASSERT(test.ui32.read() == 0x211fffff); |
---|
133 | |
---|
134 | long long unsigned int ui64_reference = 0xabcf1234ULL; |
---|
135 | ui64_reference <<= 20; |
---|
136 | ui64_reference += 0xfffffULL; |
---|
137 | |
---|
138 | #if 0 |
---|
139 | cout << "0xffffffff" << " 0x" << hex << (int) (sc_int<6>)test.i6 << endl; |
---|
140 | cout << "0x222fffff" << " 0x" << hex << (int) (sc_int<31>)test.i31 << endl; |
---|
141 | cout << "0x321fffff" << " 0x" << hex << (int) (sc_int<32>)test.i32 << endl; |
---|
142 | cout << "0x4444abcdfffff" << " 0x" << hex << (long long signed int) (sc_int<64>)test.i64 << endl; |
---|
143 | #endif |
---|
144 | |
---|
145 | ASSERT(test.ui64.read() == ui64_reference); |
---|
146 | ASSERT(test.i6.read() == (sc_int<6>) ~ 0); |
---|
147 | ASSERT(test.i31.read() == 0x222fffff); |
---|
148 | ASSERT(test.i32.read() == 0x321fffff); |
---|
149 | |
---|
150 | long long signed int i64_reference = 0x4444abcdULL; |
---|
151 | i64_reference <<= 20; |
---|
152 | i64_reference += 0xfffffULL; |
---|
153 | ASSERT(test.i64.read() == i64_reference); |
---|
154 | |
---|
155 | |
---|
156 | sc_close_vcd_trace_file(tf); |
---|
157 | |
---|
158 | return EXIT_SUCCESS; |
---|
159 | } |
---|
160 | |
---|
161 | /* |
---|
162 | # Local Variables: |
---|
163 | # tab-width: 4; |
---|
164 | # c-basic-offset: 4; |
---|
165 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
166 | # indent-tabs-mode: nil; |
---|
167 | # End: |
---|
168 | # |
---|
169 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
170 | */ |
---|
171 | |
---|