test07.cpp revision 12855:588919e0e4aa
14202Sbinkertn@umich.edu/***************************************************************************** 24202Sbinkertn@umich.edu 34202Sbinkertn@umich.edu Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 44202Sbinkertn@umich.edu more contributor license agreements. See the NOTICE file distributed 54202Sbinkertn@umich.edu with this work for additional information regarding copyright ownership. 64202Sbinkertn@umich.edu Accellera licenses this file to you under the Apache License, Version 2.0 74202Sbinkertn@umich.edu (the "License"); you may not use this file except in compliance with the 84202Sbinkertn@umich.edu License. You may obtain a copy of the License at 94202Sbinkertn@umich.edu 104202Sbinkertn@umich.edu http://www.apache.org/licenses/LICENSE-2.0 114202Sbinkertn@umich.edu 124202Sbinkertn@umich.edu Unless required by applicable law or agreed to in writing, software 134202Sbinkertn@umich.edu distributed under the License is distributed on an "AS IS" BASIS, 144202Sbinkertn@umich.edu WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 154202Sbinkertn@umich.edu implied. See the License for the specific language governing 164202Sbinkertn@umich.edu permissions and limitations under the License. 174202Sbinkertn@umich.edu 184202Sbinkertn@umich.edu *****************************************************************************/ 194202Sbinkertn@umich.edu 204202Sbinkertn@umich.edu/***************************************************************************** 214202Sbinkertn@umich.edu 224202Sbinkertn@umich.edu test07.cpp -- 234202Sbinkertn@umich.edu 244202Sbinkertn@umich.edu Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 254202Sbinkertn@umich.edu 264202Sbinkertn@umich.edu *****************************************************************************/ 274202Sbinkertn@umich.edu 284202Sbinkertn@umich.edu/***************************************************************************** 294202Sbinkertn@umich.edu 304202Sbinkertn@umich.edu MODIFICATION LOG - modifiers, enter your name, affiliation, date and 314202Sbinkertn@umich.edu changes you are making here. 324202Sbinkertn@umich.edu 338831Smrinmoy.ghosh@arm.com Name, Affiliation, Date: 347768SAli.Saidi@ARM.com Description of Modification: 3513554Sjavier.bueno@metempsy.com 365337Sstever@gmail.com *****************************************************************************/ 3713717Sivan.pizarro@metempsy.com 3813667Sjavier.bueno@metempsy.com// test of sc_event's methods; with static method receiver 3913669Sjavier.bueno@metempsy.com 4010623Smitch.hayenga@arm.com#include "systemc.h" 4113735Sivan.pizarro@metempsy.com 4213553Sjavier.bueno@metempsy.comSC_MODULE( mod_a ) 4313624Sjavier.bueno@metempsy.com{ 4413700Sjavier.bueno@metempsy.com sc_event e; 455337Sstever@gmail.com 465337Sstever@gmail.com void write( const char* msg ) 47 { 48 cout << sc_delta_count() << ":" << sc_time_stamp() 49 << " " << msg << "\n"; 50 } 51 52 void sender() 53 { 54 // wait one delta cycle 55 wait( SC_ZERO_TIME ); 56 57 while( true ) { 58 59 // test cancel() 60 cout << "*** cancel()\n"; 61 62 // immediate notification 63 e.notify(); 64 write( "sender - immediate" ); 65 wait( SC_ZERO_TIME ); 66 67 // immediate notification -- canceled (no effect) 68 e.notify(); 69 write( "sender - immediate" ); 70 e.cancel(); 71 write( "sender - canceled" ); 72 wait( SC_ZERO_TIME ); 73 74 // delta notification 75 e.notify( SC_ZERO_TIME ); 76 write( "sender - delta" ); 77 wait( SC_ZERO_TIME ); 78 wait( SC_ZERO_TIME ); 79 80 // delta notification -- canceled 81 e.notify( SC_ZERO_TIME ); 82 write( "sender - delta" ); 83 e.cancel(); 84 write( "sender - canceled" ); 85 wait( SC_ZERO_TIME ); 86 wait( SC_ZERO_TIME ); 87 88 // timed notification 89 e.notify( 1, SC_NS ); 90 write( "sender - timed 1 ns" ); 91 wait( 1, SC_NS ); 92 wait( SC_ZERO_TIME ); 93 94 // timed notification -- canceled 95 e.notify( 1, SC_NS ); 96 write( "sender - timed 1 ns" ); 97 e.cancel(); 98 write( "sender - canceled" ); 99 wait( 1, SC_NS ); 100 wait( SC_ZERO_TIME ); 101 102 // timed notifiation -- canceled 103 e.notify( 2, SC_NS ); 104 write( "sender - timed 2 ns" ); 105 wait( 1, SC_NS ); 106 e.cancel(); 107 write( "sender - canceled" ); 108 wait( 1, SC_NS ); 109 wait( SC_ZERO_TIME ); 110 111 // test notify() -- the exception test is in test03.cpp 112 cout << "*** notify()\n"; 113 114 // delta notification -- made immediate 115 e.notify( SC_ZERO_TIME ); 116 write( "sender - delta" ); 117 e.notify(); 118 write( "sender - immediate" ); 119 wait( SC_ZERO_TIME ); 120 wait( SC_ZERO_TIME ); 121 122 // timed notification -- made immediate 123 e.notify( 1, SC_NS ); 124 write( "sender - timed 1 ns" ); 125 e.notify(); 126 write( "sender - immediate" ); 127 wait( 1, SC_NS ); 128 wait( SC_ZERO_TIME ); 129 130 // timed notification -- made immediate 131 e.notify( 2, SC_NS ); 132 write( "sender - timed 2 ns" ); 133 wait( 1, SC_NS ); 134 e.notify(); 135 write( "sender - immediate" ); 136 wait( 1, SC_NS ); 137 wait( SC_ZERO_TIME ); 138 139 // test notify(t) 140 cout << "*** notify(t)\n"; 141 142 e.notify( SC_ZERO_TIME ); 143 write( "sender - delta" ); 144 e.notify( 1, SC_NS ); 145 write( "sender - timed 1 ns" ); 146 wait( 1, SC_NS ); 147 wait( SC_ZERO_TIME ); 148 149 e.notify( 1, SC_NS ); 150 write( "sender - timed 1 ns" ); 151 e.notify( SC_ZERO_TIME ); 152 write( "sender - delta" ); 153 wait( 1, SC_NS ); 154 wait( SC_ZERO_TIME ); 155 156 e.notify( 2, SC_NS ); 157 write( "sender - timed 2 ns" ); 158 e.notify( 1, SC_NS ); 159 write( "sender - timed 1 ns" ); 160 wait( 2, SC_NS ); 161 wait( SC_ZERO_TIME ); 162 163 e.notify( 1, SC_NS ); 164 write( "sender - timed 1 ns" ); 165 e.notify( 2, SC_NS ); 166 write( "sender - timed 2 ns" ); 167 wait( 2, SC_NS ); 168 wait( SC_ZERO_TIME ); 169 170 sc_stop(); 171 write( "sender - stop" ); 172 wait( SC_ZERO_TIME ); 173 } 174 } 175 176 bool receiver_first; 177 178 void receiver() 179 { 180 if( receiver_first ) { 181 receiver_first = false; 182 return; 183 } 184 write( "receiver" ); 185 } 186 187 SC_CTOR( mod_a ) 188 { 189 SC_THREAD( sender ); 190 SC_METHOD( receiver ); 191 sensitive << e; 192 receiver_first = true; 193 } 194}; 195 196int 197sc_main( int, char*[] ) 198{ 199 mod_a a( "a" ); 200 201 sc_start(); 202 203 return 0; 204} 205