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 40SC_MODULE( proc1 ) 41{ 42 SC_HAS_PROCESS( proc1 ); 43 44 sc_in_clk clk; 45 46 sc_fifo<int>& in; 47 48 // Constructor 49 proc1( sc_module_name NAME, 50 sc_clock& CLOCK, 51 sc_fifo<int>& IN_ ) 52 : in(IN_) 53 { 54 clk( CLOCK ); 55 SC_THREAD( entry ); 56 sensitive << clk.pos(); 57 } 58 59 void entry() { 60 int val; 61 cout << "Proc1:: Waiting 10 cycles before reading\n"; 62 wait( 10 ); 63 cout << "Proc1:: Wait completed\n"; 64 val = in.read(); 65 cout << "Proc1:: Read. Value = " << val << "\n"; 66 val = in.read(); 67 cout << "Proc1:: Read. Value = " << val << "\n"; 68 val = in.read(); 69 cout << "Proc1:: Read. Value = " << val << "\n"; 70 cout << "Proc1:: Waiting 10 cycles before reading\n"; 71 wait( 10 ); 72 cout << "Proc1:: Wait completed\n"; 73 val = in.read(); 74 cout << "Proc1:: Read. Value = " << val << "\n"; 75 val = in.read(); 76 cout << "Proc1:: Read. Value = " << val << "\n"; 77 val = in.read(); 78 cout << "Proc1:: Read. Value = " << val << "\n"; 79 val = in.read(); 80 cout << "Proc1:: Read. Value = " << val << "\n"; 81 val = in.read(); 82 cout << "Proc1:: Read. Value = " << val << "\n"; 83 val = in.read(); 84 cout << "Proc1:: Read. Value = " << val << "\n"; 85 cout << "Proc1:: Loop start\n"; 86 int i = 1; 87 while (true) { 88 val = in.read(); 89 cout << "Proc1:: Read. Value = " << val << "\n"; 90 wait( i ); 91 i += 3; 92 } 93 } 94}; 95 96SC_MODULE( proc2 ) 97{ 98 SC_HAS_PROCESS( proc2 ); 99 100 sc_in_clk clk; 101 102 sc_fifo<int>& out; 103 104 // Constructor 105 proc2( sc_module_name NAME, 106 sc_clock& CLOCK, 107 sc_fifo<int>& OUT_ ) 108 : out(OUT_) 109 { 110 clk( CLOCK ); 111 SC_THREAD( entry ); 112 sensitive << clk.pos(); 113 } 114 115 void entry() { 116 cout << "Proc2:: Write 8 values\n"; 117 for (int i = 1; i<=8; i++) { 118 out.write(i); 119 cout << "Proc2:: Written one value\n"; 120 } 121 cout << "Proc2:: Write completed\n"; 122 cout << "Proc2:: Wait 30 cycles before write\n"; 123 wait( 30 ); 124 cout << "Proc2:: Wait completed\n"; 125 cout << "Proc2:: Write\n"; 126 out.write(9); 127 cout << "Proc2:: Write Completed\n"; 128 cout << "Proc2:: Loop start\n"; 129 for (int i=4; i<20; i++) { 130 out.write(i); 131 wait( i + 2 ); 132 } 133 wait( 150 ); 134 sc_stop(); 135 } 136}; 137 138int sc_main(int ac, char *av[]) 139{ 140 sc_fifo<int> c("C", 5); 141 142 sc_clock clock("CLK", 20, SC_NS); 143 144 proc1 p1("P1", clock, c); 145 proc2 p2("P2", clock, c); 146 147 // sc_trace_file *tf = sc_create_vcd_trace_file("systemc"); 148 // sc_trace(tf, c, "MyChannel", 3); 149 150 sc_start(); 151 152 return 0; 153} 154