[1] | 1 | #include "systemc.h" |
---|
| 2 | #include <iostream> |
---|
| 3 | |
---|
| 4 | using namespace std; |
---|
| 5 | |
---|
| 6 | #define ASSERT(x) \ |
---|
| 7 | { errnum++; \ |
---|
| 8 | if (!(x)) \ |
---|
| 9 | { \ |
---|
| 10 | cerr << "ASSERT : " #x "\n"; \ |
---|
| 11 | exit (errnum); \ |
---|
| 12 | } \ |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | using namespace std; |
---|
| 16 | |
---|
| 17 | struct observer : sc_module |
---|
| 18 | { |
---|
| 19 | sc_in_clk clk; |
---|
| 20 | |
---|
| 21 | sc_in<int> i; |
---|
| 22 | |
---|
| 23 | void f () |
---|
| 24 | { |
---|
| 25 | #if 0 |
---|
| 26 | cerr << i.read(); |
---|
| 27 | #endif |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | SC_HAS_PROCESS(observer); |
---|
| 31 | observer(sc_module_name) : clk ("clk"), |
---|
| 32 | i ("i") |
---|
| 33 | |
---|
| 34 | { |
---|
| 35 | SC_METHOD(f); |
---|
| 36 | dont_initialize(); |
---|
| 37 | sensitive << clk.pos(); |
---|
| 38 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 39 | #endif |
---|
| 40 | } |
---|
| 41 | }; |
---|
| 42 | |
---|
| 43 | struct generator : sc_module |
---|
| 44 | { |
---|
| 45 | sc_in_clk clk; |
---|
| 46 | |
---|
| 47 | sc_out<int> o; |
---|
| 48 | sc_in<int> i; |
---|
| 49 | |
---|
| 50 | void f () |
---|
| 51 | { |
---|
| 52 | int t = (int) (sc_time_stamp ().to_double()); |
---|
| 53 | #if 0 |
---|
| 54 | cerr << "f = " << t << endl; |
---|
| 55 | #endif |
---|
| 56 | o.write(t); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | SC_HAS_PROCESS(generator); |
---|
| 60 | generator(sc_module_name) : clk ("clk"), |
---|
| 61 | o ("o") |
---|
| 62 | { |
---|
| 63 | SC_METHOD(f); |
---|
| 64 | dont_initialize(); |
---|
| 65 | sensitive << clk.neg(); |
---|
| 66 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 67 | o(i); |
---|
| 68 | #endif |
---|
| 69 | } |
---|
| 70 | }; |
---|
| 71 | |
---|
| 72 | struct top_level : sc_module |
---|
| 73 | { |
---|
| 74 | sc_in_clk clk; |
---|
| 75 | |
---|
| 76 | sc_out<int> o; |
---|
| 77 | sc_in <int> i; |
---|
| 78 | // sc_out<int> io; |
---|
| 79 | // sc_signal<int> s; |
---|
| 80 | // sc_signal<int> s2; |
---|
| 81 | |
---|
| 82 | generator g; |
---|
| 83 | observer obs1, obs2; |
---|
| 84 | |
---|
| 85 | SC_HAS_PROCESS(top_level); |
---|
| 86 | top_level(sc_module_name) : g ("generator"), |
---|
| 87 | obs1("observer1"), |
---|
| 88 | obs2("observer2"), |
---|
| 89 | clk ("clk"), |
---|
| 90 | o ("o"), |
---|
| 91 | i ("i")/*, |
---|
| 92 | s ("s")*/ |
---|
| 93 | { |
---|
| 94 | g.clk (clk); |
---|
| 95 | obs1.clk (clk); |
---|
| 96 | obs2.clk (clk); |
---|
| 97 | |
---|
| 98 | g.i (i); |
---|
| 99 | g.o (o); |
---|
| 100 | obs1.i(o); |
---|
| 101 | obs2.i(o); |
---|
| 102 | |
---|
| 103 | #ifdef SYSTEMCASS_SPECIFIC |
---|
| 104 | o (i); |
---|
| 105 | g.o (obs1.i); // <----- wrong declaration that needs detection |
---|
| 106 | #endif |
---|
| 107 | } |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | int |
---|
| 111 | sc_main (int argc, char ** argv) |
---|
| 112 | { |
---|
| 113 | int errnum = 0; |
---|
| 114 | sc_clock clk("top_clk"); |
---|
| 115 | sc_signal<int> out("top_out"); |
---|
| 116 | sc_signal<int> in ("top_in"); |
---|
| 117 | |
---|
| 118 | top_level t("top_level"); |
---|
| 119 | |
---|
| 120 | t.clk (clk); |
---|
| 121 | t.o (out); |
---|
| 122 | t.i (in); |
---|
| 123 | |
---|
| 124 | #if 0 |
---|
| 125 | /* Open trace file */ |
---|
| 126 | sc_trace_file *system_trace_file; |
---|
| 127 | system_trace_file = sc_create_vcd_trace_file ("trace_file"); |
---|
| 128 | |
---|
| 129 | /* clks waveforms are always useful */ |
---|
| 130 | sc_trace(system_trace_file, clk1, "clk1"); |
---|
| 131 | sc_trace(system_trace_file, clk2, "clk2"); |
---|
| 132 | |
---|
| 133 | /* others signals */ |
---|
| 134 | for (int i = 0; i < 10; ++i) |
---|
| 135 | sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s")); |
---|
| 136 | #endif |
---|
| 137 | |
---|
| 138 | /* initilization */ |
---|
| 139 | #if 0 |
---|
| 140 | cout << "initilization...\n"; |
---|
| 141 | #endif |
---|
| 142 | sc_initialize (); |
---|
| 143 | |
---|
| 144 | /* simulation */ |
---|
| 145 | #if 0 |
---|
| 146 | cout << "simulation...\n"; |
---|
| 147 | #endif |
---|
| 148 | int i = 0; |
---|
| 149 | while (i++ < 5) |
---|
| 150 | { |
---|
| 151 | sc_start (1); |
---|
| 152 | ASSERT(out.read() == t.obs1.i.read()) |
---|
| 153 | ASSERT(out.read() == t.obs2.i.read()) |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | #if 0 |
---|
| 157 | cout << "\ndone.\n"; |
---|
| 158 | #endif |
---|
| 159 | |
---|
| 160 | return 0; |
---|
| 161 | } |
---|
| 162 | |
---|