manual_clock.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  manual_clock.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#include "systemc.h"
39#include "isaac.h"
40
41QTIsaac<8> rng;		// Platform independent random number generator.
42
43SC_MODULE( proc1 )
44{
45    SC_HAS_PROCESS( proc1 );
46
47    sc_in_clk clk;
48
49    sc_in<bool>    a;
50    sc_in<bool>    b;
51    sc_inout<bool> c;
52
53    proc1( sc_module_name NAME,
54           sc_signal_in_if<bool>& CLK,
55           sc_signal<bool>& A,
56           sc_signal<bool>& B,
57           sc_signal<bool>& C )
58    {
59        clk( CLK );
60        a(A); b(B); c(C);
61		SC_CTHREAD( entry, clk.pos() );
62    }
63
64    void entry()
65    {
66        while (true) {
67            wait();
68            c = a.read() && b.read();
69            wait();
70	    cout << sc_time_stamp() << " P1(a&&b):: C = " << c.read()
71		<< endl;
72            c = a.read() || b.read();
73            wait();
74	    cout << sc_time_stamp() << " P1(a||b):: C = " << c.read()
75		<< endl;
76            c = a ^ b;
77        }
78    }
79};
80
81SC_MODULE( proc2 )
82{
83    SC_HAS_PROCESS( proc2 );
84
85    sc_in_clk clk;
86
87    sc_in<bool>    a;
88    sc_in<bool>    b;
89    sc_inout<bool> c;
90
91    proc2( sc_module_name NAME,
92           sc_signal_in_if<bool>& CLK,
93           sc_signal<bool>& A,
94           sc_signal<bool>& B,
95           sc_signal<bool>& C )
96    {
97        clk( CLK );
98        a(A); b(B); c(C);
99		SC_CTHREAD( entry, clk.pos() );
100    }
101
102    void entry()
103    {
104        while (true) {
105            wait();
106            c = ! (a.read() && b.read());
107            wait();
108	    cout << sc_time_stamp() << " P2(a&&b):: C = " << c.read()
109		<< endl;
110            c = ! (a.read() || b.read());
111            wait();
112	    cout << sc_time_stamp() << " P2(a||b):: C = " << c.read()
113		<< endl;
114            c = ! (a ^ b);
115        }
116    }
117};
118
119// comparator
120SC_MODULE( proc3 )
121{
122    SC_HAS_PROCESS( proc3 );
123
124    sc_in<bool>  a;
125    sc_in<bool>  b;
126    sc_out<bool> c;
127    sc_out<bool> d;
128
129    proc3( sc_module_name NAME,
130           sc_signal<bool>& A,
131           sc_signal<bool>& B,
132           sc_signal<bool>& C,
133           sc_signal<bool>& D )
134    {
135        a(A); b(B); c(C); d(D);
136        SC_METHOD( entry );
137        sensitive << a << b;
138    }
139
140    void entry()
141    {
142        c = (a == b);
143        d = (a != b);
144    }
145};
146
147int
148sc_main( int argc, char* argv[] )
149{
150    sc_signal<bool> clk1("clk1");
151    sc_signal<bool> clk2("clk2");
152
153    sc_signal<bool> a("a"), b("b");
154    sc_signal<bool> p("p"), q("q");
155    sc_signal<bool> zero("zero"), one("one");
156
157    proc1 p1( "p1", clk1, a, b, p );
158    proc2 p2( "p2", clk2, a, b, q );
159    proc3 p3( "p3", p, q, zero, one );
160
161    sc_start(0, SC_NS);
162    for (double t = 0; t < 0.00001; t += 1e-9) {
163        clk1 = 1;
164        clk2 = 1;
165        a = rng.rand() & 16;
166        b = rng.rand() & 32;
167        sc_start( 1, SC_NS );
168        clk1 = 0;
169        clk2 = 0;
170        sc_start( 1, SC_NS );
171    }
172
173    return 0;
174}
175