/*
 * 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 MEM_ARBITER_H
#define MEM_ARBITER_H

#include <systemc>
#include "my_interfaces.h"

SC_MODULE(MemArbiter)
{
protected:
  SC_HAS_PROCESS(MemArbiter);

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

  MEMORY_CTRL_CMD_OUT mem_ctrl;
  MEMORY_CTRL_CMD_IN  *mem_rq;

  MemArbiter(sc_module_name, size_t nrq);
  ~MemArbiter();

private:
  void transition();
  void genMealy_cmdack();
  void genMealy_cmdval();
  void genMealy_rsp();

  enum fsm_state_e
  {
    FSM_IDLE,
    FSM_CMD,
    FSM_RSP
  };

  size_t m_nrq;

  sc_signal<unsigned int> selected_src_s;
  sc_signal<int> fsm_s;
};

#endif
