Last change
on this file since 6 was
1,
checked in by buchmann, 17 years ago
|
Initial import from CVS repository
|
File size:
1.7 KB
|
Line | |
---|
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 | struct hard : sc_module |
---|
15 | { |
---|
16 | sc_in_clk clk; |
---|
17 | sc_in<bool> resetn; |
---|
18 | sc_in <int> i1; |
---|
19 | sc_out<int> o1; |
---|
20 | sc_signal <int> r1; |
---|
21 | |
---|
22 | void fg () |
---|
23 | { |
---|
24 | o1 = r1; |
---|
25 | } |
---|
26 | |
---|
27 | void ft () |
---|
28 | { |
---|
29 | if (resetn.read()) |
---|
30 | r1 = i1; |
---|
31 | else |
---|
32 | r1 = 0x0; |
---|
33 | } |
---|
34 | |
---|
35 | SC_HAS_PROCESS(hard); |
---|
36 | hard(sc_module_name) |
---|
37 | { |
---|
38 | SC_METHOD(ft); |
---|
39 | dont_initialize(); |
---|
40 | sensitive << clk.pos(); |
---|
41 | SC_METHOD(fg); |
---|
42 | dont_initialize(); |
---|
43 | sensitive << clk.neg(); |
---|
44 | #ifdef SYSTEMCASS_SPECIFIC |
---|
45 | #endif |
---|
46 | } |
---|
47 | }; |
---|
48 | |
---|
49 | int |
---|
50 | sc_main (int argc, char ** argv) |
---|
51 | { |
---|
52 | int errnum = 0; |
---|
53 | sc_clock clk1("clk1", 1, 0.5,0,true); |
---|
54 | sc_signal<bool> resetn; |
---|
55 | sc_signal<int> s[10]; |
---|
56 | hard a("a"); |
---|
57 | |
---|
58 | a.clk (clk1); |
---|
59 | a.resetn (resetn); |
---|
60 | |
---|
61 | a.i1 (s[0]); |
---|
62 | a.o1 (s[1]); |
---|
63 | |
---|
64 | /* Open trace file */ |
---|
65 | sc_trace_file *system_trace_file; |
---|
66 | system_trace_file = sc_create_vcd_trace_file ("trace_file"); |
---|
67 | |
---|
68 | /* clks waveforms are always useful */ |
---|
69 | sc_trace(system_trace_file, resetn, "resetn"); |
---|
70 | sc_trace(system_trace_file, s[0], "i1"); |
---|
71 | sc_trace(system_trace_file, s[1], "o1"); |
---|
72 | sc_trace(system_trace_file, clk1, "clk1"); |
---|
73 | |
---|
74 | /* initilization */ |
---|
75 | sc_initialize (); |
---|
76 | |
---|
77 | s[0] = 0; |
---|
78 | resetn = 0; |
---|
79 | |
---|
80 | sc_start (5); |
---|
81 | |
---|
82 | s[0] = 0x7B; |
---|
83 | resetn = 1; |
---|
84 | |
---|
85 | sc_start (1); |
---|
86 | |
---|
87 | for (int i = 0; i < 10; i++) |
---|
88 | { |
---|
89 | s[0] = i; |
---|
90 | sc_start (1); |
---|
91 | // cout << i << " " << s[1].read() << " " << a.o1.read() << endl; |
---|
92 | //ASSERT(((i > 0) && (s[1].read() == i - 1)) || ((i == 0) && (s[1].read() == 0x7B))); |
---|
93 | ASSERT(s[1].read() == i); |
---|
94 | } |
---|
95 | |
---|
96 | cout << "Test OK\n"; |
---|
97 | return 0; |
---|
98 | } |
---|
99 | |
---|
Note: See
TracBrowser
for help on using the repository browser.