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