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 2

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

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

powered by: WebSVN 2.1.0

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