test14.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 test14.cpp -- 23 24 Original Author: Ucar Aziz, Synopsys, Inc., 2002-02-15 25 Martin Janssen, Synopsys, Inc., 2002-02-15 26 27 *****************************************************************************/ 28 29/***************************************************************************** 30 31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 32 changes you are making here. 33 34 Name, Affiliation, Date: 35 Description of Modification: 36 37 *****************************************************************************/ 38 39// test of wait(..) for dynamic sensitivity 40 41#include "systemc.h" 42 43SC_MODULE( mod_a ) 44{ 45 sc_event e1; 46 sc_event e2; 47 sc_event e3; 48 sc_event e4; 49 sc_event e5; 50 sc_event e6; 51 52 void write( const char* msg ) 53 { 54 cout <<"simulation time" << ":" << sc_time_stamp() 55 << " " << msg << endl; 56 57 } 58 59 void sender1() 60 { 61 while(true){ 62 write( "sender_1 -e1 -e2" ); 63 e1.notify(10, SC_NS); 64 e2.notify(20, SC_NS); 65 wait(15, SC_NS, e4 | e6); 66 } 67 } 68 69 void sender2() 70 { 71 while(true){ 72 write( "sender_2 -e3 -e4" ); 73 e3.notify(10, SC_NS); 74 e4.notify(15, SC_NS); 75 wait(20, SC_NS, e2 & e5); 76 } 77 } 78 79 void receiver1() 80 { 81 while(true){ 82 wait(e1 & e3); 83 write( "receiver_1 -e5" ); 84 e5.notify(10,SC_NS ); 85 } 86 } 87 88 void receiver2() 89 { 90 while(true){ 91 wait(e2 | e4); 92 write( "receiver_2 -e6" ); 93 e6.notify(10,SC_NS ); 94 } 95 } 96 97 SC_CTOR( mod_a ) 98 { 99 SC_THREAD(sender1); 100 SC_THREAD(sender2); 101 SC_THREAD(receiver1); 102 SC_THREAD(receiver2); 103 } 104}; 105 106 107int 108sc_main( int, char*[] ) 109{ 110 mod_a a( "a" ); 111 cout<<endl; 112 cout<<"sender_1 notifies e1 after 10 ns, e2 after 20 ns\n"; 113 cout<<"sender_2 notifies e3 after 10 ns, e4 after 15 ns\n"; 114 cout<<"receiver_1 notifies e5 after 10 ns\n"; 115 cout<<"receiver_2 notifies e6 after 10 ns\n"; 116 cout << endl; 117 sc_start(100,SC_NS); 118 119 return 0; 120} 121