Changeset 55 for sources/test_regression/19042005/system.cpp
- Timestamp:
- May 28, 2013, 11:17:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/test_regression/19042005/system.cpp
r49 r55 1 #include <systemc.h> 1 2 2 #include <stdint.h> 3 3 4 #define ASSERT(x) \ 5 { errnum++; \ 6 if (!(x)) \ 7 { \ 8 cerr << "ASSERT : " #x "\n"; \ 9 exit (errnum); \ 10 } \ 11 } 4 #include "systemc.h" 5 #include "test.h" 12 6 13 7 using namespace std; 14 8 15 //#define sc_inout sc_out 16 9 17 10 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; 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; 35 26 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; 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; 45 34 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 } 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 } 57 45 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 } 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 } 71 55 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 }; 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(); 61 62 SC_METHOD(gen); 63 sensitive << clk.neg(); 64 dont_initialize(); 65 } 66 81 67 }; 82 68 83 69 84 70 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"); 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"); 105 80 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); 81 test test1("test1"); 82 test1.clk(signal_clk); 83 test1.i1(s1); 84 test1.o1(s2); 85 test1.i2(s3); 86 test1.o2(s4); 87 test1.i3(s5); 88 test1.o3(s6); 89 test1.i4(s7); 90 test1.o4(s8); 91 test1.i5(s9); 92 test1.o5(s10); 93 test1.i6(s11); 94 test1.o6(s12); 95 test1.io1(s13); 96 test1.io4(s16); 124 97 125 126 sc_trace_file *system_trace_file;127 system_trace_file = sc_create_vcd_trace_file (argv[1]);128 129 98 /* Open trace file */ 99 sc_trace_file * system_trace_file; 100 system_trace_file = sc_create_vcd_trace_file("trace_file"); 101 /* clk waveform is always useful */ 102 sc_trace(system_trace_file, signal_clk, "clk"); 130 103 131 boolb1 = 0;132 uint64_t l1 = 0;104 bool b1 = 0; 105 uint64_t l1 = 0; 133 106 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 107 #define TRACE(x) sc_trace (system_trace_file, x, #x); 108 TRACE(b1); 109 TRACE(l1); 110 TRACE(test1.i1); 111 TRACE(test1.i2); 112 TRACE(test1.i3); 113 TRACE(test1.i4); 114 TRACE(test1.i5); 115 TRACE(test1.i6); 116 TRACE(test1.o1); 117 TRACE(test1.o2); 118 TRACE(test1.o3); 119 TRACE(test1.o4); 120 TRACE(test1.o5); 121 TRACE(test1.o6); 122 TRACE(test1.io1); 123 TRACE(test1.io4); 124 TRACE(s1); 125 TRACE(s2); 126 TRACE(s3); 127 TRACE(s4); 128 TRACE(s5); 129 TRACE(s6); 130 TRACE(s7); 131 TRACE(s8); 132 TRACE(s9); 133 TRACE(s10); 134 TRACE(s11); 135 TRACE(s12); 136 TRACE(s13); 137 TRACE(s16); 138 #undef TRACE 142 139 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 140 // Init & run 141 sc_start(sc_time(0, sc_core::SC_NS)); 179 142 180 // Init & run 181 sc_initialize (); 143 ASSERT(test1.i1.read() == false); 144 ASSERT(s4.read() == 0); 145 ASSERT(s10.read() == 0); 146 ASSERT(s16.read() == 0); 182 147 183 ASSERT(test1.i1.read() == false); 184 ASSERT(s4.read() == 0); 185 ASSERT(s10.read() == 0); 186 ASSERT(s16.read() == 0); 148 sc_start(sc_time(1, sc_core::SC_NS)); 187 149 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 150 b1 = 1; 151 l1 = 5; 200 152 201 if (argc == 2) 202 { 203 cout << "Usage :\n" << argv[0] << " [#cycles]\n"; 153 int i; 154 for (i = 1; i < 60; ++i) { 155 l1 += i; 156 b1 ^= true; 157 s1 = s1.read() ^ true; 158 s3 = s3.read() + 2; 159 s5 = s5.read() + 3; 160 s7 = s7.read() + 4; 161 s9 = s9.read() + 5; 162 s11 = (s11.read() << 2) + 1; 163 sc_start(sc_time(1, sc_core::SC_NS)); 164 } 165 166 sc_close_vcd_trace_file(system_trace_file); 167 204 168 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;224 s11 = (s11.read() << 2) + 1;225 #if 0226 #if defined(SYSTEMCASS_SPECIFIC)227 ui1 <<= 1; ui1 += 1;228 i1 <<= 1; i1 += 1;229 #endif230 #endif231 #if 0232 cerr << test1.io4.read() << " " << s16.read() << "\n";233 #endif234 sc_start (1);235 }236 237 sc_close_vcd_trace_file (system_trace_file);238 239 return EXIT_SUCCESS;240 169 } 241 170 242 171 #undef sc_inout 172 173 /* 174 # Local Variables: 175 # tab-width: 4; 176 # c-basic-offset: 4; 177 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 178 # indent-tabs-mode: nil; 179 # End: 180 # 181 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 182 */ 183
Note: See TracChangeset
for help on using the changeset viewer.