[55] | 1 | |
---|
| 2 | #include <iostream> |
---|
| 3 | |
---|
| 4 | #include "systemc.h" |
---|
| 5 | #include "test.h" |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | using namespace std; |
---|
| 9 | |
---|
| 10 | struct observer : sc_module { |
---|
| 11 | sc_in_clk clk; |
---|
| 12 | |
---|
| 13 | sc_in<int> i; |
---|
| 14 | |
---|
| 15 | void f() {} |
---|
| 16 | |
---|
| 17 | SC_HAS_PROCESS(observer); |
---|
| 18 | observer(sc_module_name) : clk("clk"), i("i") { |
---|
| 19 | SC_METHOD(f); |
---|
| 20 | sensitive << clk.pos(); |
---|
| 21 | dont_initialize(); |
---|
| 22 | } |
---|
| 23 | }; |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | struct generator : sc_module { |
---|
| 27 | sc_in_clk clk; |
---|
| 28 | |
---|
| 29 | sc_out<int> o; |
---|
| 30 | sc_in<int> i; |
---|
| 31 | |
---|
| 32 | void f() { |
---|
| 33 | int t = (int) (sc_time_stamp().to_double()); |
---|
| 34 | o.write(t); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | SC_HAS_PROCESS(generator); |
---|
| 38 | generator(sc_module_name) : clk("clk"), o("o") { |
---|
| 39 | SC_METHOD(f); |
---|
| 40 | sensitive << clk.neg() << i; |
---|
| 41 | dont_initialize(); |
---|
| 42 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 43 | o(i); |
---|
| 44 | #endif |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | struct top_level : sc_module { |
---|
| 51 | sc_in_clk clk; |
---|
| 52 | |
---|
| 53 | sc_out<int> o; |
---|
| 54 | sc_in <int> i; |
---|
| 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 | i("i"), |
---|
| 64 | g("generator"), |
---|
| 65 | obs1("observer1"), |
---|
| 66 | obs2("observer2") { |
---|
| 67 | g.clk(clk); |
---|
| 68 | obs1.clk(clk); |
---|
| 69 | obs2.clk(clk); |
---|
| 70 | |
---|
| 71 | g.i(i); |
---|
| 72 | g.o(o); |
---|
| 73 | obs1.i(o); |
---|
| 74 | obs2.i(o); |
---|
| 75 | |
---|
| 76 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 77 | o(i); // wrong declaration that needs detection (no sc_method) |
---|
| 78 | #endif |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | int sc_main (int argc, char ** argv) { |
---|
| 85 | sc_clock clk("top_clk"); |
---|
| 86 | sc_signal<int> out("top_out"); |
---|
| 87 | sc_signal<int> in ("top_in"); |
---|
| 88 | |
---|
| 89 | top_level t("top_level"); |
---|
| 90 | |
---|
[60] | 91 | // Setup number of threads open-mp to 1 with the macro threads_omp() |
---|
| 92 | threads_omp(); |
---|
| 93 | |
---|
[55] | 94 | t.clk(clk); |
---|
| 95 | t.o(out); |
---|
| 96 | t.i(in); |
---|
| 97 | |
---|
| 98 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
| 99 | |
---|
| 100 | int i = 0; |
---|
| 101 | while (i++ < 5) { |
---|
| 102 | sc_start(sc_time(1, sc_core::SC_NS)); |
---|
| 103 | ASSERT(out.read() == t.obs1.i.read()); |
---|
| 104 | ASSERT(out.read() == t.obs2.i.read()); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | cout << "OK" << endl; |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | /* |
---|
| 113 | # Local Variables: |
---|
| 114 | # tab-width: 4; |
---|
| 115 | # c-basic-offset: 4; |
---|
| 116 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 117 | # indent-tabs-mode: nil; |
---|
| 118 | # End: |
---|
| 119 | # |
---|
| 120 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 121 | */ |
---|
| 122 | |
---|