Last change
on this file since 1 was
1,
checked in by buchmann, 17 years ago
|
Initial import from CVS repository
|
File size:
1.8 KB
|
Rev | Line | |
---|
[1] | 1 | #include <systemc.h> |
---|
| 2 | |
---|
| 3 | #define ASSERT(x) \ |
---|
| 4 | { errnum++; \ |
---|
| 5 | if (!(x)) \ |
---|
| 6 | { \ |
---|
| 7 | cerr << "ASSERT : " #x "\n"; \ |
---|
| 8 | exit (errnum); \ |
---|
| 9 | } \ |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | using namespace std; |
---|
| 13 | |
---|
| 14 | template<typename datatype> |
---|
| 15 | class module_base : public sc_module { |
---|
| 16 | public: |
---|
| 17 | sc_in_clk clk; |
---|
| 18 | sc_in<datatype> i1; |
---|
| 19 | sc_out<datatype> o1; |
---|
| 20 | sc_signal<datatype> reg1; |
---|
| 21 | |
---|
| 22 | private: |
---|
| 23 | void trans_module_base () |
---|
| 24 | { |
---|
| 25 | } |
---|
| 26 | void gen_module_base () |
---|
| 27 | { |
---|
| 28 | this->kikoo (); |
---|
| 29 | } |
---|
| 30 | virtual void kikoo () = 0; |
---|
| 31 | |
---|
| 32 | public: |
---|
| 33 | SC_HAS_PROCESS(module_base); |
---|
| 34 | module_base (sc_module_name n) : sc_module (n), |
---|
| 35 | clk("clk"), |
---|
| 36 | i1("i1"), |
---|
| 37 | o1("o1"), |
---|
| 38 | reg1("reg1") |
---|
| 39 | { |
---|
| 40 | SC_METHOD(trans_module_base); |
---|
| 41 | sensitive << clk.pos(); |
---|
| 42 | dont_initialize(); |
---|
| 43 | SC_METHOD(gen_module_base); |
---|
| 44 | sensitive << clk.neg(); |
---|
| 45 | dont_initialize(); |
---|
| 46 | } |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | template<typename datatype> |
---|
| 50 | class test : public module_base<datatype> { |
---|
| 51 | public: |
---|
| 52 | sc_in<datatype> i2; |
---|
| 53 | sc_out<datatype> o2; |
---|
| 54 | sc_signal<datatype> reg2; |
---|
| 55 | |
---|
| 56 | private: |
---|
| 57 | void trans () |
---|
| 58 | { |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void gen () |
---|
| 62 | { |
---|
| 63 | } |
---|
| 64 | virtual void kikoo () |
---|
| 65 | { } |
---|
| 66 | |
---|
| 67 | public: |
---|
| 68 | SC_HAS_PROCESS(test); |
---|
| 69 | test (sc_module_name n) : module_base<datatype> (n), |
---|
| 70 | i2("i2"), |
---|
| 71 | o2("o2"), |
---|
| 72 | reg2("reg2") |
---|
| 73 | { |
---|
| 74 | SC_METHOD(trans); |
---|
| 75 | this->sensitive << this->clk.pos(); |
---|
| 76 | this->dont_initialize(); |
---|
| 77 | SC_METHOD(gen); |
---|
| 78 | this->sensitive << this->clk.neg(); |
---|
| 79 | this->dont_initialize(); |
---|
| 80 | } |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | int sc_main (int argc, char *argv[]) |
---|
| 84 | { |
---|
| 85 | int errnum = 0; |
---|
| 86 | sc_clock signal_clk("my_clock",1, 0.5); |
---|
| 87 | sc_signal<int> s01("s01"), |
---|
| 88 | s02("s02"), |
---|
| 89 | s03("s03"), |
---|
| 90 | s04("s04"); |
---|
| 91 | |
---|
| 92 | test<int> test1("test1"); |
---|
| 93 | test1.clk (signal_clk); |
---|
| 94 | test1.i1 (s01); |
---|
| 95 | test1.i2 (s02); |
---|
| 96 | test1.o1 (s03); |
---|
| 97 | test1.o2 (s04); |
---|
| 98 | |
---|
| 99 | // Init & run |
---|
| 100 | sc_start (0); |
---|
| 101 | |
---|
| 102 | return EXIT_SUCCESS; |
---|
| 103 | } |
---|
| 104 | |
---|
Note: See
TracBrowser
for help on using the repository browser.