test11.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  test11.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 next_trigger() 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    bool sender_first;
56
57    void sender()
58    {
59        if( sender_first ) {
60            next_trigger( SC_ZERO_TIME );
61            sender_first = false;
62            return;
63        }
64
65        e2.cancel();
66        e3.cancel();
67        e1.notify();
68        e2.notify( SC_ZERO_TIME );
69        e3.notify( 2, SC_NS );
70        timed_out() ? write( "sender - timed out" )
71                    : write( "sender" );
72        next_trigger( 3, SC_NS, e_ack );
73    }
74
75    int receiver_state;
76
77    void receiver()
78    {
79        sc_time t1( 1, SC_NS );
80
81        switch( receiver_state ) {
82	case 0:
83	    // test next_trigger(e)
84	    cout << "*** next_trigger(e)\n";
85
86	    next_trigger( e1 );
87	    break;
88	case 1:
89	    write( "receiver - e1" );
90	    e_ack.notify();
91	    next_trigger( e2 );
92	    break;
93	case 2:
94	    write( "receiver - e2" );
95	    e_ack.notify();
96	    next_trigger( e3 );
97	    break;
98	case 3:
99	    write( "receiver - e3" );
100	    e_ack.notify();
101
102	    // test next_trigger(or_list)
103	    cout << "*** next_trigger(or_list)\n";
104
105	    next_trigger( e1 | e1 | e1 );
106	    break;
107	case 4:
108	    write( "receiver - e1 | e1 | e1" );
109	    e_ack.notify();
110	    next_trigger( e2 | e2 | e2 );
111	    break;
112	case 5:
113	    write( "receiver - e2 | e2 | e2" );
114	    e_ack.notify();
115	    next_trigger( e3 | e3 | e3 );
116	    break;
117	case 6:
118	    write( "receiver - e3 | e3 | e3" );
119	    e_ack.notify();
120	    next_trigger( e1 | e2 | e3 );
121	    break;
122	case 7:
123	    write( "receiver - e1 | e2 | e3" );
124	    e_ack.notify();
125	    next_trigger( e3 | e2 | e1 );
126	    break;
127	case 8:
128	    write( "receiver - e3 | e2 | e1" );
129	    e_ack.notify();
130
131	    // test next_trigger(and_list)
132	    cout << "*** next_trigger(and_list)\n";
133
134	    next_trigger( e1 & e1 & e1 );
135	    break;
136	case 9:
137	    write( "receiver - e1 & e1 & e1" );
138	    e_ack.notify();
139	    next_trigger( e2 & e2 & e2 );
140	    break;
141	case 10:
142	    write( "receiver - e2 & e2 & e2" );
143	    e_ack.notify();
144	    next_trigger( e3 & e3 & e3 );
145	    break;
146	case 11:
147	    write( "receiver - e3 & e3 & e3" );
148	    e_ack.notify();
149	    next_trigger( e1 & e2 & e3 );
150	    break;
151	case 12:
152	    write( "receiver - e1 & e2 & e3" );
153	    e_ack.notify();
154	    next_trigger( e3 & e2 & e1 );
155	    break;
156	case 13:
157	    write( "receiver - e3 & e2 & e1" );
158
159	    // test next_trigger(t)
160	    cout << "*** next_trigger(t)\n";
161
162	    next_trigger( 0, SC_NS );
163	    break;
164	case 14:
165	    write( "receiver - 0 ns" );
166	    next_trigger( 1, SC_NS );
167	    break;
168	case 15:
169	    write( "receiver - 1 ns" );
170
171	    e_ack.notify();
172
173	    // test next_trigger(t,e)
174	    cout << "*** next_trigger(t,e)\n";
175
176	    next_trigger( 1, SC_NS, e1 );
177	    break;
178	case 16:
179	    timed_out() ? write( "receiver - 1 ns | e1 - timed out" )
180		        : write( "receiver - 1 ns | e1" );
181	    e_ack.notify();
182	    next_trigger( t1, e2 );
183	    break;
184	case 17:
185	    timed_out() ? write( "receiver - 1 ns | e2 - timed out" )
186                        : write( "receiver - 1 ns | e2" );
187	    e_ack.notify();
188	    next_trigger( 1, SC_NS, e3 );
189	    break;
190	case 18:
191	    timed_out() ? write( "receiver - 1 ns | e3 - timed out" )
192		        : write( "receiver - 1 ns | e3" );
193	    e_ack.notify();
194
195	    // test next_trigger(t,or_list)
196	    cout << "*** next_trigger(t,or_list)\n";
197
198	    next_trigger( t1, e1 | e2 | e3 );
199	    break;
200	case 19:
201	    timed_out() ? write( "receiver - 1 ns | e1 | e2 | e3 - timed out" )
202                        : write( "receiver - 1 ns | e1 | e2 | e3" );
203	    e_ack.notify();
204
205	    // test next_trigger(t,and_list)
206	    cout << "*** next_trigger(t,and_list)\n";
207
208	    next_trigger( t1, e1 & e2 & e3 );
209	    break;
210	case 20:
211	    timed_out() ? write( "receiver - 1 ns | e1 & e2 & e3 - timed out" )
212                        : write( "receiver - 1 ns | e1 & e2 & e3" );
213
214	    sc_stop();
215	    write( "receiver - stop" );
216	    next_trigger( SC_ZERO_TIME );
217	    break;
218	default:
219	    sc_assert( false );
220        }
221	receiver_state ++;
222    }
223
224    SC_CTOR( mod_a )
225    {
226        SC_METHOD( sender );
227        sender_first = true;
228        SC_METHOD( receiver );
229        receiver_state = 0;
230    }
231};
232
233int
234sc_main( int, char*[] )
235{
236    mod_a a( "a" );
237
238    sc_start();
239
240    return 0;
241}
242