SURF  1.0
StreamPatternTester.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : StreamPatternTester.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 05/27/2016
5 -- Last update: 05/27/2016
6 -------------------------------------------------------------------------------
7 -- Description: Test which compares the data stream to selected pattern
8 -- Designed for the automated delay alignment of the fast LVDS lines
9 -- of ADCs with single or multiple serial data lanes
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 work.all;
22 use ieee.std_logic_1164.all;
23 use ieee.numeric_std.all;
24 
25 use work.StdRtlPkg.all;
26 use work.AxiLitePkg.all;
27 use work.AxiStreamPkg.all;
28 
29 --! @see entity
30  --! @ingroup devices_AnalogDevices_ad9249
32  generic (
33  TPD_G : time := 1 ns;
34  NUM_CHANNELS_G : integer range 1 to 31 := 8
35  );
36  port (
37  -- Master system clock
38  clk : in std_logic;
39  rst : in std_logic;
40 
41  -- ADC data stream inputs
43 
44  -- Axi Interface
49  );
50 end StreamPatternTester;
51 
52 
53 -- Define architecture
54 architecture RTL of StreamPatternTester is
55 
56  -------------------------------------------------------------------------------------------------
57  -- AXIL Registers
58  -------------------------------------------------------------------------------------------------
59  type AxilRegType is record
62  testChannel : slv(31 downto 0);
63  testPattern : slv(31 downto 0);
64  testDataMask : slv(31 downto 0);
65  testSamples : slv(31 downto 0);
66  testTimeout : slv(31 downto 0);
68  end record;
69 
70  constant AXIL_REG_INIT_C : AxilRegType := (
73  testChannel => (others=>'0'),
74  testPattern => (others=>'0'),
75  testDataMask => (others=>'0'),
76  testSamples => (others=>'0'),
77  testTimeout => (others=>'0'),
78  testRequest => '0'
79  );
80 
82  signal axilRin : AxilRegType;
83 
84  signal dataMux : std_logic_vector(31 downto 0);
85  signal dataValidMux : std_logic;
86  signal testCnt : unsigned(31 downto 0);
87  signal testDone : std_logic;
88  signal testPassed : std_logic;
89  signal testFailed : std_logic;
90  signal passCnt : unsigned(31 downto 0);
91  signal timeoutCnt : unsigned(31 downto 0);
92 
93 begin
94 
95  -------------------------------------------------------------------------------------------------
96  -- AXIL Interface
97  -------------------------------------------------------------------------------------------------
99  variable v : AxilRegType;
100  variable axilEp : AxiLiteEndpointType;
101  begin
102  v := axilR;
103 
104  axiSlaveWaitTxn(axilEp, axilWriteMaster, axilReadMaster, v.axilWriteSlave, v.axilReadSlave);
105 
106  axiSlaveRegister (axilEp, X"00" & "00", 0, v.testChannel);
107  axiSlaveRegister (axilEp, X"01" & "00", 0, v.testDataMask);
108  axiSlaveRegister (axilEp, X"02" & "00", 0, v.testPattern);
109  axiSlaveRegister (axilEp, X"03" & "00", 0, v.testSamples);
110  axiSlaveRegister (axilEp, X"04" & "00", 0, v.testTimeout);
111  axiSlaveRegister (axilEp, X"05" & "00", 0, v.testRequest);
112  axiSlaveRegisterR(axilEp, X"06" & "00", 0, testPassed);
113  axiSlaveRegisterR(axilEp, X"07" & "00", 0, testFailed);
114 
115  axiSlaveDefault(axilEp, v.axilWriteSlave, v.axilReadSlave, AXI_RESP_DECERR_C);
116 
117  if (rst = '1') then
118  v := AXIL_REG_INIT_C;
119  end if;
120 
121  axilRin <= v;
124 
125  end process;
126 
127  axilSeq : process (clk) is
128  begin
129  if (rising_edge(clk)) then
130  axilR <= axilRin after TPD_G;
131  end if;
132  end process axilSeq;
133 
134  -------------------------------------------------------------------------------------------------
135  -- Tester logic
136  -------------------------------------------------------------------------------------------------
137 
138  dataValidMux <= adcStreams(to_integer(unsigned(axilR.testChannel))).tValid;
139 
140  maskGen: for i in 0 to 31 generate
141  dataMux(i) <= adcStreams(to_integer(unsigned(axilR.testChannel))).tData(i) and axilR.testDataMask(i);
142  end generate maskGen;
143 
144 
145 
146  testProc: process ( clk )
147  begin
148 
149  -- test samples counter
150  if rising_edge(clk) then
151  if rst = '1' or axilR.testRequest = '1' then
152  testCnt <= (others=>'0') after TPD_G;
153  elsif dataValidMux = '1' and testDone = '0' then
154  testCnt <= testCnt + 1 after TPD_G;
155  end if;
156  end if;
157 
158  -- comparison passed counter
159  if rising_edge(clk) then
160  if rst = '1' or axilR.testRequest = '1' then
161  passCnt <= (others=>'0') after TPD_G;
162  elsif dataMux = axilR.testPattern and dataValidMux = '1' and testDone = '0' then
163  passCnt <= passCnt + 1 after TPD_G;
164  end if;
165  end if;
166 
167  -- timeout counter
168  if rising_edge(clk) then
169  if rst = '1' or axilR.testRequest = '1' or dataValidMux = '1' then
170  timeoutCnt <= unsigned(axilR.testTimeout) after TPD_G;
171  elsif timeoutCnt > 0 then
172  timeoutCnt <= timeoutCnt - 1 after TPD_G;
173  end if;
174  end if;
175 
176  end process;
177 
178  testDone <= '1' when (testCnt >= unsigned(axilR.testSamples) or timeoutCnt = 0) and axilR.testRequest = '0' else '0';
179  testPassed <= '1' when testDone = '1' and passCnt = unsigned(axilR.testSamples) else '0';
180  testFailed <= '1' when testDone = '1' and passCnt < unsigned(axilR.testSamples) else '0';
181 
182 end RTL;
183 
AxiLiteReadSlaveType axilReadSlave
slv( 31 downto 0) testSamples
AxiLiteWriteMasterType
Definition: AxiLitePkg.vhd:111
std_logic sl
Definition: StdRtlPkg.vhd:28
out axilReadSlaveAxiLiteReadSlaveType
std_logic_vector( 31 downto 0) dataMux
unsigned( 31 downto 0) timeoutCnt
in axilWriteMasterAxiLiteWriteMasterType
out axilWriteSlaveAxiLiteWriteSlaveType
NUM_CHANNELS_Ginteger range 1 to 31:= 8
slv( 31 downto 0) testPattern
slv( 127 downto 0) tData
slv( 1 downto 0) := "11" AXI_RESP_DECERR_C
Definition: AxiLitePkg.vhd:49
in adcStreamsAxiStreamMasterArray( NUM_CHANNELS_G- 1 downto 0)
AxiLiteReadMasterType
Definition: AxiLitePkg.vhd:59
slv( 31 downto 0) testDataMask
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:95
array(natural range <> ) of AxiStreamMasterType AxiStreamMasterArray
AxiLiteReadSlaveType
Definition: AxiLitePkg.vhd:85
AxilRegType :=(axilWriteSlave => AXI_LITE_WRITE_SLAVE_INIT_C,axilReadSlave => AXI_LITE_READ_SLAVE_INIT_C,testChannel =>( others => '0'),testPattern =>( others => '0'),testDataMask =>( others => '0'),testSamples =>( others => '0'),testTimeout =>( others => '0'),testRequest => '0') AXIL_REG_INIT_C
slv( 31 downto 0) testChannel
slv( 31 downto 0) testTimeout
AxiLiteWriteSlaveType axilWriteSlave
unsigned( 31 downto 0) passCnt
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:156
in axilReadMasterAxiLiteReadMasterType
AxilRegType := AXIL_REG_INIT_C axilR
unsigned( 31 downto 0) testCnt
std_logic_vector slv
Definition: StdRtlPkg.vhd:29