| 1 |  | 
|---|
| 2 | #include "systemc.h" | 
|---|
| 3 |  | 
|---|
| 4 | #include <iostream> | 
|---|
| 5 |  | 
|---|
| 6 | #include "test.h" | 
|---|
| 7 |  | 
|---|
| 8 | using namespace std; | 
|---|
| 9 |  | 
|---|
| 10 |  | 
|---|
| 11 | struct observer : sc_module { | 
|---|
| 12 | sc_in_clk clk; | 
|---|
| 13 |  | 
|---|
| 14 | sc_in<int> i; | 
|---|
| 15 |  | 
|---|
| 16 | void f() {} | 
|---|
| 17 |  | 
|---|
| 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 | } | 
|---|
| 25 | }; | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | struct generator : sc_module { | 
|---|
| 29 | sc_in_clk clk; | 
|---|
| 30 | sc_out<int> o; | 
|---|
| 31 |  | 
|---|
| 32 | void f() { | 
|---|
| 33 | int t = (int) (sc_time_stamp().to_double()); | 
|---|
| 34 | #ifdef SYSTEMCASS_SPECIFIC | 
|---|
| 35 | t = t * 1000; | 
|---|
| 36 | #endif | 
|---|
| 37 | o.write(t); | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | SC_HAS_PROCESS(generator); | 
|---|
| 41 | generator(sc_module_name) : clk("clk"), o("o") { | 
|---|
| 42 | SC_METHOD(f); | 
|---|
| 43 | sensitive << clk.pos(); | 
|---|
| 44 | dont_initialize(); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | }; | 
|---|
| 48 |  | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 | struct top_level : sc_module { | 
|---|
| 52 | sc_in_clk clk; | 
|---|
| 53 |  | 
|---|
| 54 | sc_out<int> o; | 
|---|
| 55 |  | 
|---|
| 56 | generator g; | 
|---|
| 57 | observer obs1, obs2; | 
|---|
| 58 |  | 
|---|
| 59 | SC_HAS_PROCESS(top_level); | 
|---|
| 60 | top_level(sc_module_name) : | 
|---|
| 61 | clk("clk"), | 
|---|
| 62 | o("o"), | 
|---|
| 63 | g("generator"), | 
|---|
| 64 | obs1("observer1"), | 
|---|
| 65 | obs2("observer2") { | 
|---|
| 66 | g.clk(clk); | 
|---|
| 67 | obs1.clk(clk); | 
|---|
| 68 | obs2.clk(clk); | 
|---|
| 69 |  | 
|---|
| 70 | g.o(o); | 
|---|
| 71 | obs1.i(o); | 
|---|
| 72 | obs2.i(o); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | }; | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 | int sc_main (int argc, char ** argv) { | 
|---|
| 79 | sc_clock clk("top_clk", sc_time(1, sc_core::SC_NS)); | 
|---|
| 80 | sc_signal<int> out("top_out"); | 
|---|
| 81 |  | 
|---|
| 82 | top_level t("top_level"); | 
|---|
| 83 |  | 
|---|
| 84 | t.clk(clk); | 
|---|
| 85 | t.o(out); | 
|---|
| 86 |  | 
|---|
| 87 | // QM : pourquoi est-ce tout commenté ?? | 
|---|
| 88 | #if 0 | 
|---|
| 89 | /* Open trace file */ | 
|---|
| 90 | sc_trace_file *system_trace_file; | 
|---|
| 91 | system_trace_file = sc_create_vcd_trace_file ("trace_file"); | 
|---|
| 92 |  | 
|---|
| 93 | /* clks waveforms are always useful */ | 
|---|
| 94 | sc_trace(system_trace_file, clk1, "clk1"); | 
|---|
| 95 | sc_trace(system_trace_file, clk2, "clk2"); | 
|---|
| 96 |  | 
|---|
| 97 | /* others signals */ | 
|---|
| 98 | for (int i = 0; i < 10; ++i) | 
|---|
| 99 | sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s")); | 
|---|
| 100 | #endif | 
|---|
| 101 |  | 
|---|
| 102 | sc_start(sc_time(0, sc_core::SC_NS)); | 
|---|
| 103 |  | 
|---|
| 104 | /* simulation */ | 
|---|
| 105 | int i = 0; | 
|---|
| 106 | while (i++ < 5) { | 
|---|
| 107 | sc_start(sc_time(1, sc_core::SC_NS)); | 
|---|
| 108 | cout << out.read() << " - " << t.obs1.i.read() << " - " << t.obs2.i.read() << endl; | 
|---|
| 109 | } | 
|---|
| 110 | return 0; | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 |  | 
|---|
| 114 | /* | 
|---|
| 115 | # Local Variables: | 
|---|
| 116 | # tab-width: 4; | 
|---|
| 117 | # c-basic-offset: 4; | 
|---|
| 118 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); | 
|---|
| 119 | # indent-tabs-mode: nil; | 
|---|
| 120 | # End: | 
|---|
| 121 | # | 
|---|
| 122 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
| 123 | */ | 
|---|
| 124 |  | 
|---|