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 test07.cpp -- 2312855Sgabeblack@google.com 2412855Sgabeblack@google.com Original Author: Ucar Aziz, Synopsys, Inc., 2002-02-15 2512855Sgabeblack@google.com Martin Janssen, Synopsys, Inc., 2002-02-15 2612855Sgabeblack@google.com 2712855Sgabeblack@google.com *****************************************************************************/ 2812855Sgabeblack@google.com 2912855Sgabeblack@google.com/***************************************************************************** 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3212855Sgabeblack@google.com changes you are making here. 3312855Sgabeblack@google.com 3412855Sgabeblack@google.com Name, Affiliation, Date: 3512855Sgabeblack@google.com Description of Modification: 3612855Sgabeblack@google.com 3712855Sgabeblack@google.com *****************************************************************************/ 3812855Sgabeblack@google.com 3912855Sgabeblack@google.com// test of sc_prim_channel::next_trigger(const sc_time&, sc_event&) 4012855Sgabeblack@google.com 4112855Sgabeblack@google.com#include <systemc.h> 4212855Sgabeblack@google.com 4312855Sgabeblack@google.com//write and read interfaces 4412855Sgabeblack@google.comclass write_if : virtual public 4512855Sgabeblack@google.comsc_interface 4612855Sgabeblack@google.com { 4712855Sgabeblack@google.com public: 4812855Sgabeblack@google.com virtual void write() = 0; 4912855Sgabeblack@google.com}; 5012855Sgabeblack@google.com 5112855Sgabeblack@google.comclass read_if : virtual public 5212855Sgabeblack@google.comsc_interface 5312855Sgabeblack@google.com{ 5412855Sgabeblack@google.com public: 5512855Sgabeblack@google.com virtual void read( ) = 0; 5612855Sgabeblack@google.com}; 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com// channel implements write_if and read_if interfaces 5912855Sgabeblack@google.comclass channel : 6012855Sgabeblack@google.com public sc_channel, 6112855Sgabeblack@google.com public write_if, 6212855Sgabeblack@google.com public read_if 6312855Sgabeblack@google.com{ 6412855Sgabeblack@google.com 6512855Sgabeblack@google.com public : 6612855Sgabeblack@google.com 6712855Sgabeblack@google.com //constructor 6812855Sgabeblack@google.com channel(sc_module_name name):sc_channel(name) , data(0) 6912855Sgabeblack@google.com { } 7012855Sgabeblack@google.com 7112855Sgabeblack@google.com //write to channel 7212855Sgabeblack@google.com void write(){ 7312855Sgabeblack@google.com static int i = 0; 7412855Sgabeblack@google.com next_trigger(10, SC_NS); 7512855Sgabeblack@google.com data = i; 7612855Sgabeblack@google.com cout <<"simulation time" << ":" << sc_time_stamp()<<" "; 7712855Sgabeblack@google.com cout<<"writting "<< data <<" to channel" << endl; 7812855Sgabeblack@google.com 7912855Sgabeblack@google.com if(i < 5){ 8012855Sgabeblack@google.com write_event.notify(20, SC_NS); 8112855Sgabeblack@google.com } 8212855Sgabeblack@google.com else { 8312855Sgabeblack@google.com write_event.notify(5, SC_NS); 8412855Sgabeblack@google.com } 8512855Sgabeblack@google.com 8612855Sgabeblack@google.com i++; 8712855Sgabeblack@google.com } 8812855Sgabeblack@google.com 8912855Sgabeblack@google.com //read from channel 9012855Sgabeblack@google.com void read( ){ 9112855Sgabeblack@google.com int j; 9212855Sgabeblack@google.com const sc_time t(10, SC_NS); 9312855Sgabeblack@google.com next_trigger(t, write_event); 9412855Sgabeblack@google.com j = data; 9512855Sgabeblack@google.com cout <<"simulation time" << ":" << sc_time_stamp(); 9612855Sgabeblack@google.com cout<<" reading "<<j<<" from channel" << endl; 9712855Sgabeblack@google.com } 9812855Sgabeblack@google.com 9912855Sgabeblack@google.com private: 10012855Sgabeblack@google.com int data; 10112855Sgabeblack@google.com sc_event write_event; 10212855Sgabeblack@google.com 10312855Sgabeblack@google.com}; 10412855Sgabeblack@google.com 10512855Sgabeblack@google.com//source module 10612855Sgabeblack@google.comSC_MODULE(mod_a) 10712855Sgabeblack@google.com{ 10812855Sgabeblack@google.com sc_port<write_if> out; 10912855Sgabeblack@google.com 11012855Sgabeblack@google.com void write( ) 11112855Sgabeblack@google.com { 11212855Sgabeblack@google.com out->write(); 11312855Sgabeblack@google.com } 11412855Sgabeblack@google.com 11512855Sgabeblack@google.com SC_CTOR( mod_a ){ 11612855Sgabeblack@google.com 11712855Sgabeblack@google.com SC_METHOD(write); 11812855Sgabeblack@google.com } 11912855Sgabeblack@google.com}; 12012855Sgabeblack@google.com 12112855Sgabeblack@google.com//sink module 12212855Sgabeblack@google.comSC_MODULE(mod_b) 12312855Sgabeblack@google.com{ 12412855Sgabeblack@google.com sc_port<read_if> input; 12512855Sgabeblack@google.com int i; 12612855Sgabeblack@google.com 12712855Sgabeblack@google.com void read( ) 12812855Sgabeblack@google.com { 12912855Sgabeblack@google.com input->read(); 13012855Sgabeblack@google.com } 13112855Sgabeblack@google.com 13212855Sgabeblack@google.com SC_CTOR( mod_b ){ 13312855Sgabeblack@google.com 13412855Sgabeblack@google.com SC_METHOD(read); 13512855Sgabeblack@google.com } 13612855Sgabeblack@google.com}; 13712855Sgabeblack@google.com 13812855Sgabeblack@google.com 13912855Sgabeblack@google.comint sc_main(int, char*[] ) 14012855Sgabeblack@google.com{ 14112855Sgabeblack@google.com channel a("a"); 14212855Sgabeblack@google.com mod_a modul_a("modul_a"); 14312855Sgabeblack@google.com mod_b modul_b("modul_b"); 14412855Sgabeblack@google.com modul_a.out(a); 14512855Sgabeblack@google.com modul_b.input(a); 14612855Sgabeblack@google.com 14712855Sgabeblack@google.com sc_start(100, SC_NS); 14812855Sgabeblack@google.com return 0 ; 14912855Sgabeblack@google.com} 150