sc_signal_resolved.cpp revision 12027
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 sc_signal_resolved.cpp -- The resolved signal class. 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 25 26 CHANGE LOG IS AT THE END OF THE FILE 27 *****************************************************************************/ 28 29#include "sysc/kernel/sc_simcontext.h" 30#include "sysc/kernel/sc_process_handle.h" 31#include "sysc/communication/sc_signal_resolved.h" 32 33namespace sc_core { 34 35// Note that we assume that two drivers driving the resolved signal to a 1 or 36// 0 is O.K. This might not be true for all technologies, but is certainly 37// true for CMOS, the predominant technology in use today. 38 39const sc_dt::sc_logic_value_t 40sc_logic_resolution_tbl[4][4] = 41{ // 0 1 Z X 42 { sc_dt::Log_0, sc_dt::Log_X, sc_dt::Log_0, sc_dt::Log_X }, // 0 43 { sc_dt::Log_X, sc_dt::Log_1, sc_dt::Log_1, sc_dt::Log_X }, // 1 44 { sc_dt::Log_0, sc_dt::Log_1, sc_dt::Log_Z, sc_dt::Log_X }, // Z 45 { sc_dt::Log_X, sc_dt::Log_X, sc_dt::Log_X, sc_dt::Log_X } // X 46}; 47 48 49// ---------------------------------------------------------------------------- 50// FUNCTION : sc_logic_resolve 51// 52// Resolution function for sc_dt::sc_logic. 53// ---------------------------------------------------------------------------- 54 55// resolves sc_dt::sc_logic values and returns the resolved value 56 57static void 58sc_logic_resolve( sc_dt::sc_logic& result_, 59 const std::vector<sc_dt::sc_logic>& values_ ) 60{ 61 int sz = values_.size(); 62 63 assert( sz != 0 ); 64 65 if( sz == 1 ) { 66 result_ = values_[0]; 67 return; 68 } 69 70 sc_dt::sc_logic_value_t res = values_[0].value(); 71 for( int i = sz - 1; i > 0 && res != sc_dt::Log_X; -- i ) { 72 res = sc_logic_resolution_tbl[res][values_[i].value()]; 73 } 74 result_ = res; 75} 76 77 78// ---------------------------------------------------------------------------- 79// CLASS : sc_signal_resolved 80// 81// The resolved signal class. 82// ---------------------------------------------------------------------------- 83 84// write the new value 85 86void 87sc_signal_resolved::write( const data_type& value_ ) 88{ 89 sc_process_b* cur_proc = sc_get_current_process_b(); 90 91 bool value_changed = false; 92 bool found = false; 93 94 for( int i = m_proc_vec.size() - 1; i >= 0; -- i ) { 95 if( cur_proc == m_proc_vec[i] ) { 96 if( value_ != m_val_vec[i] ) { 97 m_val_vec[i] = value_; 98 value_changed = true; 99 } 100 found = true; 101 break; 102 } 103 } 104 105 if( ! found ) { 106 m_proc_vec.push_back( cur_proc ); 107 m_val_vec.push_back( value_ ); 108 value_changed = true; 109 } 110 111 if( value_changed ) { 112 request_update(); 113 } 114} 115 116 117void 118sc_signal_resolved::update() 119{ 120 sc_logic_resolve( m_new_val, m_val_vec ); 121 base_type::update(); 122} 123 124 125} // namespace sc_core 126 127// $Log: sc_signal_resolved.cpp,v $ 128// Revision 1.5 2011/08/26 20:45:44 acg 129// Andy Goodrich: moved the modification log to the end of the file to 130// eliminate source line number skew when check-ins are done. 131// 132// Revision 1.4 2011/02/18 20:23:45 acg 133// Andy Goodrich: Copyright update. 134// 135// Revision 1.3 2011/02/07 19:16:50 acg 136// Andy Goodrich: changes for handling multiple writers. 137// 138// Revision 1.2 2011/01/20 16:52:15 acg 139// Andy Goodrich: changes for IEEE 1666 2011. 140// 141// Revision 1.1.1.1 2006/12/15 20:20:04 acg 142// SystemC 2.3 143// 144// Revision 1.4 2006/03/21 00:00:27 acg 145// Andy Goodrich: changed name of sc_get_current_process_base() to be 146// sc_get_current_process_b() since its returning an sc_process_b instance. 147// 148// Revision 1.3 2006/01/13 18:47:42 acg 149// Added $Log command so that CVS comments are reproduced in the source. 150// 151 152// Taf! 153