/*
 * $Id: Select_Priority_Fixed_allocation.cpp 88 2008-12-10 18:31:39Z rosiere $
 *
 * [ Description ]
 * 
 */

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

namespace morpheo{
namespace behavioural {
namespace generic {
namespace select {
namespace select_priority_fixed {

  void Select_Priority_Fixed::allocation (void)
  {
    log_printf(FUNC,Select_Priority_Fixed,"allocation","Begin");

    _component   = new Component (_usage);

    Entity * entity = _component->set_entity (_name                 
					     ,"Select_Priority_Fixed"
#ifdef POSITION
					     ,COMBINATORY            
#endif
					      );
    
    _interfaces = entity->set_interfaces();

    // ~~~~~[ Interface : "" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Interface_fifo * interface = _interfaces->set_interface(""
#ifdef POSITION
							    ,IN  
							    ,WEST
							    ,"Generalist interface"
#endif
							    );

     in_CLOCK        = interface->set_signal_clk              ("clock" ,1, CLOCK_VHDL_NO);
     in_NRESET       = interface->set_signal_in  <Tcontrol_t> ("nreset",1, RESET_VHDL_NO);

     in_VAL          = new SC_IN (Tcontrol_t)           * [_param->_nb_entity];
    if (_param->_encoding_one_hot)
    out_ACK          = new SC_OUT(Tcontrol_t)           * [_param->_nb_entity];

    for (uint32_t i=0; i<_param->_nb_entity; i++)
      {
	 in_VAL [i]    = interface->set_signal_in  <Tcontrol_t> ("val_"+toString(i),1);
	if (_param->_encoding_one_hot)
	out_ACK [i]    = interface->set_signal_out <Tcontrol_t> ("ack_"+toString(i),1);
      }

    if (_param->_encoding_compact)
      {
	out_ENTITY     = interface->set_signal_out <Tentity_t > ("entity"    , _param->_size_entity);
	out_ENTITY_ACK = interface->set_signal_out <Tcontrol_t> ("entity_ack", 1);
      }

    // ~~~~~[ Component ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    

#ifdef POSITION
    if (usage_is_set(_usage,USE_POSITION))
      _component->generate_file();
#endif

    log_printf(FUNC,Select_Priority_Fixed,"allocation","End");
  };

}; // end namespace select_priority_fixed
}; // end namespace select
}; // end namespace generic
}; // end namespace behavioural
}; // end namespace morpheo              
