SURF  1.0
SsiPrbsTxOld.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SsiPrbsTxOld.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-04-02
5 -- Last update: 2014-11-07
6 -------------------------------------------------------------------------------
7 -- Description: This module generates
8 -- PseudoRandom Binary Sequence (PRBS) on Virtual Channel Lane.
9 -------------------------------------------------------------------------------
10 -- This file is part of 'SLAC Firmware Standard Library'.
11 -- It is subject to the license terms in the LICENSE.txt file found in the
12 -- top-level directory of this distribution and at:
13 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
14 -- No part of 'SLAC Firmware Standard Library', including this file,
15 -- may be copied, modified, propagated, or distributed except according to
16 -- the terms contained in the LICENSE.txt file.
17 -------------------------------------------------------------------------------
18 
19 library ieee;
20 use ieee.std_logic_1164.all;
21 use ieee.std_logic_unsigned.all;
22 use ieee.std_logic_arith.all;
23 
24 use work.StdRtlPkg.all;
25 use work.AxiStreamPkg.all;
26 use work.SsiPkg.all;
27 
28 --! @see entity
29  --! @ingroup protocols_ssi
30 entity SsiPrbsTxOld is
31  generic (
32  -- General Configurations
33  TPD_G : time := 1 ns;
34  -- FIFO Configurations
35  BRAM_EN_G : boolean := true;
36  XIL_DEVICE_G : string := "7SERIES";
37  USE_BUILT_IN_G : boolean := false;
38  GEN_SYNC_FIFO_G : boolean := false;
39  ALTERA_SYN_G : boolean := false;
40  ALTERA_RAM_G : string := "M9K";
41  CASCADE_SIZE_G : natural range 1 to (2**24) := 1;
42  FIFO_ADDR_WIDTH_G : natural range 4 to 48 := 9;
43  FIFO_PAUSE_THRESH_G : natural range 1 to (2**24) := 2**8;
44  -- PRBS Configurations
45  PRBS_SEED_SIZE_G : natural range 32 to 128 := 32;
46  PRBS_TAPS_G : NaturalArray := (0 => 31, 1 => 6, 2 => 2, 3 => 1);
47  -- AXI Stream Configurations
48  MASTER_AXI_STREAM_CONFIG_G : AxiStreamConfigType := ssiAxiStreamConfig(16, TKEEP_COMP_C);
49  MASTER_AXI_PIPE_STAGES_G : natural range 0 to 16 := 0);
50  port (
51  -- Master Port (mAxisClk)
52  mAxisClk : in sl;
53  mAxisRst : in sl;
56  -- Trigger Signal (locClk domain)
57  locClk : in sl;
58  locRst : in sl := '0';
59  trig : in sl := '1';
60  packetLength : in slv(31 downto 0) := X"FFFFFFFF";
61  forceEofe : in sl := '0';
62  busy : out sl;
63  tDest : in slv(7 downto 0) := X"00";
64  tId : in slv(7 downto 0) := X"00");
65 end SsiPrbsTxOld;
66 
67 architecture rtl of SsiPrbsTxOld is
68 
69  constant PRBS_BYTES_C : natural := (PRBS_SEED_SIZE_G/8);
70  constant PRBS_SSI_CONFIG_C : AxiStreamConfigType := ssiAxiStreamConfig(PRBS_BYTES_C, TKEEP_COMP_C);
71 
72  type StateType is (
73  IDLE_S,
74  SEED_RAND_S,
75  LENGTH_S,
76  DATA_S);
77 
78  type RegType is record
79  busy : sl;
80  overflow : sl;
81  packetLength : slv(31 downto 0);
82  dataCnt : slv(31 downto 0);
83  eventCnt : slv(PRBS_SEED_SIZE_G-1 downto 0);
84  randomData : slv(PRBS_SEED_SIZE_G-1 downto 0);
85  txMaster : AxiStreamMasterType;
86  state : StateType;
87  end record;
88 
89  constant REG_INIT_C : RegType := (
90  '1',
91  '0',
92  (others => '0'),
93  (others => '0'),
94  (others => '0'),
95  (others => '0'),
97  IDLE_S);
98 
99  signal r : RegType := REG_INIT_C;
100  signal rin : RegType;
101 
102  signal txCtrl : AxiStreamCtrlType;
103 
104 begin
105 
106  assert (PRBS_SEED_SIZE_G mod 8 = 0) report "PRBS_SEED_SIZE_G must be a multiple of 8" severity failure;
107 
108  comb : process (forceEofe, locRst, packetLength, r, tDest, tId, trig, txCtrl) is
109  variable v : RegType;
110  begin
111  -- Latch the current value
112  v := r;
113 
114  -- Reset strobing signals
115  ssiResetFlags(v.txMaster);
116  v.txMaster.tData := (others => '0');
117 
118  -- Check for overflow condition or forced EOFE
119  if (txCtrl.overflow = '1') or (forceEofe = '1') then
120  -- Latch the overflow error bit for the data packet
121  v.overflow := '1';
122  end if;
123 
124  -- State Machine
125  case (r.state) is
126  ----------------------------------------------------------------------
127  when IDLE_S =>
128  -- Reset the busy flag
129  v.busy := '0';
130  -- Check for a trigger
131  if trig = '1' then
132  -- Latch the generator seed
133  v.randomData := r.eventCnt;
134  -- Set the busy flag
135  v.busy := '1';
136  -- Reset the overflow flag
137  v.overflow := '0';
138  -- Latch the configuration
139  v.txMaster.tDest := tDest;
140  v.txMaster.tId := tId;
141  -- Check the packet length request value
142  if packetLength = 0 then
143  -- Force minimum packet length of 2 (+1)
144  v.packetLength := toSlv(2, 32);
145  elsif packetLength = 1 then
146  -- Force minimum packet length of 2 (+1)
147  v.packetLength := toSlv(2, 32);
148  else
149  -- Latch the packet length
151  end if;
152  -- Next State
153  v.state := SEED_RAND_S;
154  end if;
155  ----------------------------------------------------------------------
156  when SEED_RAND_S =>
157  -- Check if the FIFO is ready
158  if txCtrl.pause = '0' then
159  -- Send the random seed word
160  v.txMaster.tvalid := '1';
161  v.txMaster.tData(PRBS_SEED_SIZE_G-1 downto 0) := r.eventCnt;
162  -- Generate the next random data word
163  v.randomData := lfsrShift(r.randomData, PRBS_TAPS_G);
164  -- Increment the counter
165  v.eventCnt := r.eventCnt + 1;
166  -- Increment the counter
167  v.dataCnt := r.dataCnt + 1;
168  -- Set the SOF bit
169  ssiSetUserSof(PRBS_SSI_CONFIG_C, v.txMaster, '1');
170  -- Next State
171  v.state := LENGTH_S;
172  end if;
173  ----------------------------------------------------------------------
174  when LENGTH_S =>
175  -- Check if the FIFO is ready
176  if txCtrl.pause = '0' then
177  -- Send the upper packetLength value
178  v.txMaster.tvalid := '1';
179  v.txMaster.tData(31 downto 0) := r.packetLength;
180  -- Increment the counter
181  v.dataCnt := r.dataCnt + 1;
182  -- Next State
183  v.state := DATA_S;
184  end if;
185  ----------------------------------------------------------------------
186  when DATA_S =>
187  -- Check if the FIFO is ready
188  if txCtrl.pause = '0' then
189  -- Send the random data word
190  v.txMaster.tValid := '1';
191  v.txMaster.tData(PRBS_SEED_SIZE_G-1 downto 0) := r.randomData;
192  -- Generate the next random data word
193  v.randomData := lfsrShift(r.randomData, PRBS_TAPS_G);
194  -- Increment the counter
195  v.dataCnt := r.dataCnt + 1;
196  -- Check the counter
197  if r.dataCnt = r.packetLength then
198  -- Reset the counter
199  v.dataCnt := (others => '0');
200  -- Set the EOF bit
201  v.txMaster.tLast := '1';
202  -- Set the EOFE bit
203  ssiSetUserEofe(PRBS_SSI_CONFIG_C, v.txMaster, r.overflow);
204  -- Reset the busy flag
205  v.busy := '0';
206  -- Next State
207  v.state := IDLE_S;
208  end if;
209  end if;
210  ----------------------------------------------------------------------
211  end case;
212 
213  -- Reset
214  if (locRst = '1') then
215  v := REG_INIT_C;
216  end if;
217 
218  -- Register the variable for next clock cycle
219  rin <= v;
220 
221  -- Outputs
222  busy <= r.busy;
223 
224  end process comb;
225 
226  seq : process (locClk) is
227  begin
228  if rising_edge(locClk) then
229  r <= rin after TPD_G;
230  end if;
231  end process seq;
232 
233  AxiStreamFifo_Inst : entity work.AxiStreamFifoV2
234  generic map(
235  -- General Configurations
236  TPD_G => TPD_G,
238  SLAVE_READY_EN_G => false,
239  VALID_THOLD_G => 1,
240  -- FIFO configurations
241  BRAM_EN_G => BRAM_EN_G,
249  FIFO_FIXED_THRESH_G => true,
252  -- AXI Stream Port Configurations
253  SLAVE_AXI_CONFIG_G => PRBS_SSI_CONFIG_C,
255  port map (
256  -- Slave Port
257  sAxisClk => locClk,
258  sAxisRst => locRst,
259  sAxisMaster => r.txMaster,
260  sAxisSlave => open,
261  sAxisCtrl => txCtrl,
262  -- Master Port
263  mAxisClk => mAxisClk,
264  mAxisRst => mAxisRst,
266  mAxisSlave => mAxisSlave);
267 
268 end rtl;
FIFO_ADDR_WIDTH_Ginteger range 4 to 48:= 9
out sAxisCtrlAxiStreamCtrlType
ALTERA_RAM_Gstring := "M9K"
MASTER_AXI_STREAM_CONFIG_GAxiStreamConfigType := ssiAxiStreamConfig( 16, TKEEP_COMP_C)
in packetLengthslv( 31 downto 0) := X"FFFFFFFF"
PIPE_STAGES_Gnatural range 0 to 16:= 1
TPD_Gtime := 1 ns
std_logic sl
Definition: StdRtlPkg.vhd:28
FIFO_ADDR_WIDTH_Gnatural range 4 to 48:= 9
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
in forceEofesl := '0'
SLAVE_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
PRBS_TAPS_GNaturalArray :=( 0=> 31, 1=> 6, 2=> 2, 3=> 1)
SLAVE_READY_EN_Gboolean := true
FIFO_FIXED_THRESH_Gboolean := true
CASCADE_SIZE_Gnatural range 1 to ( 2** 24):= 1
XIL_DEVICE_Gstring := "7SERIES"
GEN_SYNC_FIFO_Gboolean := false
in tDestslv( 7 downto 0) := X"00"
XIL_DEVICE_Gstring := "7SERIES"
PRBS_SEED_SIZE_Gnatural range 32 to 128:= 32
out mAxisMasterAxiStreamMasterType
FIFO_PAUSE_THRESH_Gnatural range 1 to ( 2** 24):= 2** 8
slv( 127 downto 0) tData
_library_ ieeeieee
Definition: SsiPrbsTx.vhd:19
array(natural range <> ) of natural NaturalArray
Definition: StdRtlPkg.vhd:34
in locRstsl := '0'
in trigsl := '1'
ALTERA_SYN_Gboolean := false
BRAM_EN_Gboolean := true
TPD_Gtime := 1 ns
out sAxisSlaveAxiStreamSlaveType
in mAxisSlaveAxiStreamSlaveType
USE_BUILT_IN_Gboolean := false
ALTERA_SYN_Gboolean := false
GEN_SYNC_FIFO_Gboolean := false
BRAM_EN_Gboolean := true
in sAxisMasterAxiStreamMasterType
out mAxisMasterAxiStreamMasterType
in tIdslv( 7 downto 0) := X"00"
in mAxisSlaveAxiStreamSlaveType
MASTER_AXI_PIPE_STAGES_Gnatural range 0 to 16:= 0
CASCADE_SIZE_Ginteger range 1 to ( 2** 24):= 1
USE_BUILT_IN_Gboolean := false
FIFO_PAUSE_THRESH_Ginteger range 1 to ( 2** 24):= 1
VALID_THOLD_Ginteger range 0 to ( 2** 24):= 1
MASTER_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
CASCADE_PAUSE_SEL_Ginteger range 0 to ( 2** 24):= 0
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
ALTERA_RAM_Gstring := "M9K"