| 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 | // Setup number of threads open-mp to 1 with the macro threads_omp() |
|---|
| 85 | threads_omp(); |
|---|
| 86 | |
|---|
| 87 | t.clk(clk); |
|---|
| 88 | t.o(out); |
|---|
| 89 | |
|---|
| 90 | // QM : pourquoi est-ce tout commenté ?? |
|---|
| 91 | #if 0 |
|---|
| 92 | /* Open trace file */ |
|---|
| 93 | sc_trace_file *system_trace_file; |
|---|
| 94 | system_trace_file = sc_create_vcd_trace_file ("trace_file"); |
|---|
| 95 | |
|---|
| 96 | /* clks waveforms are always useful */ |
|---|
| 97 | sc_trace(system_trace_file, clk1, "clk1"); |
|---|
| 98 | sc_trace(system_trace_file, clk2, "clk2"); |
|---|
| 99 | |
|---|
| 100 | /* others signals */ |
|---|
| 101 | for (int i = 0; i < 10; ++i) |
|---|
| 102 | sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s")); |
|---|
| 103 | #endif |
|---|
| 104 | |
|---|
| 105 | sc_start(sc_time(0, sc_core::SC_NS)); |
|---|
| 106 | |
|---|
| 107 | /* simulation */ |
|---|
| 108 | int i = 0; |
|---|
| 109 | while (i++ < 5) { |
|---|
| 110 | sc_start(sc_time(1, sc_core::SC_NS)); |
|---|
| 111 | cout << out.read() << " - " << t.obs1.i.read() << " - " << t.obs2.i.read() << endl; |
|---|
| 112 | } |
|---|
| 113 | return 0; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | /* |
|---|
| 118 | # Local Variables: |
|---|
| 119 | # tab-width: 4; |
|---|
| 120 | # c-basic-offset: 4; |
|---|
| 121 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
|---|
| 122 | # indent-tabs-mode: nil; |
|---|
| 123 | # End: |
|---|
| 124 | # |
|---|
| 125 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 126 | */ |
|---|
| 127 | |
|---|