#ifdef SYSTEMC
/*
 * $Id: Functionnal_unit_genMealy.cpp 118 2009-05-20 22:01:32Z rosiere $
 *
 * [ Description ]
 * 
 */

#include "Behavioural/Core/Multi_Execute_loop/Execute_loop/Multi_Execute_unit/Execute_unit/Functionnal_unit/include/Functionnal_unit.h"

namespace morpheo                    {
namespace behavioural {
namespace core {
namespace multi_execute_loop {
namespace execute_loop {
namespace multi_execute_unit {
namespace execute_unit {
namespace functionnal_unit {


#undef  FUNCTION
#define FUNCTION "Functionnal_unit::genMealy"
  void Functionnal_unit::genMealy (void)
  {
    log_begin(Functionnal_unit,FUNCTION);
    log_function(Functionnal_unit,FUNCTION,_name.c_str());

    if (PORT_READ(in_NRESET) != 0)
      {
        {
          // Can out if : have an instruction and is finish (latence == 0)
          internal_EXECUTE_OUT_VAL = (reg_BUSY_OUT and (_execute_operation_out->_timing._latence == 0));
          
          PORT_WRITE(out_EXECUTE_OUT_VAL, internal_EXECUTE_OUT_VAL);
        }
        
        {
          // Can accept an instruction if :
          //  * pipeline in is not busy (not previous instruction)
          //  * pipeline in is     busy (    previous instruction) and the instruction go to pipeline out
          if (_param->_have_pipeline_in)
            {          
          internal_EXECUTE_IN_ACK = (not reg_BUSY_IN or
                                     (reg_BUSY_IN and (not reg_BUSY_OUT or 
                                                       (internal_EXECUTE_OUT_VAL and PORT_READ(in_EXECUTE_OUT_ACK)))));
            }
          else
            {
          internal_EXECUTE_IN_ACK = (not reg_BUSY_OUT or 
                                     (internal_EXECUTE_OUT_VAL and PORT_READ(in_EXECUTE_OUT_ACK)));
            }

          PORT_WRITE(out_EXECUTE_IN_ACK , internal_EXECUTE_IN_ACK);
        }
      }

    log_end(Functionnal_unit,FUNCTION);
  };

}; // end namespace functionnal_unit
}; // end namespace execute_unit
}; // end namespace multi_execute_unit
}; // end namespace execute_loop
}; // end namespace multi_execute_loop
}; // end namespace core
}; // end namespace behavioural
}; // end namespace morpheo              
#endif
