source: sources/test_regression/15092005c/system.cpp @ 60

Last change on this file since 60 was 60, checked in by meunier, 7 years ago
  • Intégration des modifications de Clément, qui a intégré la version parallélisée de systemcass faite par Manuel.
File size: 2.0 KB
Line 
1
2
3#include <iostream>
4
5#include "systemc.h"
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"), i("i") {
20        SC_METHOD(f);
21        sensitive << clk.pos();
22        dont_initialize();
23    }
24
25};
26
27
28struct generator : sc_module {
29    sc_in_clk clk;
30
31    sc_out<int> o;
32    sc_in<int>  i;
33
34    void f() {
35        int t = (int) (sc_time_stamp ().to_double());
36        o.write(t);
37    }
38
39    SC_HAS_PROCESS(generator);
40    generator(sc_module_name) : clk ("clk"), o("o") {
41#ifdef SYSTEMCASS_SPECIFIC
42        o(i);
43#endif
44        SC_METHOD(f);
45        sensitive << clk.neg() << i;
46        dont_initialize();
47    }
48
49};
50
51
52struct top_level : sc_module {
53    sc_in_clk clk;
54
55    sc_out<int> o;
56    sc_in <int> i;
57
58    generator g;
59    observer obs1, obs2;
60
61    SC_HAS_PROCESS(top_level);
62    top_level(sc_module_name) :
63    clk ("clk"),
64    o("o"),
65    i("i"),
66    g("generator"), 
67    obs1("observer1"),
68    obs2("observer2") {
69        g.clk(clk);
70        obs1.clk(clk);
71        obs2.clk(clk);
72
73        g.i(i);
74        g.o(o);
75        obs1.i(o);
76        obs2.i(o);
77    }
78
79};
80
81
82int sc_main (int argc, char ** argv) {
83    sc_clock       clk("top_clk");
84    sc_signal<int> out("top_out");
85    sc_signal<int> in("top_in");
86
87    top_level t("top_level");
88
89    // Setup number of threads open-mp to 1 with the macro threads_omp()
90    threads_omp();
91
92    t.clk(clk);
93    t.o(out);
94    t.i(in);
95
96    sc_start(sc_time(0, sc_core::SC_NS));
97
98    /* simulation */
99    int i = 0;
100    while (i++ < 5) {
101        sc_start(sc_time(1, sc_core::SC_NS));
102        ASSERT(out.read() == t.obs1.i.read());
103        ASSERT(out.read() == t.obs2.i.read());
104    }
105
106    return 0;
107}
108
109
110/*
111# Local Variables:
112# tab-width: 4;
113# c-basic-offset: 4;
114# c-file-offsets:((innamespace . 0)(inline-open . 0));
115# indent-tabs-mode: nil;
116# End:
117#
118# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
119*/
120
Note: See TracBrowser for help on using the repository browser.