📄 sc_signal.h
字号:
/***************************************************************************** The following code is derived, directly or indirectly, from the SystemC source code Copyright (c) 1996-2006 by all Contributors. All Rights reserved. The contents of this file are subject to the restrictions and limitations set forth in the SystemC Open Source License Version 2.4 (the "License"); You may not use this file except in compliance with such restrictions and limitations. You may obtain instructions on how to receive a copy of the License at http://www.systemc.org/. Software distributed by Contributors under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. *****************************************************************************//***************************************************************************** sc_signal.h -- The sc_signal<T> primitive channel class. Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 Modification log appears at the end of the file *****************************************************************************/#ifndef SC_SIGNAL_H#define SC_SIGNAL_H#include "sysc/communication/sc_port.h"#include "sysc/communication/sc_prim_channel.h"#include "sysc/communication/sc_signal_ifs.h"#include "sysc/utils/sc_string.h"#include "sysc/kernel/sc_event.h"#include "sysc/kernel/sc_process.h"#include "sysc/kernel/sc_reset.h"#include "sysc/kernel/sc_simcontext.h"#include "sysc/datatypes/bit/sc_logic.h"#include "sysc/tracing/sc_trace.h"#include <typeinfo>namespace sc_core {// to avoid code bloat in sc_signal<T>extern void sc_deprecated_get_data_ref();extern void sc_deprecated_get_new_value();extern void sc_deprecated_trace();externvoidsc_signal_invalid_writer( sc_object* target, sc_object* first_writer, sc_object* second_writer );// ----------------------------------------------------------------------------// CLASS : sc_signal<T>//// The sc_signal<T> primitive channel class.// ----------------------------------------------------------------------------template <class T>class sc_signal: public sc_signal_inout_if<T>, public sc_prim_channel{ public: // constructors and destructor: sc_signal() : sc_prim_channel( sc_gen_unique_name( "signal" ) ), m_change_event_p( 0 ), m_cur_val( T() ), m_delta( ~sc_dt::UINT64_ONE ), m_new_val( T() ), m_output( 0 ), m_writer( 0 ) {} explicit sc_signal( const char* name_ ) : sc_prim_channel( name_ ), m_change_event_p( 0 ), m_cur_val( T() ), m_delta( ~sc_dt::UINT64_ONE ), m_new_val( T() ), m_output( 0 ), m_writer( 0 ) {} virtual ~sc_signal() { if ( !m_change_event_p ) delete m_change_event_p; } // interface methods virtual void register_port( sc_port_base&, const char* ); // get the default event virtual const sc_event& default_event() const { if ( !m_change_event_p ) m_change_event_p = new sc_event; return *m_change_event_p; } // get the value changed event virtual const sc_event& value_changed_event() const { if ( !m_change_event_p ) m_change_event_p = new sc_event; return *m_change_event_p; } // read the current value virtual const T& read() const { return m_cur_val; } // get a reference to the current value (for tracing) virtual const T& get_data_ref() const { sc_deprecated_get_data_ref(); return m_cur_val; } // was there an event? virtual bool event() const { return simcontext()->event_occurred(m_delta); } // write the new value virtual void write( const T& ); // other methods operator const T& () const { return read(); } sc_signal<T>& operator = ( const T& a ) { write( a ); return *this; } sc_signal<T>& operator = ( const sc_signal<T>& a ) { write( a.read() ); return *this; } const T& get_new_value() const { return m_new_val; } void trace( sc_trace_file* tf ) const { sc_deprecated_trace();# ifdef DEBUG_SYSTEMC sc_trace( tf, read(), name() ); # endif } virtual void print( ::std::ostream& = ::std::cout ) const; virtual void dump( ::std::ostream& = ::std::cout ) const; virtual const char* kind() const { return "sc_signal"; }protected: virtual void update();protected: mutable sc_event* m_change_event_p; T m_cur_val; sc_dt::uint64 m_delta; // delta of last event T m_new_val; sc_port_base* m_output; // used for static design rule checking sc_object* m_writer; // used for dynamic design rule checkingprivate: // disabled sc_signal( const sc_signal<T>& );};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIItemplate <class T>inlinevoidsc_signal<T>::register_port( sc_port_base& port_, const char* if_typename_ ){ if ( sc_get_curr_simcontext()->write_check() ) { std::string nm( if_typename_ ); if( nm == typeid( sc_signal_inout_if<T> ).name() ) { // an out or inout port; only one can be connected if( m_output != 0) { sc_signal_invalid_writer( this, m_output, &port_ ); } m_output = &port_; } }}// write the new valuetemplate <class T>inlinevoidsc_signal<T>::write( const T& value_ ){ sc_object* writer = sc_get_curr_simcontext()->get_current_writer(); if( m_writer == 0 ) { m_writer = writer; } else if( m_writer != writer ) { sc_signal_invalid_writer( this, m_writer, writer ); } m_new_val = value_; if( !( m_new_val == m_cur_val ) ) { request_update(); }}template <class T>inlinevoidsc_signal<T>::print( ::std::ostream& os ) const{ os << m_cur_val;}template <class T>inlinevoidsc_signal<T>::dump( ::std::ostream& os ) const{ os << " name = " << name() << ::std::endl; os << " value = " << m_cur_val << ::std::endl; os << "new value = " << m_new_val << ::std::endl;}template <class T>inlinevoidsc_signal<T>::update(){ if( !( m_new_val == m_cur_val ) ) { m_cur_val = m_new_val; if ( m_change_event_p ) m_change_event_p->notify_next_delta(); m_delta = delta_count(); }}// ----------------------------------------------------------------------------// CLASS : sc_signal<bool>//// Specialization of sc_signal<T> for type bool.// ----------------------------------------------------------------------------class sc_reset;template <>class sc_signal<bool>: public sc_signal_inout_if<bool>, public sc_prim_channel{public: // constructors and destructor: sc_signal() : sc_prim_channel( sc_gen_unique_name( "signal" ) ), m_change_event_p( 0 ), m_cur_val( false ), m_delta( ~sc_dt::UINT64_ONE ), m_negedge_event_p( 0 ), m_new_val( false ), m_output( 0 ), m_posedge_event_p( 0 ), m_reset_p( 0 ), m_writer( 0 ) {} explicit sc_signal( const char* name_ ) : sc_prim_channel( name_ ), m_change_event_p( 0 ), m_cur_val( false ), m_delta( ~sc_dt::UINT64_ONE ), m_negedge_event_p( 0 ), m_new_val( false ), m_output( 0 ), m_posedge_event_p( 0 ), m_reset_p( 0 ), m_writer( 0 ) {} virtual ~sc_signal(); // interface methods virtual void register_port( sc_port_base&, const char* ); // get the default event virtual const sc_event& default_event() const { if ( !m_change_event_p ) m_change_event_p = new sc_event; return *m_change_event_p; } // get the value changed event virtual const sc_event& value_changed_event() const { if ( !m_change_event_p ) m_change_event_p = new sc_event; return *m_change_event_p; } // get the positive edge event virtual const sc_event& posedge_event() const { if ( !m_posedge_event_p ) m_posedge_event_p = new sc_event; return *m_posedge_event_p; } // get the negative edge event virtual const sc_event& negedge_event() const { if ( !m_negedge_event_p ) m_negedge_event_p = new sc_event; return *m_negedge_event_p; } // read the current value virtual const bool& read() const { return m_cur_val; } // get a reference to the current value (for tracing) virtual const bool& get_data_ref() const { sc_deprecated_get_data_ref(); return m_cur_val; } // was there a value changed event? virtual bool event() const { return simcontext()->event_occurred(m_delta); } // was there a positive edge event? virtual bool posedge() const { return ( event() && m_cur_val ); } // was there a negative edge event? virtual bool negedge() const { return ( event() && ! m_cur_val ); } // reset creation virtual sc_reset* is_reset() const; // write the new value virtual void write( const bool& ); // other methods operator const bool& () const { return read(); } sc_signal<bool>& operator = ( const bool& a ) { write( a ); return *this; } sc_signal<bool>& operator = ( const sc_signal<bool>& a ) { write( a.read() ); return *this; } const bool& get_new_value() const { return m_new_val; } void trace( sc_trace_file* tf ) const { sc_deprecated_trace();# ifdef DEBUG_SYSTEMC sc_trace( tf, read(), name() ); # endif } virtual void print( ::std::ostream& = ::std::cout ) const; virtual void dump( ::std::ostream& = ::std::cout ) const; virtual const char* kind() const { return "sc_signal"; }protected: virtual void update(); virtual bool is_clock() const { return false; }protected: mutable sc_event* m_change_event_p; // value change event if present. bool m_cur_val; // current value of object. sc_dt::uint64 m_delta; // delta of last event mutable sc_event* m_negedge_event_p; // negative edge event if present. bool m_new_val; // next value of object. sc_port_base* m_output; // used for static design rule checking
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -