#ifdef SYSTEMC
/*
 * $Id$
 *
 * [ Description ]
 * 
 */

#include "Behavioural/Generic/RegisterFile/RegisterFile_Monolithic/include/RegisterFile_Monolithic.h"

namespace morpheo                    {
namespace behavioural                {
namespace generic                    {
namespace registerfile               {
namespace registerfile_monolithic    {

  void RegisterFile_Monolithic::genMealy_read (void)
  {
    log_printf(FUNC,RegisterFile,"genMealy_read","Begin");

#ifdef STATISTICS
    _stat_nb_read = 0;
#endif    

    for (uint32_t i=0; i<_param->_nb_port_read; i++)
      {
	// Have a write?
 	if ( PORT_READ(in_READ_VAL [i]) == 1)
 	  {
	    Taddress_t address = PORT_READ(in_READ_ADDRESS[i]);
	    Tdata_t    data    = REGISTER_READ(reg_DATA[address]);

	    log_printf(TRACE,RegisterFile,"genMealy_read","[%d] -> %.8x",static_cast<uint32_t>(address),static_cast<uint32_t>(data));

#ifdef STATISTICS
	    _stat_nb_read ++;
#endif    
	    // Write in registerFile
	    PORT_WRITE(out_READ_DATA[i],data);
 	  }
	else
	  {
	    //log_printf(TRACE,RegisterFile,"genMealy_read","Read  [%d] : No   transaction",i);
	    PORT_WRITE(out_READ_DATA[i],0);
	  }
      }

    for (uint32_t i=0; i<_param->_nb_port_read_write; i++)
      {
	Tdata_t data;

	// Have a write?
 	if ( (PORT_READ(in_READ_WRITE_VAL [i]) == 1) and
	     (PORT_READ(in_READ_WRITE_RW  [i]) == RW_READ)
	     )
 	  {
	    Taddress_t address = PORT_READ(in_READ_WRITE_ADDRESS[i]);
	    
	    data = REGISTER_READ(reg_DATA[address]);

	    log_printf(TRACE,RegisterFile,"genMealy_read","[%d] -> %.8x",static_cast<uint32_t>(address),static_cast<uint32_t>(data));

#ifdef STATISTICS
	    _stat_nb_read ++;
#endif    
	    // Write in registerFile
	    
 	  }
	else
	  {
	    //log_printf(TRACE,RegisterFile,"genMealy_read","Read  [%d] : No   transaction",i);
	    data = 0;
	  }

	PORT_WRITE(out_READ_WRITE_RDATA[i],data);
      }

    log_printf(FUNC,RegisterFile,"genMealy_read","End");
	
  };

}; // end namespace registerfile_monolithic
}; // end namespace registerfile 
}; // end namespace generic
}; // end namespace behavioural          
}; // end namespace morpheo              
#endif
