/*
 * $Id$
 *
 * [ Description ]
 * 
 */

#include "Behavioural/Generic/Select/Priority_Fixed/include/Priority_Fixed.h"

namespace morpheo                    {
namespace behavioural {
namespace generic {
namespace select {
namespace priority_fixed {


#ifdef SYSTEMC
  Priority_Fixed::Priority_Fixed (sc_module_name name,
#else
  Priority_Fixed::Priority_Fixed (string name,
#endif
#ifdef STATISTICS
			      morpheo::behavioural::Parameters_Statistics             param_statistics,
#endif
			      morpheo::behavioural::generic::select::priority_fixed::Parameters param ):
			      _name              (name)
			      ,_param            (param)
// #ifdef STATISTICS
// 			      ,_param_statistics (param_statistics)
// #endif
  {
    log_printf(FUNC,Priority_Fixed,"Priority_Fixed","Begin");

#ifdef STATISTICS
    log_printf(INFO,Priority_Fixed,"Priority_Fixed","Allocation of statistics");

    // Allocation of statistics
    _stat = new Statistics (static_cast<string>(_name),
			    param_statistics          ,
			    param);
#endif

#ifdef VHDL_TESTBENCH
    log_printf(INFO,Priority_Fixed,"Priority_Fixed","Creation of a testbench");

    // Creation of a testbench
    //  -> port
    //  -> clock's signals
    _vhdl_testbench = new Vhdl_Testbench (_name);
//     _vhdl_testbench->set_clock    ("in_CLOCK",false);
#endif

#ifdef VHDL
    // generate the vhdl
    log_printf(INFO,Priority_Fixed,"Priority_Fixed","Generate the vhdl");

    vhdl();
#endif

#ifdef VHDL_TESTBENCH
    _vhdl_testbench->set_clock    ("in_CLOCK",false);
#endif

#ifdef SYSTEMC
    log_printf(INFO,Priority_Fixed,"Priority_Fixed","Allocation");

    allocation ();

#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
    log_printf(INFO,Priority_Fixed,"Priority_Fixed","Method - transition");

    SC_METHOD (transition);
    dont_initialize ();
    sensitive_pos << *(in_CLOCK);
#endif

    log_printf(INFO,Priority_Fixed,"Priority_Fixed","Method - genMealy_entity");

    SC_METHOD (genMealy_entity);
    dont_initialize ();
    //sensitive_pos << *(in_CLOCK);
    for (uint32_t i=0; i<_param._nb_entity; i++)
      sensitive << *(in_VAL [i]);

#ifdef SYSTEMCASS_SPECIFIC
    // List dependency information

    for (uint32_t i=0; i<_param._nb_entity; i++)
      {
	if (_param._encoding_one_hot)
	  (*(out_ACK    [i])) (*(in_VAL [i]));
	if (_param._encoding_compact)
	  {
	  (*(out_ENTITY    )) (*(in_VAL [i]));
	  (*(out_ENTITY_ACK)) (*(in_VAL [i]));
	  }
      }
    
#endif    

#endif
    log_printf(FUNC,Priority_Fixed,"Priority_Fixed","End");
  };
  
  Priority_Fixed::~Priority_Fixed (void)
  {
    log_printf(FUNC,Priority_Fixed,"~Priority_Fixed","Begin");

#ifdef VHDL_TESTBENCH
    log_printf(INFO,Priority_Fixed,"~Priority_Fixed","Generate Testbench  file");

    // generate the test bench
    _vhdl_testbench->generate_file();
    delete _vhdl_testbench;
#endif

#ifdef STATISTICS
    log_printf(INFO,Priority_Fixed,"~Priority_Fixed","Generate Statistics file");

    _stat->generate_file(statistics(0));
    
    delete _stat;
#endif

#ifdef SYSTEMC
    log_printf(INFO,Priority_Fixed,"~Priority_Fixed","Deallocation");

    deallocation ();
#endif

    log_printf(FUNC,Priority_Fixed,"~Priority_Fixed","End");
  };

}; // end namespace priority_fixed
}; // end namespace select
}; // end namespace generic

}; // end namespace behavioural
}; // end namespace morpheo              
