test4.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  test4.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
40
41SC_MODULE( proc1 )
42{
43  SC_HAS_PROCESS( proc1 );
44
45  sc_signal_resolved& out;
46  sc_in<bool> in;
47
48  proc1( sc_module_name n,
49	 sc_signal_resolved& OUT_,
50	 sc_signal<bool>& IN_ )
51    : out(OUT_)
52  {
53    in(IN_);
54	SC_THREAD( entry );
55    sensitive << in;
56  }
57
58  void entry();
59};
60
61void
62proc1::entry()
63{
64  wait();
65  while (true) {
66    if ((bool) in == true) {
67      cout << "P1: Set to 1" << endl;
68      out = SC_LOGIC_1;//'1';
69    }
70    else {
71      cout << "P1: Set to Z" << endl;
72      out = SC_LOGIC_Z;//'Z';
73    }
74    wait();
75  }
76}
77
78
79SC_MODULE( proc2 )
80{
81  SC_HAS_PROCESS( proc2 );
82
83  sc_signal_resolved& out;
84  sc_in<bool> in;
85
86  proc2( sc_module_name n,
87	 sc_signal_resolved& OUT_,
88	 sc_signal<bool>& IN_ )
89    : out(OUT_)
90  {
91    in(IN_);
92	SC_THREAD( entry );
93    sensitive << in;
94  }
95
96  void entry();
97};
98
99void
100proc2::entry()
101{
102  wait();
103  while (true) {
104    if ((bool) in == false) {
105      cout << "P2: Set to 0" << endl;
106      out = SC_LOGIC_0;//'0';
107    }
108    else {
109      cout << "P2: Set to Z" << endl;
110      out = SC_LOGIC_Z;//'Z';
111    }
112    wait();
113  }
114}
115
116SC_MODULE( proc3 )
117{
118  SC_HAS_PROCESS( proc3 );
119
120  const sc_signal_resolved& in;
121
122  proc3( sc_module_name n,
123	 const sc_signal_resolved& IN_ )
124    : in(IN_)
125  {
126    SC_METHOD( entry );
127    sensitive << in;
128  }
129
130  void entry()
131  {
132    sc_logic v;
133    v = in;
134    cout << "Value on Bus = " << v.to_char() << endl;
135  }
136};
137
138int sc_main(int ac, char *av[])
139{
140  sc_signal_resolved Bus;
141  sc_signal<bool> clock;
142
143  proc1 P1("P1", Bus, clock);
144  proc2 P2("P2", Bus, clock);
145  proc3 P3("P3", Bus);
146
147  sc_start(0, SC_NS);
148  clock = 1;
149  sc_start(10, SC_NS);
150  for (int i = 0; i < 3; i++) {
151    clock = 0;
152    sc_start(10, SC_NS);
153    clock = 1;
154    sc_start(10, SC_NS);
155  }
156  return 0;
157}
158
159