disaproc3.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 disaproc3.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.posedge_event(); 65 sensitive << b.negedge_event(); 66 } 67 void entry(); 68}; 69 70void 71aproc1::entry() 72{ 73 wait(); 74 c = a + b; 75 cout << "c is (a + b)" << endl; 76 wait(); 77 c = a - b; 78 cout << "c is (a - b)" << endl; 79 wait(); 80 cout << name() << " is exiting." << endl; 81} 82 83 84SC_MODULE( aproc2 ) 85{ 86 SC_HAS_PROCESS( aproc2 ); 87 88 const sc_signal<bool>& a; 89 const sc_signal<bool>& b; 90 sc_signal<bool>& d; 91 92 aproc2( sc_module_name NAME, 93 94 const sc_signal<bool>& A, 95 const sc_signal<bool>& B, 96 sc_signal<bool>& D ) 97 : a(A), b(B), d(D) 98 { 99 SC_THREAD( entry ); 100 sensitive << a.negedge_event(); 101 sensitive << b.posedge_event(); 102 } 103 void entry(); 104}; 105 106void 107aproc2::entry() 108{ 109 wait(); 110 int loops = 0; 111 while (true) { 112 d = a * b; 113 cout << "d is (a * b)" << endl; 114 wait(); 115 if ((bool) b == 0) { 116 d = a / (b + 1); 117 cout << "d is (a / (b + 1))" << endl; 118 } else { 119 d = a / b; 120 cout << "d is (a / b)" << endl; 121 } 122 wait(); 123 if (loops < 1) { 124 // sc_assert( a.sensitive_aprocs_neg.size() == 1 ); 125 // sc_assert( a.sensitive_aprocs.size() == 1 ); 126 // sc_assert( b.sensitive_aprocs_neg.size() == 1 ); 127 // sc_assert( b.sensitive_aprocs.size() == 1 ); 128 } 129 if (loops > 5) { 130 // /* By this time aproc1 should have died. */ 131 // sc_assert( a.sensitive_aprocs_neg.size() == 1 ); 132 // sc_assert( a.sensitive_aprocs.size() == 0 ); 133 // sc_assert( b.sensitive_aprocs_neg.size() == 0 ); 134 // sc_assert( b.sensitive_aprocs.size() == 1 ); 135 } 136 loops++; 137 } 138} 139 140SC_MODULE( sync1 ) 141{ 142 SC_HAS_PROCESS( sync1 ); 143 144 sc_in_clk clk; 145 146 sc_signal<bool>& a; 147 sc_signal<bool>& b; 148 const sc_signal<bool>& c; 149 const sc_signal<bool>& d; 150 151 int count; 152 sync1( sc_module_name NAME, 153 sc_clock& CLK, 154 sc_signal<bool>& A, 155 sc_signal<bool>& B, 156 const sc_signal<bool>& C, 157 const sc_signal<bool>& D ) 158 : 159 a(A), b(B), c(C), d(D) 160 161 { 162 clk(CLK); 163 SC_CTHREAD( entry, clk.pos() ); 164 count = 0; 165 } 166 void entry(); 167}; 168 169void 170sync1::entry() 171{ 172 while (true) { 173 a = (val1[count % (sizeof(val1)/sizeof(val1[0]))] & 1); 174 b = (val2[count % (sizeof(val2)/sizeof(val2[0]))] & 1); 175 count++; 176 wait(); 177 cout << " a = " << a; 178 cout << " b = " << b; 179 cout << " c = " << c; 180 cout << " d = " << d << endl; 181 } 182} 183 184 185 186int 187sc_main(int argc, char** argv) 188{ 189 sc_clock clk("clk"); 190 sc_signal<bool> a("a"); 191 sc_signal<bool> b("b"); 192 sc_signal<bool> c("c"); 193 sc_signal<bool> d("d"); 194 195 a = 0; 196 b = 0; 197 c = 0; 198 d = 0; 199 200 aproc1 p1("p1", a, b, c); 201 aproc2 p2("p2", a, b, d); 202 sync1 s1("s1", clk, a, b, c, d); 203 204 // sc_assert( p1.aproc_handle->trigger_signals[0] == &a ); 205 // sc_assert( p1.aproc_handle->trigger_signals_edgy_neg[0] == &b ); 206 // sc_assert( p2.aproc_handle->trigger_signals[0] == &b ); 207 // sc_assert( p2.aproc_handle->trigger_signals_edgy_neg[0] == &a ); 208 209 sc_start(2000, SC_NS); 210 return 0; 211} 212