library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use IEEE.MATH_REAL.all; library work; use work.io_types.all; package socbridge_driver_tb_pkg is subtype command_size_t is integer range 1 to 128; type command_t is (NO_OP, WRITE_ADD, WRITE, READ_ADD, READ, P_ERR); type response_t is (NO_OP, WRITE_ACK, READ_RESPONSE); type state_t is (IDLE, ADDR1, ADDR2, ADDR3, ADDR4, TX_HEADER, TX_BODY, TX_ACK, RX_HEADER, RX_RESPONSE, RX_BODY_NO_OUT, RX_BODY); type ext_protocol_t is record data : std_logic_vector(interface_inst.socbridge.payload_width - 1 downto 0); clk : std_logic; parity : std_logic; end record ext_protocol_t; type state_rec_t is record curr_state: state_t; ext_in_reg, ext_out_reg : ext_protocol_t; write_stage, read_stage : NATURAL; cmd_reg : command_t; addr_reg : std_logic_vector(31 downto 0); end record state_rec_t; impure function calc_parity( d : STD_LOGIC_VECTOR(interface_inst.socbridge.payload_width - 1 downto 0) ) return std_logic; pure function create_io_type_out_from_ext_protocol( input: ext_protocol_t ) return ext_socbridge_out_t; function to_string ( a: std_logic_vector) return string; pure function get_cmd_bits(command : command_t) return std_logic_vector; pure function get_size_bits(size : command_size_t) return std_logic_vector; pure function get_size_bits_sim(size : command_size_t) return std_logic_vector; --- DEBUG GLOBAL SIGNALS --- -- synthesis translate_off signal G_next_parity_out : std_logic; signal G_ext_in_rec : ext_protocol_t; signal G_ext_out_data_cmd : std_logic_vector(interface_inst.socbridge.payload_width - 1 downto 0); signal G_next_state : state_t; signal G_curr_command : command_t; signal G_curr_command_bits : std_logic_vector(4 downto 0); signal G_curr_response : response_t; signal G_curr_response_bits : std_logic_vector(4 downto 0); signal G_st : state_rec_t; -- synthesis translate_on end package socbridge_driver_tb_pkg; package body socbridge_driver_tb_pkg is function to_string ( a: std_logic_vector) return string is variable b : string (1 to a'length) := (others => NUL); variable stri : integer := 1; begin for i in a'range loop b(stri) := std_logic'image(a((i)))(2); stri := stri+1; end loop; return b; end function; impure function calc_parity( d : STD_LOGIC_VECTOR(interface_inst.socbridge.payload_width - 1 downto 0) ) return std_logic is variable parity : std_logic; begin parity := d(0); for x in integer'(1) to d'length - 1 loop parity := parity xor d(x); end loop; return not parity; end function; pure function create_io_type_out_from_ext_protocol( input : ext_protocol_t ) return ext_socbridge_out_t is variable val : ext_socbridge_out_t; begin val.payload:= input.data; val.control(1) := input.clk; val.control(0) := input.parity; return val; end function; pure function get_cmd_bits(command : command_t) return std_logic_vector is variable val : std_logic_vector(4 downto 0); begin with command select val := "00000" when NO_OP, "10000" when WRITE_ADD, "10100" when WRITE, "11000" when READ_ADD, "11100" when READ, "01001" when P_ERR, "11111" when others; return val; end function; pure function get_size_bits(size: command_size_t) return std_logic_vector is variable val : std_logic_vector(2 downto 0); begin val := std_logic_vector(TO_UNSIGNED(size - 1, 3)); return val; end function; pure function get_size_bits_sim(size: command_size_t) return std_logic_vector is variable pow : integer; variable val : std_logic_vector(2 downto 0); begin pow := integer(CEIL(sqrt(Real(size)))); val := std_logic_vector(TO_UNSIGNED(size - 1, 3)); return val; end function; end package body socbridge_driver_tb_pkg;