tsfpga VHDL coverage


Directory: generated/vunit_out/preprocessed/
File: generated/vunit_out/preprocessed/axi/axi_stream_pkg.vhd
Date: 2021-07-26 04:08:16
Exec Total Coverage
Lines: 0 38 0.0%
Branches: 0 117 0.0%

Line Branch Exec Source
1 -- -------------------------------------------------------------------------------------------------
2 -- Copyright (c) Lukas Vik. All rights reserved.
3 --
4 -- This file is part of the tsfpga project.
5 -- https://tsfpga.com
6 -- https://gitlab.com/tsfpga/tsfpga
7 -- -------------------------------------------------------------------------------------------------
8 -- Data types for working with AXI4-Stream interfaces.
9 -- Based on the document "ARM IHI 0051A (ID030610) AMBA 4 AXI4-Stream Protocol Specification"
10 -- Available here: https://developer.arm.com/documentation/ihi0051/a/
11 -- -------------------------------------------------------------------------------------------------
12
13 library ieee;
14 use ieee.std_logic_1164.all;
15 use ieee.numeric_std.all;
16
17
18 package axi_stream_pkg is
19
20 -- Max value
21 constant axi_stream_id_sz : positive := 8;
22 constant axi_stream_dest_sz : positive := 4;
23
24 -- Data bus width in bytes, 128b seems reasonable at the moment.
25 constant axi_stream_data_sz : positive := 128;
26 -- Integer multiple of the width of the interface in bytes.
27 constant axi_stream_user_sz : positive := axi_stream_data_sz / 8;
28 constant axi_stream_strb_sz : positive := axi_stream_data_sz / 8;
29 constant axi_stream_keep_sz : positive := axi_stream_data_sz / 8;
30
31 type axi_stream_m2s_t is record
32 valid : std_logic;
33 data : std_logic_vector(axi_stream_data_sz - 1 downto 0);
34 last : std_logic;
35 user : std_logic_vector(axi_stream_user_sz - 1 downto 0);
36 -- Excluded members: tkeep, tstrb, tid, tdest.
37 -- These are optional according to the standard and should be added when needed.
38 end record;
39 type axi_stream_m2s_vec_t is array (integer range <>) of axi_stream_m2s_t;
40
41 constant axi_stream_m2s_init : axi_stream_m2s_t := (
42 valid|last => '0',
43 data|user => (others => '-')
44 );
45
46 type axi_stream_s2m_t is record
47 ready : std_logic;
48 end record;
49 type axi_stream_s2m_vec_t is array (integer range <>) of axi_stream_s2m_t;
50
51 constant axi_stream_s2m_init : axi_stream_s2m_t := (ready => '1');
52
53 function axi_stream_m2s_sz(data_width : positive; user_width : natural) return natural;
54
55 function to_slv(
56 data : axi_stream_m2s_t;
57 data_width : positive;
58 user_width : natural
59 ) return std_logic_vector;
60
61 function to_axi_stream_m2s(
62 data : std_logic_vector;
63 data_width : positive;
64 user_width : natural;
65 valid : std_logic
66 ) return axi_stream_m2s_t;
67
68 end;
69
70 package body axi_stream_pkg is
71
72 function axi_stream_m2s_sz(data_width : positive; user_width : natural) return natural is
73 begin
74 -- Exluded member: valid
75 -- The 1 is last
76 return data_width + user_width + 1;
77 end function;
78
79 function to_slv(
80 data : axi_stream_m2s_t;
81 data_width : positive;
82 user_width : natural
83 ) return std_logic_vector is
84 variable result : std_logic_vector(axi_stream_m2s_sz(data_width, user_width) - 1 downto 0);
85 variable lo, hi : natural := 0;
86 begin
87 lo := 0;
88 hi := lo + data_width - 1;
89 result(hi downto lo) := data.data(data_width - 1 downto 0);
90 lo := hi + 1;
91 hi := lo;
92 result(hi) := data.last;
93 lo := hi + 1;
94 hi := lo + user_width - 1;
95 result(hi downto lo) := data.user(user_width - 1 downto 0);
96 assert hi = result'high severity failure;
97 return result;
98 end function;
99
100 function to_axi_stream_m2s(
101 data : std_logic_vector;
102 data_width : positive;
103 user_width : natural;
104 valid : std_logic
105 ) return axi_stream_m2s_t is
106 variable offset : natural := data'low;
107 variable result : axi_stream_m2s_t := axi_stream_m2s_init;
108 variable lo, hi : natural := 0;
109 begin
110 lo := 0;
111 hi := lo + data_width - 1;
112 result.data(data_width - 1 downto 0) := data(hi + offset downto lo + offset);
113 lo := hi + 1;
114 hi := lo;
115 result.last := data(hi + offset);
116 lo := hi + 1;
117 hi := lo + user_width - 1;
118 result.user(user_width - 1 downto 0) := data(hi + offset downto lo + offset);
119 assert hi + offset = data'high severity failure;
120 result.valid := valid;
121 return result;
122 end function;
123
124 end;
125