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// test02.cpp -- test that suspended processes with static sensitivity 2312855Sgabeblack@google.com// wake up when resumed. 2412855Sgabeblack@google.com// 2512855Sgabeblack@google.com// Original Author: Andy Goodrich, Forte Design Systems, Inc. 2612855Sgabeblack@google.com// 2712855Sgabeblack@google.com// CVS MODIFICATION LOG - modifiers, enter your name, affiliation, date and 2812855Sgabeblack@google.com// changes you are making here. 2912855Sgabeblack@google.com// 3012855Sgabeblack@google.com// $Log: test2.cpp,v $ 3112855Sgabeblack@google.com// Revision 1.5 2011/04/02 00:08:19 acg 3212855Sgabeblack@google.com// Andy Goodrich: turn off corner case error checking. 3312855Sgabeblack@google.com// 3412855Sgabeblack@google.com// Revision 1.4 2011/03/07 19:32:09 acg 3512855Sgabeblack@google.com// Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners 3612855Sgabeblack@google.com// to true so that this test avoids corner case error messages. 3712855Sgabeblack@google.com// 3812855Sgabeblack@google.com// Revision 1.3 2011/02/20 13:43:49 acg 3912855Sgabeblack@google.com// Andy Goodrich: updates for IEEE 1666 2011. 4012855Sgabeblack@google.com// 4112855Sgabeblack@google.com// Revision 1.2 2011/02/04 15:26:52 acg 4212855Sgabeblack@google.com// Andy Goodrich: changes for process control semantics. 4312855Sgabeblack@google.com// 4412855Sgabeblack@google.com// Revision 1.1 2009/07/28 18:43:55 acg 4512855Sgabeblack@google.com// Andy Goodrich: new standard test bench version of this test. 4612855Sgabeblack@google.com// 4712855Sgabeblack@google.com//***************************************************************************** 4812855Sgabeblack@google.com 4912855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 5012855Sgabeblack@google.com#include "systemc.h" 5112855Sgabeblack@google.com 5212855Sgabeblack@google.comenum my_process_states { 5312855Sgabeblack@google.com ST_SUSPENDD, 5412855Sgabeblack@google.com ST_NORMAL, 5512855Sgabeblack@google.com ST_SUSPENDED 5612855Sgabeblack@google.com}; 5712855Sgabeblack@google.com 5812855Sgabeblack@google.cominline ostream& time_stamp( ostream& os ) 5912855Sgabeblack@google.com{ 6012855Sgabeblack@google.com os << dec << sc_time_stamp() << "[" << sc_delta_count() << "]: "; 6112855Sgabeblack@google.com return os; 6212855Sgabeblack@google.com} 6312855Sgabeblack@google.com 6412855Sgabeblack@google.comSC_MODULE(top) { 6512855Sgabeblack@google.com // constructor: 6612855Sgabeblack@google.com 6712855Sgabeblack@google.com SC_CTOR(top) 6812855Sgabeblack@google.com { 6912855Sgabeblack@google.com m_state_cthread0 = ST_NORMAL; 7012855Sgabeblack@google.com m_state_method0 = ST_NORMAL; 7112855Sgabeblack@google.com m_state_thread0 = ST_NORMAL; 7212855Sgabeblack@google.com 7312855Sgabeblack@google.com SC_THREAD(stimulator0); 7412855Sgabeblack@google.com 7512855Sgabeblack@google.com SC_CTHREAD( target_cthread0, m_clk.pos() ); 7612855Sgabeblack@google.com m_target_cthread0 = sc_get_current_process_handle(); 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com SC_METHOD(target_method0); 7912855Sgabeblack@google.com sensitive << m_clk.pos(); 8012855Sgabeblack@google.com m_target_method0 = sc_get_current_process_handle(); 8112855Sgabeblack@google.com 8212855Sgabeblack@google.com SC_THREAD(target_thread0); 8312855Sgabeblack@google.com sensitive << m_clk.neg(); 8412855Sgabeblack@google.com m_target_thread0 = sc_get_current_process_handle(); 8512855Sgabeblack@google.com } 8612855Sgabeblack@google.com 8712855Sgabeblack@google.com // processes: 8812855Sgabeblack@google.com 8912855Sgabeblack@google.com void stimulator0(); 9012855Sgabeblack@google.com void target_cthread0(); 9112855Sgabeblack@google.com void target_method0(); 9212855Sgabeblack@google.com void target_thread0(); 9312855Sgabeblack@google.com 9412855Sgabeblack@google.com // Storage: 9512855Sgabeblack@google.com 9612855Sgabeblack@google.com sc_in<bool> m_clk; 9712855Sgabeblack@google.com int m_state_cthread0; 9812855Sgabeblack@google.com int m_state_method0; 9912855Sgabeblack@google.com int m_state_thread0; 10012855Sgabeblack@google.com sc_process_handle m_target_cthread0; 10112855Sgabeblack@google.com sc_process_handle m_target_method0; 10212855Sgabeblack@google.com sc_process_handle m_target_thread0; 10312855Sgabeblack@google.com}; 10412855Sgabeblack@google.com 10512855Sgabeblack@google.com#define SUSPEND(TARGET) \ 10612855Sgabeblack@google.com cout << endl; \ 10712855Sgabeblack@google.com time_stamp(cout) << name << ": suspending target_" << #TARGET << endl; \ 10812855Sgabeblack@google.com m_state_##TARGET = ST_SUSPENDD; \ 10912855Sgabeblack@google.com m_target_##TARGET.suspend(); \ 11012855Sgabeblack@google.com cout << endl; 11112855Sgabeblack@google.com 11212855Sgabeblack@google.com#define RESUME(TARGET) \ 11312855Sgabeblack@google.com cout << endl; \ 11412855Sgabeblack@google.com time_stamp(cout) << name << ": resuming target_" << #TARGET << endl; \ 11512855Sgabeblack@google.com m_state_##TARGET = ST_NORMAL; \ 11612855Sgabeblack@google.com m_target_##TARGET.resume(); \ 11712855Sgabeblack@google.com cout << endl; 11812855Sgabeblack@google.com 11912855Sgabeblack@google.comvoid top::stimulator0() 12012855Sgabeblack@google.com{ 12112855Sgabeblack@google.com const char* name = "stimulator"; 12212855Sgabeblack@google.com 12312855Sgabeblack@google.com wait(2, SC_NS); 12412855Sgabeblack@google.com 12512855Sgabeblack@google.com SUSPEND(cthread0) 12612855Sgabeblack@google.com wait(3, SC_NS); 12712855Sgabeblack@google.com SUSPEND(method0) 12812855Sgabeblack@google.com wait(3, SC_NS); 12912855Sgabeblack@google.com SUSPEND(thread0) 13012855Sgabeblack@google.com wait(3, SC_NS); 13112855Sgabeblack@google.com 13212855Sgabeblack@google.com RESUME(cthread0) 13312855Sgabeblack@google.com wait(3, SC_NS); 13412855Sgabeblack@google.com RESUME(method0) 13512855Sgabeblack@google.com wait(3, SC_NS); 13612855Sgabeblack@google.com RESUME(thread0) 13712855Sgabeblack@google.com wait(3, SC_NS); 13812855Sgabeblack@google.com 13912855Sgabeblack@google.com SUSPEND(cthread0) 14012855Sgabeblack@google.com wait(3, SC_NS); 14112855Sgabeblack@google.com SUSPEND(method0) 14212855Sgabeblack@google.com wait(3, SC_NS); 14312855Sgabeblack@google.com SUSPEND(thread0) 14412855Sgabeblack@google.com wait(3, SC_NS); 14512855Sgabeblack@google.com 14612855Sgabeblack@google.com RESUME(cthread0) 14712855Sgabeblack@google.com wait(3, SC_NS); 14812855Sgabeblack@google.com RESUME(method0) 14912855Sgabeblack@google.com wait(3, SC_NS); 15012855Sgabeblack@google.com RESUME(thread0) 15112855Sgabeblack@google.com wait(3, SC_NS); 15212855Sgabeblack@google.com 15312855Sgabeblack@google.com ::sc_core::wait(1000, SC_NS); 15412855Sgabeblack@google.com cout << endl; 15512855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 15612855Sgabeblack@google.com sc_stop(); 15712855Sgabeblack@google.com} 15812855Sgabeblack@google.com 15912855Sgabeblack@google.comvoid top::target_cthread0() 16012855Sgabeblack@google.com{ 16112855Sgabeblack@google.com const char* name = "target_cthread0"; 16212855Sgabeblack@google.com 16312855Sgabeblack@google.com time_stamp(cout) << name << ": starting" << endl; 16412855Sgabeblack@google.com for (int i = 0; i < 12; i++) 16512855Sgabeblack@google.com { 16612855Sgabeblack@google.com wait(); 16712855Sgabeblack@google.com if ( m_state_cthread0 == ST_SUSPENDD ) 16812855Sgabeblack@google.com { 16912855Sgabeblack@google.com time_stamp(cout) << name << ": ERROR should not see this" << endl; 17012855Sgabeblack@google.com } 17112855Sgabeblack@google.com else 17212855Sgabeblack@google.com { 17312855Sgabeblack@google.com time_stamp(cout) << name << ": active" << endl; 17412855Sgabeblack@google.com } 17512855Sgabeblack@google.com } 17612855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 17712855Sgabeblack@google.com} 17812855Sgabeblack@google.com 17912855Sgabeblack@google.comvoid top::target_method0() 18012855Sgabeblack@google.com{ 18112855Sgabeblack@google.com const char* name = "target_method0"; 18212855Sgabeblack@google.com static int state = 0; 18312855Sgabeblack@google.com switch( state ) 18412855Sgabeblack@google.com { 18512855Sgabeblack@google.com case 0: 18612855Sgabeblack@google.com time_stamp(cout) << name << ": starting" << endl; 18712855Sgabeblack@google.com break; 18812855Sgabeblack@google.com default: 18912855Sgabeblack@google.com if ( m_state_method0 == ST_SUSPENDD ) 19012855Sgabeblack@google.com { 19112855Sgabeblack@google.com time_stamp(cout) << name << ": ERROR should not see this" << endl; 19212855Sgabeblack@google.com } 19312855Sgabeblack@google.com else if ( state < 20 ) 19412855Sgabeblack@google.com { 19512855Sgabeblack@google.com time_stamp(cout) << name << ": active" << endl; 19612855Sgabeblack@google.com } 19712855Sgabeblack@google.com break; 19812855Sgabeblack@google.com case 21: 19912855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 20012855Sgabeblack@google.com break; 20112855Sgabeblack@google.com } 20212855Sgabeblack@google.com state++; 20312855Sgabeblack@google.com} 20412855Sgabeblack@google.com 20512855Sgabeblack@google.comvoid top::target_thread0() 20612855Sgabeblack@google.com{ 20712855Sgabeblack@google.com const char* name = "target_thread0"; 20812855Sgabeblack@google.com 20912855Sgabeblack@google.com time_stamp(cout) << name << ": starting" << endl; 21012855Sgabeblack@google.com for (int i = 0; i < 12; i++) 21112855Sgabeblack@google.com { 21212855Sgabeblack@google.com wait(); 21312855Sgabeblack@google.com if ( m_state_thread0 == ST_SUSPENDD ) 21412855Sgabeblack@google.com { 21512855Sgabeblack@google.com time_stamp(cout) << name << ": ERROR should not see this" << endl; 21612855Sgabeblack@google.com } 21712855Sgabeblack@google.com else 21812855Sgabeblack@google.com { 21912855Sgabeblack@google.com time_stamp(cout) << name << ": active" << endl; 22012855Sgabeblack@google.com } 22112855Sgabeblack@google.com } 22212855Sgabeblack@google.com time_stamp(cout) << name << ": terminating" << endl; 22312855Sgabeblack@google.com} 22412855Sgabeblack@google.com 22512855Sgabeblack@google.comint sc_main (int argc, char *argv[]) 22612855Sgabeblack@google.com{ 22712855Sgabeblack@google.com sc_core::sc_allow_process_control_corners = true; 22812855Sgabeblack@google.com sc_clock clock( "clock", 2.0, SC_NS ); 22912855Sgabeblack@google.com 23012855Sgabeblack@google.com top* top_p = new top("top"); 23112855Sgabeblack@google.com top_p->m_clk(clock); 23212855Sgabeblack@google.com 23312855Sgabeblack@google.com sc_core::sc_allow_process_control_corners = true; 23412855Sgabeblack@google.com sc_start(); 23512855Sgabeblack@google.com return 0; 23612855Sgabeblack@google.com} 23712855Sgabeblack@google.com 238