1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 test01.cpp -- Test of suspend resume on processes 23 24 Original Author: Andy Goodrich 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 Revision log at end of the file to let __LINE__ give the same results 37 after a check-in. 38 *****************************************************************************/ 39 40 41#include "systemc.h" 42 43SC_MODULE(DUT) 44{ 45 SC_CTOR(DUT) 46 { 47 SC_CTHREAD(cthread,m_clk.pos()); 48 SC_METHOD(dynamic_method); 49 SC_THREAD(dynamic_thread); 50 SC_METHOD(static_method); 51 sensitive << m_clk.pos(); 52 SC_THREAD(static_thread); 53 sensitive << m_clk.pos(); 54 SC_CTHREAD(stimulus,m_clk.pos()); 55 reset_signal_is(m_reset, true); 56 } 57 void cthread() 58 { 59 m_cthread = sc_get_current_process_handle(); 60 for (;;) 61 { 62 wait(); 63 cout << sc_time_stamp() << ": cthread (" << __LINE__ << ")" 64 << endl; 65 } 66 } 67 void dynamic_method() 68 { 69 static int state = 0; 70 switch ( state ) 71 { 72 case 0: 73 m_dynamic_method = sc_get_current_process_handle(); 74 next_trigger( m_clk.posedge_event() ); 75 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 76 << "," << state << ") initialization call " << endl; 77 break; 78 case 1: 79 next_trigger( m_clk.posedge_event() ); 80 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 81 << "," << state << ") after wait on m_clk.posedge_event() " 82 << endl; 83 break; 84 case 2: 85 next_trigger( m_clk.negedge_event() ); 86 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 87 << "," << state << ") after wait on m_clk.posedge_event() " 88 << endl; 89 break; 90 case 3: 91 next_trigger( m_event1 & m_event2 ); 92 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 93 << "," << state << ") after wait on m_clk.negedge() " << endl; 94 break; 95 case 4: 96 next_trigger( m_clk.posedge_event() ); 97 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 98 << "," << state << ") after wait on m_event1 & m_event2 " 99 << endl; 100 break; 101 default: 102 next_trigger( m_clk.posedge_event() ); 103 cout << sc_time_stamp() << ": dynamic method (" << __LINE__ 104 << "," << state << ") after wait on m_clk.posedge_event() " 105 << endl; 106 break; 107 } 108 state = state + 1; 109 if ( state == 5 ) state = 1; 110 } 111 void dynamic_thread() 112 { 113 m_dynamic_thread = sc_get_current_process_handle(); 114 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ << ")" 115 << " initialization call " << endl; 116 wait(m_clk.posedge_event()); 117 for (;;) 118 { 119 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ 120 << ") after wait on m_clk.posedge_event() " << endl; 121 wait(m_clk.posedge_event()); 122 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ 123 << ") after wait on m_clk.posedge_event() " << endl; 124 wait(m_clk.negedge_event()); 125 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ 126 << ") after wait on m_clk.negedge_event() " << endl; 127 wait(m_event1 & m_event2 ); 128 cout << sc_time_stamp() << ": dynamic thread (" << __LINE__ 129 << ") after wait on m_event1 & m_event2 " << endl; 130 wait(m_clk.posedge_event()); 131 } 132 } 133 void static_method() 134 { 135 m_static_method = sc_get_current_process_handle(); 136 cout << sc_time_stamp() << ": static method (" << __LINE__ << ")" 137 << endl; 138 } 139 void static_thread() 140 { 141 m_static_thread = sc_get_current_process_handle(); 142 for (;;) 143 { 144 wait(); 145 cout << sc_time_stamp() << ": static thread (" << __LINE__ 146 << ")" << endl; 147 } 148 } 149 void stimulus() 150 { 151 for (;;) 152 { 153 wait(); 154 wait(); 155 cout << sc_time_stamp() << ": stimulus (" 156 << __LINE__ << ") - suspending all processes" << endl; 157 m_cthread.suspend(); 158 m_dynamic_method.suspend(); 159 m_dynamic_thread.suspend(); 160 m_static_method.suspend(); 161 m_static_thread.suspend(); 162 wait(); 163 wait(); 164 wait(); 165 m_cthread.resume(); 166 m_dynamic_method.resume(); 167 m_dynamic_thread.resume(); 168 m_static_method.resume(); 169 m_static_thread.resume(); 170 cout << endl << sc_time_stamp() << ": stimulus (" 171 << __LINE__ << ") - resuming all processes" << endl; 172 wait(); 173 cout << sc_time_stamp() << ": stimulus (" 174 << __LINE__ << ") - suspending all processes" << endl; 175 m_cthread.suspend(); 176 m_dynamic_method.suspend(); 177 m_dynamic_thread.suspend(); 178 m_static_method.suspend(); 179 m_static_thread.suspend(); 180 wait(); 181 m_event1.notify(SC_ZERO_TIME); 182 cout << sc_time_stamp() << ": stimulus (" 183 << __LINE__ << ") - firing event1 " << endl; 184 wait(); 185 m_cthread.resume(); 186 m_dynamic_method.resume(); 187 m_dynamic_thread.resume(); 188 m_static_method.resume(); 189 m_static_thread.resume(); 190 cout << endl << sc_time_stamp() << ": stimulus (" 191 << __LINE__ << ") - resuming all processes" << endl; 192 wait(); 193 m_event2.notify(SC_ZERO_TIME); 194 cout << sc_time_stamp() << ": stimulus (" 195 << __LINE__ << ") - firing event2 " << endl; 196 wait(); 197 wait(); 198 wait(); 199 } 200 } 201 sc_in<bool> m_clk; 202 sc_process_handle m_cthread; 203 sc_process_handle m_dynamic_method; 204 sc_process_handle m_dynamic_thread; 205 sc_event m_event1; 206 sc_event m_event2; 207 sc_event m_event3; 208 sc_event m_event4; 209 sc_in<bool> m_reset; 210 sc_process_handle m_static_method; 211 sc_process_handle m_static_thread; 212}; 213 214int sc_main(int argc, char* argv[]) 215{ 216 sc_core::sc_allow_process_control_corners = true; 217 sc_clock clock; 218 DUT dut("dut"); 219 sc_signal<bool> reset; 220 221 dut.m_clk(clock); 222 dut.m_reset(reset); 223 224 sc_core::sc_allow_process_control_corners = true; 225 reset = true; 226 sc_start(1, SC_NS); 227 reset = false; 228 sc_start(21, SC_NS); 229 230 cout << "Program completed" << endl; 231 return 0; 232} 233 234// $Log: test01.cpp,v $ 235// Revision 1.5 2011/04/02 00:08:23 acg 236// Andy Goodrich: turn off corner case error checking. 237// 238// Revision 1.4 2011/03/07 19:32:10 acg 239// Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners 240// to true so that this test avoids corner case error messages. 241// 242// Revision 1.3 2011/02/20 13:43:54 acg 243// Andy Goodrich: updates for IEEE 1666 2011. 244// 245// Revision 1.2 2011/02/14 16:59:58 acg 246// Andy Goodrich: updated copyright and added cvs logging information inline. 247// 248// Revision 1.1.1.1 2006/12/15 20:26:03 acg 249// systemc_tests-2.3 250// 251// Revision 1.1 2006/12/14 21:39:59 acg 252// Andy Goodrich: moving test to new directory. 253// 254// Revision 1.2 2006/04/20 19:43:31 acg 255// Andy Goodrich: moved CVS log to end of file so that __LINE__ does not 256// change when a checkin is done. 257// 258// Revision 1.1 2006/04/17 20:10:55 acg 259// Andy Goodrich: First inclusion of test for suspend and resume support. 260// 261