SURF  1.0
SsiIncrementingTx.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SsiIncrementingTx.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-04-02
5 -- Last update: 2014-07-18
6 -------------------------------------------------------------------------------
7 -- Description: This module generates
8 -- PseudoRandom Binary Sequence (INCREMENTING) 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
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 := true;
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 Config
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 IO Config
48  MASTER_AXI_STREAM_CONFIG_G : AxiStreamConfigType := ssiAxiStreamConfig(16, TKEEP_NORMAL_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 
57  -- Trigger Signal (locClk domain)
58  locClk : in sl;
59  locRst : in sl := '0';
60  trig : in sl := '1';
61  packetLength : in slv(31 downto 0) := X"FFFFFFFF";
62  busy : out sl;
63  tDest : in slv(7 downto 0) := X"00";
64  tId : in slv(7 downto 0) := X"00");
65 
66 
67 end SsiIncrementingTx;
68 
69 architecture rtl of SsiIncrementingTx is
70 
71  constant PRBS_BYTES_C : natural := PRBS_SEED_SIZE_G / 8;
72  constant PRBS_SSI_CONFIG_C : AxiStreamConfigType := ssiAxiStreamConfig(PRBS_BYTES_C, TKEEP_NORMAL_C);
73 
74  type StateType is (
75  IDLE_S,
76  SEED_RAND_S,
77  LENGTH_S,
78  DATA_S,
79  LAST_S);
80 
81  type RegType is record
82  busy : sl;
83  packetLength : slv(31 downto 0);
84  dataCnt : slv(31 downto 0);
85  eventCnt : slv(PRBS_SEED_SIZE_G-1 downto 0);
86  randomData : slv(PRBS_SEED_SIZE_G-1 downto 0);
87  txAxisMaster : AxiStreamMasterType;
88  state : StateType;
89  end record;
90 
91  constant REG_INIT_C : RegType := (
92  '1',
93  (others => '0'),
94  (others => '0'),
95  (others => '0'),
96  (others => '0'),
98  IDLE_S);
99 
100  signal r : RegType := REG_INIT_C;
101  signal rin : RegType;
102 
103  signal txAxisMaster : AxiStreamMasterType;
104  signal txAxisSlave : AxiStreamSlaveType;
105 
106 begin
107 
108  assert (PRBS_SEED_SIZE_G mod 8 = 0) report "PRBS_SEED_SIZE_G must be a multiple of 8" severity failure;
109 
110  comb : process (locRst, packetLength, r, tDest, tId, trig, txAxisSlave) is
111  variable i : integer;
112  variable v : RegType;
113  begin
114  -- Latch the current value
115  v := r;
116 
117  case (r.state) is
118  ----------------------------------------------------------------------
119  when IDLE_S =>
120 
121  v.txAxisMaster.tValid := '0';
122 
123  -- Reset the busy flag
124  v.busy := '0';
125  -- Check for a trigger
126  if trig = '1' then
127  -- Latch the generator seed
128  v.randomData := r.eventCnt;
129  -- Set the busy flag
130  v.busy := '1';
131  -- Latch the configuration
132  v.txAxisMaster.tDest := tDest;
133  v.txAxisMaster.tId := tId;
134  -- Check the packet length request value
135  if packetLength = 0 then
136  -- Force minimum packet length of 2 (+1)
137  v.packetLength := toSlv(2, 32);
138  elsif packetLength = 1 then
139  -- Force minimum packet length of 2 (+1)
140  v.packetLength := toSlv(2, 32);
141  else
142  -- Latch the packet length
144  end if;
145  -- Next State
146  v.state := SEED_RAND_S;
147  end if;
148  ----------------------------------------------------------------------
149  when SEED_RAND_S =>
150  -- Check the status
151  --if txAxisSlave.tReady = '1' then
152  -- Send the random seed word
153  v.txAxisMaster.tvalid := '1';
154  v.txAxisMaster.tData(PRBS_SEED_SIZE_G-1 downto 0) := r.eventCnt;
155  -- Generate the next random data word
156  v.randomData := r.randomData + 1;
157  -- Increment the counter
158  v.eventCnt := r.eventCnt + 1;
159  -- Increment the counter
160  v.dataCnt := r.dataCnt + 1;
161 
162  axiStreamSetUserBit(PRBS_SSI_CONFIG_C,v.txAxisMaster,SSI_SOF_C,'1',0);
163 
164  -- Next State
165  v.state := LENGTH_S;
166  --end if;
167  ----------------------------------------------------------------------
168  when LENGTH_S =>
169  -- Check the status
170  if txAxisSlave.tReady = '1' then
171 
172  axiStreamSetUserBit(PRBS_SSI_CONFIG_C,v.txAxisMaster,SSI_SOF_C,'0',0);
173 
174  -- Send the upper packetLength value
175  v.txAxisMaster.tvalid := '1';
176  v.txAxisMaster.tData(31 downto 0) := r.packetLength;
177  -- Increment the counter
178  v.dataCnt := r.dataCnt + 1;
179  -- Next State
180  v.state := DATA_S;
181  end if;
182  ----------------------------------------------------------------------
183  when DATA_S =>
184  -- Check the status
185  if txAxisSlave.tReady = '1' then
186  -- Send the random data word
187  v.txAxisMaster.tValid := '1';
188  v.txAxisMaster.tData(PRBS_SEED_SIZE_G-1 downto 0) := r.randomData;
189 
190  -- Generate the next random data word
191  v.randomData := r.randomData + 1;
192  -- Increment the counter
193  v.dataCnt := r.dataCnt + 1;
194  -- Check the counter
195  if r.dataCnt = r.packetLength then
196  -- Reset the counter
197  v.dataCnt := (others => '0');
198  -- Set the end of frame flag
199  v.txAxisMaster.tLast := '1';
200  -- Reset the busy flag
201  v.busy := '0';
202  -- Next State
203  v.state := LAST_S;
204  end if;
205  end if;
206 
207  ----------------------------------------------------------------------
208  when LAST_S =>
209  if txAxisSlave.tReady = '1' then
210  v.txAxisMaster.tValid := '0';
211  v.txAxisMaster.tLast := '0';
212  v.state := IDLE_S;
213  end if;
214 
215  ----------------------------------------------------------------------
216  end case;
217 
218  -- Reset
219  if (locRst = '1') then
220  v := REG_INIT_C;
221  end if;
222 
223  -- Register the variable for next clock cycle
224  rin <= v;
225 
226  -- Outputs
227  txAxisMaster <= r.txAxisMaster;
228  busy <= r.busy;
229 
230  end process comb;
231 
232  seq : process (locClk) is
233  begin
234  if rising_edge(locClk) then
235  r <= rin after TPD_G;
236  end if;
237  end process seq;
238 
239  AxiStreamFifo_Inst : entity work.AxiStreamFifoV2
240  generic map(
241  -- General Configurations
242  TPD_G => TPD_G,
244  -- FIFO configurations
245  BRAM_EN_G => BRAM_EN_G,
253  FIFO_FIXED_THRESH_G => true,
255  -- AXI Stream Port Configurations
256  SLAVE_AXI_CONFIG_G => PRBS_SSI_CONFIG_C,
258  port map (
259  -- Slave Port
260  sAxisClk => locClk,
261  sAxisRst => locRst,
262  sAxisMaster => txAxisMaster,
263  sAxisSlave => txAxisSlave,
264  sAxisCtrl => open,
265  -- Master Port
266  mAxisClk => mAxisClk,
267  mAxisRst => mAxisRst,
269  mAxisSlave => mAxisSlave);
270 
271 end rtl;
BRAM_EN_Gboolean := true
FIFO_ADDR_WIDTH_Ginteger range 4 to 48:= 9
out sAxisCtrlAxiStreamCtrlType
ALTERA_RAM_Gstring := "M9K"
in mAxisSlaveAxiStreamSlaveType
USE_BUILT_IN_Gboolean := false
in tIdslv( 7 downto 0) := X"00"
PIPE_STAGES_Gnatural range 0 to 16:= 1
FIFO_PAUSE_THRESH_Gnatural range 1 to ( 2** 24):= 2** 8
GEN_SYNC_FIFO_Gboolean := false
in packetLengthslv( 31 downto 0) := X"FFFFFFFF"
std_logic sl
Definition: StdRtlPkg.vhd:28
in tDestslv( 7 downto 0) := X"00"
integer := 1 SSI_SOF_C
Definition: SsiPkg.vhd:31
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
XIL_DEVICE_Gstring := "7SERIES"
FIFO_FIXED_THRESH_Gboolean := true
CASCADE_SIZE_Gnatural range 1 to ( 2** 24):= 1
GEN_SYNC_FIFO_Gboolean := false
XIL_DEVICE_Gstring := "7SERIES"
slv( 127 downto 0) tData
MASTER_AXI_STREAM_CONFIG_GAxiStreamConfigType := ssiAxiStreamConfig( 16, TKEEP_NORMAL_C)
array(natural range <> ) of natural NaturalArray
Definition: StdRtlPkg.vhd:34
PRBS_SEED_SIZE_Gnatural range 32 to 128:= 32
BRAM_EN_Gboolean := true
MASTER_AXI_PIPE_STAGES_Gnatural range 0 to 16:= 0
TPD_Gtime := 1 ns
out mAxisMasterAxiStreamMasterType
PRBS_TAPS_GNaturalArray :=( 0=> 31, 1=> 6, 2=> 2, 3=> 1)
out sAxisSlaveAxiStreamSlaveType
ALTERA_SYN_Gboolean := false
FIFO_ADDR_WIDTH_Gnatural range 4 to 48:= 9
_library_ ieeeieee
in sAxisMasterAxiStreamMasterType
out mAxisMasterAxiStreamMasterType
ALTERA_RAM_Gstring := "M9K"
in mAxisSlaveAxiStreamSlaveType
CASCADE_SIZE_Ginteger range 1 to ( 2** 24):= 1
USE_BUILT_IN_Gboolean := false
FIFO_PAUSE_THRESH_Ginteger range 1 to ( 2** 24):= 1
ALTERA_SYN_Gboolean := true
MASTER_AXI_CONFIG_GAxiStreamConfigType := AXI_STREAM_CONFIG_INIT_C
std_logic_vector slv
Definition: StdRtlPkg.vhd:29