test02.cpp revision 12855:588919e0e4aa
13534Sgblack@eecs.umich.edu/***************************************************************************** 23534Sgblack@eecs.umich.edu 33534Sgblack@eecs.umich.edu Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 43534Sgblack@eecs.umich.edu more contributor license agreements. See the NOTICE file distributed 53534Sgblack@eecs.umich.edu with this work for additional information regarding copyright ownership. 63534Sgblack@eecs.umich.edu Accellera licenses this file to you under the Apache License, Version 2.0 73534Sgblack@eecs.umich.edu (the "License"); you may not use this file except in compliance with the 83534Sgblack@eecs.umich.edu License. You may obtain a copy of the License at 93534Sgblack@eecs.umich.edu 103534Sgblack@eecs.umich.edu http://www.apache.org/licenses/LICENSE-2.0 113534Sgblack@eecs.umich.edu 123534Sgblack@eecs.umich.edu Unless required by applicable law or agreed to in writing, software 133534Sgblack@eecs.umich.edu distributed under the License is distributed on an "AS IS" BASIS, 143534Sgblack@eecs.umich.edu WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 153534Sgblack@eecs.umich.edu implied. See the License for the specific language governing 163534Sgblack@eecs.umich.edu permissions and limitations under the License. 173534Sgblack@eecs.umich.edu 183534Sgblack@eecs.umich.edu *****************************************************************************/ 193534Sgblack@eecs.umich.edu 203534Sgblack@eecs.umich.edu/***************************************************************************** 213534Sgblack@eecs.umich.edu 223534Sgblack@eecs.umich.edu test02.cpp -- Test of resume after dynamic event completion 233534Sgblack@eecs.umich.edu 243534Sgblack@eecs.umich.edu Original Author: Andy Goodrich 253534Sgblack@eecs.umich.edu 263534Sgblack@eecs.umich.edu *****************************************************************************/ 273534Sgblack@eecs.umich.edu 283534Sgblack@eecs.umich.edu/***************************************************************************** 293534Sgblack@eecs.umich.edu 303534Sgblack@eecs.umich.edu MODIFICATION LOG - modifiers, enter your name, affiliation, date and 313534Sgblack@eecs.umich.edu changes you are making here. 324202Sbinkertn@umich.edu 333534Sgblack@eecs.umich.edu Name, Affiliation, Date: 344202Sbinkertn@umich.edu Description of Modification: 354202Sbinkertn@umich.edu 364202Sbinkertn@umich.edu Revision log at end of the file to let __LINE__ give the same results 374202Sbinkertn@umich.edu after a check-in. 384202Sbinkertn@umich.edu *****************************************************************************/ 394202Sbinkertn@umich.edu 404202Sbinkertn@umich.edu#include "systemc.h" 414202Sbinkertn@umich.edu 424202Sbinkertn@umich.eduSC_MODULE(DUT) 434218Ssaidi@eecs.umich.edu{ 444202Sbinkertn@umich.edu SC_CTOR(DUT) 454202Sbinkertn@umich.edu { 464202Sbinkertn@umich.edu SC_CTHREAD(cthread,m_clk.pos()); 474202Sbinkertn@umich.edu reset_signal_is(m_reset, true); 484202Sbinkertn@umich.edu m_cthread = sc_get_current_process_handle(); 494202Sbinkertn@umich.edu 504202Sbinkertn@umich.edu SC_METHOD(dynamic_method); 514202Sbinkertn@umich.edu m_dynamic_method = sc_get_current_process_handle(); 524202Sbinkertn@umich.edu 534202Sbinkertn@umich.edu SC_THREAD(dynamic_thread); 544202Sbinkertn@umich.edu m_dynamic_thread = sc_get_current_process_handle(); 554202Sbinkertn@umich.edu 564202Sbinkertn@umich.edu SC_METHOD(static_method); 574202Sbinkertn@umich.edu sensitive << m_event1 << m_event2; 58 m_static_method = sc_get_current_process_handle(); 59 60 SC_THREAD(static_thread); 61 sensitive << m_event1 << m_event2; 62 m_static_thread = sc_get_current_process_handle(); 63 64 SC_CTHREAD(stimulus,m_clk.pos()); 65 reset_signal_is(m_reset, true); 66 } 67 void cthread() 68 { 69 for (;;) 70 { 71 wait(); 72 cout << sc_time_stamp() << ": clocked thread (" << __LINE__ 73 << ") after wait on m_clk.pos() " << endl; 74 } 75 } 76 void dynamic_method() 77 { 78 static int state = 0; 79 switch ( state ) 80 { 81 case 0: 82 next_trigger( m_clk.posedge_event() ); 83 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 84 << "," << state << ") initialization call " << endl; 85 state = 1; 86 break; 87 default: 88 case 1: 89 next_trigger( m_event1 & m_event2 ); 90 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 91 << "," << state << ") after wait on m_clk.posedge() " << endl; 92 break; 93 } 94 } 95 void dynamic_thread() 96 { 97 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ << ")" 98 << " initialization call " << endl; 99 wait(m_clk.posedge_event()); 100 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ 101 << ") after wait on m_clk.posedge_event() " << endl; 102 for (;;) 103 { 104 wait(m_event1 & m_event2 ); 105 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ 106 << ") after wait on m_event1 & m_event2 " << endl; 107 } 108 } 109 void static_method() 110 { 111 static bool initialized = false; 112 if ( !initialized ) 113 { 114 initialized = true; 115 cout << sc_time_stamp() << ": static method (" << __LINE__ 116 << ")" << " initialization call " << endl; 117 } 118 else 119 { 120 cout << sc_time_stamp() << ": static method (" << __LINE__ 121 << ") after wait on m_event1 | m_event2 " << endl; 122 } 123 } 124 void static_thread() 125 { 126 cout << sc_time_stamp() << ": static thread (" << __LINE__ << ")" 127 << " initialization call " << endl; 128 for (;;) 129 { 130 wait(); 131 cout << sc_time_stamp() << ": static thread (" << __LINE__ 132 << ") after wait on m_event1 | m_event2 " << endl; 133 } 134 135 } 136 void stimulus() 137 { 138 for (;;) 139 { 140 wait(); 141 wait(); 142 cout << sc_time_stamp() << ": stimulus (" 143 << __LINE__ << ") - suspending all processes" << endl; 144 m_cthread.suspend(); 145 m_dynamic_method.suspend(); 146 m_dynamic_thread.suspend(); 147 m_static_method.suspend(); 148 m_static_thread.suspend(); 149 wait(); 150 151 m_event1.notify(SC_ZERO_TIME); 152 cout << sc_time_stamp() << ": stimulus (" 153 << __LINE__ << ") - firing event1 " << endl; 154 wait(); 155 m_event2.notify(SC_ZERO_TIME); 156 cout << sc_time_stamp() << ": stimulus (" 157 << __LINE__ << ") - firing event2 " << endl; 158 wait(); 159 wait(); 160 161 m_cthread.resume(); 162 m_dynamic_method.resume(); 163 m_dynamic_thread.resume(); 164 m_static_method.resume(); 165 m_static_thread.resume(); 166 cout << endl << sc_time_stamp() << ": stimulus (" 167 << __LINE__ << ") - resuming all processes" << endl; 168 wait(); 169 wait(); 170 wait(); 171 sc_stop(); 172 } 173 } 174 sc_in<bool> m_clk; 175 sc_process_handle m_cthread; 176 sc_process_handle m_dynamic_method; 177 sc_process_handle m_dynamic_thread; 178 sc_event m_event1; 179 sc_event m_event2; 180 sc_event m_event3; 181 sc_event m_event4; 182 sc_in<bool> m_reset; 183 sc_process_handle m_static_method; 184 sc_process_handle m_static_thread; 185}; 186 187int sc_main(int argc, char* argv[]) 188{ 189 sc_core::sc_allow_process_control_corners = true; 190 sc_clock clock; 191 DUT dut("dut"); 192 sc_signal<bool> reset; 193 194 dut.m_clk(clock); 195 dut.m_reset(reset); 196 197 sc_core::sc_allow_process_control_corners = true; 198 reset = true; 199 sc_start(1, SC_NS); 200 reset = false; 201 sc_start(21, SC_NS); 202 203 cout << "Program completed" << endl; 204 return 0; 205} 206 207// $Log: test02.cpp,v $ 208// Revision 1.6 2011/04/02 00:08:27 acg 209// Andy Goodrich: turn off corner case error checking. 210// 211// Revision 1.5 2011/03/07 19:32:11 acg 212// Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners 213// to true so that this test avoids corner case error messages. 214// 215// Revision 1.4 2011/02/20 13:43:58 acg 216// Andy Goodrich: updates for IEEE 1666 2011. 217// 218// Revision 1.3 2011/02/14 17:00:00 acg 219// Andy Goodrich: updated copyright and added cvs logging information inline. 220// 221// Revision 1.2 2011/01/20 16:55:23 acg 222// Andy Goodrich: changes for IEEE 1666 2011. 223// 224// Revision 1.1.1.1 2006/12/15 20:26:03 acg 225// systemc_tests-2.3 226// 227// Revision 1.1 2006/12/14 21:40:06 acg 228// Andy Goodrich: moving test to new directory. 229// 230// Revision 1.2 2006/04/20 19:43:34 acg 231// Andy Goodrich: moved CVS log to end of file so that __LINE__ does not 232// change when a checkin is done. 233// 234// Revision 1.1 2006/04/17 20:11:02 acg 235// Andy Goodrich: First inclusion of test for suspend and resume support. 236// 237 238