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// test01.cpp -- test self disables on processes 2312855Sgabeblack@google.com// 2412855Sgabeblack@google.com// Original Author: Andy Goodrich, Forte Design Systems, Inc. 2512855Sgabeblack@google.com// 2612855Sgabeblack@google.com// CVS MODIFICATION LOG - modifiers, enter your name, affiliation, date and 2712855Sgabeblack@google.com// changes you are making here. 2812855Sgabeblack@google.com// 2912855Sgabeblack@google.com// $Log: test1.cpp,v $ 3012855Sgabeblack@google.com// Revision 1.2 2009/07/28 01:09:48 acg 3112855Sgabeblack@google.com// Andy Goodrich: replacement test using standardized environment. 3212855Sgabeblack@google.com// 3312855Sgabeblack@google.com//***************************************************************************** 3412855Sgabeblack@google.com 3512855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 3612855Sgabeblack@google.com#include "systemc.h" 3712855Sgabeblack@google.com 3812855Sgabeblack@google.comenum my_process_states { 3912855Sgabeblack@google.com ST_DISABLED, 4012855Sgabeblack@google.com ST_NORMAL, 4112855Sgabeblack@google.com ST_SUSPENDED 4212855Sgabeblack@google.com}; 4312855Sgabeblack@google.com 4412855Sgabeblack@google.cominline ostream& time_stamp( ostream& os ) 4512855Sgabeblack@google.com{ 4612855Sgabeblack@google.com os << dec << sc_time_stamp() << "[" << sc_delta_count() << "]: "; 4712855Sgabeblack@google.com return os; 4812855Sgabeblack@google.com} 4912855Sgabeblack@google.com 5012855Sgabeblack@google.comSC_MODULE(top) { 5112855Sgabeblack@google.com // constructor: 5212855Sgabeblack@google.com 5312855Sgabeblack@google.com SC_CTOR(top) : 5412855Sgabeblack@google.com m_state_cthread0(ST_NORMAL), 5512855Sgabeblack@google.com m_state_method0(ST_NORMAL), 5612855Sgabeblack@google.com m_state_thread0(ST_NORMAL) 5712855Sgabeblack@google.com { 5812855Sgabeblack@google.com SC_THREAD(stimulator0); 5912855Sgabeblack@google.com 6012855Sgabeblack@google.com SC_CTHREAD( target_cthread0, m_clk.pos() ); 6112855Sgabeblack@google.com m_target_cthread0 = sc_get_current_process_handle(); 6212855Sgabeblack@google.com 6312855Sgabeblack@google.com SC_METHOD(target_method0); 6412855Sgabeblack@google.com sensitive << m_clk.pos(); 6512855Sgabeblack@google.com m_target_method0 = sc_get_current_process_handle(); 6612855Sgabeblack@google.com 6712855Sgabeblack@google.com SC_THREAD(target_thread0); 6812855Sgabeblack@google.com m_target_thread0 = sc_get_current_process_handle(); 6912855Sgabeblack@google.com } 7012855Sgabeblack@google.com 7112855Sgabeblack@google.com // processes: 7212855Sgabeblack@google.com 7312855Sgabeblack@google.com void stimulator0(); 7412855Sgabeblack@google.com void target_cthread0(); 7512855Sgabeblack@google.com void target_method0(); 7612855Sgabeblack@google.com void target_thread0(); 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com // Storage: 7912855Sgabeblack@google.com 8012855Sgabeblack@google.com sc_in<bool> m_clk; 8112855Sgabeblack@google.com int m_state_cthread0; 8212855Sgabeblack@google.com int m_state_method0; 8312855Sgabeblack@google.com int m_state_thread0; 8412855Sgabeblack@google.com sc_process_handle m_target_cthread0; 8512855Sgabeblack@google.com sc_process_handle m_target_method0; 8612855Sgabeblack@google.com sc_process_handle m_target_thread0; 8712855Sgabeblack@google.com}; 8812855Sgabeblack@google.com 8912855Sgabeblack@google.comvoid top::stimulator0() 9012855Sgabeblack@google.com{ 9112855Sgabeblack@google.com const char* name = "stimulator"; 9212855Sgabeblack@google.com wait(10, SC_NS); 9312855Sgabeblack@google.com cout << endl; 9412855Sgabeblack@google.com time_stamp(cout) << name << ": enabling target_cthread0" << endl; 9512855Sgabeblack@google.com cout << endl; 9612855Sgabeblack@google.com m_state_cthread0 = ST_NORMAL; 9712855Sgabeblack@google.com m_target_cthread0.enable(); 9812855Sgabeblack@google.com wait(10, SC_NS); 9912855Sgabeblack@google.com 10012855Sgabeblack@google.com cout << endl; 10112855Sgabeblack@google.com time_stamp(cout) << name << ": enabling target_method0" << endl; 10212855Sgabeblack@google.com cout << endl; 10312855Sgabeblack@google.com m_state_method0 = ST_NORMAL; 10412855Sgabeblack@google.com m_target_method0.enable(); 10512855Sgabeblack@google.com wait(10, SC_NS); 10612855Sgabeblack@google.com 10712855Sgabeblack@google.com cout << endl; 10812855Sgabeblack@google.com time_stamp(cout) << name << ": enabling target_thread0" << endl; 10912855Sgabeblack@google.com cout << endl; 11012855Sgabeblack@google.com m_state_thread0 = ST_NORMAL; 11112855Sgabeblack@google.com m_target_thread0.enable(); 11212855Sgabeblack@google.com ::sc_core::wait(1000, SC_NS); 11312855Sgabeblack@google.com 11412855Sgabeblack@google.com cout << endl; 11512855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 11612855Sgabeblack@google.com sc_stop(); 11712855Sgabeblack@google.com} 11812855Sgabeblack@google.com 11912855Sgabeblack@google.comvoid top::target_cthread0() 12012855Sgabeblack@google.com{ 12112855Sgabeblack@google.com int i; 12212855Sgabeblack@google.com const char* name = "target_cthread0"; 12312855Sgabeblack@google.com 12412855Sgabeblack@google.com time_stamp(cout) << name << ": starting" << endl; 12512855Sgabeblack@google.com time_stamp(cout) << name << ": issuing self disable" << endl; 12612855Sgabeblack@google.com m_state_cthread0 = ST_DISABLED; 12712855Sgabeblack@google.com m_target_cthread0.disable(); 12812855Sgabeblack@google.com time_stamp(cout) << name << ": after issuing self disable" << endl; 12912855Sgabeblack@google.com cout << endl; 13012855Sgabeblack@google.com for ( i = 0; i < 100; i++ ) 13112855Sgabeblack@google.com { 13212855Sgabeblack@google.com wait(); 13312855Sgabeblack@google.com if ( m_state_cthread0 == ST_DISABLED ) 13412855Sgabeblack@google.com { 13512855Sgabeblack@google.com time_stamp(cout) << name << ": ERROR should not see this" << endl; 13612855Sgabeblack@google.com } 13712855Sgabeblack@google.com } 13812855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 13912855Sgabeblack@google.com} 14012855Sgabeblack@google.com 14112855Sgabeblack@google.comvoid top::target_method0() 14212855Sgabeblack@google.com{ 14312855Sgabeblack@google.com const char* name = "target_method0"; 14412855Sgabeblack@google.com static int state = 0; 14512855Sgabeblack@google.com switch( state ) 14612855Sgabeblack@google.com { 14712855Sgabeblack@google.com case 0: 14812855Sgabeblack@google.com time_stamp(cout) << name << ": starting" << endl; 14912855Sgabeblack@google.com time_stamp(cout) << name << ": issuing self disable" << endl; 15012855Sgabeblack@google.com m_state_method0 = ST_DISABLED; 15112855Sgabeblack@google.com m_target_method0.disable(); 15212855Sgabeblack@google.com time_stamp(cout) << name << ": after issuing self disable" << endl; 15312855Sgabeblack@google.com cout << endl; 15412855Sgabeblack@google.com break; 15512855Sgabeblack@google.com default: 15612855Sgabeblack@google.com if ( m_state_method0 == ST_DISABLED ) 15712855Sgabeblack@google.com { 15812855Sgabeblack@google.com time_stamp(cout) << name << ": ERROR should not see this" << endl; 15912855Sgabeblack@google.com } 16012855Sgabeblack@google.com break; 16112855Sgabeblack@google.com case 99: 16212855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 16312855Sgabeblack@google.com break; 16412855Sgabeblack@google.com } 16512855Sgabeblack@google.com state++; 16612855Sgabeblack@google.com} 16712855Sgabeblack@google.com 16812855Sgabeblack@google.comvoid top::target_thread0() 16912855Sgabeblack@google.com{ 17012855Sgabeblack@google.com const char* name = "target_thread0"; 17112855Sgabeblack@google.com 17212855Sgabeblack@google.com time_stamp(cout) << name << ": starting" << endl; 17312855Sgabeblack@google.com time_stamp(cout) << name << ": issuing self disable" << endl; 17412855Sgabeblack@google.com m_state_thread0 = ST_DISABLED; 17512855Sgabeblack@google.com m_target_thread0.disable(); 17612855Sgabeblack@google.com time_stamp(cout) << name << ": after issuing self disable" << endl; 17712855Sgabeblack@google.com cout << endl; 17812855Sgabeblack@google.com 17912855Sgabeblack@google.com // We wait a long enough time that our event will not occur until 18012855Sgabeblack@google.com // after we are re-enabled. Otherwise this thread will just go away 18112855Sgabeblack@google.com // quietly when the disable cancels the event. 18212855Sgabeblack@google.com 18312855Sgabeblack@google.com ::sc_core::wait(80, SC_NS); 18412855Sgabeblack@google.com if ( m_state_thread0 == ST_DISABLED ) 18512855Sgabeblack@google.com { 18612855Sgabeblack@google.com time_stamp(cout) << name << ": ERROR should not see this" << endl; 18712855Sgabeblack@google.com } 18812855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 18912855Sgabeblack@google.com} 19012855Sgabeblack@google.com 19112855Sgabeblack@google.comint sc_main (int argc, char *argv[]) 19212855Sgabeblack@google.com{ 19312855Sgabeblack@google.com sc_clock clock( "clock", 1.0, SC_NS ); 19412855Sgabeblack@google.com 19512855Sgabeblack@google.com top* top_p = new top("top"); 19612855Sgabeblack@google.com top_p->m_clk(clock); 19712855Sgabeblack@google.com 19812855Sgabeblack@google.com sc_start(); 19912855Sgabeblack@google.com return 0; 20012855Sgabeblack@google.com} 20112855Sgabeblack@google.com 202