source: sources/test_regression/09092005c/system.cpp @ 55

Last change on this file since 55 was 55, checked in by meunier, 11 years ago

Tried to clean the test_regression directory:

  • Code formatting
  • Supressed warnings
  • Made comprehensible outputs
  • Factorized Makefiles

There's still a lot to do (many tests don't pass for either good or bad reasons)

File size: 2.2 KB
Line 
1
2#include "systemc.h"
3
4#include <iostream>
5
6#include "test.h"
7
8using namespace std;
9
10
11struct observer : sc_module {
12    sc_in_clk clk;
13
14    sc_in<int> i;
15
16    void f() {}
17
18    SC_HAS_PROCESS(observer);
19    observer(sc_module_name) : clk ("clk"),
20    i("i") {
21        SC_METHOD(f);
22        sensitive << clk.pos();
23        dont_initialize();
24    }
25};
26
27
28struct generator : sc_module {
29    sc_in_clk clk;
30    sc_out<int> o;
31
32    void f() {
33        int t = (int) (sc_time_stamp().to_double());
34        o.write(t);
35    }
36
37    SC_HAS_PROCESS(generator);
38    generator(sc_module_name) : clk("clk"), o("o") {
39        SC_METHOD(f);
40        sensitive << clk.neg();
41        dont_initialize();
42    }
43
44};
45
46
47
48struct top_level : sc_module {
49    sc_in_clk clk;
50
51    sc_out<int> o;
52
53    generator g;
54    observer obs1, obs2;
55
56    SC_HAS_PROCESS(top_level);
57    top_level(sc_module_name) :
58        clk("clk"),
59        o("o"),
60        g("generator"), 
61        obs1("observer1"),
62        obs2("observer2"){
63        g.clk(clk);
64        obs1.clk(clk);
65        obs2.clk(clk);
66
67        g.o(o);
68        obs1.i(o);
69        obs2.i(o);
70    }
71
72};
73
74
75int sc_main (int argc, char ** argv) {
76    sc_clock       clk("top_clk");
77    sc_signal<int> out("top_out");
78
79    top_level t("top_level");
80
81    t.clk(clk);
82    t.(out);
83
84    // QM : pourquoi est-ce tout commenté ??
85#if 0
86    /* Open trace file */
87    sc_trace_file *system_trace_file;
88    system_trace_file = sc_create_vcd_trace_file ("trace_file");
89
90    /* clks waveforms are always useful */
91    sc_trace(system_trace_file, clk1, "clk1");
92    sc_trace(system_trace_file, clk2, "clk2");
93
94    /* others signals */
95    for (int i = 0; i < 10; ++i)
96        sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s"));
97#endif
98
99    sc_start(sc_time(0, sc_core::SC_NS));
100
101    /* simulation */
102    int i = 0;
103    while (i++ < 5) {
104        sc_start(sc_time(1, sc_core::SC_NS));
105        cout << out.read() << " - " << t.obs1.i.read() << " - " << t.obs2.i.read() << endl;
106    }
107    return 0;
108}
109
110
111/*
112# Local Variables:
113# tab-width: 4;
114# c-basic-offset: 4;
115# c-file-offsets:((innamespace . 0)(inline-open . 0));
116# indent-tabs-mode: nil;
117# End:
118#
119# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
120*/
121
Note: See TracBrowser for help on using the repository browser.