-- Do not edit; this file was generated by Cheby using these options:
--  -i svec_ref_fmc_adc_100Ms_mmap.cheby --gen-hdl=svec_ref_fmc_adc_100Ms_mmap.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.wishbone_pkg.all;

entity svec_ref_fmc_adc_100m_mmap is
  port (
    rst_n_i              : in    std_logic;
    clk_i                : in    std_logic;
    wb_i                 : in    t_wishbone_slave_in;
    wb_o                 : out   t_wishbone_slave_out;

    -- a ROM containing the application metadata
    metadata_i           : in    t_wishbone_master_in;
    metadata_o           : out   t_wishbone_master_out;

    -- FMC ADC Mezzanine slot 1
    fmc1_adc_mezzanine_i : in    t_wishbone_master_in;
    fmc1_adc_mezzanine_o : out   t_wishbone_master_out;

    -- FMC ADC Mezzanine slot 2
    fmc2_adc_mezzanine_i : in    t_wishbone_master_in;
    fmc2_adc_mezzanine_o : out   t_wishbone_master_out
  );
end svec_ref_fmc_adc_100m_mmap;

architecture syn of svec_ref_fmc_adc_100m_mmap is
  signal rd_int                         : std_logic;
  signal wr_int                         : std_logic;
  signal rd_ack_int                     : std_logic;
  signal wr_ack_int                     : std_logic;
  signal wb_en                          : std_logic;
  signal ack_int                        : std_logic;
  signal wb_rip                         : std_logic;
  signal wb_wip                         : std_logic;
  signal metadata_re                    : std_logic;
  signal metadata_wt                    : std_logic;
  signal metadata_rt                    : std_logic;
  signal metadata_tr                    : std_logic;
  signal metadata_wack                  : std_logic;
  signal metadata_rack                  : std_logic;
  signal fmc1_adc_mezzanine_re          : std_logic;
  signal fmc1_adc_mezzanine_wt          : std_logic;
  signal fmc1_adc_mezzanine_rt          : std_logic;
  signal fmc1_adc_mezzanine_tr          : std_logic;
  signal fmc1_adc_mezzanine_wack        : std_logic;
  signal fmc1_adc_mezzanine_rack        : std_logic;
  signal fmc2_adc_mezzanine_re          : std_logic;
  signal fmc2_adc_mezzanine_wt          : std_logic;
  signal fmc2_adc_mezzanine_rt          : std_logic;
  signal fmc2_adc_mezzanine_tr          : std_logic;
  signal fmc2_adc_mezzanine_wack        : std_logic;
  signal fmc2_adc_mezzanine_rack        : std_logic;
  signal reg_rdat_int                   : std_logic_vector(31 downto 0);
  signal rd_ack1_int                    : std_logic;
begin

  -- WB decode signals
  wb_en <= wb_i.cyc and wb_i.stb;

  process (clk_i) begin
    if rising_edge(clk_i) then
      if rst_n_i = '0' then
        wb_rip <= '0';
      else
        wb_rip <= (wb_rip or (wb_en and not wb_i.we)) and not rd_ack_int;
      end if;
    end if;
  end process;
  rd_int <= (wb_en and not wb_i.we) and not wb_rip;

  process (clk_i) begin
    if rising_edge(clk_i) then
      if rst_n_i = '0' then
        wb_wip <= '0';
      else
        wb_wip <= (wb_wip or (wb_en and wb_i.we)) and not wr_ack_int;
      end if;
    end if;
  end process;
  wr_int <= (wb_en and wb_i.we) and not wb_wip;

  ack_int <= rd_ack_int or wr_ack_int;
  wb_o.ack <= ack_int;
  wb_o.stall <= not ack_int and wb_en;
  wb_o.rty <= '0';
  wb_o.err <= '0';

  -- Assign outputs

  -- Assignments for submap metadata
  metadata_tr <= metadata_wt or metadata_rt;
  process (clk_i) begin
    if rising_edge(clk_i) then
      if rst_n_i = '0' then
        metadata_rt <= '0';
      else
        metadata_rt <= (metadata_rt or metadata_re) and not metadata_rack;
      end if;
    end if;
  end process;
  metadata_o.cyc <= metadata_tr;
  metadata_o.stb <= metadata_tr;
  metadata_wack <= metadata_i.ack and metadata_wt;
  metadata_rack <= metadata_i.ack and metadata_rt;
  metadata_o.adr <= ((25 downto 0 => '0') & wb_i.adr(5 downto 2)) & (1 downto 0 => '0');
  metadata_o.sel <= (others => '1');
  metadata_o.we <= metadata_wt;
  metadata_o.dat <= wb_i.dat;

  -- Assignments for submap fmc1_adc_mezzanine
  fmc1_adc_mezzanine_tr <= fmc1_adc_mezzanine_wt or fmc1_adc_mezzanine_rt;
  process (clk_i) begin
    if rising_edge(clk_i) then
      if rst_n_i = '0' then
        fmc1_adc_mezzanine_rt <= '0';
      else
        fmc1_adc_mezzanine_rt <= (fmc1_adc_mezzanine_rt or fmc1_adc_mezzanine_re) and not fmc1_adc_mezzanine_rack;
      end if;
    end if;
  end process;
  fmc1_adc_mezzanine_o.cyc <= fmc1_adc_mezzanine_tr;
  fmc1_adc_mezzanine_o.stb <= fmc1_adc_mezzanine_tr;
  fmc1_adc_mezzanine_wack <= fmc1_adc_mezzanine_i.ack and fmc1_adc_mezzanine_wt;
  fmc1_adc_mezzanine_rack <= fmc1_adc_mezzanine_i.ack and fmc1_adc_mezzanine_rt;
  fmc1_adc_mezzanine_o.adr <= ((18 downto 0 => '0') & wb_i.adr(12 downto 2)) & (1 downto 0 => '0');
  fmc1_adc_mezzanine_o.sel <= (others => '1');
  fmc1_adc_mezzanine_o.we <= fmc1_adc_mezzanine_wt;
  fmc1_adc_mezzanine_o.dat <= wb_i.dat;

  -- Assignments for submap fmc2_adc_mezzanine
  fmc2_adc_mezzanine_tr <= fmc2_adc_mezzanine_wt or fmc2_adc_mezzanine_rt;
  process (clk_i) begin
    if rising_edge(clk_i) then
      if rst_n_i = '0' then
        fmc2_adc_mezzanine_rt <= '0';
      else
        fmc2_adc_mezzanine_rt <= (fmc2_adc_mezzanine_rt or fmc2_adc_mezzanine_re) and not fmc2_adc_mezzanine_rack;
      end if;
    end if;
  end process;
  fmc2_adc_mezzanine_o.cyc <= fmc2_adc_mezzanine_tr;
  fmc2_adc_mezzanine_o.stb <= fmc2_adc_mezzanine_tr;
  fmc2_adc_mezzanine_wack <= fmc2_adc_mezzanine_i.ack and fmc2_adc_mezzanine_wt;
  fmc2_adc_mezzanine_rack <= fmc2_adc_mezzanine_i.ack and fmc2_adc_mezzanine_rt;
  fmc2_adc_mezzanine_o.adr <= ((18 downto 0 => '0') & wb_i.adr(12 downto 2)) & (1 downto 0 => '0');
  fmc2_adc_mezzanine_o.sel <= (others => '1');
  fmc2_adc_mezzanine_o.we <= fmc2_adc_mezzanine_wt;
  fmc2_adc_mezzanine_o.dat <= wb_i.dat;

  -- Process for write requests.
  process (clk_i) begin
    if rising_edge(clk_i) then
      if rst_n_i = '0' then
        wr_ack_int <= '0';
        metadata_wt <= '0';
        fmc1_adc_mezzanine_wt <= '0';
        fmc2_adc_mezzanine_wt <= '0';
      else
        wr_ack_int <= '0';
        metadata_wt <= '0';
        fmc1_adc_mezzanine_wt <= '0';
        fmc2_adc_mezzanine_wt <= '0';
        case wb_i.adr(14 downto 13) is
        when "01" => 
          -- Submap metadata
          metadata_wt <= (metadata_wt or wr_int) and not metadata_wack;
          wr_ack_int <= metadata_wack;
        when "10" => 
          -- Submap fmc1_adc_mezzanine
          fmc1_adc_mezzanine_wt <= (fmc1_adc_mezzanine_wt or wr_int) and not fmc1_adc_mezzanine_wack;
          wr_ack_int <= fmc1_adc_mezzanine_wack;
        when "11" => 
          -- Submap fmc2_adc_mezzanine
          fmc2_adc_mezzanine_wt <= (fmc2_adc_mezzanine_wt or wr_int) and not fmc2_adc_mezzanine_wack;
          wr_ack_int <= fmc2_adc_mezzanine_wack;
        when others =>
          wr_ack_int <= wr_int;
        end case;
      end if;
    end if;
  end process;

  -- Process for registers read.
  process (clk_i) begin
    if rising_edge(clk_i) then
      if rst_n_i = '0' then
        rd_ack1_int <= '0';
      else
        reg_rdat_int <= (others => '0');
        case wb_i.adr(14 downto 13) is
        when "01" => 
        when "10" => 
        when "11" => 
        when others =>
          reg_rdat_int <= (others => 'X');
          rd_ack1_int <= rd_int;
        end case;
      end if;
    end if;
  end process;

  -- Process for read requests.
  process (wb_i.adr, reg_rdat_int, rd_ack1_int, rd_int, rd_int, metadata_i.dat, metadata_rack, metadata_rt, rd_int, fmc1_adc_mezzanine_i.dat, fmc1_adc_mezzanine_rack, fmc1_adc_mezzanine_rt, rd_int, fmc2_adc_mezzanine_i.dat, fmc2_adc_mezzanine_rack, fmc2_adc_mezzanine_rt) begin
    -- By default ack read requests
    wb_o.dat <= (others => '0');
    metadata_re <= '0';
    fmc1_adc_mezzanine_re <= '0';
    fmc2_adc_mezzanine_re <= '0';
    case wb_i.adr(14 downto 13) is
    when "01" => 
      -- Submap metadata
      metadata_re <= rd_int;
      wb_o.dat <= metadata_i.dat;
      rd_ack_int <= metadata_rack;
    when "10" => 
      -- Submap fmc1_adc_mezzanine
      fmc1_adc_mezzanine_re <= rd_int;
      wb_o.dat <= fmc1_adc_mezzanine_i.dat;
      rd_ack_int <= fmc1_adc_mezzanine_rack;
    when "11" => 
      -- Submap fmc2_adc_mezzanine
      fmc2_adc_mezzanine_re <= rd_int;
      wb_o.dat <= fmc2_adc_mezzanine_i.dat;
      rd_ack_int <= fmc2_adc_mezzanine_rack;
    when others =>
      rd_ack_int <= rd_int;
    end case;
  end process;
end syn;
