Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
pkg_bpmframe_stream.vhd 2.83 KiB
-- Package BPMFRAME STREAM
-- this package describe the format of the AXI-Stream interface used by blocs of the module COMBPM.
--
-- The usefull things are :
--   * Two record types for port interfaces: t_bpmframe_axis_m2s and t_bpmframe_axis_s2m.
--   * One record type for frame fields: t_bpmframe.
--   * Two functions to transform TDATA (std_logic_vector) to/from t_bpmframe: slv2bpmframe and bpmframe2slv.
library ieee;
use ieee.std_logic_1164.all;

package pkg_bpmframe_stream is

    ----------------------
    -- MACRO PARAMETERS --
    ----------------------
    constant C_TDEST_W : natural := 7;
    constant C_TDATA_W : natural := 128;

    ---------------------------------
    -- AXIS MASTER/SLAVE INTERFACE --
    ---------------------------------
    type t_bpmframe_axis_m2s is record
        tdest  : std_logic_vector(C_TDEST_W-1 downto 0);
        tdata  : std_logic_vector(C_TDATA_W-1 downto 0);
        tlast  : std_logic;
        tvalid : std_logic;
    end record t_bpmframe_axis_m2s;

    type t_bpmframe_axis_s2m is record
        tready : std_logic;
    end record t_bpmframe_axis_s2m;

    ------------------------
    -- AXIS STREAM PACKET --
    ------------------------
    type t_bpmframe is record
        pos_x                        : std_logic_vector(31 downto 0);
        pos_y                        : std_logic_vector(31 downto 0);
        bpm_id                       : std_logic_vector(15 downto 0);
        mc_timestamp                 : std_logic_vector(39 downto 0);
        fa_seq                       : std_logic_vector(7 downto 0);
    end record t_bpmframe;

    constant C_BPMFRAME_ZERO : t_bpmframe := (
        pos_x         => (others => '0'),
        pos_y         => (others => '0'),
        bpm_id        => (others => '0'),
        mc_timestamp  => (others => '0'),
        fa_seq        => (others => '0')
        );

    function slv2bpmframe(
        signal tdata : std_logic_vector(C_TDATA_W-1 downto 0)
        )
        return t_bpmframe;

    function bpmframe2slv(
        signal packet : t_bpmframe
        )
        return std_logic_vector;


end package;

package body pkg_bpmframe_stream is


    function slv2bpmframe(
        signal tdata : std_logic_vector(C_TDATA_W-1 downto 0)
        )
        return t_bpmframe is
        variable packet : t_bpmframe;
    begin
        packet.pos_x        := tdata(31 downto 0);
        packet.pos_y        := tdata(63 downto 32);
        packet.bpm_id       := tdata(79 downto 64);
        packet.mc_timestamp := tdata(119 downto 80);
        packet.fa_seq       := tdata(127 downto 120);
        return packet;
    end function;

    function bpmframe2slv(
        signal packet : t_bpmframe
        )
        return std_logic_vector is
    begin
        return packet.fa_seq & packet.mc_timestamp & packet.bpm_id & packet.pos_y & packet.pos_x;
    end function;

end package body;