[1] | 1 | #include <systemc.h> |
---|
| 2 | |
---|
| 3 | #define ASSERT(x) \ |
---|
| 4 | { errnum++; \ |
---|
| 5 | if (!(x)) \ |
---|
| 6 | { \ |
---|
| 7 | cerr << "ASSERT : " #x "\n"; \ |
---|
| 8 | exit (errnum); \ |
---|
| 9 | } \ |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | using namespace std; |
---|
| 13 | |
---|
| 14 | //#define sc_inout sc_out |
---|
| 15 | |
---|
| 16 | struct test : sc_module { |
---|
| 17 | sc_in_clk clk; |
---|
| 18 | sc_in<bool> i1; |
---|
| 19 | sc_in<char> i2; |
---|
| 20 | sc_in<int> i3; |
---|
| 21 | sc_in<sc_int<4> > i4; |
---|
| 22 | sc_in<sc_uint<4> > i5; |
---|
| 23 | sc_in<sc_uint<64> > i6; |
---|
| 24 | sc_out<bool> o1; |
---|
| 25 | sc_out<char> o2; |
---|
| 26 | sc_out<int > o3; |
---|
| 27 | sc_out<sc_int<4> > o4; |
---|
| 28 | sc_out<sc_uint<4> > o5; |
---|
| 29 | sc_out<sc_uint<64> > o6; |
---|
| 30 | sc_inout<sc_uint<64> > io1; |
---|
| 31 | // sc_inout<sc_signed > io2; |
---|
| 32 | // sc_inout<sc_unsigned > io3; |
---|
| 33 | sc_inout<sc_uint<32> > io4; |
---|
| 34 | |
---|
| 35 | sc_signal<bool> reg1; |
---|
| 36 | sc_signal<char> reg2; |
---|
| 37 | sc_signal<int> reg3; |
---|
| 38 | sc_signal<sc_int<4> > reg4; |
---|
| 39 | sc_signal<sc_uint<4> > reg5; |
---|
| 40 | sc_signal<sc_uint<64> > reg6; |
---|
| 41 | // sc_signal<sc_signed > reg7; |
---|
| 42 | // sc_signal<sc_unsigned > reg8; |
---|
| 43 | sc_signal<sc_uint<32> > reg9; |
---|
| 44 | |
---|
| 45 | void gen () |
---|
| 46 | { |
---|
| 47 | o1 = reg1.read() ^ true; |
---|
| 48 | o2 = reg2.read()+ 1; |
---|
| 49 | o3 = reg3.read()+ 1; |
---|
| 50 | o4 = reg4.read()+ 1; |
---|
| 51 | o5 = reg5.read()+ 1; |
---|
| 52 | o6 = reg6.read()+ 1; |
---|
| 53 | io1 = reg6.read() * 2 + 1; |
---|
| 54 | io4 = reg9.read()+ 1; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void trans () |
---|
| 58 | { |
---|
| 59 | // io2 = io2.read() + 1; |
---|
| 60 | // io3 = io3.read() + 1; |
---|
| 61 | |
---|
| 62 | reg1 = reg1.read() ^ 1; |
---|
| 63 | reg2 = reg2.read() + 1; |
---|
| 64 | reg3 = reg3.read() + 1; |
---|
| 65 | reg4 = reg4.read() + 1; |
---|
| 66 | reg5 = reg5.read() + 1; |
---|
| 67 | reg6 = reg6.read() * 2 + 1; |
---|
| 68 | reg9 = reg9.read() + 1; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | SC_CTOR (test) : clk("clk"), i1("i1"), o1("o1"), i2("i2"), o2("o2"), |
---|
| 72 | i3("i3"), o3("o3"), io1("io1"), io4("io4"), reg9("reg9") { |
---|
| 73 | SC_METHOD(trans); |
---|
| 74 | sensitive << clk.pos(); |
---|
| 75 | dont_initialize(); |
---|
| 76 | SC_METHOD(gen); |
---|
| 77 | sensitive << clk.neg(); |
---|
| 78 | dont_initialize(); |
---|
| 79 | }; |
---|
| 80 | }; |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | int sc_main (int argc, char *argv[]) |
---|
| 85 | { |
---|
| 86 | int errnum = 0; |
---|
| 87 | sc_clock signal_clk("my_clock",1, 0.5); |
---|
| 88 | sc_signal<bool> s1 ("s01"), |
---|
| 89 | s2 ("s02"); |
---|
| 90 | sc_signal<char> s3 ("s03"), |
---|
| 91 | s4 ("s04"); |
---|
| 92 | sc_signal<int> s5 ("s05"), |
---|
| 93 | s6 ("s06"); |
---|
| 94 | sc_signal<sc_int<4> > s7 ("s07"), |
---|
| 95 | s8 ("s08"); |
---|
| 96 | sc_signal<sc_uint<4> > s9 ("s09"), |
---|
| 97 | s10("s10"); |
---|
| 98 | sc_signal<sc_uint<64> > s11("s11"), |
---|
| 99 | s12("s12"), |
---|
| 100 | s13("s13"); |
---|
| 101 | // sc_signal<sc_signed > s14("s14"); |
---|
| 102 | // sc_signal<sc_unsigned > s15("s15"); |
---|
| 103 | sc_signal<sc_uint<32> > s16("s16"); |
---|
| 104 | |
---|
| 105 | test test1("test1"); |
---|
| 106 | test1.clk (signal_clk); |
---|
| 107 | test1.i1 (s1); |
---|
| 108 | test1.o1 (s2); |
---|
| 109 | test1.i2 (s3); |
---|
| 110 | test1.o2 (s4); |
---|
| 111 | test1.i3 (s5); |
---|
| 112 | test1.o3 (s6); |
---|
| 113 | test1.i4 (s7); |
---|
| 114 | test1.o4 (s8); |
---|
| 115 | test1.i5 (s9); |
---|
| 116 | test1.o5 (s10); |
---|
| 117 | test1.i6 (s11); |
---|
| 118 | test1.o6 (s12); |
---|
| 119 | test1.io1(s13); |
---|
| 120 | // test1.io2(s14); |
---|
| 121 | // test1.io3(s15); |
---|
| 122 | test1.io4(s16); |
---|
| 123 | |
---|
| 124 | /* Open trace file */ |
---|
| 125 | sc_trace_file *system_trace_file; |
---|
| 126 | system_trace_file = sc_create_vcd_trace_file (argv[1]); |
---|
| 127 | /* clk waveform is always useful */ |
---|
| 128 | sc_trace(system_trace_file, signal_clk, "clk"); |
---|
| 129 | |
---|
[23] | 130 | bool b1 = 0; |
---|
| 131 | uint64_t l1 = 0; |
---|
[1] | 132 | |
---|
| 133 | #if 0 |
---|
| 134 | #if defined(SYSTEMCASS_SPECIFIC) |
---|
| 135 | uint64 ui1 = 0; |
---|
| 136 | int64 i1 = 0; |
---|
| 137 | sc_trace(system_trace_file, ui1, "ui1"); |
---|
| 138 | sc_trace(system_trace_file, i1, "i1"); |
---|
| 139 | #endif |
---|
| 140 | #endif |
---|
| 141 | |
---|
| 142 | #define TRACE(x) sc_trace (system_trace_file, x, #x); |
---|
| 143 | TRACE(b1); |
---|
| 144 | TRACE(l1); |
---|
| 145 | TRACE(test1.i1); |
---|
| 146 | TRACE(test1.i2); |
---|
| 147 | TRACE(test1.i3); |
---|
| 148 | TRACE(test1.i4); |
---|
| 149 | TRACE(test1.i5); |
---|
| 150 | TRACE(test1.i6); |
---|
| 151 | TRACE(test1.o1); |
---|
| 152 | TRACE(test1.o2); |
---|
| 153 | TRACE(test1.o3); |
---|
| 154 | TRACE(test1.o4); |
---|
| 155 | TRACE(test1.o5); |
---|
| 156 | TRACE(test1.o6); |
---|
| 157 | TRACE(test1.io1); |
---|
| 158 | // TRACE(test1.io2); |
---|
| 159 | // TRACE(test1.io3); |
---|
| 160 | TRACE(test1.io4); |
---|
| 161 | TRACE(s1); |
---|
| 162 | TRACE(s2); |
---|
| 163 | TRACE(s3); |
---|
| 164 | TRACE(s4); |
---|
| 165 | TRACE(s5); |
---|
| 166 | TRACE(s6); |
---|
| 167 | TRACE(s7); |
---|
| 168 | TRACE(s8); |
---|
| 169 | TRACE(s9); |
---|
| 170 | TRACE(s10); |
---|
| 171 | TRACE(s11); |
---|
| 172 | TRACE(s12); |
---|
| 173 | TRACE(s13); |
---|
| 174 | // TRACE(s14); |
---|
| 175 | // TRACE(s15); |
---|
| 176 | TRACE(s16); |
---|
| 177 | #undef TRACE |
---|
| 178 | |
---|
| 179 | // Init & run |
---|
| 180 | sc_initialize (); |
---|
| 181 | |
---|
| 182 | ASSERT(test1.i1.read() == false); |
---|
| 183 | ASSERT(s4.read() == 0); |
---|
| 184 | ASSERT(s10.read() == 0); |
---|
| 185 | ASSERT(s16.read() == 0); |
---|
| 186 | |
---|
| 187 | #if 0 |
---|
| 188 | #if SYSTEMCASS_SPECIFIC |
---|
| 189 | cerr << "s16 = " << hex << s16.get_pointer () << endl; |
---|
| 190 | cerr << "io4 = " << hex << test1.io4.get_pointer () << endl; |
---|
| 191 | // cerr << "io4(base) = " << hex << &(test1.io4.val) << endl; |
---|
| 192 | #endif |
---|
| 193 | cerr << s16 << " " << test1.io4 << endl; |
---|
| 194 | s16 = 5; |
---|
| 195 | cerr << s16 << " " << test1.io4 << endl; |
---|
| 196 | test1.io4 = 7; |
---|
| 197 | cerr << s16 << " " << test1.io4 << endl; |
---|
| 198 | #endif |
---|
| 199 | |
---|
| 200 | if (argc == 2) |
---|
| 201 | { |
---|
| 202 | cout << "Usage :\n" << argv[0] << " [#cycles]\n"; |
---|
| 203 | return EXIT_SUCCESS; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | int nb = atoi(argv[2]); |
---|
| 207 | |
---|
| 208 | sc_start (1); |
---|
| 209 | |
---|
| 210 | b1 = 1; |
---|
| 211 | l1 = 5; |
---|
| 212 | |
---|
| 213 | int i; |
---|
| 214 | for (i = 1; i < nb; ++i) |
---|
| 215 | { |
---|
| 216 | l1 += i; |
---|
| 217 | b1 ^= true; |
---|
| 218 | s1 = s1.read() ^ true; |
---|
| 219 | s3 = s3.read() + 2; |
---|
| 220 | s5 = s5.read() + 3; |
---|
| 221 | s7 = s7.read() + 4; |
---|
| 222 | s9 = s9.read() + 5; |
---|
[32] | 223 | s11 = (s11.read() << 2) + 1; |
---|
[1] | 224 | #if 0 |
---|
| 225 | #if defined(SYSTEMCASS_SPECIFIC) |
---|
| 226 | ui1 <<= 1; ui1 += 1; |
---|
| 227 | i1 <<= 1; i1 += 1; |
---|
| 228 | #endif |
---|
| 229 | #endif |
---|
| 230 | #if 0 |
---|
| 231 | cerr << test1.io4.read() << " " << s16.read() << "\n"; |
---|
| 232 | #endif |
---|
| 233 | sc_start (1); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | sc_close_vcd_trace_file (system_trace_file); |
---|
| 237 | |
---|
| 238 | return EXIT_SUCCESS; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | #undef sc_inout |
---|