00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "sysc/kernel/sc_simcontext.h"
00044 #include "sysc/kernel/sc_reset.h"
00045 #include "sysc/kernel/sc_process_handle.h"
00046 #include "sysc/communication/sc_signal.h"
00047 #include "sysc/communication/sc_signal_ports.h"
00048
00049
00050 namespace sc_core {
00051
00052 class sc_reset_finder;
00053 static sc_reset_finder* reset_finder_q=0;
00054
00055
00056
00057
00058
00059 class sc_reset_finder {
00060 friend class sc_reset;
00061 public:
00062 sc_reset_finder(
00063 const sc_in<bool>* port_p, bool level, sc_process_b* target_p);
00064
00065 protected:
00066 bool m_level;
00067 sc_reset_finder* m_next_p;
00068 const sc_in<bool>* m_port_p;
00069 sc_process_b* m_target_p;
00070
00071 private:
00072 sc_reset_finder( const sc_reset_finder& );
00073 const sc_reset_finder& operator = ( const sc_reset_finder& );
00074 };
00075
00076 inline sc_reset_finder::sc_reset_finder(
00077 const sc_in<bool>* port_p, bool level, sc_process_b* target_p
00078 ) :
00079 m_level(level), m_port_p(port_p), m_target_p(target_p)
00080 {
00081 m_next_p = reset_finder_q;
00082 reset_finder_q = this;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091 void sc_reset::notify_processes()
00092 {
00093 int process_i;
00094 int process_n;
00095 process_n = m_processes.size();
00096 for ( process_i = 0; process_i < process_n; process_i++ )
00097 {
00098 m_processes[process_i]->reset_changed();
00099 }
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109 bool sc_reset::read()
00110 {
00111 return m_iface_p->read();
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 void sc_reset::reconcile_resets()
00127 {
00128 const sc_signal_in_if<bool>* iface_p;
00129 sc_reset_finder* next_p;
00130 sc_reset_finder* now_p;
00131 sc_reset* reset_p;
00132
00133 for ( now_p = reset_finder_q; now_p; now_p = next_p )
00134 {
00135 next_p = now_p->m_next_p;
00136 if ( now_p->m_target_p->m_reset_p )
00137 SC_REPORT_ERROR(SC_ID_MULTIPLE_RESETS_,now_p->m_target_p->name());
00138 iface_p = DCAST<const sc_signal_in_if<bool>*>(
00139 now_p->m_port_p->get_interface());
00140 assert( iface_p != 0 );
00141 reset_p = iface_p->is_reset();
00142 now_p->m_target_p->m_reset_p = reset_p;
00143 now_p->m_target_p->m_reset_level = now_p->m_level;
00144 reset_p->m_processes.push_back(now_p->m_target_p);
00145 delete now_p;
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154 void sc_reset::remove_process( sc_process_b* process_p )
00155 {
00156 int process_i;
00157 int process_n;
00158
00159 process_n = m_processes.size();
00160 for ( process_i = 0; process_i < process_n; process_i++ )
00161 {
00162 if ( m_processes[process_i] == process_p )
00163 {
00164 m_processes[process_i] = m_processes[process_n-1];
00165 m_processes.resize(process_n-1);
00166 return;
00167 }
00168 }
00169 }
00170
00171
00172
00173
00174
00175 void sc_reset::reset_signal_is( const sc_in<bool>& port, bool level )
00176 {
00177 const sc_signal_in_if<bool>* iface_p;
00178 sc_process_b* process_p;
00179
00180 process_p = (sc_process_b*)sc_get_current_process_handle();
00181 assert( process_p );
00182 switch ( process_p->proc_kind() )
00183 {
00184 case SC_THREAD_PROC_:
00185 case SC_METHOD_PROC_:
00186 SC_REPORT_ERROR(SC_ID_RESET_SIGNAL_IS_NOT_ALLOWED_,"");
00187 break;
00188 case SC_CTHREAD_PROC_:
00189 process_p->m_reset_level = level;
00190 iface_p = DCAST<const sc_signal_in_if<bool>*>(port.get_interface());
00191 if ( iface_p )
00192 reset_signal_is( *iface_p, level );
00193 else
00194 {
00195 new sc_reset_finder( &port, level, process_p );
00196 }
00197 break;
00198 default:
00199 SC_REPORT_ERROR(SC_ID_UNKNOWN_PROCESS_TYPE_, process_p->name());
00200 break;
00201 }
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 void sc_reset::reset_signal_is( const sc_signal_in_if<bool>& iface, bool level )
00213 {
00214 sc_process_b* process_p;
00215 sc_reset* reset_p;
00216
00217 process_p = sc_process_b::last_created_process_base();
00218 assert( process_p );
00219 if ( process_p->m_reset_p )
00220 SC_REPORT_ERROR(SC_ID_MULTIPLE_RESETS_,process_p->name());
00221 switch ( process_p->proc_kind() )
00222 {
00223 case SC_CTHREAD_PROC_:
00224 process_p->m_reset_level = level;
00225 reset_p = iface.is_reset();
00226 process_p->m_reset_p = reset_p;
00227 reset_p->m_processes.push_back(process_p);
00228 break;
00229 case SC_THREAD_PROC_:
00230 case SC_METHOD_PROC_:
00231 SC_REPORT_ERROR(SC_ID_RESET_SIGNAL_IS_NOT_ALLOWED_,"");
00232 break;
00233 default:
00234 SC_REPORT_ERROR(SC_ID_UNKNOWN_PROCESS_TYPE_, process_p->name());
00235 break;
00236 }
00237 }
00238
00239
00240 }