async_reset_init.cpp revision 12855:588919e0e4aa
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 async_reset_init.cpp -- Starting a process in async reset state 23 24 Original Author: Philipp A. Hartmann, Intel Corporation, 2017-07-23 25 26 *****************************************************************************/ 27 28#include <systemc> 29#include <iomanip> 30 31SC_MODULE(module) 32{ 33 sc_core::sc_in<bool> rst_in; 34 sc_core::sc_event ev; 35 36 SC_CTOR(module) 37 : rst_in("rst_in") 38 , ev("ev") 39 { 40 SC_THREAD(thread0); 41 sensitive << ev; 42 async_reset_signal_is(rst_in,true); 43 44 SC_THREAD(thread1); 45 sensitive << ev; 46 async_reset_signal_is(rst_in,true); 47 dont_initialize(); 48 49 SC_METHOD(method0); 50 sensitive << ev; 51 async_reset_signal_is(rst_in,true); 52 53 SC_METHOD(method1); 54 sensitive << ev; 55 async_reset_signal_is(rst_in,true); 56 dont_initialize(); 57 } 58 59 void thread0() { do_thread(); } 60 void thread1() { do_thread(); } 61 62 void do_thread() 63 { 64 print( "reset state" ); 65 wait(); 66 print( "reset done" ); 67 68 while(1) // main loop 69 { 70 wait(); 71 print( "continuing" ); 72 } 73 } 74 75 void method0() { do_method(); } 76 void method1() { do_method(); } 77 78 void do_method() 79 { 80 if( rst_in.read() ) { 81 print("reset state"); 82 } else { 83 print("running"); 84 } 85 } 86 87 void print(const char* msg) 88 { 89 using namespace sc_core; 90 using namespace std; 91 cout 92 << setw(6) << sc_time_stamp() 93 << " (" << sc_delta_count() << "): " 94 << sc_get_current_process_handle().name() << ": " 95 << msg 96 << endl; 97 } 98}; // SC_MODULE(module) 99 100int sc_main(int argc, char* argv[]) 101{ 102 using namespace sc_core; 103 using namespace std; 104 105 sc_signal<bool> rst_sig; 106 rst_sig.write(true); 107 108 module top("top"); 109 top.rst_in(rst_sig); 110 111 cout << "Starting simulation ... " << endl; 112 113 sc_start(10, SC_NS); 114 top.ev.notify(SC_ZERO_TIME); 115 sc_start(10, SC_NS); 116 117 rst_sig.write(false); // releasing reset 118 119 sc_start(10, SC_NS); 120 top.ev.notify(SC_ZERO_TIME); 121 sc_start(10, SC_NS); 122 top.ev.notify(SC_ZERO_TIME); 123 sc_start(10, SC_NS); 124 125 rst_sig.write(true); // entering reset 126 127 sc_start(10, SC_NS); 128 top.ev.notify(SC_ZERO_TIME); 129 sc_start(10, SC_NS); 130 131 cout << "... done." << endl; 132 sc_stop(); 133 return 0; 134} 135 136