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

Subversion Repositories astron_diagnostics

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

Go to most recent revision | 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
LIBRARY IEEE, common_pkg_lib;
22
USE IEEE.STD_LOGIC_1164.ALL;
23
USE IEEE.MATH_REAL.ALL;
24
USE common_pkg_lib.common_pkg.ALL;
25
 
26
PACKAGE diag_pkg IS
27
 
28
  -----------------------------------------------------------------------------
29
  -- PHY interface tests (e.g. for ethernet, transceivers, lvds, memory)
30
  -----------------------------------------------------------------------------
31
 
32
  CONSTANT c_diag_test_mode_no_tst      : NATURAL := 0;   -- no test, the PHY interface runs in normal user mode
33
  CONSTANT c_diag_test_mode_loop_local  : NATURAL := 1;   -- loop back via PHY chip
34
  CONSTANT c_diag_test_mode_loop_remote : NATURAL := 2;   -- loop back via loopback cable or plug in the connector
35
  CONSTANT c_diag_test_mode_tx          : NATURAL := 4;   -- transmit only
36
  CONSTANT c_diag_test_mode_rx          : NATURAL := 5;   -- receive only
37
  CONSTANT c_diag_test_mode_tx_rx       : NATURAL := 6;   -- transmit and receive
38
 
39
  CONSTANT c_diag_test_data_lfsr        : NATURAL := 0;   -- use pseudo random data
40
  CONSTANT c_diag_test_data_incr        : NATURAL := 1;   -- use incrementing counter data
41
 
42
  CONSTANT c_diag_test_duration_quick   : NATURAL := 0;   -- end Rx test after 1 data frame or word, end Tx test after correspondingly sufficient data frames or words transmitted, or all memory lines
43
  CONSTANT c_diag_test_duration_normal  : NATURAL := 1;   -- idem for e.g. 100 data frames or words, or full memory
44
  CONSTANT c_diag_test_duration_extra   : NATURAL := 2;   -- idem for e.g. 100000 data frames or words
45
 
46
  CONSTANT c_diag_test_result_ok        : NATURAL := 0;   -- test went OK
47
  CONSTANT c_diag_test_result_none      : NATURAL := 1;   -- test did not run, default
48
  CONSTANT c_diag_test_result_timeout   : NATURAL := 2;   -- test started but no valid data was received
49
  CONSTANT c_diag_test_result_error     : NATURAL := 3;   -- test received valid data, but the value was wrong for one or more
50
  CONSTANT c_diag_test_result_illegal   : NATURAL := 4;   -- exception, condition that can not occur in the logic
51
 
52
 
53
  -----------------------------------------------------------------------------
54
  -- Waveform Generator
55
  -----------------------------------------------------------------------------
56
 
57
  -- control register
58
  CONSTANT c_diag_wg_mode_w             : NATURAL :=  8;
59
  CONSTANT c_diag_wg_nofsamples_w       : NATURAL := 16;  -- >~ minimum data path block size
60
  CONSTANT c_diag_wg_phase_w            : NATURAL := 16;  -- =  c_diag_wg_nofsamples_w
61
  CONSTANT c_diag_wg_freq_w             : NATURAL := 31;  -- >> c_diag_wg_nofsamples_w, determines the minimum frequency = Fs / 2**c_diag_wg_freq_w
62
  CONSTANT c_diag_wg_ampl_w             : NATURAL := 17;  -- Typically fit DSP multiply 18x18 element so use <= 17, to fit unsigned in 18 bit signed,
63
                                                          -- = waveform data width-1 (sign bit) to be able to make a 1 LSBit amplitude sinus
64
 
65
  CONSTANT c_diag_wg_mode_off           : NATURAL := 0;
66
  CONSTANT c_diag_wg_mode_calc          : NATURAL := 1;
67
  CONSTANT c_diag_wg_mode_repeat        : NATURAL := 2;
68
  CONSTANT c_diag_wg_mode_single        : NATURAL := 3;
69
 
70
  TYPE t_diag_wg IS RECORD
71
    mode        : STD_LOGIC_VECTOR(c_diag_wg_mode_w       -1 DOWNTO 0);
72
    nof_samples : STD_LOGIC_VECTOR(c_diag_wg_nofsamples_w -1 DOWNTO 0);  -- unsigned value
73
    phase       : STD_LOGIC_VECTOR(c_diag_wg_phase_w      -1 DOWNTO 0);  -- unsigned value
74
    freq        : STD_LOGIC_VECTOR(c_diag_wg_freq_w       -1 DOWNTO 0);  -- unsigned value
75
    ampl        : STD_LOGIC_VECTOR(c_diag_wg_ampl_w       -1 DOWNTO 0);  -- unsigned value, range [0:2**c_diag_wg_ampl_w> normalized to range [0 c_diag_wg_gain>
76
  END RECORD;
77
 
78
  CONSTANT c_diag_wg_ampl_norm          : REAL := 1.0;   -- Use this default amplitude norm = 1.0 when WG data width = WG waveform buffer data width,
79
                                                         -- else use extra amplitude unit scaling by (WG data max)/(WG data max + 1)
80
  CONSTANT c_diag_wg_gain_w             : NATURAL := 1;  -- Normalized range [0 1>  maps to fixed point range [0:2**c_diag_wg_ampl_w>
81
                                                         -- . use gain 2**0             = 1 to have fulle scale without clipping
82
                                                         -- . use gain 2**g_calc_gain_w > 1 to cause clipping
83
  CONSTANT c_diag_wg_ampl_unit          : REAL := 2**REAL(c_diag_wg_ampl_w-c_diag_wg_gain_w)*c_diag_wg_ampl_norm;  -- ^= Full Scale range [-c_wg_full_scale +c_wg_full_scale] without clipping
84
  CONSTANT c_diag_wg_freq_unit          : REAL := 2**REAL(c_diag_wg_freq_w);                                       -- ^= c_clk_freq = Fs (sample frequency), assuming one sinus waveform in the buffer
85
  CONSTANT c_diag_wg_phase_unit         : REAL := 2**REAL(c_diag_wg_phase_w)/ 360.0;                               -- ^= 1 degree
86
 
87
  CONSTANT c_diag_wg_rst : t_diag_wg := (TO_UVEC(c_diag_wg_mode_off, c_diag_wg_mode_w),
88
                                         TO_UVEC(              1024, c_diag_wg_nofsamples_w),
89
                                         TO_UVEC(                 0, c_diag_wg_phase_w),
90
                                         TO_UVEC(                 0, c_diag_wg_freq_w),
91
                                         TO_UVEC(                 0, c_diag_wg_ampl_w));
92
 
93
  TYPE t_diag_wg_arr IS ARRAY (INTEGER RANGE <>) OF t_diag_wg;
94
 
95
  -----------------------------------------------------------------------------
96
  -- Block Generator
97
  -----------------------------------------------------------------------------
98
 
99
  -- control register
100
  CONSTANT c_diag_bg_reg_nof_dat : NATURAL := 8;
101
  CONSTANT c_diag_bg_reg_adr_w   : NATURAL := ceil_log2(c_diag_bg_reg_nof_dat);
102
 
103
  CONSTANT c_diag_bg_mode_w               : NATURAL :=  8;
104
  CONSTANT c_diag_bg_samples_per_packet_w : NATURAL := 24;
105
  CONSTANT c_diag_bg_blocks_per_sync_w    : NATURAL := 24;
106
  CONSTANT c_diag_bg_gapsize_w            : NATURAL := 24;
107
  CONSTANT c_diag_bg_mem_adrs_w           : NATURAL := 24;
108
  CONSTANT c_diag_bg_mem_low_adrs_w       : NATURAL := c_diag_bg_mem_adrs_w;
109
  CONSTANT c_diag_bg_mem_high_adrs_w      : NATURAL := c_diag_bg_mem_adrs_w;
110
  CONSTANT c_diag_bg_bsn_init_w           : NATURAL := 64;
111
 
112
  TYPE t_diag_block_gen IS RECORD
113
    enable             : STD_LOGIC;  -- block enable
114
    enable_sync        : STD_LOGIC;  -- block enable on sync pulse
115
    samples_per_packet : STD_LOGIC_VECTOR(c_diag_bg_samples_per_packet_w -1 DOWNTO 0);
116
    blocks_per_sync    : STD_LOGIC_VECTOR(c_diag_bg_blocks_per_sync_w    -1 DOWNTO 0);
117
    gapsize            : STD_LOGIC_VECTOR(c_diag_bg_gapsize_w            -1 DOWNTO 0);
118
    mem_low_adrs       : STD_LOGIC_VECTOR(c_diag_bg_mem_low_adrs_w       -1 DOWNTO 0);
119
    mem_high_adrs      : STD_LOGIC_VECTOR(c_diag_bg_mem_high_adrs_w      -1 DOWNTO 0);
120
    bsn_init           : STD_LOGIC_VECTOR(c_diag_bg_bsn_init_w           -1 DOWNTO 0);
121
  END RECORD;
122
 
123
  CONSTANT c_diag_block_gen_rst     : t_diag_block_gen := (         '0',
124
                                                                    '0',
125
                                                           TO_UVEC( 256, c_diag_bg_samples_per_packet_w),
126
                                                           TO_UVEC(  10, c_diag_bg_blocks_per_sync_w),
127
                                                           TO_UVEC( 128, c_diag_bg_gapsize_w),
128
                                                           TO_UVEC(   0, c_diag_bg_mem_low_adrs_w),
129
                                                           TO_UVEC(   1, c_diag_bg_mem_high_adrs_w),
130
                                                           TO_UVEC(   0, c_diag_bg_bsn_init_w));
131
 
132
  CONSTANT c_diag_block_gen_enabled : t_diag_block_gen := (         '1',
133
                                                                    '0',
134
                                                           TO_UVEC(  50, c_diag_bg_samples_per_packet_w),
135
                                                           TO_UVEC(  10, c_diag_bg_blocks_per_sync_w),
136
                                                           TO_UVEC(   7, c_diag_bg_gapsize_w),
137
                                                           TO_UVEC(   0, c_diag_bg_mem_low_adrs_w),
138
                                                           TO_UVEC(  15, c_diag_bg_mem_high_adrs_w),   -- fits any BG buffer that has address width >= 4
139
                                                           TO_UVEC(   0, c_diag_bg_bsn_init_w));
140
 
141
  TYPE t_diag_block_gen_arr IS ARRAY (INTEGER RANGE <>) OF t_diag_block_gen;
142
 
143
  -- Overloaded sel_a_b (from common_pkg) for t_diag_block_gen
144
  FUNCTION sel_a_b(sel : BOOLEAN; a, b : t_diag_block_gen) RETURN t_diag_block_gen;
145
 
146
  -----------------------------------------------------------------------------
147
  -- Data buffer
148
  -----------------------------------------------------------------------------
149
  CONSTANT c_diag_db_reg_nof_dat : NATURAL := 2;
150
  CONSTANT c_diag_db_reg_adr_w   : NATURAL := ceil_log2(c_diag_db_reg_nof_dat);
151
 
152
  CONSTANT c_diag_db_max_data_w  : NATURAL := 32;
153
 
154
  TYPE t_diag_data_type_enum IS (
155
    e_data,
156
    e_complex,           -- im & re
157
    e_real,
158
    e_imag
159
  );
160
 
161
  -----------------------------------------------------------------------------
162
  -- Data buffer dev
163
  -----------------------------------------------------------------------------
164
  CONSTANT c_diag_db_dev_reg_nof_dat : NATURAL := 8;   -- Create headroom of 4 registers. 
165
  CONSTANT c_diag_db_dev_reg_adr_w   : NATURAL := ceil_log2(c_diag_db_dev_reg_nof_dat);
166
 
167
  -----------------------------------------------------------------------------
168
  -- CNTR / PSRG sequence test data
169
  -----------------------------------------------------------------------------
170
 
171
  CONSTANT c_diag_seq_tx_reg_nof_dat      : NATURAL := 4;
172
  CONSTANT c_diag_seq_tx_reg_adr_w        : NATURAL := ceil_log2(c_diag_seq_tx_reg_nof_dat);
173
  CONSTANT c_diag_seq_rx_reg_nof_steps_wi : NATURAL := 4;
174
  CONSTANT c_diag_seq_rx_reg_nof_steps    : NATURAL := 4;
175
  CONSTANT c_diag_seq_rx_reg_nof_dat      : NATURAL := c_diag_seq_rx_reg_nof_steps_wi + c_diag_seq_rx_reg_nof_steps;
176
  CONSTANT c_diag_seq_rx_reg_adr_w        : NATURAL := ceil_log2(c_diag_seq_rx_reg_nof_dat);
177
 
178
  -- Record with all diag seq MM register fields
179
  TYPE t_diag_seq_mm_reg IS RECORD
180
    -- readback control
181
    tx_init   : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
182
    tx_mod    : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
183
    tx_ctrl   : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
184
    rx_ctrl   : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
185
    rx_steps  : t_integer_arr(c_diag_seq_rx_reg_nof_steps-1 DOWNTO 0);
186
    -- read only status
187
    tx_cnt    : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
188
    rx_cnt    : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
189
    rx_stat   : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
190
    rx_sample : STD_LOGIC_VECTOR(c_word_w -1 DOWNTO 0);
191
  END RECORD;
192
 
193
  CONSTANT c_diag_seq_tx_reg_dis        : NATURAL := 0;
194
  CONSTANT c_diag_seq_tx_reg_en_psrg    : NATURAL := 1;
195
  CONSTANT c_diag_seq_tx_reg_en_cntr    : NATURAL := 3;
196
 
197
  TYPE t_diag_seq_mm_reg_arr IS ARRAY (INTEGER RANGE <>) OF t_diag_seq_mm_reg;
198
 
199
END diag_pkg;
200
 
201
PACKAGE BODY diag_pkg IS
202
 
203
  FUNCTION sel_a_b(sel : BOOLEAN; a, b : t_diag_block_gen) RETURN t_diag_block_gen IS
204
  BEGIN
205
    IF sel = TRUE THEN
206
      RETURN a;
207
    ELSE
208
      RETURN b;
209
    END IF;
210
  END;
211
 
212
END diag_pkg;

powered by: WebSVN 2.1.0

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