Changeset 55 for sources/test_regression/25032005/system.cpp
- Timestamp:
- May 28, 2013, 11:17:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/test_regression/25032005/system.cpp
r35 r55 1 #include <systemc.h>2 1 #include <signal.h> 3 #include "chrono.h" 2 3 #include "systemc.h" 4 #include "test.h" 5 4 6 5 7 using namespace std; 6 8 7 9 struct A : sc_module { 8 sc_in_clkclk;9 sc_out<bool>o1;10 sc_in_clk clk; 11 sc_out<bool> o1; 10 12 11 void eval() {12 o1 = (rand()%2) == 0;13 }13 void eval() { 14 o1 = (rand() % 2) == 0; 15 } 14 16 15 SC_CTOR (A) : clk ("clk"), o1("o1") { 16 SC_METHOD(eval); 17 sensitive << clk.neg(); 18 #ifdef SYSTEMCASS_SPECIFIC 19 // s1(); 20 #endif 21 }; 17 SC_CTOR (A) : clk("clk"), o1("o1") { 18 SC_METHOD(eval); 19 sensitive << clk.neg(); 20 dont_initialize(); 21 } 22 22 }; 23 23 24 24 25 struct B : sc_module { 25 sc_in_clkclk;26 sc_in<bool>i1;27 sc_in<bool> i2;28 sc_out<bool> o1;29 sc_out<bool>o2;26 sc_in_clk clk; 27 sc_in<bool> i1; 28 sc_out<bool> o1; 29 sc_in<bool> i2; 30 sc_out<bool> o2; 30 31 31 void eval1 () { 32 o1 = ~i1; 33 } 34 void eval2 () { 35 o2 = ~i2; 36 } 32 void eval1() { 33 o1 = ~i1; 34 } 37 35 38 SC_CTOR (B) : clk ("clk"), i1 ("i1"), o1("o1"), i2 ("i2"), o2 ("o2") { 39 SC_METHOD(eval1); 40 sensitive << clk.neg(); 41 sensitive << i1; 36 void eval2() { 37 o2 = ~i2; 38 } 39 40 SC_CTOR (B) : clk("clk"), i1("i1"), o1("o1"), i2("i2"), o2("o2") { 41 SC_METHOD(eval1); 42 sensitive << clk.neg(); 43 sensitive << i1; 44 dont_initialize(); 42 45 #ifdef SYSTEMCASS_SPECIFIC 43 o1(i1);46 o1(i1); 44 47 #endif 45 SC_METHOD(eval2); 46 sensitive << clk.neg(); 47 sensitive << i2; 48 SC_METHOD(eval2); 49 sensitive << clk.neg(); 50 sensitive << i2; 51 dont_initialize(); 48 52 #ifdef SYSTEMCASS_SPECIFIC 49 o2(i2);53 o2(i2); 50 54 #endif 51 }; 55 } 56 52 57 }; 53 58 59 54 60 struct C : sc_module { 55 sc_in_clkclk;56 sc_in<bool>i1;57 sc_in<bool> i2;58 sc_out<bool> o1;61 sc_in_clk clk; 62 sc_in<bool> i1; 63 sc_out<bool> o1; 64 sc_in<bool> i2; 59 65 60 void eval1() {61 o1 = i1 ^ i2;62 }66 void eval1() { 67 o1 = i1 ^ i2; 68 } 63 69 64 SC_CTOR (C) : clk ("clk"), i1 ("i1"), o1("o1"), i2 ("i2") { 65 SC_METHOD(eval1); 66 sensitive << clk.neg(); 67 sensitive << i1 << i2; 70 SC_CTOR (C) : clk ("clk"), i1("i1"), o1("o1"), i2("i2") { 71 SC_METHOD(eval1); 72 sensitive << clk.neg(); 73 sensitive << i1 << i2; 74 dont_initialize(); 68 75 #ifdef SYSTEMCASS_SPECIFIC 69 o1(i1);70 o1(i2);76 o1(i1); 77 o1(i2); 71 78 #endif 72 }; 79 } 80 73 81 }; 74 82 83 75 84 struct D : sc_module { 76 sc_in_clkclk;77 sc_out<bool>o1;85 sc_in_clk clk; 86 sc_out<bool> o1; 78 87 79 void eval() {80 o1 = (rand()%2) == 0;81 }88 void eval() { 89 o1 = (rand() % 2) == 0; 90 } 82 91 83 SC_CTOR (D) : clk ("clk"), o1("o1") { 84 SC_METHOD(eval); 85 sensitive << clk.neg(); 86 #ifdef SYSTEMCASS_SPECIFIC 87 // s1(); 88 #endif 89 }; 92 SC_CTOR (D) : clk("clk"), o1("o1") { 93 SC_METHOD(eval); 94 sensitive << clk.neg(); 95 dont_initialize(); 96 } 97 90 98 }; 91 99 92 int sc_main (int argc, char *argv[])93 {94 sc_clock signal_clk("my_clock",1, 0.5);95 sc_signal<bool> s1("s1"),s2("s2"),s3("s3"),s4("s4"),s5("s5");96 100 97 A a("a"); 98 B b("b"); 99 C c("c"); 100 D d("d"); 101 102 a.clk (signal_clk); 103 b.clk (signal_clk); 104 c.clk (signal_clk); 105 d.clk (signal_clk); 106 107 a.o1 (s1); 108 b.i1 (s1); 109 110 d.o1 (s2); 111 c.i2 (s2); 101 int sc_main (int argc, char * argv[]) { 102 sc_clock signal_clk("my_clock"); 103 sc_signal<bool> s1("s1"), s2("s2"), s3("s3"), s4("s4"), s5("s5"); 112 104 113 b.o1 (s3); 114 c.i1 (s3); 115 116 c.o1 (s4); 117 b.i2 (s4); 118 119 b.o2 (s5); 120 121 // Init & run 122 sc_initialize (); 105 A a("a"); 106 B b("b"); 107 C c("c"); 108 D d("d"); 123 109 124 if (argc == 1) 125 { 126 cout << "Usage :\n" << argv[0] << " [#cycles]\n"; 110 a.clk(signal_clk); 111 b.clk(signal_clk); 112 c.clk(signal_clk); 113 d.clk(signal_clk); 114 115 a.o1(s1); 116 b.i1(s1); 117 118 d.o1(s2); 119 c.i2(s2); 120 121 b.o1(s3); 122 c.i1(s3); 123 124 c.o1(s4); 125 b.i2(s4); 126 127 b.o2(s5); 128 129 // Init & run 130 sc_start(sc_time(1, sc_core::SC_NS)); 131 127 132 return EXIT_SUCCESS; 128 133 } 129 134 130 chrono_t chrono;131 chrono.start ();132 135 133 sc_start (atoi(argv[1])); 136 /* 137 # Local Variables: 138 # tab-width: 4; 139 # c-basic-offset: 4; 140 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 141 # indent-tabs-mode: nil; 142 # End: 143 # 144 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 145 */ 134 146 135 chrono.stop ();136 unsigned int t = chrono;137 cout << "Time elapsed (sec) : " << t << endl;138 cout << "Cycles done : " << sc_simulation_time () << endl;139 cout << "Performance : " << sc_simulation_time () / t << endl;140 printf("\nPress <RETURN> to exit simulation.");141 char buf_ret[2];142 cin.getline(buf_ret,1);143 return EXIT_SUCCESS;144 }
Note: See TracChangeset
for help on using the changeset viewer.