[55] | 1 | |
---|
[1] | 2 | #include "systemc.h" |
---|
[55] | 3 | |
---|
[1] | 4 | #include <iostream> |
---|
| 5 | |
---|
[55] | 6 | #include "test.h" |
---|
[1] | 7 | |
---|
| 8 | using namespace std; |
---|
| 9 | |
---|
| 10 | |
---|
[55] | 11 | struct observer : sc_module { |
---|
| 12 | sc_in_clk clk; |
---|
[1] | 13 | |
---|
[55] | 14 | sc_in<int> i; |
---|
[1] | 15 | |
---|
[55] | 16 | void f() {} |
---|
[1] | 17 | |
---|
[55] | 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 | } |
---|
[1] | 25 | }; |
---|
| 26 | |
---|
| 27 | |
---|
[55] | 28 | struct generator : sc_module { |
---|
| 29 | sc_in_clk clk; |
---|
| 30 | sc_out<int> o; |
---|
[1] | 31 | |
---|
[55] | 32 | void f() { |
---|
| 33 | int t = (int) (sc_time_stamp().to_double()); |
---|
[56] | 34 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 35 | t = t * 1000; |
---|
| 36 | #endif |
---|
[55] | 37 | o.write(t); |
---|
| 38 | } |
---|
[1] | 39 | |
---|
[55] | 40 | SC_HAS_PROCESS(generator); |
---|
| 41 | generator(sc_module_name) : clk("clk"), o("o") { |
---|
| 42 | SC_METHOD(f); |
---|
[56] | 43 | sensitive << clk.pos(); |
---|
[55] | 44 | dont_initialize(); |
---|
| 45 | } |
---|
| 46 | |
---|
[1] | 47 | }; |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | |
---|
[55] | 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"), |
---|
[56] | 65 | obs2("observer2") { |
---|
[55] | 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 | |
---|
[1] | 75 | }; |
---|
| 76 | |
---|
| 77 | |
---|
[55] | 78 | int sc_main (int argc, char ** argv) { |
---|
[56] | 79 | sc_clock clk("top_clk", sc_time(1, sc_core::SC_NS)); |
---|
[55] | 80 | sc_signal<int> out("top_out"); |
---|
[1] | 81 | |
---|
[55] | 82 | top_level t("top_level"); |
---|
[1] | 83 | |
---|
[60] | 84 | // Setup number of threads open-mp to 1 with the macro threads_omp() |
---|
| 85 | threads_omp(); |
---|
| 86 | |
---|
[55] | 87 | t.clk(clk); |
---|
[56] | 88 | t.o(out); |
---|
[55] | 89 | |
---|
| 90 | // QM : pourquoi est-ce tout commenté ?? |
---|
[1] | 91 | #if 0 |
---|
[55] | 92 | /* Open trace file */ |
---|
| 93 | sc_trace_file *system_trace_file; |
---|
| 94 | system_trace_file = sc_create_vcd_trace_file ("trace_file"); |
---|
[1] | 95 | |
---|
[55] | 96 | /* clks waveforms are always useful */ |
---|
| 97 | sc_trace(system_trace_file, clk1, "clk1"); |
---|
| 98 | sc_trace(system_trace_file, clk2, "clk2"); |
---|
[1] | 99 | |
---|
[55] | 100 | /* others signals */ |
---|
| 101 | for (int i = 0; i < 10; ++i) |
---|
| 102 | sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s")); |
---|
[1] | 103 | #endif |
---|
| 104 | |
---|
[55] | 105 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
[1] | 106 | |
---|
[55] | 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; |
---|
[1] | 114 | } |
---|
| 115 | |
---|
[55] | 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 | |
---|