test02.cpp revision 13158
15831Sgblack@eecs.umich.edu/***************************************************************************** 25831Sgblack@eecs.umich.edu 35831Sgblack@eecs.umich.edu Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 45831Sgblack@eecs.umich.edu more contributor license agreements. See the NOTICE file distributed 55831Sgblack@eecs.umich.edu with this work for additional information regarding copyright ownership. 65831Sgblack@eecs.umich.edu Accellera licenses this file to you under the Apache License, Version 2.0 75831Sgblack@eecs.umich.edu (the "License"); you may not use this file except in compliance with the 85831Sgblack@eecs.umich.edu License. You may obtain a copy of the License at 95831Sgblack@eecs.umich.edu 105831Sgblack@eecs.umich.edu http://www.apache.org/licenses/LICENSE-2.0 115831Sgblack@eecs.umich.edu 125831Sgblack@eecs.umich.edu Unless required by applicable law or agreed to in writing, software 135831Sgblack@eecs.umich.edu distributed under the License is distributed on an "AS IS" BASIS, 145831Sgblack@eecs.umich.edu WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 155831Sgblack@eecs.umich.edu implied. See the License for the specific language governing 165831Sgblack@eecs.umich.edu permissions and limitations under the License. 175831Sgblack@eecs.umich.edu 185831Sgblack@eecs.umich.edu *****************************************************************************/ 195831Sgblack@eecs.umich.edu 205831Sgblack@eecs.umich.edu/***************************************************************************** 215831Sgblack@eecs.umich.edu 225831Sgblack@eecs.umich.edu test02.cpp -- Test SC_FORK and SC_JOIN macros. 235831Sgblack@eecs.umich.edu 245831Sgblack@eecs.umich.edu Original Author: Andy Goodrich, Forte Design Systems, 10 October 2004 255831Sgblack@eecs.umich.edu 265831Sgblack@eecs.umich.edu *****************************************************************************/ 275831Sgblack@eecs.umich.edu 285831Sgblack@eecs.umich.edu/***************************************************************************** 295831Sgblack@eecs.umich.edu 305831Sgblack@eecs.umich.edu MODIFICATION LOG - modifiers, enter your name, affiliation, date and 315831Sgblack@eecs.umich.edu changes you are making here. 325831Sgblack@eecs.umich.edu 3312653Sandreas.sandberg@arm.com Name, Affiliation, Date: 345831Sgblack@eecs.umich.edu Description of Modification: 355831Sgblack@eecs.umich.edu 365831Sgblack@eecs.umich.edu *****************************************************************************/ 375831Sgblack@eecs.umich.edu 389338SAndreas.Sandberg@arm.com#include "systemc.h" 395859Sgblack@eecs.umich.edu 405859Sgblack@eecs.umich.eduSC_MODULE(X) 415831Sgblack@eecs.umich.edu{ 425831Sgblack@eecs.umich.edu SC_CTOR(X) 435831Sgblack@eecs.umich.edu { 445831Sgblack@eecs.umich.edu 455831Sgblack@eecs.umich.edu SC_THREAD(waiting); 465831Sgblack@eecs.umich.edu } 4712653Sandreas.sandberg@arm.com void sync(int context) 4812653Sandreas.sandberg@arm.com { 4912653Sandreas.sandberg@arm.com for ( int i = 0; i < context; i++ ) 50 { 51 wait(m_clk.posedge_event()); 52 } 53 cout << sc_time_stamp() << ": sync(" << context << ") terminating"<< endl; 54 } 55 void waiting() 56 { 57 SC_FORK 58 sc_spawn( sc_bind( &X::sync, this, 3 ) ), 59 sc_spawn( sc_bind( &X::sync, this, 4 ) ), 60 sc_spawn( sc_bind( &X::sync, this, 5 ) ), 61 sc_spawn( sc_bind( &X::sync, this, 5 ) ), 62 sc_spawn( sc_bind( &X::sync, this, 7 ) ), 63 sc_spawn( sc_bind( &X::sync, this, 11) ), 64 sc_spawn( sc_bind( &X::sync, this, 21) ) 65 SC_JOIN 66 cout << sc_time_stamp() << ": waiting waking" << endl; 67 } 68 69 sc_in_clk m_clk; 70 sc_join m_join; 71}; 72 73int sc_main( int argc, char* argv[] ) 74{ 75 sc_clock clock; 76 X x("x"); 77 x.m_clk(clock); 78 79 sc_start(1000, SC_NS); 80 81 cout << "Program completed" << endl; 82 return 0; 83} 84 85