---------------------------------------------------------------------------------------
-- Title          : Wishbone slave core for Mock Turtle CPU Control/Status registers block
---------------------------------------------------------------------------------------
-- File           : wrc_cpu_csr_wbgen2_pkg.vhd
-- Author         : auto-generated by wbgen2 from wrc_cpu_csr.wb
-- Created        : Fri Feb 19 19:31:37 2021
-- Standard       : VHDL'87
---------------------------------------------------------------------------------------
-- THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE wrc_cpu_csr.wb
-- DO NOT HAND-EDIT UNLESS IT'S ABSOLUTELY NECESSARY!
---------------------------------------------------------------------------------------

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

package wrc_cpu_csr_wbgen2_pkg is
  
  
  -- Input registers (user design -> WB slave)
  
  type t_wrc_cpu_csr_in_registers is record
    udata_i                                  : std_logic_vector(31 downto 0);
    dbg_status_i                             : std_logic_vector(7 downto 0);
    dbg_insn_ready_i                         : std_logic_vector(7 downto 0);
    dbg_core0_mbx_i                          : std_logic_vector(31 downto 0);
  end record;
  
  constant c_wrc_cpu_csr_in_registers_init_value: t_wrc_cpu_csr_in_registers := (
    udata_i => (others => '0'),
    dbg_status_i => (others => '0'),
    dbg_insn_ready_i => (others => '0'),
    dbg_core0_mbx_i => (others => '0')
  );
  
  -- Output registers (WB slave -> user design)
  
  type t_wrc_cpu_csr_out_registers is record
    reset_o                                  : std_logic_vector(7 downto 0);
    uaddr_addr_o                             : std_logic_vector(19 downto 0);
    udata_o                                  : std_logic_vector(31 downto 0);
    udata_load_o                             : std_logic;
    dbg_force_o                              : std_logic_vector(7 downto 0);
    dbg_core0_insn_o                         : std_logic_vector(31 downto 0);
    dbg_core0_insn_wr_o                      : std_logic;
    dbg_core0_mbx_o                          : std_logic_vector(31 downto 0);
    dbg_core0_mbx_load_o                     : std_logic;
  end record;
  
  constant c_wrc_cpu_csr_out_registers_init_value: t_wrc_cpu_csr_out_registers := (
    reset_o => (others => '0'),
    uaddr_addr_o => (others => '0'),
    udata_o => (others => '0'),
    udata_load_o => '0',
    dbg_force_o => (others => '0'),
    dbg_core0_insn_o => (others => '0'),
    dbg_core0_insn_wr_o => '0',
    dbg_core0_mbx_o => (others => '0'),
    dbg_core0_mbx_load_o => '0'
  );

function "or" (left, right: t_wrc_cpu_csr_in_registers) return t_wrc_cpu_csr_in_registers;
function f_x_to_zero (x:std_logic) return std_logic;
function f_x_to_zero (x:std_logic_vector) return std_logic_vector;

component wrc_cpu_csr_wb_slave is
  port (
    rst_n_i                                  : in     std_logic;
    clk_sys_i                                : in     std_logic;
    slave_i                                  : in     t_wishbone_slave_in;
    slave_o                                  : out    t_wishbone_slave_out;
    int_o                                    : out    std_logic;
    regs_i                                   : in     t_wrc_cpu_csr_in_registers;
    regs_o                                   : out    t_wrc_cpu_csr_out_registers
  );
end component;

end package;

package body wrc_cpu_csr_wbgen2_pkg is
function f_x_to_zero (x:std_logic) return std_logic is
begin
  if x = '1' then
    return '1';
  else
    return '0';
  end if;
end function;

function f_x_to_zero (x:std_logic_vector) return std_logic_vector is
  variable tmp: std_logic_vector(x'length-1 downto 0);
begin
  for i in 0 to x'length-1 loop
    if(x(i) = 'X' or x(i) = 'U') then
      tmp(i):= '0';
    else
      tmp(i):=x(i);
    end if; 
  end loop; 
  return tmp;
end function;

function "or" (left, right: t_wrc_cpu_csr_in_registers) return t_wrc_cpu_csr_in_registers is
  variable tmp: t_wrc_cpu_csr_in_registers;
begin
  tmp.udata_i := f_x_to_zero(left.udata_i) or f_x_to_zero(right.udata_i);
  tmp.dbg_status_i := f_x_to_zero(left.dbg_status_i) or f_x_to_zero(right.dbg_status_i);
  tmp.dbg_insn_ready_i := f_x_to_zero(left.dbg_insn_ready_i) or f_x_to_zero(right.dbg_insn_ready_i);
  tmp.dbg_core0_mbx_i := f_x_to_zero(left.dbg_core0_mbx_i) or f_x_to_zero(right.dbg_core0_mbx_i);
  return tmp;
end function;

end package body;
