[55] | 1 | |
---|
[49] | 2 | #include <stdint.h> |
---|
[1] | 3 | |
---|
[55] | 4 | #include "systemc.h" |
---|
| 5 | #include "test.h" |
---|
[1] | 6 | |
---|
| 7 | using namespace std; |
---|
| 8 | |
---|
[55] | 9 | |
---|
[1] | 10 | struct test : sc_module { |
---|
[55] | 11 | sc_in_clk clk; |
---|
| 12 | sc_in<bool> i1; |
---|
| 13 | sc_in<char> i2; |
---|
| 14 | sc_in<int> i3; |
---|
| 15 | sc_in<sc_int<4> > i4; |
---|
| 16 | sc_in<sc_uint<4> > i5; |
---|
| 17 | sc_in<sc_uint<64> > i6; |
---|
| 18 | sc_out<bool> o1; |
---|
| 19 | sc_out<char> o2; |
---|
| 20 | sc_out<int > o3; |
---|
| 21 | sc_out<sc_int<4> > o4; |
---|
| 22 | sc_out<sc_uint<4> > o5; |
---|
| 23 | sc_out<sc_uint<64> > o6; |
---|
| 24 | sc_inout<sc_uint<64> > io1; |
---|
| 25 | sc_inout<sc_uint<32> > io4; |
---|
[1] | 26 | |
---|
[55] | 27 | sc_signal<bool> reg1; |
---|
| 28 | sc_signal<char> reg2; |
---|
| 29 | sc_signal<int> reg3; |
---|
| 30 | sc_signal<sc_int<4> > reg4; |
---|
| 31 | sc_signal<sc_uint<4> > reg5; |
---|
| 32 | sc_signal<sc_uint<64> > reg6; |
---|
| 33 | sc_signal<sc_uint<32> > reg9; |
---|
[1] | 34 | |
---|
[55] | 35 | void gen() { |
---|
| 36 | o1 = reg1.read() ^ true; |
---|
| 37 | o2 = reg2.read() + 1; |
---|
| 38 | o3 = reg3.read() + 1; |
---|
| 39 | o4 = reg4.read() + 1; |
---|
| 40 | o5 = reg5.read() + 1; |
---|
| 41 | o6 = reg6.read() + 1; |
---|
| 42 | io1 = reg6.read() * 2 + 1; |
---|
| 43 | io4 = reg9.read() + 1; |
---|
| 44 | } |
---|
[1] | 45 | |
---|
[55] | 46 | void trans() { |
---|
| 47 | reg1 = reg1.read() ^ 1; |
---|
| 48 | reg2 = reg2.read() + 1; |
---|
| 49 | reg3 = reg3.read() + 1; |
---|
| 50 | reg4 = reg4.read() + 1; |
---|
| 51 | reg5 = reg5.read() + 1; |
---|
| 52 | reg6 = reg6.read() * 2 + 1; |
---|
| 53 | reg9 = reg9.read() + 1; |
---|
| 54 | } |
---|
[1] | 55 | |
---|
[55] | 56 | SC_CTOR (test) : clk("clk"), i1("i1"), i2("i2"), i3("i3"), o1("o1"), |
---|
| 57 | o2("o2"), o3("o3"), io1("io1"), io4("io4"), reg9("reg9") { |
---|
| 58 | SC_METHOD(trans); |
---|
| 59 | sensitive << clk.pos(); |
---|
| 60 | dont_initialize(); |
---|
[1] | 61 | |
---|
[55] | 62 | SC_METHOD(gen); |
---|
| 63 | sensitive << clk.neg(); |
---|
| 64 | dont_initialize(); |
---|
| 65 | } |
---|
[1] | 66 | |
---|
[55] | 67 | }; |
---|
[1] | 68 | |
---|
| 69 | |
---|
| 70 | |
---|
[55] | 71 | int sc_main (int argc, char * argv[]) { |
---|
| 72 | sc_clock signal_clk("my_clock", 1, 0.5); |
---|
| 73 | sc_signal<bool> s1 ("s01"), s2 ("s02"); |
---|
| 74 | sc_signal<char> s3 ("s03"), s4 ("s04"); |
---|
| 75 | sc_signal<int> s5 ("s05"), s6 ("s06"); |
---|
| 76 | sc_signal< sc_int<4> > s7 ("s07"), s8 ("s08"); |
---|
| 77 | sc_signal< sc_uint<4> > s9 ("s09"), s10("s10"); |
---|
| 78 | sc_signal< sc_uint<64> > s11("s11"), s12("s12"), s13("s13"); |
---|
| 79 | sc_signal< sc_uint<32> > s16("s16"); |
---|
[1] | 80 | |
---|
[60] | 81 | // Setup number of threads open-mp to 1 with the macro threads_omp() |
---|
| 82 | threads_omp(); |
---|
| 83 | |
---|
[55] | 84 | test test1("test1"); |
---|
| 85 | test1.clk(signal_clk); |
---|
| 86 | test1.i1(s1); |
---|
| 87 | test1.o1(s2); |
---|
| 88 | test1.i2(s3); |
---|
| 89 | test1.o2(s4); |
---|
| 90 | test1.i3(s5); |
---|
| 91 | test1.o3(s6); |
---|
| 92 | test1.i4(s7); |
---|
| 93 | test1.o4(s8); |
---|
| 94 | test1.i5(s9); |
---|
| 95 | test1.o5(s10); |
---|
| 96 | test1.i6(s11); |
---|
| 97 | test1.o6(s12); |
---|
| 98 | test1.io1(s13); |
---|
| 99 | test1.io4(s16); |
---|
[1] | 100 | |
---|
[55] | 101 | /* Open trace file */ |
---|
| 102 | sc_trace_file * system_trace_file; |
---|
| 103 | system_trace_file = sc_create_vcd_trace_file("trace_file"); |
---|
| 104 | /* clk waveform is always useful */ |
---|
| 105 | sc_trace(system_trace_file, signal_clk, "clk"); |
---|
[1] | 106 | |
---|
[55] | 107 | bool b1 = 0; |
---|
| 108 | uint64_t l1 = 0; |
---|
[1] | 109 | |
---|
[55] | 110 | #define TRACE(x) sc_trace (system_trace_file, x, #x); |
---|
| 111 | TRACE(b1); |
---|
| 112 | TRACE(l1); |
---|
| 113 | TRACE(test1.i1); |
---|
| 114 | TRACE(test1.i2); |
---|
| 115 | TRACE(test1.i3); |
---|
| 116 | TRACE(test1.i4); |
---|
| 117 | TRACE(test1.i5); |
---|
| 118 | TRACE(test1.i6); |
---|
| 119 | TRACE(test1.o1); |
---|
| 120 | TRACE(test1.o2); |
---|
| 121 | TRACE(test1.o3); |
---|
| 122 | TRACE(test1.o4); |
---|
| 123 | TRACE(test1.o5); |
---|
| 124 | TRACE(test1.o6); |
---|
| 125 | TRACE(test1.io1); |
---|
| 126 | TRACE(test1.io4); |
---|
| 127 | TRACE(s1); |
---|
| 128 | TRACE(s2); |
---|
| 129 | TRACE(s3); |
---|
| 130 | TRACE(s4); |
---|
| 131 | TRACE(s5); |
---|
| 132 | TRACE(s6); |
---|
| 133 | TRACE(s7); |
---|
| 134 | TRACE(s8); |
---|
| 135 | TRACE(s9); |
---|
| 136 | TRACE(s10); |
---|
| 137 | TRACE(s11); |
---|
| 138 | TRACE(s12); |
---|
| 139 | TRACE(s13); |
---|
| 140 | TRACE(s16); |
---|
| 141 | #undef TRACE |
---|
[1] | 142 | |
---|
[55] | 143 | // Init & run |
---|
| 144 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
[1] | 145 | |
---|
[55] | 146 | ASSERT(test1.i1.read() == false); |
---|
| 147 | ASSERT(s4.read() == 0); |
---|
| 148 | ASSERT(s10.read() == 0); |
---|
| 149 | ASSERT(s16.read() == 0); |
---|
[1] | 150 | |
---|
[55] | 151 | sc_start(sc_time(1, sc_core::SC_NS)); |
---|
[1] | 152 | |
---|
[55] | 153 | b1 = 1; |
---|
| 154 | l1 = 5; |
---|
[1] | 155 | |
---|
[55] | 156 | int i; |
---|
| 157 | for (i = 1; i < 60; ++i) { |
---|
| 158 | l1 += i; |
---|
| 159 | b1 ^= true; |
---|
| 160 | s1 = s1.read() ^ true; |
---|
| 161 | s3 = s3.read() + 2; |
---|
| 162 | s5 = s5.read() + 3; |
---|
| 163 | s7 = s7.read() + 4; |
---|
| 164 | s9 = s9.read() + 5; |
---|
| 165 | s11 = (s11.read() << 2) + 1; |
---|
| 166 | sc_start(sc_time(1, sc_core::SC_NS)); |
---|
| 167 | } |
---|
[1] | 168 | |
---|
[55] | 169 | sc_close_vcd_trace_file(system_trace_file); |
---|
[1] | 170 | |
---|
[55] | 171 | return EXIT_SUCCESS; |
---|
[1] | 172 | } |
---|
| 173 | |
---|
| 174 | #undef sc_inout |
---|
[55] | 175 | |
---|
| 176 | /* |
---|
| 177 | # Local Variables: |
---|
| 178 | # tab-width: 4; |
---|
| 179 | # c-basic-offset: 4; |
---|
| 180 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 181 | # indent-tabs-mode: nil; |
---|
| 182 | # End: |
---|
| 183 | # |
---|
| 184 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 185 | */ |
---|
| 186 | |
---|