112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com/***************************************************************************** 2112855Sgabeblack@google.com 2212855Sgabeblack@google.com disaproc3.cpp -- 2312855Sgabeblack@google.com 2412855Sgabeblack@google.com Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 2512855Sgabeblack@google.com 2612855Sgabeblack@google.com *****************************************************************************/ 2712855Sgabeblack@google.com 2812855Sgabeblack@google.com/***************************************************************************** 2912855Sgabeblack@google.com 3012855Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112855Sgabeblack@google.com changes you are making here. 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com Name, Affiliation, Date: 3412855Sgabeblack@google.com Description of Modification: 3512855Sgabeblack@google.com 3612855Sgabeblack@google.com *****************************************************************************/ 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com#include "systemc.h" 3912855Sgabeblack@google.com 4012855Sgabeblack@google.comint val1[17] = { 34329, 32492, 1034, 12000, 102, 12981, 1902, 19409, 4112855Sgabeblack@google.com 10029, 2149, 12030, 20099, 90, 10009, 9345, 57483, 4212855Sgabeblack@google.com 10903 }; 4312855Sgabeblack@google.com 4412855Sgabeblack@google.comint val2[19] = { 239, 923, 1240, 129, 191, 101, 1010, 190, 4512855Sgabeblack@google.com 19820, 2349, 24039, 34728, 5745, 78234, 17838, 37482, 4612855Sgabeblack@google.com 17498, 1347, 3721 }; 4712855Sgabeblack@google.com 4812855Sgabeblack@google.comSC_MODULE( aproc1 ) 4912855Sgabeblack@google.com{ 5012855Sgabeblack@google.com SC_HAS_PROCESS( aproc1 ); 5112855Sgabeblack@google.com 5212855Sgabeblack@google.com const sc_signal<bool>& a; 5312855Sgabeblack@google.com const sc_signal<bool>& b; 5412855Sgabeblack@google.com sc_signal<bool>& c; 5512855Sgabeblack@google.com 5612855Sgabeblack@google.com aproc1( sc_module_name NAME, 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com const sc_signal<bool>& A, 5912855Sgabeblack@google.com const sc_signal<bool>& B, 6012855Sgabeblack@google.com sc_signal<bool>& C ) 6112855Sgabeblack@google.com : a(A), b(B), c(C) 6212855Sgabeblack@google.com { 6312855Sgabeblack@google.com SC_THREAD( entry ); 6412855Sgabeblack@google.com sensitive << a.posedge_event(); 6512855Sgabeblack@google.com sensitive << b.negedge_event(); 6612855Sgabeblack@google.com } 6712855Sgabeblack@google.com void entry(); 6812855Sgabeblack@google.com}; 6912855Sgabeblack@google.com 7012855Sgabeblack@google.comvoid 7112855Sgabeblack@google.comaproc1::entry() 7212855Sgabeblack@google.com{ 7312855Sgabeblack@google.com wait(); 7412855Sgabeblack@google.com c = a + b; 7512855Sgabeblack@google.com cout << "c is (a + b)" << endl; 7612855Sgabeblack@google.com wait(); 7712855Sgabeblack@google.com c = a - b; 7812855Sgabeblack@google.com cout << "c is (a - b)" << endl; 7912855Sgabeblack@google.com wait(); 8012855Sgabeblack@google.com cout << name() << " is exiting." << endl; 8112855Sgabeblack@google.com} 8212855Sgabeblack@google.com 8312855Sgabeblack@google.com 8412855Sgabeblack@google.comSC_MODULE( aproc2 ) 8512855Sgabeblack@google.com{ 8612855Sgabeblack@google.com SC_HAS_PROCESS( aproc2 ); 8712855Sgabeblack@google.com 8812855Sgabeblack@google.com const sc_signal<bool>& a; 8912855Sgabeblack@google.com const sc_signal<bool>& b; 9012855Sgabeblack@google.com sc_signal<bool>& d; 9112855Sgabeblack@google.com 9212855Sgabeblack@google.com aproc2( sc_module_name NAME, 9312855Sgabeblack@google.com 9412855Sgabeblack@google.com const sc_signal<bool>& A, 9512855Sgabeblack@google.com const sc_signal<bool>& B, 9612855Sgabeblack@google.com sc_signal<bool>& D ) 9712855Sgabeblack@google.com : a(A), b(B), d(D) 9812855Sgabeblack@google.com { 9912855Sgabeblack@google.com SC_THREAD( entry ); 10012855Sgabeblack@google.com sensitive << a.negedge_event(); 10112855Sgabeblack@google.com sensitive << b.posedge_event(); 10212855Sgabeblack@google.com } 10312855Sgabeblack@google.com void entry(); 10412855Sgabeblack@google.com}; 10512855Sgabeblack@google.com 10612855Sgabeblack@google.comvoid 10712855Sgabeblack@google.comaproc2::entry() 10812855Sgabeblack@google.com{ 10912855Sgabeblack@google.com wait(); 11012855Sgabeblack@google.com int loops = 0; 11112855Sgabeblack@google.com while (true) { 11212855Sgabeblack@google.com d = a * b; 11312855Sgabeblack@google.com cout << "d is (a * b)" << endl; 11412855Sgabeblack@google.com wait(); 11512855Sgabeblack@google.com if ((bool) b == 0) { 11612855Sgabeblack@google.com d = a / (b + 1); 11712855Sgabeblack@google.com cout << "d is (a / (b + 1))" << endl; 11812855Sgabeblack@google.com } else { 11912855Sgabeblack@google.com d = a / b; 12012855Sgabeblack@google.com cout << "d is (a / b)" << endl; 12112855Sgabeblack@google.com } 12212855Sgabeblack@google.com wait(); 12312855Sgabeblack@google.com if (loops < 1) { 12412855Sgabeblack@google.com // sc_assert( a.sensitive_aprocs_neg.size() == 1 ); 12512855Sgabeblack@google.com // sc_assert( a.sensitive_aprocs.size() == 1 ); 12612855Sgabeblack@google.com // sc_assert( b.sensitive_aprocs_neg.size() == 1 ); 12712855Sgabeblack@google.com // sc_assert( b.sensitive_aprocs.size() == 1 ); 12812855Sgabeblack@google.com } 12912855Sgabeblack@google.com if (loops > 5) { 13012855Sgabeblack@google.com // /* By this time aproc1 should have died. */ 13112855Sgabeblack@google.com // sc_assert( a.sensitive_aprocs_neg.size() == 1 ); 13212855Sgabeblack@google.com // sc_assert( a.sensitive_aprocs.size() == 0 ); 13312855Sgabeblack@google.com // sc_assert( b.sensitive_aprocs_neg.size() == 0 ); 13412855Sgabeblack@google.com // sc_assert( b.sensitive_aprocs.size() == 1 ); 13512855Sgabeblack@google.com } 13612855Sgabeblack@google.com loops++; 13712855Sgabeblack@google.com } 13812855Sgabeblack@google.com} 13912855Sgabeblack@google.com 14012855Sgabeblack@google.comSC_MODULE( sync1 ) 14112855Sgabeblack@google.com{ 14212855Sgabeblack@google.com SC_HAS_PROCESS( sync1 ); 14312855Sgabeblack@google.com 14412855Sgabeblack@google.com sc_in_clk clk; 14512855Sgabeblack@google.com 14612855Sgabeblack@google.com sc_signal<bool>& a; 14712855Sgabeblack@google.com sc_signal<bool>& b; 14812855Sgabeblack@google.com const sc_signal<bool>& c; 14912855Sgabeblack@google.com const sc_signal<bool>& d; 15012855Sgabeblack@google.com 15112855Sgabeblack@google.com int count; 15212855Sgabeblack@google.com sync1( sc_module_name NAME, 15312855Sgabeblack@google.com sc_clock& CLK, 15412855Sgabeblack@google.com sc_signal<bool>& A, 15512855Sgabeblack@google.com sc_signal<bool>& B, 15612855Sgabeblack@google.com const sc_signal<bool>& C, 15712855Sgabeblack@google.com const sc_signal<bool>& D ) 15812855Sgabeblack@google.com : 15912855Sgabeblack@google.com a(A), b(B), c(C), d(D) 16012855Sgabeblack@google.com 16112855Sgabeblack@google.com { 16212855Sgabeblack@google.com clk(CLK); 16312855Sgabeblack@google.com SC_CTHREAD( entry, clk.pos() ); 16412855Sgabeblack@google.com count = 0; 16512855Sgabeblack@google.com } 16612855Sgabeblack@google.com void entry(); 16712855Sgabeblack@google.com}; 16812855Sgabeblack@google.com 16912855Sgabeblack@google.comvoid 17012855Sgabeblack@google.comsync1::entry() 17112855Sgabeblack@google.com{ 17212855Sgabeblack@google.com while (true) { 17312855Sgabeblack@google.com a = (val1[count % (sizeof(val1)/sizeof(val1[0]))] & 1); 17412855Sgabeblack@google.com b = (val2[count % (sizeof(val2)/sizeof(val2[0]))] & 1); 17512855Sgabeblack@google.com count++; 17612855Sgabeblack@google.com wait(); 17712855Sgabeblack@google.com cout << " a = " << a; 17812855Sgabeblack@google.com cout << " b = " << b; 17912855Sgabeblack@google.com cout << " c = " << c; 18012855Sgabeblack@google.com cout << " d = " << d << endl; 18112855Sgabeblack@google.com } 18212855Sgabeblack@google.com} 18312855Sgabeblack@google.com 18412855Sgabeblack@google.com 18512855Sgabeblack@google.com 18612855Sgabeblack@google.comint 18712855Sgabeblack@google.comsc_main(int argc, char** argv) 18812855Sgabeblack@google.com{ 18912855Sgabeblack@google.com sc_clock clk("clk"); 19012855Sgabeblack@google.com sc_signal<bool> a("a"); 19112855Sgabeblack@google.com sc_signal<bool> b("b"); 19212855Sgabeblack@google.com sc_signal<bool> c("c"); 19312855Sgabeblack@google.com sc_signal<bool> d("d"); 19412855Sgabeblack@google.com 19512855Sgabeblack@google.com a = 0; 19612855Sgabeblack@google.com b = 0; 19712855Sgabeblack@google.com c = 0; 19812855Sgabeblack@google.com d = 0; 19912855Sgabeblack@google.com 20012855Sgabeblack@google.com aproc1 p1("p1", a, b, c); 20112855Sgabeblack@google.com aproc2 p2("p2", a, b, d); 20212855Sgabeblack@google.com sync1 s1("s1", clk, a, b, c, d); 20312855Sgabeblack@google.com 20412855Sgabeblack@google.com // sc_assert( p1.aproc_handle->trigger_signals[0] == &a ); 20512855Sgabeblack@google.com // sc_assert( p1.aproc_handle->trigger_signals_edgy_neg[0] == &b ); 20612855Sgabeblack@google.com // sc_assert( p2.aproc_handle->trigger_signals[0] == &b ); 20712855Sgabeblack@google.com // sc_assert( p2.aproc_handle->trigger_signals_edgy_neg[0] == &a ); 20812855Sgabeblack@google.com 20912855Sgabeblack@google.com sc_start(2000, SC_NS); 21012855Sgabeblack@google.com return 0; 21112855Sgabeblack@google.com} 212