SURF  1.0
SsiInsertSof.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SsiInsertSof.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-08-18
5 -- Last update: 2015-10-23
6 -------------------------------------------------------------------------------
7 -- Description: Inserts the SOF for converting a generic AXIS into a SSI bus
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_unsigned.all;
21 use ieee.std_logic_arith.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiStreamPkg.all;
25 use work.SsiPkg.all;
26 
27 --! @see entity
28  --! @ingroup protocols_ssi
29 entity SsiInsertSof is
30  generic (
31  TPD_G : time := 1 ns;
32  TUSER_MASK_G : slv(127 downto 0) := (others => '1'); -- '1' = masked off bit
33  COMMON_CLK_G : boolean := false; -- True if sAxisClk and mAxisClk are the same clock
34  INSERT_USER_HDR_G : boolean := false; -- If True the module adds one user header word (mUserHdr = user header data)
35  SLAVE_FIFO_G : boolean := true;
36  MASTER_FIFO_G : boolean := true;
39  port (
40  -- Slave Port
41  sAxisClk : in sl;
42  sAxisRst : in sl;
45  -- Master Port
46  mAxisClk : in sl;
47  mAxisRst : in sl;
48  mUserHdr : in slv(127 downto 0) := (others => '0');
51 end SsiInsertSof;
52 
53 architecture rtl of SsiInsertSof is
54 
55  type StateType is (
56  IDLE_S,
57  MOVE_S);
58 
59  type RegType is record
60  rxSlave : AxiStreamSlaveType;
61  txMaster : AxiStreamMasterType;
62  state : StateType;
63  end record RegType;
64  constant REG_INIT_C : RegType := (
65  rxSlave => AXI_STREAM_SLAVE_INIT_C,
66  txMaster => AXI_STREAM_MASTER_INIT_C,
67  state => IDLE_S);
68 
69  signal r : RegType := REG_INIT_C;
70  signal rin : RegType;
71 
72  signal rxMaster : AxiStreamMasterType;
73  signal rxSlave : AxiStreamSlaveType;
74  signal txMaster : AxiStreamMasterType;
75  signal txSlave : AxiStreamSlaveType;
76 
77 begin
78 
79  BYPASS_FIFO_RX : if ( (SLAVE_FIFO_G = false) and (COMMON_CLK_G = true) and (SLAVE_AXI_CONFIG_G = MASTER_AXI_CONFIG_G) ) generate
80  rxMaster <= sAxisMaster;
81  sAxisSlave <= rxSlave;
82  end generate;
83 
84  GEN_FIFO_RX : if ( (SLAVE_FIFO_G = true) or (COMMON_CLK_G = false) or (SLAVE_AXI_CONFIG_G /= MASTER_AXI_CONFIG_G) ) generate
85  FIFO_RX : entity work.AxiStreamFifoV2
86  generic map (
87  -- General Configurations
88  TPD_G => TPD_G,
89  PIPE_STAGES_G => 0,
90  SLAVE_READY_EN_G => true,
91  VALID_THOLD_G => 1,
92  -- FIFO configurations
93  BRAM_EN_G => false,
94  USE_BUILT_IN_G => false,
96  CASCADE_SIZE_G => 1,
97  FIFO_ADDR_WIDTH_G => 4,
98  -- AXI Stream Port Configurations
101  port map (
102  -- Slave Port
103  sAxisClk => sAxisClk,
104  sAxisRst => sAxisRst,
107  -- Master Port
108  mAxisClk => mAxisClk,
109  mAxisRst => mAxisRst,
110  mAxisMaster => rxMaster,
111  mAxisSlave => rxSlave);
112  end generate;
113 
114 
115  comb : process (mAxisRst, mUserHdr, r, rxMaster, txSlave) is
116  variable v : RegType;
117  variable i : natural;
118  begin
119  -- Latch the current value
120  v := r;
121 
122  -- Reset the flags
123  v.rxSlave := AXI_STREAM_SLAVE_INIT_C;
124  if txSlave.tReady = '1' then
125  v.txMaster.tValid := '0';
126  end if;
127 
128  -- State Machine
129  case r.state is
130  ----------------------------------------------------------------------
131  when IDLE_S =>
132  -- Check if ready to move data
133  if (v.txMaster.tValid = '0') and (rxMaster.tValid = '1') then
134  if INSERT_USER_HDR_G = false then
135  -- Accept the data
136  v.rxSlave.tReady := '1';
137  -- Move the data
138  v.txMaster := rxMaster;
139  -- Mask off the TUSER bits
140  for i in 127 downto 0 loop
141  if TUSER_MASK_G(i) = '1' then
142  v.txMaster.tUser(i) := '0';
143  end if;
144  end loop;
145  -- Insert the SOF bit
146  ssiSetUserSof(MASTER_AXI_CONFIG_G, v.txMaster, '1');
147  -- Check for no EOF
148  if (rxMaster.tLast = '0') then
149  -- Next state
150  v.state := MOVE_S;
151  end if;
152  else
153  -- Insert User Header
154  v.txMaster := AXI_STREAM_MASTER_INIT_C;
155  v.txMaster.tValid := '1';
156  v.txMaster.tData := mUserHdr;
157  v.txMaster.tDest := rxMaster.tDest;
158  -- Insert the SOF bit
159  ssiSetUserSof(MASTER_AXI_CONFIG_G, v.txMaster, '1');
160  -- Next state
161  v.state := MOVE_S;
162  end if;
163  end if;
164  ----------------------------------------------------------------------
165  when MOVE_S =>
166  -- Check if ready to move data
167  if (v.txMaster.tValid = '0') and (rxMaster.tValid = '1') then
168  -- Accept the data
169  v.rxSlave.tReady := '1';
170  -- Move the data
171  v.txMaster := rxMaster;
172  -- Mask off the TUSER bits
173  for i in 127 downto 0 loop
174  if TUSER_MASK_G(i) = '1' then
175  v.txMaster.tUser(i) := '0';
176  end if;
177  end loop;
178  -- Mask off the SOF bits
179  ssiSetUserSof(MASTER_AXI_CONFIG_G, v.txMaster, '0');
180  -- Check for EOF
181  if (rxMaster.tLast = '1') then
182  -- Next state
183  v.state := IDLE_S;
184  end if;
185  end if;
186  ----------------------------------------------------------------------
187  end case;
188 
189  -- Reset
190  if (mAxisRst = '1') then
191  v := REG_INIT_C;
192  end if;
193 
194  -- Register the variable for next clock cycle
195  rin <= v;
196 
197  -- Outputs
198  rxSlave <= v.rxSlave;
199  txMaster <= r.txMaster;
200 
201  end process comb;
202 
203  seq : process (mAxisClk) is
204  begin
205  if rising_edge(mAxisClk) then
206  r <= rin after TPD_G;
207  end if;
208  end process seq;
209 
210  BYPASS_FIFO_TX : if (MASTER_FIFO_G = false) generate
211  mAxisMaster <= txMaster;
212  txSlave <= mAxisSlave;
213  end generate;
214 
215  GEN_FIFO_TX : if (MASTER_FIFO_G = true) generate
216  FIFO_TX : entity work.AxiStreamFifoV2
217  generic map (
218  -- General Configurations
219  TPD_G => TPD_G,
220  PIPE_STAGES_G => 0,
221  SLAVE_READY_EN_G => true,
222  VALID_THOLD_G => 1,
223  -- FIFO configurations
224  BRAM_EN_G => false,
225  USE_BUILT_IN_G => false,
226  GEN_SYNC_FIFO_G => true,
227  CASCADE_SIZE_G => 1,
228  FIFO_ADDR_WIDTH_G => 4,
229  -- AXI Stream Port Configurations
232  port map (
233  -- Slave Port
234  sAxisClk => mAxisClk,
235  sAxisRst => mAxisRst,
236  sAxisMaster => txMaster,
237  sAxisSlave => txSlave,
238  -- Master Port
239  mAxisClk => mAxisClk,
240  mAxisRst => mAxisRst,
242  mAxisSlave => mAxisSlave);
243  end generate;
244 
245 end rtl;
FIFO_ADDR_WIDTH_Ginteger range 4 to 48:= 9
TPD_Gtime := 1 ns
PIPE_STAGES_Gnatural range 0 to 16:= 1
MASTER_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
std_logic sl
Definition: StdRtlPkg.vhd:28
AxiStreamMasterType :=(tValid => '0',tData =>( others => '0'),tStrb =>( others => '1'),tKeep =>( others => '1'),tLast => '0',tDest =>( others => '0'),tId =>( others => '0'),tUser =>( others => '0')) AXI_STREAM_MASTER_INIT_C
SLAVE_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
COMMON_CLK_Gboolean := false
SLAVE_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
SLAVE_READY_EN_Gboolean := true
in sAxisMasterAxiStreamMasterType
INSERT_USER_HDR_Gboolean := false
MASTER_FIFO_Gboolean := true
in mUserHdrslv( 127 downto 0) :=( others => '0')
GEN_SYNC_FIFO_Gboolean := false
SLAVE_FIFO_Gboolean := true
TUSER_MASK_Gslv( 127 downto 0) :=( others => '1')
slv( 127 downto 0) tData
out sAxisSlaveAxiStreamSlaveType
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
BRAM_EN_Gboolean := true
slv( 127 downto 0) tUser
TPD_Gtime := 1 ns
out sAxisSlaveAxiStreamSlaveType
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
in mAxisSlaveAxiStreamSlaveType
in sAxisMasterAxiStreamMasterType
out mAxisMasterAxiStreamMasterType
in mAxisSlaveAxiStreamSlaveType
CASCADE_SIZE_Ginteger range 1 to ( 2** 24):= 1
USE_BUILT_IN_Gboolean := false
out mAxisMasterAxiStreamMasterType
VALID_THOLD_Ginteger range 0 to ( 2** 24):= 1
MASTER_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
std_logic_vector slv
Definition: StdRtlPkg.vhd:29