/*
 * SecBus - This file is part of SecBus
 * Copyright (C) 2012 - Telecom ParisTech
 * 
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at    
 * http://www.cecill.info/licences/Licence_CeCILL_V1.1-US.txt
 *
 */

#ifndef _VCI_MERGE_H
#define _VCI_MERGE_H

#include <systemc>
#include "vci_initiator.h"
#include "vci_target.h"

template<typename vci_param>
SC_MODULE(VciMerge)
{
protected:
  SC_HAS_PROCESS(VciMerge);

public:
  sc_in<bool> p_clk;
  sc_in<bool> p_resetn;

  soclib::caba::VciTarget<vci_param> *p_vci_initiator;

  soclib::caba::VciInitiator<vci_param> p_vci_target;

  VciMerge(sc_module_name name, size_t n_init);
  ~VciMerge();

private:
  enum fsm_state_e
  {
    FSM_IDLE,
    FSM_CMD,
    FSM_RSP
  };

  size_t m_n_init;
  sc_signal<int> fsm_s;

  sc_signal<unsigned int> sel_s;
  
  void transition();
  void genMealy_i2t();
  void genMealy_t2i();
};

#endif
