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 2

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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