test10.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 test10.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// test of wait() for dynamic sensitivity 39 40#include "systemc.h" 41 42SC_MODULE( mod_a ) 43{ 44 sc_event e1; 45 sc_event e2; 46 sc_event e3; 47 sc_event e_ack; 48 49 void write( const char* msg ) 50 { 51 cout << sc_delta_count() << ":" << sc_time_stamp() 52 << " " << msg << "\n"; 53 } 54 55 void sender() 56 { 57 // wait one delta cycle 58 wait( SC_ZERO_TIME ); 59 60 while( true ) { 61 e1.notify(); 62 e2.notify( SC_ZERO_TIME ); 63 e3.notify( 2, SC_NS ); 64 timed_out() ? write( "sender - timed out" ) 65 : write( "sender" ); 66 wait( 3, SC_NS, e_ack ); 67 e2.cancel(); 68 e3.cancel(); 69 } 70 } 71 72 void receiver() 73 { 74 sc_time t1( 1, SC_NS ); 75 76 while( true ) { 77 78 // test wait(e) 79 cout << "*** wait(e)\n"; 80 81 wait( e1 ); 82 write( "receiver - e1" ); 83 e_ack.notify(); 84 wait( e2 ); 85 write( "receiver - e2" ); 86 e_ack.notify(); 87 wait( e3 ); 88 write( "receiver - e3" ); 89 e_ack.notify(); 90 91 // test wait(or_list) 92 cout << "*** wait(or_list)\n"; 93 94 wait( e1 | e1 | e1 ); 95 write( "receiver - e1 | e1 | e1" ); 96 e_ack.notify(); 97 wait( e2 | e2 | e2 ); 98 write( "receiver - e2 | e2 | e2" ); 99 e_ack.notify(); 100 wait( e3 | e3 | e3 ); 101 write( "receiver - e3 | e3 | e3" ); 102 e_ack.notify(); 103 wait( e1 | e2 | e3 ); 104 write( "receiver - e1 | e2 | e3" ); 105 e_ack.notify(); 106 wait( e3 | e2 | e1 ); 107 write( "receiver - e3 | e2 | e1" ); 108 e_ack.notify(); 109 110 // test wait(and_list) 111 cout << "*** wait(and_list)\n"; 112 113 wait( e1 & e1 & e1 ); 114 write( "receiver - e1 & e1 & e1" ); 115 e_ack.notify(); 116 wait( e2 & e2 & e2 ); 117 write( "receiver - e2 & e2 & e2" ); 118 e_ack.notify(); 119 wait( e3 & e3 & e3 ); 120 write( "receiver - e3 & e3 & e3" ); 121 e_ack.notify(); 122 wait( e1 & e2 & e3 ); 123 write( "receiver - e1 & e2 & e3" ); 124 e_ack.notify(); 125 wait( e3 & e2 & e1 ); 126 write( "receiver - e3 & e2 & e1" ); 127 128 // test wait(t) 129 cout << "*** wait(t)\n"; 130 131 wait( 0, SC_NS ); 132 write( "receiver - 0 ns" ); 133 wait( 1, SC_NS ); 134 write( "receiver - 1 ns" ); 135 136 e_ack.notify(); 137 138 // test wait(t,e) 139 cout << "*** wait(t,e)\n"; 140 141 wait( 1, SC_NS, e1 ); 142 timed_out() ? write( "receiver - 1 ns | e1 - timed out" ) 143 : write( "receiver - 1 ns | e1" ); 144 e_ack.notify(); 145 wait( t1, e2 ); 146 timed_out() ? write( "receiver - 1 ns | e2 - timed out" ) 147 : write( "receiver - 1 ns | e2" ); 148 e_ack.notify(); 149 wait( 1, SC_NS, e3 ); 150 timed_out() ? write( "receiver - 1 ns | e3 - timed out" ) 151 : write( "receiver - 1 ns | e3" ); 152 e_ack.notify(); 153 154 // test wait(t,or_list) 155 cout << "*** wait(t,or_list)\n"; 156 157 wait( t1, e1 | e2 | e3 ); 158 timed_out() ? write( "receiver - 1 ns | e1 | e2 | e3 - timed out" ) 159 : write( "receiver - 1 ns | e1 | e2 | e3" ); 160 e_ack.notify(); 161 162 // test wait(t,and_list) 163 cout << "*** wait(t,and_list)\n"; 164 165 wait( t1, e1 & e2 & e3 ); 166 timed_out() ? write( "receiver - 1 ns | e1 & e2 & e3 - timed out" ) 167 : write( "receiver - 1 ns | e1 & e2 & e3" ); 168 169 sc_stop(); 170 write( "receiver - stop" ); 171 wait( SC_ZERO_TIME ); 172 } 173 } 174 175 SC_CTOR( mod_a ) 176 { 177 SC_THREAD( sender ); 178 SC_THREAD( receiver ); 179 } 180}; 181 182int 183sc_main( int, char*[] ) 184{ 185 mod_a a( "a" ); 186 187 sc_start(); 188 189 return 0; 190} 191