test09.cpp revision 12855
12931Sktlim@umich.edu/*****************************************************************************
22931Sktlim@umich.edu
32931Sktlim@umich.edu  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
42931Sktlim@umich.edu  more contributor license agreements.  See the NOTICE file distributed
52931Sktlim@umich.edu  with this work for additional information regarding copyright ownership.
62931Sktlim@umich.edu  Accellera licenses this file to you under the Apache License, Version 2.0
72931Sktlim@umich.edu  (the "License"); you may not use this file except in compliance with the
82931Sktlim@umich.edu  License.  You may obtain a copy of the License at
92931Sktlim@umich.edu
102931Sktlim@umich.edu    http://www.apache.org/licenses/LICENSE-2.0
112931Sktlim@umich.edu
122931Sktlim@umich.edu  Unless required by applicable law or agreed to in writing, software
132931Sktlim@umich.edu  distributed under the License is distributed on an "AS IS" BASIS,
142931Sktlim@umich.edu  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152931Sktlim@umich.edu  implied.  See the License for the specific language governing
162931Sktlim@umich.edu  permissions and limitations under the License.
172931Sktlim@umich.edu
182931Sktlim@umich.edu *****************************************************************************/
192931Sktlim@umich.edu
202931Sktlim@umich.edu/*****************************************************************************
212931Sktlim@umich.edu
222931Sktlim@umich.edu  test09.cpp --
232931Sktlim@umich.edu
242931Sktlim@umich.edu  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
252931Sktlim@umich.edu
262931Sktlim@umich.edu *****************************************************************************/
272931Sktlim@umich.edu
282931Sktlim@umich.edu/*****************************************************************************
292774SN/A
302774SN/A  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
312774SN/A  changes you are making here.
322566SN/A
332902SN/A      Name, Affiliation, Date:
342902SN/A  Description of Modification:
352902SN/A
362566SN/A *****************************************************************************/
372902SN/A
382902SN/A// test of sc_event's methods; with functional notation for notifying events.
392902SN/A
402902SN/A#include "systemc.h"
412902SN/A
422902SN/ASC_MODULE( mod_a )
432902SN/A{
442902SN/A    sc_event e;
452902SN/A
462902SN/A    void write( const char* msg )
472774SN/A    {
482774SN/A        cout << sc_delta_count() << ":" << sc_time_stamp()
492774SN/A             << " " << msg << "\n";
502784SN/A    }
512566SN/A
522902SN/A    void sender()
532902SN/A    {
542774SN/A        // wait one delta cycle
552774SN/A        wait( SC_ZERO_TIME );
562774SN/A
572566SN/A        while( true ) {
582902SN/A
592902SN/A            // test cancel()
602902SN/A            cout << "*** cancel()\n";
612902SN/A
622902SN/A            // immediate notification
632902SN/A            e.notify();
642566SN/A            write( "sender - immediate" );
652902SN/A            wait( SC_ZERO_TIME );
662902SN/A
672902SN/A            // immediate notification -- canceled (no effect)
682902SN/A            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( e );
180            write( "receiver" );
181        }
182    }
183
184    SC_CTOR( mod_a )
185    {
186        SC_THREAD( sender );
187        SC_THREAD( receiver );
188    }
189};
190
191int
192sc_main( int, char*[] )
193{
194    mod_a a( "a" );
195
196    sc_start();
197
198    return 0;
199}
200