method_suspends_itself.cpp revision 12855:588919e0e4aa
1#define SC_INCLUDE_DYNAMIC_PROCESSES 2 3#include <systemc> 4 5using namespace sc_core; 6using std::cout; 7using std::endl; 8 9struct M5: sc_module 10{ 11 M5(sc_module_name _name) 12 { 13 SC_THREAD(ticker); 14 SC_THREAD(calling); 15 SC_METHOD(target); 16 sensitive << ev; 17 dont_initialize(); 18 t = sc_get_current_process_handle(); 19 suspend_target = false; 20 resume_target = false; 21 } 22 23 sc_process_handle t; 24 sc_event ev; 25 bool suspend_target; 26 bool resume_target; 27 28 void ticker() 29 { 30 for (;;) 31 { 32 wait(10, SC_NS); 33 ev.notify(); 34 } 35 } 36 37 void calling() 38 { 39 wait(15, SC_NS); 40 // Target runs at 10 NS 41 42 suspend_target = true; 43 wait(10, SC_NS); 44 // Target runs at 20 NS and suspends itself 45 46 wait(10, SC_NS); 47 // Target does not run at 30 NS 48 49 suspend_target = false; 50 t.resume(); 51 // Target runs at 35 NS 52 53 wait(10, SC_NS); 54 // Target runs at 40 NS 55 56 suspend_target = true; 57 resume_target = true; 58 wait(10, SC_NS); 59 // Target runs at 50 NS 60 61 sc_stop(); 62 } 63 64 void target() 65 { 66 cout << "Target called at " << sc_time_stamp() << endl; 67 if (suspend_target) 68 t.suspend(); 69 if (resume_target) 70 { 71 t.resume(); 72 suspend_target = false; 73 } 74 } 75 76 SC_HAS_PROCESS(M5); 77}; 78 79int sc_main(int argc, char* argv[]) 80{ 81 M5 m("m"); 82 83 sc_core::sc_allow_process_control_corners = true; 84 sc_start(); 85 86 return 0; 87} 88 89