test03.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  test03.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// test of sc_signal_resolved port classes.
39
40#include "systemc.h"
41
42SC_MODULE( mod_a )
43{
44    // ports
45    sc_out_resolved out1;
46    sc_out_resolved out2;
47    // sc_in_resolved  in;
48    sc_in<sc_logic> in;
49
50    // variables
51    sc_logic l1;
52    sc_logic l2;
53
54    // events
55    sc_event ready1;
56    sc_event ready2;
57
58    void out_action1()
59    {
60        for( int i = 0; i < 4; ++ i ) {
61            l1 = sc_dt::sc_logic_value_t( i );
62            for( int j = 0; j < 4; ++j ) {
63                out1.write( l1 );
64                wait( 1, SC_NS );
65                ready1.notify();
66                wait( SC_ZERO_TIME );
67            }
68        }
69    }
70
71    void out_action2()
72    {
73        for( int i = 0; i < 4; ++ i ) {
74            for( int j = 0; j < 4; ++ j ) {
75                l2 = sc_dt::sc_logic_value_t( j );
76                out2.write( l2 );
77                wait( 1, SC_NS );
78                ready2.notify();
79                wait( SC_ZERO_TIME );
80            }
81        }
82    }
83
84    void in_action()
85    {
86        for( int i = 0; i < 16; ++ i ) {
87            wait( ready1 & ready2 );
88            cout << l1 << " " << l2 << " -> " << in.read() << endl;
89        }
90    }
91
92    SC_CTOR( mod_a )
93    {
94        SC_THREAD( out_action1 );
95        SC_THREAD( out_action2 );
96        SC_THREAD( in_action );
97    }
98};
99
100int
101sc_main( int, char*[] )
102{
103    sc_signal_resolved sig_resolved;
104    sc_signal<sc_logic> sig_logic;
105
106    mod_a a( "a" );
107
108    a.out1( sig_resolved );
109    a.out2( sig_logic );
110    a.in( sig_logic );
111
112    sc_start();
113
114    return 0;
115}
116