SURF  1.0
AxiStreamResize.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiStreamResize.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2016-06-16
5 -- Last update: 2016-06-16
6 -------------------------------------------------------------------------------
7 -- Description:
8 -- Block to resize AXI Streams. Re-sizing is always little endian.
9 -- Resizer should not be used when interleaving tDests
10 -------------------------------------------------------------------------------
11 -- This file is part of 'SLAC Firmware Standard Library'.
12 -- It is subject to the license terms in the LICENSE.txt file found in the
13 -- top-level directory of this distribution and at:
14 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
15 -- No part of 'SLAC Firmware Standard Library', including this file,
16 -- may be copied, modified, propagated, or distributed except according to
17 -- the terms contained in the LICENSE.txt file.
18 -------------------------------------------------------------------------------
19 
20 library ieee;
21 use ieee.std_logic_1164.all;
22 use ieee.std_logic_unsigned.all;
23 use ieee.std_logic_arith.all;
24 
25 use work.StdRtlPkg.all;
26 use work.AxiStreamPkg.all;
27 
28 --! @see entity
29  --! @ingroup axi
30 entity AxiStreamResize is
31  generic (
32 
33  -- General Configurations
34  TPD_G : time := 1 ns;
35  READY_EN_G : boolean := true;
36 
37  -- AXI Stream Port Configurations
40  );
41  port (
42 
43  -- Clock and reset
44  axisClk : in sl;
45  axisRst : in sl;
46 
47  -- Slave Port
50 
51  -- Master Port
54  );
55 end AxiStreamResize;
56 
57 architecture rtl of AxiStreamResize is
58 
59  constant SLV_BYTES_C : integer := SLAVE_AXI_CONFIG_G.TDATA_BYTES_C;
60  constant MST_BYTES_C : integer := MASTER_AXI_CONFIG_G.TDATA_BYTES_C;
61 
62  constant SLV_USER_C : integer := SLAVE_AXI_CONFIG_G.TUSER_BITS_C;
63  constant MST_USER_C : integer := MASTER_AXI_CONFIG_G.TUSER_BITS_C;
64 
65  constant COUNT_C : integer := ite(SLV_BYTES_C > MST_BYTES_C, SLV_BYTES_C / MST_BYTES_C, MST_BYTES_C / SLV_BYTES_C);
66 
67  type RegType is record
68  count : slv(bitSize(COUNT_C)-1 downto 0);
69  obMaster : AxiStreamMasterType;
70  ibSlave : AxiStreamSlaveType;
71  end record RegType;
72 
73  constant REG_INIT_C : RegType := (
74  count => (others => '0'),
75  obMaster => axiStreamMasterInit(MASTER_AXI_CONFIG_G),
76  ibSlave => AXI_STREAM_SLAVE_INIT_C
77  );
78 
79  signal r : RegType := REG_INIT_C;
80  signal rin : RegType;
81 
82 begin
83 
84  -- Make sure data widths are appropriate.
85  assert ((SLV_BYTES_C >= MST_BYTES_C and SLV_BYTES_C mod MST_BYTES_C = 0) or
86  (MST_BYTES_C >= SLV_BYTES_C and MST_BYTES_C mod SLV_BYTES_C = 0))
87  report "Data widths must be even number multiples of each other" severity failure;
88 
89  -- When going from a large bus to a small bus, ready is neccessary
90  assert (SLV_BYTES_C <= MST_BYTES_C or READY_EN_G = true)
91  report "READY_EN_G must be true if slave width is great than master" severity failure;
92 
93  comb : process (mAxisSlave, sAxisMaster, r) is
94  variable v : RegType;
95  variable ibM : AxiStreamMasterType;
96  variable idx : integer; -- index version of counter
97  variable byteCnt : integer; -- Number of valid bytes in incoming bus
98  variable bytes : integer; -- byte version of counter
99  begin
100  v := r;
101  idx := conv_integer(r.count);
102  bytes := (idx+1) * MST_BYTES_C;
103  byteCnt := getTKeep(sAxisMaster.tKeep);
104 
105  -- Init ready
106  v.ibSlave.tReady := '0';
107 
108  -- Choose ready source and clear valid
109  if READY_EN_G = false or mAxisSlave.tReady = '1' then
110  v.obMaster.tValid := '0';
111  end if;
112 
113  -- Inbound data with normalized user bits (8 user bits)
114  ibM := sAxisMaster;
115  ibM.tUser := (others=>'0');
116 
117  for i in 0 to 15 loop
118  ibM.tUser((i*8)+(SLV_USER_C-1) downto (i*8)) := sAxisMaster.tUser((i*SLV_USER_C)+(SLV_USER_C-1) downto (i*SLV_USER_C));
119  end loop;
120 
121  -- Pipeline advance
122  if v.obMaster.tValid = '0' then
123 
124  -- Increasing size
125  if MST_BYTES_C > SLV_BYTES_C then
126  v.ibSlave.tReady := '1';
127 
128  -- init when count = 0
129  if (r.count = 0) then
130  v.obMaster := axiStreamMasterInit(MASTER_AXI_CONFIG_G);
131  v.obMaster.tKeep := (others=>'0');
132  v.obMaster.tStrb := (others=>'0');
133  end if;
134 
135  v.obMaster.tData((SLV_BYTES_C*8*idx)+((SLV_BYTES_C*8)-1) downto (SLV_BYTES_C*8*idx)) := ibM.tData((SLV_BYTES_C*8)-1 downto 0);
136  v.obMaster.tUser((SLV_BYTES_C*8*idx)+((SLV_BYTES_C*8)-1) downto (SLV_BYTES_C*8*idx)) := ibM.tUser((SLV_BYTES_C*8)-1 downto 0);
137  v.obMaster.tStrb((SLV_BYTES_C*idx)+(SLV_BYTES_C-1) downto (SLV_BYTES_C*idx)) := ibM.tStrb(SLV_BYTES_C-1 downto 0);
138  v.obMaster.tKeep((SLV_BYTES_C*idx)+(SLV_BYTES_C-1) downto (SLV_BYTES_C*idx)) := ibM.tKeep(SLV_BYTES_C-1 downto 0);
139 
140  v.obMaster.tId := ibM.tId;
141  v.obMaster.tDest := ibM.tDest;
142  v.obMaster.tLast := ibM.tLast;
143 
144  -- Determine if we move data
145  if ibM.tValid = '1' then
146  if r.count = (COUNT_C-1) or ibM.tLast = '1' then
147  v.obMaster.tValid := '1';
148  v.count := (others => '0');
149  else
150  v.count := r.count + 1;
151  end if;
152  end if;
153 
154  -- Decreasing size
155  else
156 
157  v.obMaster := axiStreamMasterInit(MASTER_AXI_CONFIG_G);
158 
159  v.obMaster.tData((MST_BYTES_C*8)-1 downto 0) := ibM.tData((MST_BYTES_C*8*idx)+((MST_BYTES_C*8)-1) downto (MST_BYTES_C*8*idx));
160  v.obMaster.tUser((MST_BYTES_C*8)-1 downto 0) := ibM.tUser((MST_BYTES_C*8*idx)+((MST_BYTES_C*8)-1) downto (MST_BYTES_C*8*idx));
161  v.obMaster.tStrb(MST_BYTES_C-1 downto 0) := ibM.tStrb((MST_BYTES_C*idx)+(MST_BYTES_C-1) downto (MST_BYTES_C*idx));
162  v.obMaster.tKeep(MST_BYTES_C-1 downto 0) := ibM.tKeep((MST_BYTES_C*idx)+(MST_BYTES_C-1) downto (MST_BYTES_C*idx));
163 
164  v.obMaster.tId := ibM.tId;
165  v.obMaster.tDest := ibM.tDest;
166 
167  -- Determine if we move data
168  if ibM.tValid = '1' then
169  if (r.count = (COUNT_C-1)) or ((bytes >= byteCnt) and (ibM.tLast = '1')) then
170  v.count := (others => '0');
171  v.ibSlave.tReady := '1';
172  v.obMaster.tLast := ibM.tLast;
173  else
174  v.count := r.count + 1;
175  v.ibSlave.tReady := '0';
176  v.obMaster.tLast := '0';
177  end if;
178  end if;
179 
180  -- Drop transfers with no tKeep bits set, except on tLast
181  v.obMaster.tValid := ibM.tValid and (uOr(v.obMaster.tKeep(COUNT_C-1 downto 0)) or v.obMaster.tLast);
182 
183  end if;
184  end if;
185 
186  -- Resize disabled
187  if SLV_BYTES_C = MST_BYTES_C then
190  else
191  sAxisSlave <= v.ibSlave;
192 
193  -- Outbound data with proper user bits
194  mAxisMaster <= r.obMaster;
195  mAxisMaster.tUser <= (others=>'0');
196 
197  for i in 0 to 15 loop
198  mAxisMaster.tUser((i*MST_USER_C)+(MST_USER_C-1) downto (i*MST_USER_C)) <= r.obMaster.tUser((i*8)+(MST_USER_C-1) downto (i*8));
199  end loop;
200  end if;
201 
202  rin <= v;
203 
204  end process comb;
205 
206  seq : process (axisClk) is
207  begin
208  if (rising_edge(axisClk)) then
209  if axisRst = '1' or (SLV_BYTES_C = MST_BYTES_C) then
210  r <= REG_INIT_C after TPD_G;
211  else
212  r <= rin after TPD_G;
213  end if;
214  end if;
215  end process seq;
216 
217 end rtl;
218 
slv( 7 downto 0) tId
std_logic sl
Definition: StdRtlPkg.vhd:28
SLAVE_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
slv( 15 downto 0) tStrb
slv( 15 downto 0) tKeep
natural range 1 to 16 TDATA_BYTES_C
slv( 127 downto 0) tData
out mAxisMasterAxiStreamMasterType
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
in mAxisSlaveAxiStreamSlaveType
in sAxisMasterAxiStreamMasterType
slv( 127 downto 0) tUser
TPD_Gtime := 1 ns
natural range 0 to 8 TUSER_BITS_C
READY_EN_Gboolean := true
AxiStreamConfigType :=(TSTRB_EN_C => false,TDATA_BYTES_C => 16,TDEST_BITS_C => 4,TID_BITS_C => 0,TKEEP_MODE_C => TKEEP_NORMAL_C,TUSER_BITS_C => 4,TUSER_MODE_C => TUSER_NORMAL_C) AXI_STREAM_CONFIG_INIT_C
slv( 7 downto 0) tDest
MASTER_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
out sAxisSlaveAxiStreamSlaveType
_library_ ieeeieee
std_logic_vector slv
Definition: StdRtlPkg.vhd:29