libraries/onchipcommunication/systemc/PtP.h

Go to the documentation of this file.
00001 //============================================================================
00002 // Author      : Alessandro Pinto <apinto@eecs.berkeley.edu>
00003 //               University of California, Berkeley
00004 //               545 Cory Hall, Berkeley, CA 94720
00005 // Copyright   : See COPYING file that comes with this distribution
00006 //============================================================================
00007 
00008 #include "systemc.h"
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <math.h>
00012 #include "Technology.h"
00013 
00014 #ifndef _PTPCONNECTION_H_
00015 #define _PTPCONNECTION_H_
00016 
00019 
00020 
00035 template<int FlitWidth>
00036 class PtP : public sc_module
00037 {
00038  public:
00041   
00043   sc_in< sc_bv< FlitWidth > > DataIn;
00044   sc_in< bool > ValidIn ;
00045   sc_out< bool > AckOut ;
00046   sc_out< bool > FullOut ;
00047   
00048   
00050   sc_out< sc_bv< FlitWidth > > DataOut;
00051   sc_out< bool > ValidOut ;
00052   sc_in< bool > AckIn ;
00053   sc_in< bool > FullIn ;
00054   
00055 
00056 
00057   SC_HAS_PROCESS( PtP );
00058 
00061 
00064  PtP( sc_module_name n,
00065       TechnologyNode tech,
00066       int layer,
00067       double length ) : sc_module( n ),
00068     _tech( tech ),
00069     _layer( layer ),
00070     _length( length )    {
00071       
00072       
00073       SC_THREAD( Transfer ) ;
00074       sensitive << DataIn << ValidIn << AckIn << FullIn ;
00075       
00076     }
00077 
00078   double GetDynamicPower( ) {
00079     return ( total_sw_energy / ( sc_simulation_time( ) * 10e-9) ) ;
00080   }
00081   
00082   double GetLeakagePower( ) {
00083     return ( total_leak_energy / ( sc_simulation_time( ) * 10e-9) ) ;
00084   }
00085 
00086   void Transfer( ) ;
00087 
00088     TechnologyNode _tech ;
00089     int _layer ;
00090     double _length ;
00091     
00092     double total_sw_energy;
00093     double total_sc_energy;
00094     double total_leak_energy;
00095     double total_energy;
00096 
00097 private:
00098     sc_bv< FlitWidth > _prev_word ;
00099      bool  _prev_valid ;
00100     bool  _prev_ack ;
00101      bool  _prev_full ;
00102     double _prev_time ;
00103 
00104 };
00105 
00106 template< int FlitWidth >
00107 void PtP<FlitWidth>::Transfer( )
00108 {
00109   double _delay, _tau;
00110   double _e_switching, _e_leakage, _e_sc ;
00111   
00112   sc_bv< FlitWidth > _curr_word ;
00113   
00114   while (true)
00115     {
00116       
00117       wait( ) ;
00118       
00119       if ( _prev_valid != ValidIn ) {
00120         total_sw_energy = total_sw_energy + _tech.Edyn*_length ;
00121         total_energy = total_sw_energy ;
00122         _prev_valid = ValidIn ;
00123         ValidOut = ValidIn ;
00124       }
00125       
00126       if ( _prev_ack != AckIn ) {
00127         total_sw_energy = total_sw_energy + _tech.Edyn*_length ;
00128         total_energy = total_sw_energy ;
00129         _prev_ack = AckIn ;
00130         AckOut = AckIn ;
00131       }
00132       
00133       if ( _prev_full != FullIn ) {
00134         total_sw_energy = total_sw_energy + _tech.Edyn*_length ;
00135         total_energy = total_sw_energy ;
00136         _prev_full = FullIn ;
00137         FullOut = FullIn ;
00138       }
00139       
00140       _curr_word = DataIn ;
00141       if ( _prev_word != _curr_word )  {
00142 
00143         
00144         
00145         //charge delay
00146         //wait( _delay , SC_SEC );
00147         
00148         //compute energy
00149         
00150         
00151         for( int i = 0 ; i < FlitWidth ; i ++ )
00152           {
00153             if ( _curr_word[i] != _prev_word[i] )
00154               {
00155                 total_sw_energy = total_sw_energy + _tech.Edyn*_length ;
00156                 total_energy = total_sw_energy ;
00157               }
00158           }
00159         
00160         _prev_word = _curr_word ;
00161         
00162         _prev_time = (double)sc_simulation_time( );
00163         
00164         DataOut = _curr_word;
00165       }
00166     }  
00167 };
00168 
00169 
00170 #endif

Generated on Sun Sep 7 18:37:42 2008 for COSI by  doxygen 1.5.4
Contact 
©2002-2018 U.C. Regents