Last change
on this file since 36 was
35,
checked in by buchmann, 15 years ago
|
Code cleanup.
Add --dynamiclink option to systemcass executable.
|
File size:
2.8 KB
|
Rev | Line | |
---|
[1] | 1 | #include <systemc.h> |
---|
| 2 | #include <signal.h> |
---|
| 3 | #include "chrono.h" |
---|
| 4 | |
---|
| 5 | using namespace std; |
---|
[35] | 6 | |
---|
[1] | 7 | struct A : sc_module { |
---|
[35] | 8 | sc_in_clk clk; |
---|
| 9 | sc_out<bool> o1; |
---|
[1] | 10 | |
---|
[35] | 11 | void eval () { |
---|
[1] | 12 | o1 = (rand()%2) == 0; |
---|
[35] | 13 | } |
---|
[1] | 14 | |
---|
[35] | 15 | SC_CTOR (A) : clk ("clk"), o1("o1") { |
---|
| 16 | SC_METHOD(eval); |
---|
| 17 | sensitive << clk.neg(); |
---|
[1] | 18 | #ifdef SYSTEMCASS_SPECIFIC |
---|
[35] | 19 | // s1(); |
---|
[1] | 20 | #endif |
---|
[35] | 21 | }; |
---|
[1] | 22 | }; |
---|
| 23 | |
---|
| 24 | struct B : sc_module { |
---|
[35] | 25 | sc_in_clk clk; |
---|
| 26 | sc_in<bool> i1; |
---|
| 27 | sc_in<bool> i2; |
---|
| 28 | sc_out<bool> o1; |
---|
| 29 | sc_out<bool> o2; |
---|
[1] | 30 | |
---|
[35] | 31 | void eval1 () { |
---|
[1] | 32 | o1 = ~i1; |
---|
[35] | 33 | } |
---|
| 34 | void eval2 () { |
---|
[1] | 35 | o2 = ~i2; |
---|
[35] | 36 | } |
---|
[1] | 37 | |
---|
[35] | 38 | SC_CTOR (B) : clk ("clk"), i1 ("i1"), o1("o1"), i2 ("i2"), o2 ("o2") { |
---|
| 39 | SC_METHOD(eval1); |
---|
| 40 | sensitive << clk.neg(); |
---|
| 41 | sensitive << i1; |
---|
[1] | 42 | #ifdef SYSTEMCASS_SPECIFIC |
---|
[35] | 43 | o1(i1); |
---|
[1] | 44 | #endif |
---|
[35] | 45 | SC_METHOD(eval2); |
---|
| 46 | sensitive << clk.neg(); |
---|
| 47 | sensitive << i2; |
---|
[1] | 48 | #ifdef SYSTEMCASS_SPECIFIC |
---|
[35] | 49 | o2(i2); |
---|
[1] | 50 | #endif |
---|
[35] | 51 | }; |
---|
[1] | 52 | }; |
---|
| 53 | |
---|
| 54 | struct C : sc_module { |
---|
[35] | 55 | sc_in_clk clk; |
---|
| 56 | sc_in<bool> i1; |
---|
| 57 | sc_in<bool> i2; |
---|
| 58 | sc_out<bool> o1; |
---|
[1] | 59 | |
---|
[35] | 60 | void eval1 () { |
---|
[1] | 61 | o1 = i1 ^ i2; |
---|
[35] | 62 | } |
---|
[1] | 63 | |
---|
[35] | 64 | SC_CTOR (C) : clk ("clk"), i1 ("i1"), o1("o1"), i2 ("i2") { |
---|
| 65 | SC_METHOD(eval1); |
---|
| 66 | sensitive << clk.neg(); |
---|
| 67 | sensitive << i1 << i2; |
---|
[1] | 68 | #ifdef SYSTEMCASS_SPECIFIC |
---|
[35] | 69 | o1(i1); |
---|
| 70 | o1(i2); |
---|
[1] | 71 | #endif |
---|
[35] | 72 | }; |
---|
[1] | 73 | }; |
---|
| 74 | |
---|
| 75 | struct D : sc_module { |
---|
[35] | 76 | sc_in_clk clk; |
---|
| 77 | sc_out<bool> o1; |
---|
[1] | 78 | |
---|
[35] | 79 | void eval () { |
---|
[1] | 80 | o1 = (rand()%2) == 0; |
---|
[35] | 81 | } |
---|
[1] | 82 | |
---|
[35] | 83 | SC_CTOR (D) : clk ("clk"), o1("o1") { |
---|
| 84 | SC_METHOD(eval); |
---|
| 85 | sensitive << clk.neg(); |
---|
[1] | 86 | #ifdef SYSTEMCASS_SPECIFIC |
---|
[35] | 87 | // s1(); |
---|
[1] | 88 | #endif |
---|
[35] | 89 | }; |
---|
[1] | 90 | }; |
---|
| 91 | |
---|
| 92 | int sc_main (int argc, char *argv[]) |
---|
| 93 | { |
---|
[35] | 94 | sc_clock signal_clk("my_clock",1, 0.5); |
---|
| 95 | sc_signal<bool> s1("s1"),s2("s2"),s3("s3"),s4("s4"),s5("s5"); |
---|
[1] | 96 | |
---|
[35] | 97 | A a("a"); |
---|
| 98 | B b("b"); |
---|
| 99 | C c("c"); |
---|
| 100 | D d("d"); |
---|
| 101 | |
---|
| 102 | a.clk (signal_clk); |
---|
| 103 | b.clk (signal_clk); |
---|
| 104 | c.clk (signal_clk); |
---|
| 105 | d.clk (signal_clk); |
---|
| 106 | |
---|
| 107 | a.o1 (s1); |
---|
| 108 | b.i1 (s1); |
---|
| 109 | |
---|
| 110 | d.o1 (s2); |
---|
| 111 | c.i2 (s2); |
---|
[1] | 112 | |
---|
[35] | 113 | b.o1 (s3); |
---|
| 114 | c.i1 (s3); |
---|
| 115 | |
---|
| 116 | c.o1 (s4); |
---|
| 117 | b.i2 (s4); |
---|
| 118 | |
---|
| 119 | b.o2 (s5); |
---|
| 120 | |
---|
| 121 | // Init & run |
---|
| 122 | sc_initialize (); |
---|
[1] | 123 | |
---|
| 124 | if (argc == 1) |
---|
| 125 | { |
---|
| 126 | cout << "Usage :\n" << argv[0] << " [#cycles]\n"; |
---|
| 127 | return EXIT_SUCCESS; |
---|
| 128 | } |
---|
| 129 | |
---|
[35] | 130 | chrono_t chrono; |
---|
| 131 | chrono.start (); |
---|
[1] | 132 | |
---|
| 133 | sc_start (atoi(argv[1])); |
---|
| 134 | |
---|
[35] | 135 | chrono.stop (); |
---|
| 136 | unsigned int t = chrono; |
---|
| 137 | cout << "Time elapsed (sec) : " << t << endl; |
---|
| 138 | cout << "Cycles done : " << sc_simulation_time () << endl; |
---|
| 139 | cout << "Performance : " << sc_simulation_time () / t << endl; |
---|
| 140 | printf("\nPress <RETURN> to exit simulation."); |
---|
| 141 | char buf_ret[2]; |
---|
| 142 | cin.getline(buf_ret,1); |
---|
| 143 | return EXIT_SUCCESS; |
---|
[1] | 144 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.