[1] | 1 | #include <systemc.h> |
---|
| 2 | |
---|
| 3 | #define ASSERT(x) \ |
---|
| 4 | { \ |
---|
| 5 | if (!(x)) \ |
---|
| 6 | { \ |
---|
| 7 | cerr << "ASSERT : " #x "\n"; \ |
---|
| 8 | exit (1); \ |
---|
| 9 | } \ |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | using namespace std; |
---|
| 13 | |
---|
| 14 | struct test : sc_module { |
---|
[23] | 15 | int32_t reg; |
---|
[1] | 16 | sc_signal<bool> reg_bool; |
---|
| 17 | sc_signal<int> reg_int; |
---|
| 18 | sc_signal<unsigned int> reg_unsigned_int; |
---|
| 19 | sc_signal<char> reg_char; |
---|
| 20 | sc_signal<double> reg_double; |
---|
| 21 | sc_signal<long> reg_long; |
---|
| 22 | sc_signal<sc_uint<32> > reg_ui32; |
---|
| 23 | sc_signal<sc_uint<16> > reg_ui16; |
---|
| 24 | sc_signal<sc_uint<6> > reg_ui6; |
---|
| 25 | sc_signal<sc_int<32> > reg_i32; |
---|
| 26 | sc_signal<sc_int<16> > reg_i16; |
---|
| 27 | sc_signal<sc_int<6> > reg_i6; |
---|
| 28 | |
---|
| 29 | sc_in_clk clk; |
---|
| 30 | sc_in<bool> resetn; |
---|
| 31 | |
---|
| 32 | void trans () |
---|
| 33 | { |
---|
| 34 | if (resetn.read() == true) |
---|
| 35 | { |
---|
| 36 | ASSERT(((reg & 1)) == reg_bool .read()); |
---|
| 37 | ASSERT(((int) reg) == reg_int .read()); |
---|
| 38 | ASSERT(((unsigned int)reg) == reg_unsigned_int .read()); |
---|
| 39 | ASSERT(((char) reg) == reg_char .read()); |
---|
[23] | 40 | #if 0 |
---|
| 41 | cout << (double)reg << " " << reg_double.read() << endl; |
---|
| 42 | cout << sizeof (double) << " " << sizeof (reg_double.read()) << endl; |
---|
| 43 | #endif |
---|
[1] | 44 | ASSERT(((double)reg) == reg_double.read()); |
---|
| 45 | ASSERT(((long) reg) == reg_long .read()); |
---|
| 46 | ASSERT(((unsigned int) reg & 0xFFFFFFFF) == (unsigned int) (reg_ui32 .read())); |
---|
| 47 | ASSERT(((unsigned int) reg & 0x0000FFFF) == (unsigned int) (reg_ui16 .read())); |
---|
| 48 | #if 0 |
---|
| 49 | cerr << reg_ui6.read() << " " << (reg & 0x0000003F) << endl; |
---|
| 50 | #endif |
---|
| 51 | ASSERT(((unsigned int) reg & 0x0000003F) == (unsigned int) (reg_ui6 .read())); |
---|
| 52 | ASSERT(((signed int) reg & 0xFFFFFFFF) == (signed int) (reg_i32 .read())); |
---|
| 53 | ASSERT(((signed int) reg & 0x0000FFFF) == (signed int) (reg_i16 .read())); |
---|
[23] | 54 | ASSERT(((signed int) reg & 0x0000003F) == (signed int) (reg_i6 .read())); |
---|
[1] | 55 | reg = reg + 1; |
---|
| 56 | reg_bool = reg & 1; |
---|
| 57 | reg_int = reg; |
---|
| 58 | reg_unsigned_int = reg; |
---|
| 59 | reg_char = reg; |
---|
[23] | 60 | reg_double .write(reg); |
---|
[1] | 61 | reg_long = reg; |
---|
| 62 | reg_ui32 = reg; |
---|
| 63 | reg_ui16 = reg; |
---|
| 64 | reg_ui6 = reg; |
---|
| 65 | reg_i32 = reg; |
---|
| 66 | reg_i16 = reg; |
---|
| 67 | reg_i6 = reg; |
---|
| 68 | } else { |
---|
| 69 | reg = 0; |
---|
| 70 | reg_bool = 0; |
---|
| 71 | reg_int = 0; |
---|
| 72 | reg_unsigned_int = 0; |
---|
| 73 | reg_char = 0; |
---|
| 74 | reg_double = 0; |
---|
| 75 | reg_long = 0; |
---|
| 76 | reg_ui32 = 0; |
---|
| 77 | reg_ui16 = 0; |
---|
| 78 | reg_ui6 = 0; |
---|
| 79 | reg_i32 = 0; |
---|
| 80 | reg_i16 = 0; |
---|
| 81 | reg_i6 = 0; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | SC_HAS_PROCESS(test); |
---|
[23] | 86 | test (sc_module_name n) : sc_module (n), |
---|
[1] | 87 | clk("clk") |
---|
| 88 | { |
---|
[23] | 89 | SC_METHOD(trans); |
---|
| 90 | sensitive << clk.pos(); |
---|
[1] | 91 | dont_initialize(); |
---|
[23] | 92 | }; |
---|
[1] | 93 | }; |
---|
| 94 | |
---|
| 95 | int sc_main (int argc, char *argv[]) |
---|
| 96 | { |
---|
[23] | 97 | sc_clock signal_clk("my_clock",1, 0.5); |
---|
[1] | 98 | sc_signal<bool> resetn("resetn"); |
---|
| 99 | |
---|
| 100 | test test1("test1"); |
---|
| 101 | test1.clk (signal_clk); |
---|
| 102 | test1.resetn (resetn); |
---|
| 103 | |
---|
[23] | 104 | // Init & run |
---|
| 105 | sc_start (0); |
---|
[1] | 106 | |
---|
| 107 | resetn = false; |
---|
[23] | 108 | sc_start (4); |
---|
[1] | 109 | resetn = true; |
---|
| 110 | sc_start (100); |
---|
| 111 | |
---|
[23] | 112 | return EXIT_SUCCESS; |
---|
[1] | 113 | } |
---|
| 114 | |
---|
| 115 | #undef sc_inout |
---|