hshake2.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 hshake2.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 40SC_MODULE( proc1 ) 41{ 42 SC_HAS_PROCESS( proc1 ); 43 44 sc_in_clk clk; 45 46 sc_fifo<int>& in; 47 sc_fifo<bool>& done; 48 sc_fifo<int>& out; 49 sc_fifo<bool>& ready; 50 51 // Constructor 52 proc1( sc_module_name NAME, 53 sc_clock& CLOCK, 54 sc_fifo<int>& IN_, 55 sc_fifo<bool>& DONE, 56 sc_fifo<int>& OUT_, 57 sc_fifo<bool>& READY ) 58 : in(IN_), done(DONE), out(OUT_), ready(READY) 59 { 60 clk(CLOCK); 61 SC_THREAD( entry ); 62 sensitive << clk.pos(); 63 } 64 65 void entry() { 66 ready.write(1); 67 bool done_ = done.read(); 68 cout << "Done is " << done_ << endl; 69 for (int i=0; i < 100; i++) { 70 out.write(i); 71 int in_ = in.read(); 72 cout << "Input is " << in_ << endl; 73 } 74 ready.write(0); 75 } 76}; 77 78SC_MODULE( proc2 ) 79{ 80 SC_HAS_PROCESS( proc2 ); 81 82 sc_in_clk clk; 83 84 sc_fifo<int>& in; 85 sc_fifo<bool>& done; 86 sc_fifo<int>& out; 87 sc_fifo<bool>& ready; 88 89 // Constructor 90 proc2( sc_module_name NAME, 91 sc_clock& CLOCK, 92 sc_fifo<int>& IN_, 93 sc_fifo<bool>& DONE, 94 sc_fifo<int>& OUT_, 95 sc_fifo<bool>& READY) 96 : in(IN_), done(DONE), out(OUT_), ready(READY) 97 { 98 clk(CLOCK); 99 SC_THREAD( entry ); 100 sensitive << clk.pos(); 101 } 102 103 void entry() { 104 ready.write(1); 105 bool done_ = done.read(); 106 cout << "Proc2::Done is " << done_ << endl; 107 for (int i=0; i < 100; i++) { 108 out.write(i); 109 int in_ = in.read(); 110 cout << "Proc2::Input is " << in_ << endl; 111 } 112 ready.write(0); 113 } 114}; 115 116int sc_main(int ac, char *av[]) 117{ 118 sc_fifo<bool> a(3); 119 sc_fifo<bool> b(10); 120 sc_fifo<int> c("C", 10); 121 sc_fifo<int> d("D", 2); 122 123 sc_clock clock("CLK", 20, SC_NS); 124 125 proc1 p1("P1", clock, c, a, d, b); 126 proc2 p2("P2", clock, d, b, c, a); 127 128 sc_start(1000, SC_NS); 129 return 0; 130} 131