[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()); |
---|
| 34 | o.write(t); |
---|
| 35 | } |
---|
[1] | 36 | |
---|
[55] | 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 | |
---|
[1] | 44 | }; |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
[55] | 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 | |
---|
[1] | 72 | }; |
---|
| 73 | |
---|
| 74 | |
---|
[55] | 75 | int sc_main (int argc, char ** argv) { |
---|
| 76 | sc_clock clk("top_clk"); |
---|
| 77 | sc_signal<int> out("top_out"); |
---|
[1] | 78 | |
---|
[55] | 79 | top_level t("top_level"); |
---|
[1] | 80 | |
---|
[55] | 81 | t.clk(clk); |
---|
| 82 | t.o (out); |
---|
| 83 | |
---|
| 84 | // QM : pourquoi est-ce tout commenté ?? |
---|
[1] | 85 | #if 0 |
---|
[55] | 86 | /* Open trace file */ |
---|
| 87 | sc_trace_file *system_trace_file; |
---|
| 88 | system_trace_file = sc_create_vcd_trace_file ("trace_file"); |
---|
[1] | 89 | |
---|
[55] | 90 | /* clks waveforms are always useful */ |
---|
| 91 | sc_trace(system_trace_file, clk1, "clk1"); |
---|
| 92 | sc_trace(system_trace_file, clk2, "clk2"); |
---|
[1] | 93 | |
---|
[55] | 94 | /* others signals */ |
---|
| 95 | for (int i = 0; i < 10; ++i) |
---|
| 96 | sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s")); |
---|
[1] | 97 | #endif |
---|
| 98 | |
---|
[55] | 99 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
[1] | 100 | |
---|
[55] | 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; |
---|
[1] | 108 | } |
---|
| 109 | |
---|
[55] | 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 | |
---|