OpenCores
URL https://opencores.org/ocsvn/astron_diagnostics/astron_diagnostics/trunk

Subversion Repositories astron_diagnostics

[/] [astron_diagnostics/] [trunk/] [diag_rx_seq.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
--------------------------------------------------------------------------------
2
--
3 3 danv
-- Copyright 2020
4 2 danv
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6 3 danv
-- 
7
-- Licensed under the Apache License, Version 2.0 (the "License");
8
-- you may not use this file except in compliance with the License.
9
-- You may obtain a copy of the License at
10
-- 
11
--     http://www.apache.org/licenses/LICENSE-2.0
12
-- 
13
-- Unless required by applicable law or agreed to in writing, software
14
-- distributed under the License is distributed on an "AS IS" BASIS,
15
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
-- See the License for the specific language governing permissions and
17
-- limitations under the License.
18 2 danv
--
19
--------------------------------------------------------------------------------
20
 
21
-- Purpose: Verify received continuous test sequence data.
22
-- Description:
23
--   The diag_rx_seq can operate in one of two modes that depend on g_use_steps:
24
--
25
-- . g_use_steps = FALSE
26
--   The test data can be PRSG or COUNTER dependent on diag_sel.
27
--   The Rx is enabled by diag_en. Typically the Tx should already be running,
28
--   but it is also allowed to first enable the Rx.
29
--   The Rx is always ready to accept data, therefore it has no in_ready output.
30
--   Inititally when diag_en is low then diag_res = -1, when diag_en is high
31
--   then diag_res becomes valid, indicated by diag_res_val, after two test
32
--   data words have been received. The diag_res verifies per input dat bit,
33
--   when an in_dat bit goes wrong then the corresponding bit in diag_res goes
34
--   high and remains high until the Rx is restarted again. This is useful if
35
--   the test data bits go via separate physical lines (e.g. an LVDS bus).
36
--   When the Rx is disabled then diag_res = -1. Typically the g_diag_res_w >
37
--   g_dat_w:
38
--   . diag_res(g_diag_res_w-1:g_dat_w) => NOT diag_res_val
39
--   . diag_res(     g_dat_w-1:0      ) => aggregated diff of in_dat during
40
--                                         diag_en
41
--   It is possible to use g_diag_res_w=g_dat_w, but then it is not possible to
42
--   distinguish between whether the test has ran at all or whether all bits
43
--   got errors.
44
--   The diag_sample keeps the last valid in_dat value. When diag_en='0' it is
45
--   reset to 0. Reading diag_sample via MM gives an impression of the valid
46
--   in_dat activity. The diag_sample_diff shows the difference of the last and
47
--   the previous in_dat value. The diag_sample_diff can be useful to determine
48
--   or debug the values that are needed for diag_steps_arr.
49
--
50
-- . g_use_steps = TRUE
51
--   The test data is fixed to COUNTER and diag_sel is ignored. The rx_seq can
52
--   verify counter data that increments in steps that are specified via
53
--   diag_steps_arr[3:0]. Up to g_nof_steps <= c_diag_seq_rx_reg_nof_steps = 4
54
--   step sizes are supported. If all steps are set to 1 then there is no
55
--   difference compared using the COUNTER in g_use_steps = FALSE. Constant
56
--   value data can be verified by setting alls step to 0. Usinf different
57
--   steps is useful when the data is generated in linear incrementing order,
58
--   but received in a different order. Eg. like after a transpose operation
59
--   where blocks of data are written in row and and read in colums:
60
--   
61
--     tx:          0 1   2 3   4 5   6 7   8 9   10 11
62
--     transpose:   0 1   4 5   8 9   2 3   6 7   10 11
63
--     rx steps:     +1    +1    +1    +1    +1      +1
64
--                -11    +3    +3    -7    +3    +3
65
-- 
66
--   The step size value range is set by the 32 bit range of the VHDL integer.
67
--   Therefore typically g_dat_w should be <= 32 b. For a transpose that 
68
--   contains more than 2**32 data words this means that the COUNTER data 
69
--   wraps within the transpose. This is acceptable, because it use g_dat_w
70
--   <= 32 then still provides sufficient coverage to detect all errors.
71
--
72
--   Data errors that match a step size cannot be detected. However if such
73
--   an error occurs then typically the next increment will cause a mismatch.
74
--
75
-- Remarks:
76
-- . The feature of being able to detect errors per bit as with g_use_steps=
77
--   FALSE is not supported when g_use_steps=TRUE. Therefore the
78
--   diag_res[g_dat_w-1:0] = -1 (all '1') when a difference occurs that is no
79
--   in diag_steps_arr.
80
-- . The common_lfsr_nxt_seq() that is used when g_use_steps=FALSE uses the
81
--   in_dat_reg as initialization value for the reference sequence. All
82
--   subsequent values are derived when in_val_reg='1'. This is possible
83
--   because given a first value all subsequent values for PSRG or COUNTER
84
--   with +1 increment are known. For g_use_steps=TRUE the sequence is not
85
--   known in advance because different increment steps can occur at 
86
--   arbitrary instants. Therefore then the in_dat_reg input is also used 
87
--   during the sequence, to determine all g_nof_steps next values are correct
88
--   in case they occur.
89
 
90 4 danv
LIBRARY IEEE, common_pkg_lib, common_components_lib, astron_counter_lib;
91 2 danv
USE IEEE.std_logic_1164.ALL;
92
USE IEEE.numeric_std.ALL;
93
USE common_pkg_lib.common_pkg.ALL;
94
USE common_pkg_lib.common_lfsr_sequences_pkg.ALL;
95
USE work.diag_pkg.ALL;
96
 
97
ENTITY diag_rx_seq IS
98
  GENERIC (
99
    g_input_reg  : BOOLEAN := FALSE;  -- Use unregistered input to save logic, use registered input to ease achieving timing constrains.
100
    g_use_steps  : BOOLEAN := FALSE;
101
    g_nof_steps  : NATURAL := c_diag_seq_rx_reg_nof_steps;
102
    g_sel        : STD_LOGIC := '1';  -- '0' = PRSG, '1' = COUNTER
103
    g_cnt_incr   : INTEGER := 1;
104
    g_cnt_w      : NATURAL := c_word_w;
105
    g_dat_w      : NATURAL := 12;
106
    g_diag_res_w : NATURAL := 16
107
  );
108
  PORT (
109
    rst            : IN  STD_LOGIC;
110
    clk            : IN  STD_LOGIC;
111
    clken          : IN  STD_LOGIC := '1';
112
 
113
    -- Static control input (connect via MM or leave open to use default)
114
    diag_en        : IN  STD_LOGIC;                                  -- '0' = init and disable, '1' = enable
115
    diag_sel       : IN  STD_LOGIC := g_sel;
116
    diag_steps_arr : t_integer_arr(g_nof_steps-1 DOWNTO 0) := (OTHERS=>1);
117
    diag_res       : OUT STD_LOGIC_VECTOR(g_diag_res_w-1 DOWNTO 0);  -- diag_res valid indication bits & aggregate diff of in_dat during diag_en
118
    diag_res_val   : OUT STD_LOGIC;
119
    diag_sample      : OUT STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);  -- monitor last valid in_dat
120
    diag_sample_diff : OUT STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);  -- monitor difference between last valid in_dat and previous valid in_dat
121
    diag_sample_val  : OUT STD_LOGIC;
122
 
123
    -- ST input
124
    in_cnt         : OUT STD_LOGIC_VECTOR(g_cnt_w-1 DOWNTO 0);  -- count valid input test sequence data
125
    in_dat         : IN  STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);  -- input test sequence data
126
    in_val         : IN  STD_LOGIC    -- gaps are allowed, however diag_res requires at least 2 valid in_dat to report a valid result
127
  );
128
END diag_rx_seq;
129
 
130
 
131
ARCHITECTURE rtl OF diag_rx_seq IS
132
 
133
  CONSTANT c_lfsr_nr          : NATURAL := g_dat_w - c_common_lfsr_first;
134
 
135
  CONSTANT c_diag_res_latency : NATURAL := 3;
136
 
137
  -- Used special value to signal invalid diag_res, unique assuming g_diag_res_w > g_dat_w
138
  CONSTANT c_diag_res_invalid : STD_LOGIC_VECTOR(diag_res'RANGE) := (OTHERS=>'1');
139
 
140
  SIGNAL in_val_reg      : STD_LOGIC;
141
  SIGNAL in_dat_reg      : STD_LOGIC_VECTOR(in_dat'RANGE);
142
 
143
  SIGNAL in_dat_dly1     : STD_LOGIC_VECTOR(in_dat'RANGE);  -- latency common_lfsr_nxt_seq
144
  SIGNAL in_dat_dly2     : STD_LOGIC_VECTOR(in_dat'RANGE);  -- latency ref_dat
145
  SIGNAL in_val_dly1     : STD_LOGIC;                       -- latency common_lfsr_nxt_seq
146
  SIGNAL in_val_dly2     : STD_LOGIC;                       -- latency ref_dat
147
 
148
  SIGNAL prsg            : STD_LOGIC_VECTOR(in_dat'RANGE);
149
  SIGNAL nxt_prsg        : STD_LOGIC_VECTOR(in_dat'RANGE);
150
  SIGNAL cntr            : STD_LOGIC_VECTOR(in_dat'RANGE);
151
  SIGNAL nxt_cntr        : STD_LOGIC_VECTOR(in_dat'RANGE);
152
 
153
  SIGNAL diag_dis        : STD_LOGIC;
154
  SIGNAL ref_en          : STD_LOGIC;
155
  SIGNAL diff_dis        : STD_LOGIC;
156
  SIGNAL diag_res_en     : STD_LOGIC;
157
  SIGNAL nxt_diag_res_en : STD_LOGIC;
158
  SIGNAL nxt_diag_res_val: STD_LOGIC;
159
 
160
  SIGNAL in_val_1        : STD_LOGIC;
161
  SIGNAL in_val_act      : STD_LOGIC;
162
  SIGNAL in_val_2        : STD_LOGIC;
163
  SIGNAL in_val_2_dly    : STD_LOGIC_VECTOR(0 TO c_diag_res_latency-1) := (OTHERS=>'0');
164
  SIGNAL in_val_2_act    : STD_LOGIC;
165
 
166
  SIGNAL ref_dat         : STD_LOGIC_VECTOR(in_dat'RANGE);
167
  SIGNAL nxt_ref_dat     : STD_LOGIC_VECTOR(in_dat'RANGE);
168
  SIGNAL diff_dat        : STD_LOGIC_VECTOR(in_dat'RANGE) := (OTHERS=>'0');
169
  SIGNAL nxt_diff_dat    : STD_LOGIC_VECTOR(in_dat'RANGE);
170
  SIGNAL diff_res        : STD_LOGIC_VECTOR(in_dat'RANGE);
171
  SIGNAL nxt_diag_res    : STD_LOGIC_VECTOR(diag_res'RANGE);
172
 
173
  SIGNAL diag_res_int    : STD_LOGIC_VECTOR(diag_res'RANGE) := c_diag_res_invalid;
174
 
175
  SIGNAL i_diag_sample        : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
176
  SIGNAL nxt_diag_sample      : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
177
  SIGNAL i_diag_sample_diff   : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
178
  SIGNAL nxt_diag_sample_diff : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
179
  SIGNAL nxt_diag_sample_val  : STD_LOGIC;
180
 
181
  TYPE t_dat_arr IS ARRAY (INTEGER RANGE <>) OF STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
182
 
183
  SIGNAL ref_dat_arr      : t_dat_arr(g_nof_steps-1 DOWNTO 0) := (OTHERS=>(OTHERS=>'0'));
184
  SIGNAL nxt_ref_dat_arr  : t_dat_arr(g_nof_steps-1 DOWNTO 0);
185
  SIGNAL diff_arr         : STD_LOGIC_VECTOR(g_nof_steps-1 DOWNTO 0) := (OTHERS=>'0');
186
  SIGNAL nxt_diff_arr     : STD_LOGIC_VECTOR(g_nof_steps-1 DOWNTO 0);
187
  SIGNAL diff_detect      : STD_LOGIC := '0';
188
  SIGNAL nxt_diff_detect  : STD_LOGIC;
189
  SIGNAL diff_hold        : STD_LOGIC;
190
 
191
BEGIN
192
 
193
  diag_dis <= NOT diag_en;
194
  diag_sample <= i_diag_sample;
195
  diag_sample_diff <= i_diag_sample_diff;
196
 
197
  gen_input_reg : IF g_input_reg=TRUE GENERATE
198
    p_reg : PROCESS (clk)
199
    BEGIN
200
      IF rising_edge(clk) THEN
201
        IF clken='1' THEN
202
          in_val_reg  <= in_val;
203
          in_dat_reg  <= in_dat;
204
        END IF;
205
      END IF;
206
    END PROCESS;
207
  END GENERATE;
208
  no_input_reg : IF g_input_reg=FALSE GENERATE
209
    in_val_reg  <= in_val;
210
    in_dat_reg  <= in_dat;
211
  END GENERATE;
212
 
213
  -- Use initialisation to set initial diag_res to invalid
214
  diag_res <= diag_res_int;  -- use initialisation of internal signal diag_res_int rather than initialisation of entity output diag_res
215
 
216
--   -- Use rst to set initial diag_res to invalid
217
--   p_rst_clk : PROCESS (rst, clk)
218
--   BEGIN
219
--     IF rst='1' THEN
220
--       diag_res     <= c_diag_res_invalid;
221
--     ELSIF rising_edge(clk) THEN
222
--       IF clken='1' THEN
223
--         -- Internal.
224
--         diag_res     <= nxt_diag_res;
225
--         -- Outputs.
226
--       END IF;
227
--     END IF;
228
--   END PROCESS;
229
 
230
  p_clk : PROCESS (clk)
231
  BEGIN
232
    IF rising_edge(clk) THEN
233
      IF clken='1' THEN
234
        -- Inputs.
235
        in_dat_dly1  <= in_dat_reg;
236
        in_dat_dly2  <= in_dat_dly1;
237
        in_val_dly1  <= in_val_reg;
238
        in_val_dly2  <= in_val_dly1;
239
        -- Internal.
240
        in_val_2_dly <= in_val_2 & in_val_2_dly(0 TO c_diag_res_latency-2);
241
        diag_res_int <= nxt_diag_res;
242
        diag_res_en  <= nxt_diag_res_en;
243
        diag_res_val <= nxt_diag_res_val;
244
        -- . g_use_steps=FALSE
245
        prsg         <= nxt_prsg;
246
        cntr         <= nxt_cntr;
247
        ref_dat      <= nxt_ref_dat;
248
        diff_dat     <= nxt_diff_dat;
249
        -- . g_use_steps=TRUE
250
        ref_dat_arr  <= nxt_ref_dat_arr;
251
        diff_arr     <= nxt_diff_arr;
252
        diff_detect  <= nxt_diff_detect;
253
        -- Outputs.
254
        i_diag_sample      <= nxt_diag_sample;
255
        i_diag_sample_diff <= nxt_diag_sample_diff;
256
        diag_sample_val    <= nxt_diag_sample_val;
257
      END IF;
258
    END IF;
259
  END PROCESS;
260
 
261
  ------------------------------------------------------------------------------
262
  -- Keep last valid in_dat value for MM monitoring
263
  ------------------------------------------------------------------------------
264
  nxt_diag_sample      <= (OTHERS=>'0') WHEN diag_en='0' ELSE in_dat_reg                          WHEN in_val_reg='1' ELSE i_diag_sample;
265
  nxt_diag_sample_diff <= (OTHERS=>'0') WHEN diag_en='0' ELSE SUB_UVEC(in_dat_reg, i_diag_sample) WHEN in_val_reg='1' ELSE i_diag_sample_diff;
266
  nxt_diag_sample_val  <=          '0'  WHEN diag_en='0' ELSE in_val_reg;
267
 
268
  ------------------------------------------------------------------------------
269
  -- Detect that there has been valid input data for at least two clock cycles
270
  ------------------------------------------------------------------------------
271
 
272
  u_in_val_1 : ENTITY common_components_lib.common_switch
273
  PORT MAP(
274
    clk         => clk,
275
    rst         => rst,
276
    switch_high => in_val_reg,
277
    switch_low  => diag_dis,
278
    out_level   => in_val_1  -- first in_val has been detected, but this one was used as seed for common_lfsr_nxt_seq
279
  );
280
 
281
  in_val_act <= in_val_1 AND in_val_reg;      -- Signal the second valid in_dat after diag_en='1'
282
 
283
  u_in_val_2 : ENTITY common_components_lib.common_switch
284
  PORT MAP(
285
    clk         => clk,
286
    rst         => rst,
287
    switch_high => in_val_act,
288
    switch_low  => diag_dis,
289
    out_level   => in_val_2  -- second in_val has been detected, representing a true next sequence value
290
  );
291
 
292
  -- Use in_val_2_act instead of in_val_2 to have stable start in case diag_dis takes just a pulse and in_val is continue high
293
  in_val_2_act <= vector_and(in_val_2 & in_val_2_dly);
294
 
295
  -- Use the first valid in_dat after diag_en='1' to initialize the reference data sequence
296
  ref_en <= in_val_1;
297
 
298
  -- Use the detection of second valid in_dat after diag_en='1' to start detection of differences
299
  diff_dis <= NOT in_val_2_act;
300
 
301
  no_steps : IF g_use_steps=FALSE GENERATE
302
    -- Determine next reference dat based on current input dat
303
    common_lfsr_nxt_seq(c_lfsr_nr,    -- IN
304
                        g_cnt_incr,   -- IN
305
                        ref_en,       -- IN
306
                        in_val_reg,   -- IN, use in_val_reg to allow gaps in the input data valid stream
307
                        in_dat_reg,   -- IN, used only to init nxt_prsg and nxt_cntr when ref_en='0'
308
                        prsg,         -- IN
309
                        cntr,         -- IN
310
                        nxt_prsg,     -- OUT
311
                        nxt_cntr);    -- OUT
312
 
313
    nxt_ref_dat <= prsg WHEN diag_sel='0' ELSE cntr;
314
 
315
    -- Detect difference per bit. The ref_dat has latency 2 compared to the in_dat, because of the register stage in psrg/cntr and the register stage in ref_dat.
316
    p_diff_dat : PROCESS (diff_dat, ref_dat, in_val_dly2, in_dat_dly2)
317
    BEGIN
318
      nxt_diff_dat <= diff_dat;
319
      IF in_val_dly2='1' THEN
320
        FOR I IN in_dat'RANGE LOOP
321
          nxt_diff_dat(I) <= ref_dat(I) XOR in_dat_dly2(I);
322
        END LOOP;
323
      END IF;
324
    END PROCESS;
325
 
326
    gen_verify_dat : FOR I IN in_dat'RANGE GENERATE
327
      -- Detect and report undefined diff input 'X', which in simulation leaves diff_res at OK, because switch_high only acts on '1'
328
      p_sim_only : PROCESS(clk)
329
      BEGIN
330
        IF rising_edge(clk) THEN
331
          IF diff_dat(I)/='0' AND diff_dat(I)/='1' THEN
332
            REPORT "diag_rx_seq : undefined input" SEVERITY FAILURE;
333
          END IF;
334
        END IF;
335
      END PROCESS;
336
 
337
      -- Hold any difference on the in_dat bus lines
338
      u_dat : ENTITY common_components_lib.common_switch
339
      PORT MAP(
340
        clk         => clk,
341
        rst         => rst,
342
        switch_high => diff_dat(I),
343
        switch_low  => diff_dis,
344
        out_level   => diff_res(I)
345
      );
346
    END GENERATE;
347
  END GENERATE;
348
 
349
  use_steps : IF g_use_steps=TRUE GENERATE
350
    -- Determine next reference data for all steps increments of current input dat
351
    p_ref_dat_arr : PROCESS(in_dat_reg, in_val_reg, ref_dat_arr)
352
    BEGIN
353
      nxt_ref_dat_arr <= ref_dat_arr;
354
      IF in_val_reg='1' THEN
355
        FOR I IN g_nof_steps-1 DOWNTO 0 LOOP
356
          nxt_ref_dat_arr(I) <= INCR_UVEC(in_dat_reg, diag_steps_arr(I));
357
        END LOOP;
358
      END IF;
359
    END PROCESS;
360
 
361
    -- Detect difference for each allowed reference data.
362
    p_diff_arr : PROCESS(diff_arr, in_val_reg, in_dat_reg, ref_dat_arr)
363
    BEGIN
364
      nxt_diff_arr <= diff_arr;
365
      IF in_val_reg='1' THEN
366
        nxt_diff_arr <= (OTHERS=>'1');
367
        FOR I IN g_nof_steps-1 DOWNTO 0 LOOP
368
          IF UNSIGNED(ref_dat_arr(I))=UNSIGNED(in_dat_reg) THEN
369
            nxt_diff_arr(I) <= '0';
370
          END IF;
371
        END LOOP;
372
      END IF;
373
    END PROCESS;
374
 
375
    -- detect diff when none of the step counter value matches
376
    p_diff_detect : PROCESS(diff_detect, diff_arr, in_val_dly1)
377
    BEGIN
378
      nxt_diff_detect <= diff_detect;
379
      IF in_val_dly1='1' THEN
380
        nxt_diff_detect <= '0';
381
        IF vector_and(diff_arr)='1' THEN
382
          nxt_diff_detect <= '1';
383
        END IF;
384
      END IF;
385
    END PROCESS;
386
 
387
    -- hold detected diff detect
388
    u_dat : ENTITY common_components_lib.common_switch
389
    PORT MAP(
390
      clk         => clk,
391
      rst         => rst,
392
      switch_high => diff_detect,
393
      switch_low  => diff_dis,
394
      out_level   => diff_hold
395
    );
396
 
397
    diff_res <= (OTHERS=> diff_hold);  -- convert diff_hold to diff_res slv format as used for g_use_steps=FALSE
398
  END GENERATE;
399
 
400
 
401
  ------------------------------------------------------------------------------
402
  -- Report valid diag_res  
403
  ------------------------------------------------------------------------------
404
 
405
  nxt_diag_res_en  <= diag_en AND in_val_2_act;
406
  nxt_diag_res_val <= diag_res_en;
407
 
408
  p_diag_res : PROCESS (diff_res, diag_res_en)
409
  BEGIN
410
    nxt_diag_res <= c_diag_res_invalid;
411
    IF diag_res_en='1' THEN
412
      -- The test runs AND there have been valid input samples to verify
413
      nxt_diag_res                 <= (OTHERS=>'0');  -- MSBits of valid diag_res are 0
414
      nxt_diag_res(diff_res'RANGE) <= diff_res;       -- diff_res of dat[]
415
    END IF;
416
  END PROCESS;
417
 
418
 
419
  ------------------------------------------------------------------------------
420
  -- Count number of valid input data
421
  ------------------------------------------------------------------------------
422 4 danv
  u_common_counter : ENTITY astron_counter_lib.common_counter
423 2 danv
  GENERIC MAP (
424
    g_latency   => 1,  -- default 1 for registered count output, use 0 for immediate combinatorial count output
425
    g_width     => g_cnt_w
426
  )
427
  PORT MAP (
428
    rst     => rst,
429
    clk     => clk,
430
    clken   => clken,
431
    cnt_clr => diag_dis,    -- synchronous cnt_clr is only interpreted when clken is active
432
    cnt_en  => in_val,
433
    count   => in_cnt
434
  );
435
END rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.