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