[1] | 1 | #include <systemc.h> |
---|
| 2 | #include <signal.h> |
---|
| 3 | #include "chrono.h" |
---|
| 4 | |
---|
| 5 | using namespace std; |
---|
| 6 | |
---|
| 7 | struct M1_3i3o : sc_module { |
---|
| 8 | sc_in_clk clk; |
---|
| 9 | sc_in<bool> i1; |
---|
| 10 | sc_in<bool> i2; |
---|
| 11 | sc_in<bool> i3; |
---|
| 12 | sc_out<bool> o1; |
---|
| 13 | sc_out<bool> o2; |
---|
| 14 | sc_out<bool> o3; |
---|
| 15 | |
---|
| 16 | sc_signal<bool> reg; |
---|
| 17 | |
---|
| 18 | void eval_mealy1 () { |
---|
| 19 | o1 = ~i1; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | void eval_mealy2 () { |
---|
| 23 | o2 = ~i2; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | void tr_moore () { |
---|
| 27 | reg = i3; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | void gen_moore () { |
---|
| 31 | o3 = ~reg; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | SC_CTOR (M1_3i3o) : clk("clk"), i1("i1"), o1("o1"), i2("i2"), o2("o2"), |
---|
| 35 | i3("i3"), o3("o3") { |
---|
| 36 | SC_METHOD(eval_mealy1); |
---|
| 37 | sensitive << clk.neg(); |
---|
| 38 | sensitive << i1; |
---|
| 39 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 40 | o1(i1); |
---|
| 41 | #endif |
---|
| 42 | SC_METHOD(eval_mealy2); |
---|
| 43 | sensitive << clk.neg(); |
---|
| 44 | sensitive << i2; |
---|
| 45 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 46 | o2(i2); |
---|
| 47 | #endif |
---|
| 48 | SC_METHOD(tr_moore); |
---|
| 49 | sensitive << clk.pos(); |
---|
| 50 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 51 | #endif |
---|
| 52 | SC_METHOD(gen_moore); |
---|
| 53 | sensitive << clk.neg(); |
---|
| 54 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 55 | #endif |
---|
| 56 | }; |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | struct M2_4i4o : sc_module { |
---|
| 61 | sc_in_clk clk; |
---|
| 62 | sc_in<bool> i1; |
---|
| 63 | sc_in<bool> i2; |
---|
| 64 | sc_in<bool> i3; |
---|
| 65 | sc_in<bool> i4; |
---|
| 66 | sc_out<bool> o1; |
---|
| 67 | sc_out<bool> o2; |
---|
| 68 | sc_out<bool> o3; |
---|
| 69 | sc_out<bool> o4; |
---|
| 70 | sc_signal<sc_uint<2> > reg; |
---|
| 71 | |
---|
| 72 | void tr_moore () { |
---|
| 73 | reg = ((i1.read() & i3.read())?2:0) + (i2.read() | i4.read()); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void gen_moore () { |
---|
| 77 | o1 = reg.read() & 1; |
---|
| 78 | o2 = reg.read() & 2; |
---|
| 79 | o3 = ~(reg.read() & 1); |
---|
| 80 | o4 = ~(reg.read() & 2); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | SC_CTOR (M2_4i4o) : clk ("clk"), i1 ("i1"), o1("o1"), i2 ("i2"), o2 ("o2"), i3 ("i3"), o3("o3"), i4 ("i4"), o4 ("o4") { |
---|
| 84 | SC_METHOD(tr_moore); |
---|
| 85 | sensitive << clk.pos(); |
---|
| 86 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 87 | // no needs |
---|
| 88 | #endif |
---|
| 89 | SC_METHOD(gen_moore); |
---|
| 90 | sensitive << clk.neg(); |
---|
| 91 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 92 | #endif |
---|
| 93 | }; |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | int sc_main (int argc, char *argv[]) |
---|
| 97 | { |
---|
| 98 | sc_clock signal_clk("my_clock",1, 0.5); |
---|
| 99 | sc_signal<bool> s1 ("s01"), |
---|
| 100 | s2 ("s02"), |
---|
| 101 | s3 ("s03"), |
---|
| 102 | s4 ("s04"), |
---|
| 103 | s5 ("s05"), |
---|
| 104 | s6 ("s06"), |
---|
| 105 | s7 ("s07"), |
---|
| 106 | s8 ("s08"), |
---|
| 107 | s9 ("s09"), |
---|
| 108 | s10("s10"), |
---|
| 109 | s11("s11"), |
---|
| 110 | s12("s12"), |
---|
| 111 | s13("s13"), |
---|
| 112 | s14("s14"), |
---|
| 113 | s15("s15"); |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | M1_3i3o a ("a"); |
---|
| 117 | M1_3i3o b ("b"); |
---|
| 118 | M2_4i4o Moore("Moore"); |
---|
| 119 | |
---|
| 120 | a.clk (signal_clk); |
---|
| 121 | b.clk (signal_clk); |
---|
| 122 | Moore.clk (signal_clk); |
---|
| 123 | |
---|
| 124 | Moore.o1 (s1); |
---|
| 125 | a.i1 (s1); |
---|
| 126 | |
---|
| 127 | a.o1 (s2); |
---|
| 128 | b.i1 (s2); |
---|
| 129 | |
---|
| 130 | b.o1 (s3); |
---|
| 131 | Moore.i1 (s3); |
---|
| 132 | |
---|
| 133 | Moore.o2 (s4); |
---|
| 134 | b.i2 (s4); |
---|
| 135 | |
---|
| 136 | b.o2 (s5); |
---|
| 137 | a.i2 (s5); |
---|
| 138 | |
---|
| 139 | a.o2 (s6); |
---|
| 140 | Moore.i2 (s6); |
---|
| 141 | |
---|
| 142 | Moore.o3 (s7); |
---|
| 143 | b.i3 (s7); |
---|
| 144 | |
---|
| 145 | Moore.o4 (s8); |
---|
| 146 | a.i3 (s8); |
---|
| 147 | |
---|
| 148 | b.o3 (s9); |
---|
| 149 | Moore.i4 (s9); |
---|
| 150 | |
---|
| 151 | a.o3 (s10); |
---|
| 152 | Moore.i3 (s10); |
---|
| 153 | |
---|
| 154 | // Init & run |
---|
| 155 | sc_initialize (); |
---|
| 156 | |
---|
| 157 | if (argc == 1) |
---|
| 158 | { |
---|
| 159 | cout << "Usage :\n" << argv[0] << " [#cycles]\n"; |
---|
| 160 | return EXIT_SUCCESS; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | chrono_t chrono; |
---|
| 164 | chrono.start (); |
---|
| 165 | |
---|
| 166 | sc_start (atoi(argv[1])); |
---|
| 167 | |
---|
| 168 | chrono.stop (); |
---|
| 169 | unsigned int t = chrono; |
---|
| 170 | cout << "Time elapsed (sec) : " << t << endl; |
---|
| 171 | cout << "Cycles done : " << sc_simulation_time () << endl; |
---|
| 172 | cout << "Performance : " << sc_simulation_time () / t << endl; |
---|
| 173 | return EXIT_SUCCESS; |
---|
| 174 | } |
---|