test12.cpp revision 12855:588919e0e4aa
113521Sgabeblack@google.com/***************************************************************************** 213521Sgabeblack@google.com 313521Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 413521Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 513521Sgabeblack@google.com with this work for additional information regarding copyright ownership. 613521Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 713521Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 813521Sgabeblack@google.com License. You may obtain a copy of the License at 913521Sgabeblack@google.com 1013521Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1113521Sgabeblack@google.com 1213521Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1313521Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1413521Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1513521Sgabeblack@google.com implied. See the License for the specific language governing 1613521Sgabeblack@google.com permissions and limitations under the License. 1713521Sgabeblack@google.com 1813521Sgabeblack@google.com *****************************************************************************/ 1913521Sgabeblack@google.com 2013521Sgabeblack@google.com/***************************************************************************** 2113521Sgabeblack@google.com 2213521Sgabeblack@google.com test12.cpp -- 2313586Sgabeblack@google.com 2413521Sgabeblack@google.com Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 2513521Sgabeblack@google.com 2613521Sgabeblack@google.com *****************************************************************************/ 2713521Sgabeblack@google.com 2813521Sgabeblack@google.com/***************************************************************************** 2913521Sgabeblack@google.com 3013521Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3113521Sgabeblack@google.com changes you are making here. 3213521Sgabeblack@google.com 3313521Sgabeblack@google.com Name, Affiliation, Date: 3413521Sgabeblack@google.com Description of Modification: 3513521Sgabeblack@google.com 3613521Sgabeblack@google.com *****************************************************************************/ 3713521Sgabeblack@google.com 3813521Sgabeblack@google.com// test of next_trigger() for dynamic sensitivity; last call counts 3913521Sgabeblack@google.com 4013521Sgabeblack@google.com#include "systemc.h" 4113521Sgabeblack@google.com 4213521Sgabeblack@google.comSC_MODULE( mod_a ) 4313521Sgabeblack@google.com{ 4413521Sgabeblack@google.com sc_event e1; 4513521Sgabeblack@google.com sc_event e2; 4613521Sgabeblack@google.com sc_event e3; 4713521Sgabeblack@google.com sc_event e_ack; 4813521Sgabeblack@google.com 4913521Sgabeblack@google.com void write( const char* msg ) 5013521Sgabeblack@google.com { 5113521Sgabeblack@google.com cout << sc_delta_count() << ":" << sc_time_stamp() 5213521Sgabeblack@google.com << " " << msg << "\n"; 5313521Sgabeblack@google.com } 5413521Sgabeblack@google.com 5513521Sgabeblack@google.com bool sender_first; 5613521Sgabeblack@google.com 5713521Sgabeblack@google.com void sender() 5813521Sgabeblack@google.com { 5913521Sgabeblack@google.com next_trigger( SC_ZERO_TIME ); 6013521Sgabeblack@google.com if( sender_first ) { 6113521Sgabeblack@google.com sender_first = false; 6213521Sgabeblack@google.com return; 6313521Sgabeblack@google.com } 6413521Sgabeblack@google.com 6513521Sgabeblack@google.com e2.cancel(); 6613521Sgabeblack@google.com e3.cancel(); 6713521Sgabeblack@google.com e1.notify(); 6813521Sgabeblack@google.com e2.notify( SC_ZERO_TIME ); 6913521Sgabeblack@google.com e3.notify( 2, SC_NS ); 7013521Sgabeblack@google.com timed_out() ? write( "sender - timed out" ) 7113521Sgabeblack@google.com : write( "sender" ); 7213521Sgabeblack@google.com next_trigger( 3, SC_NS, e_ack ); 7313521Sgabeblack@google.com } 7413521Sgabeblack@google.com 7513521Sgabeblack@google.com int receiver_state; 7613521Sgabeblack@google.com 7713521Sgabeblack@google.com void receiver() 7813521Sgabeblack@google.com { 7913521Sgabeblack@google.com sc_time t1( 1, SC_NS ); 8013521Sgabeblack@google.com 8113521Sgabeblack@google.com switch( receiver_state ) { 8213521Sgabeblack@google.com case 0: 8313521Sgabeblack@google.com // test next_trigger(e) 8413521Sgabeblack@google.com cout << "*** next_trigger(e)\n"; 8513521Sgabeblack@google.com 8613521Sgabeblack@google.com next_trigger( e1 ); 8713521Sgabeblack@google.com break; 8813521Sgabeblack@google.com case 1: 8913521Sgabeblack@google.com write( "receiver - e1" ); 9013521Sgabeblack@google.com e_ack.notify(); 9113521Sgabeblack@google.com next_trigger( e1 ); 9213521Sgabeblack@google.com next_trigger( e2 ); 9313521Sgabeblack@google.com break; 9413521Sgabeblack@google.com case 2: 9513521Sgabeblack@google.com write( "receiver - e2" ); 9613521Sgabeblack@google.com e_ack.notify(); 9713521Sgabeblack@google.com next_trigger( e2 ); 9813521Sgabeblack@google.com next_trigger( e3 ); 9913521Sgabeblack@google.com break; 10013521Sgabeblack@google.com case 3: 101 write( "receiver - e3" ); 102 e_ack.notify(); 103 104 // test next_trigger(or_list) 105 cout << "*** next_trigger(or_list)\n"; 106 107 next_trigger( e3 ); 108 next_trigger( e1 | e1 | e1 ); 109 break; 110 case 4: 111 write( "receiver - e1 | e1 | e1" ); 112 e_ack.notify(); 113 next_trigger( e1 | e1 | e1 ); 114 next_trigger( e2 | e2 | e2 ); 115 break; 116 case 5: 117 write( "receiver - e2 | e2 | e2" ); 118 e_ack.notify(); 119 next_trigger( e2 | e2 | e2 ); 120 next_trigger( e3 | e3 | e3 ); 121 break; 122 case 6: 123 write( "receiver - e3 | e3 | e3" ); 124 e_ack.notify(); 125 next_trigger( e3 | e3 | e3 ); 126 next_trigger( e1 | e2 | e3 ); 127 break; 128 case 7: 129 write( "receiver - e1 | e2 | e3" ); 130 e_ack.notify(); 131 next_trigger( e1 | e2 | e3 ); 132 next_trigger( e3 | e2 | e1 ); 133 break; 134 case 8: 135 write( "receiver - e3 | e2 | e1" ); 136 e_ack.notify(); 137 138 // test next_trigger(and_list) 139 cout << "*** next_trigger(and_list)\n"; 140 141 next_trigger( e3 | e2 | e1 ); 142 next_trigger( e1 & e1 & e1 ); 143 break; 144 case 9: 145 write( "receiver - e1 & e1 & e1" ); 146 e_ack.notify(); 147 next_trigger( e1 & e1 & e1 ); 148 next_trigger( e2 & e2 & e2 ); 149 break; 150 case 10: 151 write( "receiver - e2 & e2 & e2" ); 152 e_ack.notify(); 153 next_trigger( e2 & e2 & e2 ); 154 next_trigger( e3 & e3 & e3 ); 155 break; 156 case 11: 157 write( "receiver - e3 & e3 & e3" ); 158 e_ack.notify(); 159 next_trigger( e3 & e3 & e3 ); 160 next_trigger( e1 & e2 & e3 ); 161 break; 162 case 12: 163 write( "receiver - e1 & e2 & e3" ); 164 e_ack.notify(); 165 next_trigger( e1 & e2 & e3 ); 166 next_trigger( e3 & e2 & e1 ); 167 break; 168 case 13: 169 write( "receiver - e3 & e2 & e1" ); 170 171 // test next_trigger(t) 172 cout << "*** next_trigger(t)\n"; 173 174 next_trigger( e3 & e2 & e1 ); 175 next_trigger( 0, SC_NS ); 176 break; 177 case 14: 178 write( "receiver - 0 ns" ); 179 next_trigger( 0, SC_NS ); 180 next_trigger( 1, SC_NS ); 181 break; 182 case 15: 183 write( "receiver - 1 ns" ); 184 185 e_ack.notify(); 186 187 // test next_trigger(t,e) 188 cout << "*** next_trigger(t,e)\n"; 189 190 next_trigger( 1, SC_NS ); 191 next_trigger( 1, SC_NS, e1 ); 192 break; 193 case 16: 194 timed_out() ? write( "receiver - 1 ns | e1 - timed out" ) 195 : write( "receiver - 1 ns | e1" ); 196 e_ack.notify(); 197 next_trigger( 1, SC_NS, e1 ); 198 next_trigger( t1, e2 ); 199 break; 200 case 17: 201 timed_out() ? write( "receiver - 1 ns | e2 - timed out" ) 202 : write( "receiver - 1 ns | e2" ); 203 e_ack.notify(); 204 next_trigger( t1, e2 ); 205 next_trigger( 1, SC_NS, e3 ); 206 break; 207 case 18: 208 timed_out() ? write( "receiver - 1 ns | e3 - timed out" ) 209 : write( "receiver - 1 ns | e3" ); 210 e_ack.notify(); 211 212 // test next_trigger(t,or_list) 213 cout << "*** next_trigger(t,or_list)\n"; 214 215 next_trigger( 1, SC_NS, e3 ); 216 next_trigger( t1, e1 | e2 | e3 ); 217 break; 218 case 19: 219 timed_out() ? write( "receiver - 1 ns | e1 | e2 | e3 - timed out" ) 220 : write( "receiver - 1 ns | e1 | e2 | e3" ); 221 e_ack.notify(); 222 223 // test next_trigger(t,and_list) 224 cout << "*** next_trigger(t,and_list)\n"; 225 226 next_trigger( t1, e1 | e2 | e3 ); 227 next_trigger( t1, e1 & e2 & e3 ); 228 break; 229 case 20: 230 timed_out() ? write( "receiver - 1 ns | e1 & e2 & e3 - timed out" ) 231 : write( "receiver - 1 ns | e1 & e2 & e3" ); 232 233 sc_stop(); 234 write( "receiver - stop" ); 235 next_trigger( t1, e1 & e2 & e3 ); 236 next_trigger( SC_ZERO_TIME ); 237 break; 238 default: 239 sc_assert( false ); 240 } 241 receiver_state ++; 242 } 243 244 SC_CTOR( mod_a ) 245 { 246 SC_METHOD( sender ); 247 sender_first = true; 248 SC_METHOD( receiver ); 249 receiver_state = 0; 250 } 251}; 252 253int 254sc_main( int, char*[] ) 255{ 256 mod_a a( "a" ); 257 258 sc_start(); 259 260 return 0; 261} 262