test06.cpp revision 12855:588919e0e4aa
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 test06.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// test of sc_event's methods; with static thread receiver 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com#include "systemc.h" 4112855Sgabeblack@google.com 4212855Sgabeblack@google.comSC_MODULE( mod_a ) 4312855Sgabeblack@google.com{ 4412855Sgabeblack@google.com sc_event e; 4512855Sgabeblack@google.com 4612855Sgabeblack@google.com void write( const char* msg ) 4712855Sgabeblack@google.com { 4812855Sgabeblack@google.com cout << sc_delta_count() << ":" << sc_time_stamp() 4912855Sgabeblack@google.com << " " << msg << "\n"; 5012855Sgabeblack@google.com } 5112855Sgabeblack@google.com 5212855Sgabeblack@google.com void sender() 5312855Sgabeblack@google.com { 5412855Sgabeblack@google.com // wait one delta cycle 5512855Sgabeblack@google.com wait( SC_ZERO_TIME ); 5612855Sgabeblack@google.com 5712855Sgabeblack@google.com while( true ) { 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com // test cancel() 6012855Sgabeblack@google.com cout << "*** cancel()\n"; 6112855Sgabeblack@google.com 6212855Sgabeblack@google.com // 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 void receiver() 177 { 178 while( true ) { 179 wait(); 180 write( "receiver" ); 181 } 182 } 183 184 SC_CTOR( mod_a ) 185 { 186 SC_THREAD( sender ); 187 SC_THREAD( receiver ); 188 sensitive << e; 189 } 190}; 191 192int 193sc_main( int, char*[] ) 194{ 195 mod_a a( "a" ); 196 197 sc_start(); 198 199 return 0; 200} 201