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