disaproc1.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 disaproc1.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 40int val1[17] = { 34329, 32492, 1034, 12000, 102, 12981, 1902, 19409, 41 10029, 2149, 12030, 20099, 90, 10009, 9345, 57483, 42 10903 }; 43 44int val2[19] = { 239, 923, 1240, 129, 191, 101, 1010, 190, 45 19820, 2349, 24039, 34728, 5745, 78234, 17838, 37482, 46 17498, 1347, 3721 }; 47 48SC_MODULE( aproc1 ) 49{ 50 SC_HAS_PROCESS( aproc1 ); 51 52 const sc_signal<bool>& a; 53 const sc_signal<bool>& b; 54 sc_signal<bool>& c; 55 56 aproc1( sc_module_name NAME, 57 58 const sc_signal<bool>& A, 59 const sc_signal<bool>& B, 60 sc_signal<bool>& C ) 61 : a(A), b(B), c(C) 62 { 63 SC_THREAD( entry ); 64 sensitive << a << b; 65 } 66 void entry(); 67}; 68 69void 70aproc1::entry() 71{ 72 wait(); 73 c = a + b; 74 cout << "c is (a + b)" << endl; 75 wait(); 76 c = a - b; 77 cout << "c is (a - b)" << endl; 78 wait(); 79 cout << name() << " is exiting." << endl; 80} 81 82 83SC_MODULE( aproc2 ) 84{ 85 SC_HAS_PROCESS( aproc2 ); 86 87 const sc_signal<bool>& a; 88 const sc_signal<bool>& b; 89 sc_signal<bool>& d; 90 91 aproc2( sc_module_name NAME, 92 93 const sc_signal<bool>& A, 94 const sc_signal<bool>& B, 95 sc_signal<bool>& D ) 96 : a(A), b(B), d(D) 97 { 98 SC_THREAD( entry ); 99 sensitive << a << b; 100 } 101 void entry(); 102}; 103 104void 105aproc2::entry() 106{ 107 wait(); 108 int loops = 0; 109 while (true) { 110 d = a * b; 111 cout << "d is (a * b)" << endl; 112 wait(); 113 if ((bool) b == 0) { 114 d = a / (b + 1); 115 cout << "d is (a / (b + 1))" << endl; 116 } else { 117 d = a / b; 118 cout << "d is (a / b)" << endl; 119 } 120 wait(); 121 if (loops < 1) { 122 // sc_assert( a.sensitive_aprocs_neg.size() == 2 ); 123 // sc_assert( a.sensitive_aprocs.size() == 2 ); 124 } 125 if (loops > 5) { 126 /* By this time aproc1 should have died. */ 127 // sc_assert( a.sensitive_aprocs_neg.size() == 1 ); 128 // sc_assert( a.sensitive_aprocs.size() == 1 ); 129 } 130 loops++; 131 } 132} 133 134SC_MODULE( sync1 ) 135{ 136 SC_HAS_PROCESS( sync1 ); 137 138 sc_in_clk clk; 139 140 sc_signal<bool>& a; 141 sc_signal<bool>& b; 142 const sc_signal<bool>& c; 143 const sc_signal<bool>& d; 144 145 int count; 146 sync1( sc_module_name NAME, 147 sc_clock& CLK, 148 sc_signal<bool>& A, 149 sc_signal<bool>& B, 150 const sc_signal<bool>& C, 151 const sc_signal<bool>& D ) 152 : 153 a(A), b(B), c(C), d(D) 154 155 { 156 clk(CLK); 157 SC_CTHREAD( entry, clk.pos() ); 158 count = 0; 159 } 160 void entry(); 161}; 162 163void 164sync1::entry() 165{ 166 while (true) { 167 a = (val1[count % (sizeof(val1)/sizeof(val1[0]))] & 1); 168 b = (val2[count % (sizeof(val2)/sizeof(val2[0]))] & 1); 169 count++; 170 wait(); 171 cout << " a = " << a; 172 cout << " b = " << b; 173 cout << " c = " << c; 174 cout << " d = " << d << endl; 175 } 176} 177 178 179 180int 181sc_main(int argc, char** argv) 182{ 183 sc_clock clk("clk"); 184 sc_signal<bool> a("a"); 185 sc_signal<bool> b("b"); 186 sc_signal<bool> c("c"); 187 sc_signal<bool> d("d"); 188 189 a = 0; 190 b = 0; 191 c = 0; 192 d = 0; 193 194 aproc1 p1("p1", a, b, c); 195 aproc2 p2("p2", a, b, d); 196 sync1 s1("s1", clk, a, b, c, d); 197 198 sc_start(2000, SC_NS); 199 return 0; 200} 201