Changeset 55 for sources/test_regression/09092005c/system.cpp
- Timestamp:
- May 28, 2013, 11:17:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/test_regression/09092005c/system.cpp
r1 r55 1 1 2 #include "systemc.h" 3 2 4 #include <iostream> 5 6 #include "test.h" 3 7 4 8 using namespace std; 5 9 6 #define ASSERT(x) \7 { errnum++; \8 if (!(x)) \9 { \10 cerr << "ASSERT : " #x "\n"; \11 exit (errnum); \12 } \13 }14 10 15 using namespace std; 11 struct observer : sc_module { 12 sc_in_clk clk; 16 13 17 struct observer : sc_module 18 { 19 sc_in_clk clk; 14 sc_in<int> i; 20 15 21 sc_in<int> i;16 void f() {} 22 17 23 void f () 24 { 25 #if 0 26 cerr << i.read(); 27 #endif 28 } 29 30 SC_HAS_PROCESS(observer); 31 observer(sc_module_name) : clk ("clk"), 32 i ("i") 33 34 { 35 SC_METHOD(f); 36 dont_initialize(); 37 sensitive << clk.pos(); 38 #ifdef SYSTEMCASS_SPECIFIC 39 #endif 40 } 18 SC_HAS_PROCESS(observer); 19 observer(sc_module_name) : clk ("clk"), 20 i("i") { 21 SC_METHOD(f); 22 sensitive << clk.pos(); 23 dont_initialize(); 24 } 41 25 }; 42 26 43 struct generator : sc_module44 {45 sc_in_clk clk;46 27 47 sc_out<int> o; 28 struct generator : sc_module { 29 sc_in_clk clk; 30 sc_out<int> o; 48 31 49 void f () 50 { 51 int t = (int) (sc_time_stamp ().to_double()); 52 #if 0 53 cerr << "f = " << t << endl; 54 #endif 55 o.write(t); 56 } 32 void f() { 33 int t = (int) (sc_time_stamp().to_double()); 34 o.write(t); 35 } 57 36 58 SC_HAS_PROCESS(generator); 59 generator(sc_module_name) : clk ("clk"), 60 o ("o") 61 { 62 SC_METHOD(f); 63 dont_initialize(); 64 sensitive << clk.neg(); 65 #ifdef SYSTEMCASS_SPECIFIC 66 #endif 67 } 37 SC_HAS_PROCESS(generator); 38 generator(sc_module_name) : clk("clk"), o("o") { 39 SC_METHOD(f); 40 sensitive << clk.neg(); 41 dont_initialize(); 42 } 43 68 44 }; 69 45 70 struct top_level : sc_module71 {72 sc_in_clk clk;73 74 sc_out<int> o;75 // sc_out<int> io;76 // sc_signal<int> s;77 // sc_signal<int> s2;78 46 79 generator g;80 observer obs1, obs2;81 82 SC_HAS_PROCESS(top_level);83 top_level(sc_module_name) : g ("generator"),84 obs1("observer1"),85 obs2("observer2"),86 clk ("clk"),87 o ("o")/*,88 s ("s")*/89 {90 g.clk (clk);91 obs1.clk (clk);92 obs2.clk (clk);93 47 94 g.o (o); 95 obs1.i(o); 96 obs2.i(o); 97 } 48 struct top_level : sc_module { 49 sc_in_clk clk; 50 51 sc_out<int> o; 52 53 generator g; 54 observer obs1, obs2; 55 56 SC_HAS_PROCESS(top_level); 57 top_level(sc_module_name) : 58 clk("clk"), 59 o("o"), 60 g("generator"), 61 obs1("observer1"), 62 obs2("observer2"){ 63 g.clk(clk); 64 obs1.clk(clk); 65 obs2.clk(clk); 66 67 g.o(o); 68 obs1.i(o); 69 obs2.i(o); 70 } 71 98 72 }; 99 73 100 int101 sc_main (int argc, char ** argv)102 {103 int errnum = 0;104 sc_clock clk("top_clk");105 sc_signal<int> out("top_out");106 74 107 top_level t("top_level"); 75 int sc_main (int argc, char ** argv) { 76 sc_clock clk("top_clk"); 77 sc_signal<int> out("top_out"); 108 78 109 t.clk (clk); 110 t.o (out); 79 top_level t("top_level"); 111 80 81 t.clk(clk); 82 t.o (out); 83 84 // QM : pourquoi est-ce tout commenté ?? 112 85 #if 0 113 /* Open trace file */ 114 sc_trace_file *system_trace_file; 115 system_trace_file = sc_create_vcd_trace_file ("trace_file"); 116 117 /* clks waveforms are always useful */ 118 sc_trace(system_trace_file, clk1, "clk1"); 119 sc_trace(system_trace_file, clk2, "clk2"); 86 /* Open trace file */ 87 sc_trace_file *system_trace_file; 88 system_trace_file = sc_create_vcd_trace_file ("trace_file"); 120 89 121 /* others signals */ 122 for (int i = 0; i < 10; ++i) 123 sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s")); 90 /* clks waveforms are always useful */ 91 sc_trace(system_trace_file, clk1, "clk1"); 92 sc_trace(system_trace_file, clk2, "clk2"); 93 94 /* others signals */ 95 for (int i = 0; i < 10; ++i) 96 sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s")); 124 97 #endif 125 98 126 /* initilization */ 127 #if 0 128 cout << "initilization...\n"; 129 #endif 130 sc_initialize (); 99 sc_start(sc_time(0, sc_core::SC_NS)); 131 100 132 /* simulation */ 133 #if 0 134 cout << "simulation...\n"; 135 #endif 136 int i = 0; 137 while (i++ < 5) 138 { 139 sc_start (1); 140 ASSERT(out.read() == t.obs1.i.read()) 141 ASSERT(out.read() == t.obs2.i.read()) 142 } 143 144 #if 0 145 cout << "\ndone.\n"; 146 #endif 147 148 return 0; 101 /* simulation */ 102 int i = 0; 103 while (i++ < 5) { 104 sc_start(sc_time(1, sc_core::SC_NS)); 105 cout << out.read() << " - " << t.obs1.i.read() << " - " << t.obs2.i.read() << endl; 106 } 107 return 0; 149 108 } 150 109 110 111 /* 112 # Local Variables: 113 # tab-width: 4; 114 # c-basic-offset: 4; 115 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 116 # indent-tabs-mode: nil; 117 # End: 118 # 119 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 120 */ 121
Note: See TracChangeset
for help on using the changeset viewer.