SURF  1.0
AxiStreamPacker.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiStreamPacker
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-09-29
5 -- Last update: 2016-07-13
6 -------------------------------------------------------------------------------
7 -- Description: AXI stream Packer Module
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 use ieee.std_logic_arith.all;
21 use ieee.std_logic_unsigned.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiStreamPkg.all;
25 use work.SsiPkg.all;
26 
27 --! @see entity
28  --! @ingroup axi
29 entity AxiStreamPacker is
30 
31  generic (
32  TPD_G : time := 1 ns;
34  RANGE_HIGH_G : integer := 13;
35  RANGE_LOW_G : integer := 2);
36  port (
37  axisClk : in sl;
38  axisRst : in sl;
39 
43 
47 
48  );
49 
50 end entity AxiStreamPacker;
51 
52 architecture rtl of AxiStreamPacker is
53 
54 
55  constant STREAM_WIDTH_C : integer := AXI_STREAM_CONFIG_G.TDATA_BYTES_C*8;
56  constant PACK_SIZE_C : integer := RANGE_HIGH_G-RANGE_LOW_G+1;
57  constant SIZE_DIFFERENCE_C : integer := STREAM_WIDTH_C-PACK_SIZE_C;
58 
59  -- Vivado chokes if you try to calculate these on the fly inside the comb process.
60  -- Precompute all of the assignment indicies instead
61  function computeIndicies return IntegerArray is
62  variable ret : IntegerArray(0 to STREAM_WIDTH_C/SIZE_DIFFERENCE_C-1);
63  begin
64  for i in ret'range loop
65  ret(i) := STREAM_WIDTH_C - (i*SIZE_DIFFERENCE_C);
66  end loop;
67  return ret;
68  end function computeIndicies;
69 
70  constant ASSIGNMENT_INDECIES_C : IntegerArray := computeIndicies;
71 
72  type RegType is record
73  packedSsiMaster : SsiMasterType;
74  rawSsiSlave : SsiSlaveType;
75  data : slv(STREAM_WIDTH_C*2-1 downto 0);
76  index : slv(log2(STREAM_WIDTH_C/SIZE_DIFFERENCE_C)-1 downto 0);
77  end record RegType;
78 
79  constant REG_INIT_C : RegType := (
80  packedSsiMaster => ssiMasterInit(AXI_STREAM_CONFIG_G),
81  rawSsiSlave => ssiSlaveInit(AXI_STREAM_CONFIG_G),
82  data => (others => '0'),
83  index => (others => '0'));
84 
85  signal r : RegType := REG_INIT_C;
86  signal rin : RegType;
87 
88  signal rawSsiMaster : SsiMasterType;
89  signal packedSsiSlave : SsiSlaveType;
90 
91 begin
92 
93  -- Convert AXI-Stream signals to SSI
94  packedSsiSlave <= axis2ssiSlave(AXI_STREAM_CONFIG_G, packedAxisSlave, packedAxisCtrl);
95  rawSsiMaster <= axis2SsiMaster(AXI_STREAM_CONFIG_G, rawAxisMaster);
96 
97  comb : process (axisRst, r, rawSsiMaster) is
98  variable v : RegType;
99  variable indexInt : integer;
100  begin
101  v := r;
102 
103  v.packedSsiMaster.sof := '0';
104  v.packedSsiMaster.eof := '0';
105  v.packedSsiMaster.eofe := '0';
106  v.packedSsiMaster.valid := '0';
107 
108  v.rawSsiSlave.ready := '1';
109  v.rawSsiSlave.pause := '0';
110  v.rawSsiSlave.overflow := '0';
111 
112 
113  if (rawSsiMaster.valid = '1') then
114  if (rawSsiMaster.sof = '1') then
115  -- Frame header goes through unmodified
116  v.data := (others => '0');
117  v.data(STREAM_WIDTH_C-1 downto 0) := rawSsiMaster.data(STREAM_WIDTH_C-1 downto 0);
118  v.packedSsiMaster.valid := '1';
119  v.packedSsiMaster.sof := '1';
120  v.index := (others => '0');
121 
122  else
123  -- Pack all other txns
124  v.packedSsiMaster.eof := rawSsiMaster.eof;
125  v.packedSsiMaster.eofe := rawSsiMaster.eofe;
126 
127 
128  -- Shift the data over
129  v.data(STREAM_WIDTH_C-1 downto 0) := r.data(STREAM_WIDTH_C*2-1 downto STREAM_WIDTH_C);
130 
131  -- Assign new data at proper index
132  indexInt := ASSIGNMENT_INDECIES_C(conv_integer(r.index));
133  v.data(indexInt+PACK_SIZE_C-1 downto indexInt) := rawSsiMaster.data(RANGE_HIGH_G downto RANGE_LOW_G);
134 
135  -- Disable write until we have enough data
136 -- v.packedSsiMaster.valid := toSl(indexInt+PACK_SIZE_C >= STREAM_WIDTH_C);
137  v.packedSsiMaster.valid := toSl(r.index /= 0) or rawSsiMaster.eofe or rawSsiMaster.eof;
138 
139 
140  -- Increment index
141  v.index := r.index + 1;
142 
143 
144  end if;
145  end if;
146 
147  v.packedSsiMaster.data(STREAM_WIDTH_C-1 downto 0) := v.data(STREAM_WIDTH_C-1 downto 0);
148 
149  ----------------------------------------------------------------------------------------------
150  -- Reset
151  ----------------------------------------------------------------------------------------------
152  if (axisRst = '1') then
153  v := REG_INIT_C;
154  end if;
155 
156  rin <= v;
157 
158  ----------------------------------------------------------------------------------------------
159  -- Outputs
160  ----------------------------------------------------------------------------------------------
161  packedAxisMaster <= ssi2AxisMaster(AXI_STREAM_CONFIG_G, r.packedSsiMaster);
162  rawAxisSlave <= ssi2AxisSlave(r.rawSsiSlave);
163  rawAxisCtrl <= ssi2AxisCtrl(r.rawSsiSlave);
164 
165  end process comb;
166 
167  seq : process (axisClk) is
168  begin
169  if (rising_edge(axisClk)) then
170  r <= rin after TPD_G;
171  end if;
172  end process seq;
173 
174 end architecture rtl;
slv( 127 downto 0) data
Definition: SsiPkg.vhd:67
sl sof
Definition: SsiPkg.vhd:72
RANGE_HIGH_Ginteger := 13
std_logic sl
Definition: StdRtlPkg.vhd:28
sl eofe
Definition: SsiPkg.vhd:74
in rawAxisMasterAxiStreamMasterType
natural range 1 to 16 TDATA_BYTES_C
in packedAxisCtrlAxiStreamCtrlType
out packedAxisMasterAxiStreamMasterType
SsiMasterType
Definition: SsiPkg.vhd:65
SsiSlaveType
Definition: SsiPkg.vhd:77
RANGE_LOW_Ginteger := 2
sl valid
Definition: SsiPkg.vhd:66
AxiStreamConfigType := ssiAxiStreamConfig( 16) SSI_CONFIG_INIT_C
Definition: SsiPkg.vhd:60
sl ready
Definition: SsiPkg.vhd:78
out rawAxisSlaveAxiStreamSlaveType
TPD_Gtime := 1 ns
out rawAxisCtrlAxiStreamCtrlType
AXI_STREAM_CONFIG_GAxiStreamConfigType := SSI_CONFIG_INIT_C
sl eof
Definition: SsiPkg.vhd:73
array(natural range <> ) of integer IntegerArray
Definition: StdRtlPkg.vhd:33
in packedAxisSlaveAxiStreamSlaveType
_library_ ieeeieee
std_logic_vector slv
Definition: StdRtlPkg.vhd:29