Debian Codegraph @

hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_iq_8bit_tb.vhd

raw
1 -- Copyright (c) 2022 Nuand LLC
2 --
3 -- Permission is hereby granted, free of charge, to any person obtaining a copy
4 -- of this software and associated documentation files (the "Software"), to deal
5 -- in the Software without restriction, including without limitation the rights
6 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 -- copies of the Software, and to permit persons to whom the Software is
8 -- furnished to do so, subject to the following conditions:
9 --
10 -- The above copyright notice and this permission notice shall be included in
11 -- all copies or substantial portions of the Software.
12 --
13 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 -- THE SOFTWARE.
20
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use ieee.numeric_std.all;
24
25 library rtl_work;
26
27 library altera_lnsim;
28 use altera_lnsim.altera_pll;
29
30 library nuand;
31 use nuand.util.all ;
32 use nuand.fifo_readwrite_p.all;
33 use nuand.common_dcfifo_p.all;
34 use nuand.bladerf_p.all;
35 use nuand.fx3_gpif_p.all;
36
37 entity fx3_gpif_iq_8bit_tb is
38 generic (
39 -- For bladeRF2 (2x2 MIMO):
40 NUM_MIMO_STREAMS : natural := 2;
41 FIFO_READER_READ_THROTTLE : natural := 0;
42
43 ENABLE_CHANNEL_0 : std_logic := '1';
44 ENABLE_CHANNEL_1 : std_logic := '1';
45 EIGHT_BIT_MODE_EN : std_logic := '1'
46 );
47 end entity;
48
49 architecture arch of fx3_gpif_iq_8bit_tb is
50
51 -- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock
52 constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0);
53
54 -- For reasons unknown, simulation of this system in ModelSim requires that
55 -- wrreq and data be asserted shortly before the rising clock edge. Sigh...
56 constant FIFO_WORKAROUND : time := 1 ps;
57
58 type fx3_control_t is record
59 usb_speed : std_logic;
60 tx_enable : std_logic;
61 rx_enable : std_logic;
62 meta_enable : std_logic;
63 packet : std_logic;
64 end record;
65
66 type fx3_gpif_t is record
67 gpif_in : std_logic_vector(31 downto 0);
68 gpif_out : std_logic_vector(31 downto 0);
69 gpif_oe : std_logic;
70 ctl_in : std_logic_vector(12 downto 0);
71 ctl_out : std_logic_vector(12 downto 0);
72 ctl_oe : std_logic_vector(12 downto 0);
73 end record;
74
75 signal sys_rst : std_logic := '1';
76 signal done : boolean := false;
77
78 signal fx3_pclk : std_logic := '1';
79 signal fx3_pclk_pll : std_logic := '1';
80 signal sys_clk : std_logic := '1';
81
82 signal pll_reset : std_logic := '0';
83 signal pll_locked : std_logic := '0';
84 signal fx3_control : fx3_control_t;
85 signal fx3_gpif : fx3_gpif_t;
86 signal fx3_gpif_i : std_logic_vector(31 downto 0);
87 signal fx3_ctl_i : std_logic_vector(12 downto 0);
88
89 -- Control mapping
90 alias dma0_rx_ack is fx3_ctl_i( 0);
91 alias dma1_rx_ack is fx3_ctl_i( 1);
92 alias dma2_tx_ack is fx3_ctl_i( 2);
93 alias dma3_tx_ack is fx3_ctl_i( 3);
94 alias dma_rx_enable is fx3_ctl_i( 4);
95 alias dma_tx_enable is fx3_ctl_i( 5);
96 alias dma_idle is fx3_ctl_i( 6);
97 alias system_reset is fx3_ctl_i( 7);
98 alias dma0_rx_reqx is fx3_ctl_i( 8);
99 alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk
100 alias dma2_tx_reqx is fx3_ctl_i(10);
101 alias dma3_tx_reqx is fx3_ctl_i(11);
102
103 signal loopback_i : signed(15 downto 0) := (others =>'0');
104 signal loopback_q : signed(15 downto 0) := (others =>'0');
105 signal loopback_valid : std_logic := '0';
106 signal loopback_enabled : std_logic := '0';
107
108 signal tx_clock : std_logic := '1' ;
109 signal rx_clock : std_logic := '1' ;
110
111 signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT;
112 signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT;
113 signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT;
114 signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT;
115 signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT;
116
117 signal rx_mux_i : signed(15 downto 0);
118 signal rx_mux_q : signed(15 downto 0);
119 signal rx_mux_valid : std_logic;
120
121 signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' );
122 signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' );
123
124 constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ;
125 constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
126 constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
127
128 signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
129 signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE);
130 signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
131 signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE);
132
133 signal tx_reset : std_logic := '0';
134 signal tx_ts_reset : std_logic := '0';
135 signal rx_reset : std_logic := '0';
136 signal rx_ts_reset : std_logic := '0';
137
138 signal meta_en_tx : std_logic := '0';
139 signal meta_en_rx : std_logic := '0';
140
141 signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT;
142 signal tx_packet_control : packet_control_t;
143
144 signal trigger_signal_sync_tb : std_logic;
145 signal adc_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' );
146
147 function data_gen (count : natural) return std_logic_vector is
148 variable msw, lsw : std_logic_vector(15 downto 0);
149 begin
150 msw := std_logic_vector(to_signed(count, 16));
151 lsw := std_logic_vector(to_signed(-count, 16));
152
153 return (msw & lsw);
154 end function data_gen;
155
156 signal rx_packet_ready : std_logic;
157
158 begin
159
160 -- ========================================================================
161 -- Brief summary of data flow
162 -- ========================================================================
163 --
164 -- Simulated samples flow from fx3_model's TX side to its RX side. The
165 -- validity of the data is checked there.
166 --
167 -- entity U_fx3_model FX3 model, TX process
168 -- signal fx3_gpif_i fx3_gpif.gpif_oe is '0'
169 -- process register_gpif
170 -- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA)
171 -- entity U_fx3_gpif GPIF implementation, write side
172 -- signal tx_sample_fifo.w* TX fifo, write side
173 -- entity U_tx_sample_fifo
174 -- signal tx_sample_fifo.r* TX fifo, read side
175 -- process tx_mux
176 -- signal loopback_fifo.w* Loopback fifo, write side
177 -- entity U_rx_loopback_fifo
178 -- signal loopback_fifo.r* Loopback fifo, read side
179 -- process loopback_fifo_control
180 -- signal loopback_{i,q,valid}
181 -- process rx_mux
182 -- signal rx_mux_{i,q,valid}
183 -- entity U_fifo_writer
184 -- signal rx_sample_fifo.w* RX fifo, write side
185 -- entity U_rx_sample_fifo
186 -- signal rx_sample_fifo.r* RX fifo, read side
187 -- entity U_fx3_gpif GPIF implementation, read side
188 -- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3)
189 -- process register_gpif
190 -- signal fx3_gpif_i fx3_gpif.gpif_oe is '1'
191 -- entity U_fx3_model FX3 model, RX process
192
193
194 -- ========================================================================
195 -- Instantiations
196 -- ========================================================================
197
198 -- Unit under test
199 -- Clock domain: fx3_pclk_pll
200 U_fx3_gpif : entity nuand.fx3_gpif
201 port map (
202 pclk => fx3_pclk_pll,
203 reset => sys_rst,
204 usb_speed => fx3_control.usb_speed,
205 gpif_in => fx3_gpif.gpif_in,
206 gpif_out => fx3_gpif.gpif_out,
207 gpif_oe => fx3_gpif.gpif_oe,
208 ctl_in => fx3_gpif.ctl_in,
209 ctl_out => fx3_gpif.ctl_out,
210 ctl_oe => fx3_gpif.ctl_oe,
211 tx_enable => fx3_control.tx_enable,
212 rx_enable => fx3_control.rx_enable,
213 meta_enable => fx3_control.meta_enable,
214 packet_enable => fx3_control.packet,
215 tx_fifo_write => tx_sample_fifo.wreq,
216 tx_fifo_full => tx_sample_fifo.wfull,
217 tx_fifo_empty => tx_sample_fifo.wempty,
218 tx_fifo_usedw => tx_sample_fifo.wused,
219 tx_fifo_data => tx_sample_fifo.wdata,
220 tx_timestamp => tx_timestamp,
221 tx_meta_fifo_write => tx_meta_fifo.wreq,
222 tx_meta_fifo_full => tx_meta_fifo.wfull,
223 tx_meta_fifo_empty => tx_meta_fifo.wempty,
224 tx_meta_fifo_usedw => tx_meta_fifo.wused,
225 tx_meta_fifo_data => tx_meta_fifo.wdata,
226 rx_fifo_read => rx_sample_fifo.rreq,
227 rx_fifo_full => rx_sample_fifo.rfull,
228 rx_fifo_empty => rx_sample_fifo.rempty,
229 rx_fifo_usedw => rx_sample_fifo.rused,
230 rx_fifo_data => rx_sample_fifo.rdata,
231 rx_meta_fifo_read => rx_meta_fifo.rreq,
232 rx_meta_fifo_full => rx_meta_fifo.rfull,
233 rx_meta_fifo_empty => rx_meta_fifo.rempty,
234 rx_meta_fifo_usedr => rx_meta_fifo.rused,
235 rx_meta_fifo_data => rx_meta_fifo.rdata
236 );
237
238 -- Discrete control signals for fx3_gpif
239 fx3_control.usb_speed <= '0';
240 fx3_control.meta_enable <= '0';
241 fx3_control.packet <= '0';
242
243 U_pkt_gen : entity nuand.rx_packet_generator
244 port map(
245 rx_clock => rx_clock,
246 rx_reset => rx_reset,
247
248 rx_enable => fx3_control.rx_enable,
249 rx_packet_enable => fx3_control.packet,
250
251 rx_packet_ready => rx_packet_ready,
252
253 rx_packet_control => rx_packet_control
254
255 );
256
257
258 meta_en_tx <= fx3_control.meta_enable;
259 meta_en_rx <= fx3_control.meta_enable;
260
261 increment_tx_ts : process(tx_clock)
262 variable ping : boolean := true ;
263 begin
264 if( rising_edge(tx_clock) ) then
265 ping := not ping ;
266 if( ping = true ) then
267 tx_timestamp <= tx_timestamp + 1 ;
268 end if ;
269 end if ;
270 end process ;
271
272 increment_rx_ts : process(rx_clock)
273 variable ping : boolean := true ;
274 begin
275 if( rising_edge(rx_clock) ) then
276 ping := not ping ;
277 if( ping = true ) then
278 rx_timestamp <= rx_timestamp + 1 ;
279 end if ;
280 end if ;
281 end process ;
282
283 -- Model of FX3's GPIF interface
284 -- Clock domain: fx3_pclk (source)
285 U_fx3_model : entity nuand.fx3_model(micro_dma)
286 port map (
287 fx3_pclk => fx3_pclk,
288 fx3_gpif => fx3_gpif_i,
289 fx3_ctl => fx3_ctl_i,
290 fx3_uart_rxd => '0',
291 fx3_uart_txd => open,
292 fx3_uart_cts => open,
293 fx3_rx_en => '1',
294 fx3_rx_meta_en => meta_en_rx,
295 fx3_tx_en => '1',
296 fx3_tx_meta_en => meta_en_tx,
297 eight_bit_mode_en => EIGHT_BIT_MODE_EN,
298 done => done
299 );
300
301 -- Generate phase-shifted PLL clock
302 U_fx3_pll : entity rtl_work.fx3_pll
303 port map (
304 inclk0 => fx3_pclk,
305 areset => pll_reset,
306 c0 => fx3_pclk_pll,
307 locked => pll_locked
308 );
309
310 tx_clock <= not tx_clock after TX_HALF_PERIOD ;
311 rx_clock <= not rx_clock after RX_HALF_PERIOD ;
312
313
314 -- Reset handler
315 sys_rst <= '0' after 100 ns;
316
317 -- Generate system clock
318 sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0';
319
320
321 tx_reset <= sys_rst;
322 tx_ts_reset <= sys_rst;
323 rx_reset <= sys_rst;
324 rx_ts_reset <= sys_rst;
325
326 meta_en_tx <= fx3_control.meta_enable;
327 meta_en_rx <= fx3_control.meta_enable;
328
329 -- TX Submodule
330 U_tx : entity work.tx
331 generic map (
332 NUM_STREAMS => dac_controls'length
333 )
334 port map (
335 tx_reset => tx_reset,
336 tx_clock => tx_clock,
337 tx_enable => fx3_control.tx_enable,
338
339 meta_en => meta_en_tx,
340 timestamp_reset => tx_ts_reset,
341 usb_speed => fx3_control.usb_speed,
342 tx_underflow_led => open,
343 tx_timestamp => tx_timestamp,
344
345 -- Triggering
346 trigger_arm => '0',
347 trigger_fire => '0',
348 trigger_master => '0',
349 trigger_line => open,
350
351 -- Packet FIFO
352 packet_en => fx3_control.packet,
353 packet_empty => open,
354 packet_control => tx_packet_control,
355 packet_ready => '1',
356
357 -- 8-bit mode
358 eight_bit_mode_en => EIGHT_BIT_MODE_EN,
359
360 -- Samples from host via FX3
361 sample_fifo_wclock => fx3_pclk_pll,
362 sample_fifo_wreq => tx_sample_fifo.wreq,
363 sample_fifo_wdata => tx_sample_fifo.wdata,
364 sample_fifo_wempty => tx_sample_fifo.wempty,
365 sample_fifo_wfull => tx_sample_fifo.wfull,
366 sample_fifo_wused => tx_sample_fifo.wused,
367
368 -- Metadata from host via FX3
369 meta_fifo_wclock => fx3_pclk_pll,
370 meta_fifo_wreq => tx_meta_fifo.wreq,
371 meta_fifo_wdata => tx_meta_fifo.wdata,
372 meta_fifo_wempty => tx_meta_fifo.wempty,
373 meta_fifo_wfull => tx_meta_fifo.wfull,
374 meta_fifo_wused => tx_meta_fifo.wused,
375
376 -- Digital Loopback Interface
377 loopback_enabled => '0',
378 loopback_fifo_wdata => loopback_fifo.wdata,
379 loopback_fifo_wreq => loopback_fifo.wreq,
380 loopback_fifo_wfull => loopback_fifo.wfull,
381 loopback_fifo_wused => loopback_fifo.wused,
382
383 -- RFFE Interface
384 dac_controls => dac_controls,
385 dac_streams => dac_streams
386 );
387
388 -- RX Submodule
389 U_rx : entity work.rx
390 generic map (
391 NUM_STREAMS => adc_controls'length
392 )
393 port map (
394 rx_reset => rx_reset,
395 rx_clock => rx_clock,
396 rx_enable => fx3_control.rx_enable,
397
398 meta_en => meta_en_rx,
399 timestamp_reset => rx_ts_reset,
400 usb_speed => fx3_control.usb_speed,
401 rx_mux_sel => to_unsigned(0, 3),
402 rx_overflow_led => open,
403 rx_timestamp => rx_timestamp,
404
405 -- Triggering
406 trigger_arm => '0',
407 trigger_fire => '0',
408 trigger_master => '0',
409 trigger_line => open,
410 trigger_signal_sync_tb => trigger_signal_sync_tb,
411
412 -- Packet FIFO
413 packet_en => fx3_control.packet,
414 packet_control => rx_packet_control,
415 packet_ready => rx_packet_ready,
416
417 -- 8-bit mode
418 eight_bit_mode_en => EIGHT_BIT_MODE_EN,
419
420 -- Samples to host via FX3
421 sample_fifo_rclock => fx3_pclk_pll,
422 sample_fifo_raclr => not fx3_control.rx_enable,
423 sample_fifo_rreq => rx_sample_fifo.rreq,
424 sample_fifo_rdata => rx_sample_fifo.rdata,
425 sample_fifo_rempty => rx_sample_fifo.rempty,
426 sample_fifo_rfull => rx_sample_fifo.rfull,
427 sample_fifo_rused => rx_sample_fifo.rused,
428
429 -- Mini expansion signals
430 mini_exp => "00",
431
432 -- Metadata to host via FX3
433 meta_fifo_rclock => fx3_pclk_pll,
434 meta_fifo_raclr => not fx3_control.rx_enable,
435 meta_fifo_rreq => rx_meta_fifo.rreq,
436 meta_fifo_rdata => rx_meta_fifo.rdata,
437 meta_fifo_rempty => rx_meta_fifo.rempty,
438 meta_fifo_rfull => rx_meta_fifo.rfull,
439 meta_fifo_rused => rx_meta_fifo.rused,
440
441 -- Digital Loopback Interface
442 loopback_fifo_wenabled => open,
443 loopback_fifo_wreset => tx_reset,
444 loopback_fifo_wclock => tx_clock,
445 loopback_fifo_wdata => loopback_fifo.wdata,
446 loopback_fifo_wreq => loopback_fifo.wreq,
447 loopback_fifo_wfull => loopback_fifo.wfull,
448 loopback_fifo_wused => loopback_fifo.wused,
449
450 -- RFFE Interface
451 adc_controls => adc_controls,
452 adc_streams => adc_streams
453 );
454
455 -- ========================================================================
456 -- Data converters
457 -- ========================================================================
458
459 gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate
460 -- The TX side of the AD9361 HDL is a FIFO pull interface
461 -- that expects a readahead FIFO. It toggles the data request
462 -- signal every other cycle. This behavior is mimicked here.
463 process( tx_clock, sys_rst )
464 begin
465 if( sys_rst = '1' ) then
466 dac_controls <= (
467 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
468 1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
469 );
470 elsif( rising_edge(tx_clock) ) then
471 for i in dac_controls'range loop
472 dac_controls(i) <= (
473 enable => dac_controls(i).enable,
474 data_req => not dac_controls(i).data_req );
475 end loop;
476 end if;
477 end process;
478 else generate
479 dac_controls <= (others => SAMPLE_CONTROL_ENABLE);
480 end generate;
481
482 gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate
483 process( rx_clock, sys_rst )
484 constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
485 constant COUNT_RESET : integer := 0;
486 variable count : integer range -2047 to 2047 := COUNT_RESET;
487 begin
488 if( sys_rst = '1' ) then
489 count := COUNT_RESET;
490 adc_controls <= (
491 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
492 1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
493 );
494 elsif( rising_edge(rx_clock) ) then
495 for i in adc_controls'range loop
496 adc_controls(i) <= (
497 enable => adc_controls(i).enable,
498 data_req => not adc_controls(i).data_req );
499 if( adc_controls(i).enable = '1') then
500 if( adc_streams(i).data_v = '1' ) then
501 if( EIGHT_BIT_MODE_EN = '1' ) then
502 adc_streams(i).data_i <= "0000" & to_signed(count, 8) & SIGMA_DELTA_BITS;
503 adc_streams(i).data_q <= "0000" & to_signed(-count, 8) & SIGMA_DELTA_BITS;
504 count := (count + 1) mod 128;
505 else
506 adc_streams(i).data_i <= to_signed(count, 16);
507 adc_streams(i).data_q <= to_signed(-count, 16);
508 count := (count + 1) mod 2048;
509 end if;
510 end if;
511 adc_streams(i).data_v <= not adc_streams(i).data_v;
512 end if;
513 end loop;
514 end if;
515 end process;
516 else generate
517 adc_controls <= (others => SAMPLE_CONTROL_ENABLE);
518 end generate;
519
520 -- ========================================================================
521 -- Processes
522 -- ========================================================================
523
524 -- FX3 GPIF bidirectional signal control
525 -- Adapted from same process in bladerf-hosted.vhd
526 register_gpif : process(sys_rst, fx3_pclk_pll)
527 begin
528 if( sys_rst = '1' ) then
529 fx3_gpif_i <= (others => 'Z');
530 fx3_gpif.gpif_in <= (others => 'Z');
531 elsif( rising_edge(fx3_pclk_pll) ) then
532 fx3_gpif.gpif_in <= fx3_gpif_i;
533
534 if( fx3_gpif.gpif_oe = '1' ) then
535 fx3_gpif_i <= fx3_gpif.gpif_out;
536 else
537 fx3_gpif_i <= (others =>'Z');
538 end if;
539 end if;
540 end process;
541
542 -- FX3 CTL bidirectional signals
543 -- Adapted from same generator in bladerf-hosted.vhd
544 generate_ctl : for i in fx3_ctl_i'range generate
545 fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z';
546 end generate;
547
548 fx3_gpif.ctl_in <= fx3_ctl_i;
549
550 -- Controller for loopback FIFO
551 -- Stripped-down version of same process from rx.vhd
552 loopback_fifo_control : process( sys_rst, loopback_fifo.rclock )
553 begin
554 if( sys_rst = '1' ) then
555 loopback_enabled <= '0';
556 loopback_fifo.rreq <= '0';
557 loopback_i <= (others => '0');
558 loopback_q <= (others => '0');
559 loopback_valid <= '0';
560 elsif( rising_edge(loopback_fifo.rclock) ) then
561 loopback_enabled <= '0';
562 loopback_fifo.rreq <= '0';
563 loopback_i <= loopback_i;
564 loopback_q <= loopback_q;
565 loopback_valid <= '0';
566
567 -- Is loopback enabled?
568 loopback_enabled <= fx3_control.rx_enable;
569
570 -- Do the loopback
571 loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length);
572 loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length);
573 loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty;
574
575 -- Read from the FIFO if req'd
576 loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty);
577 end if;
578 end process;
579
580 -- RX multiplexer
581 -- Stripped-down version of same process from rx.vhd
582 rx_mux : process(sys_rst, sys_clk)
583 begin
584 if( sys_rst = '1' ) then
585 rx_mux_i <= (others =>'0');
586 rx_mux_q <= (others =>'0');
587 rx_mux_valid <= '0';
588 elsif( rising_edge(sys_clk) ) then
589 rx_mux_i <= loopback_i;
590 rx_mux_q <= loopback_q;
591 rx_mux_valid <= loopback_valid;
592 end if;
593 end process;
594
595 -- TX multiplexer
596 -- Stripped-down version of mimo_channel_sel_mux from tx.vhd
597 --tx_mux : process( sys_clk )
598 --begin
599 -- if( rising_edge(sys_clk) ) then
600 -- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty;
601
602 -- loopback_fifo.wdata <= tx_sample_fifo.rdata;
603 -- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty;
604 -- end if;
605 --end process;
606
607
608 -- ========================================================================
609 -- Verification
610 -- ========================================================================
611 print_config: process
612 begin
613 wait until rising_edge(fx3_control.tx_enable);
614 report lf&
615 "[CONFIG] EIGHT_BIT_MODE_EN: " & std_logic'image(EIGHT_BIT_MODE_EN) &lf&
616 "[CONFIG] ENABLE_CHANNEL_0: " & std_logic'image(ENABLE_CHANNEL_0) &lf&
617 "[CONFIG] ENABLE_CHANNEL_1: " & std_logic'image(ENABLE_CHANNEL_1);
618 end process print_config;
619
620
621 --
622 -- Check for metavalues
623 -- We should never see metavalues written to the FIFOs
624 --
625 check_fifo_write : process(fx3_pclk_pll) is
626 begin
627 if( rising_edge(fx3_pclk_pll) ) then
628 if( tx_sample_fifo.wreq = '1' and fx3_control.meta_enable = '0' ) then
629 for i in tx_sample_fifo.wdata'range loop
630 assert tx_sample_fifo.wdata(i) = '0' or tx_sample_fifo.wdata(i) = '1'
631 severity failure;
632 end loop;
633 end if;
634 end if;
635 end process;
636
637 check_fifo_read : process(fx3_pclk_pll) is
638 begin
639 if( rising_edge(fx3_pclk_pll) ) then
640 if( rx_sample_fifo.rreq = '1' ) then
641 for i in rx_sample_fifo.rdata'range loop
642 assert rx_sample_fifo.rdata(i) = '0' or rx_sample_fifo.rdata(i) = '1'
643 severity failure;
644 end loop;
645 end if;
646 end if;
647 end process check_fifo_read;
648
649 --
650 -- Check for fullness on FIFOs
651 --
652 assert(rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning;
653 assert(tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning;
654 assert(loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning;
655
656 --
657 -- Tx Sample Check
658 --
659 look_for_dropped_tx_samples : process(tx_clock) is
660 constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
661 constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
662 variable current_message_count : natural := 1;
663 variable valid_sample_count : natural := 0;
664 variable iq_value : signed (15 downto 0) := x"0000";
665 variable expected_sample_i : signed (15 downto 0);
666 variable expected_sample_q : signed (15 downto 0);
667 variable failure_count : natural := 0;
668 begin
669 for i in dac_controls'range loop
670 if( rising_edge(tx_clock)
671 and dac_controls(i).enable = '1'
672 and dac_streams(i).data_v = '1'
673 and fx3_control.tx_enable = '1' )
674 then
675 valid_sample_count := valid_sample_count + 1;
676 if( EIGHT_BIT_MODE_EN = '1' ) then
677 expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS;
678 expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS;
679
680 assert ( dac_streams(i).data_i = expected_sample_i )
681 report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " &
682 "expected_sample_i: " & to_hstring(expected_sample_i)
683 severity warning;
684 assert ( dac_streams(i).data_q = expected_sample_q )
685 report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " &
686 "expected_sample_q: " & to_hstring(expected_sample_q)
687 severity warning;
688
689 if ( dac_streams(i).data_i /= expected_sample_i or dac_streams(i).data_q /= expected_sample_q ) then
690 failure_count := failure_count + 1;
691 if ( failure_count >= 6 ) then
692 report "tx fail count tolerance exceeded" severity failure;
693 end if;
694 end if;
695
696 iq_value := (iq_value + 2) mod 128;
697 else
698 expected_sample_i := iq_value;
699 expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
700
701 assert(dac_streams(i).data_i = expected_sample_i)
702 report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " &
703 "expected_sample_i: " & to_hstring(expected_sample_i)
704 severity failure;
705 assert(dac_streams(i).data_q = expected_sample_q)
706 report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " &
707 "expected_sample_q: " & to_hstring(expected_sample_q)
708 severity failure;
709
710 -- Set iq values based on blocks received
711 -- See tx_sample_stream's encoding scheme in fx3_model.vhd
712 if( valid_sample_count mod GPIF_BUF_SIZE_SS = 0 ) then
713 iq_value := x"0000";
714 if( current_message_count < MESSAGES_PER_ITERATION ) then
715 current_message_count := current_message_count + 1;
716 else
717 current_message_count := 1;
718 end if;
719 else
720 iq_value := (iq_value + 2) mod 2048;
721 end if;
722 end if;
723 end if;
724 end loop;
725
726 end process look_for_dropped_tx_samples;
727
728 --
729 -- Rx Sample Check
730 --
731 first_rx_val_at_mux: process
732 -- Catches and saves the first sample of
733 -- each rx enabled burst seen by the mux
734 begin
735 for i in adc_controls'range loop
736 if( adc_controls(i).enable = '1') then
737 if( ENABLE_CHANNEL_0 = '1' and ENABLE_CHANNEL_1 = '1' ) then
738 adc_stream_val_at_rx_enable <= adc_streams(i).data_i - 1;
739 else
740 adc_stream_val_at_rx_enable <= adc_streams(i).data_i;
741 end if;
742 end if;
743 end loop;
744 wait until rising_edge(trigger_signal_sync_tb);
745 end process first_rx_val_at_mux;
746
747 look_for_dropped_rx_samples: process(fx3_pclk_pll)
748 variable rx_val : integer := 0;
749
750 variable q_expected : std_logic_vector (15 downto 0);
751 variable i_expected : std_logic_vector (15 downto 0);
752 variable q_out : std_logic_vector (15 downto 0);
753 variable i_out : std_logic_vector (15 downto 0);
754
755 variable q0_expected_eight_bit_mode : std_logic_vector (7 downto 0);
756 variable i0_expected_eight_bit_mode : std_logic_vector (7 downto 0);
757 variable q1_expected_eight_bit_mode : std_logic_vector (7 downto 0);
758 variable i1_expected_eight_bit_mode : std_logic_vector (7 downto 0);
759 variable q0_out_eight_bit_mode : std_logic_vector (7 downto 0);
760 variable i0_out_eight_bit_mode : std_logic_vector (7 downto 0);
761 variable q1_out_eight_bit_mode : std_logic_vector (7 downto 0);
762 variable i1_out_eight_bit_mode : std_logic_vector (7 downto 0);
763
764 variable previous_adc_stream_val_at_rx_enable : signed (15 downto 0) := ( others => '0');
765 variable fail_count: natural := 0;
766 variable both_channels_en : std_logic;
767 begin
768 if( previous_adc_stream_val_at_rx_enable /= adc_stream_val_at_rx_enable ) then
769 rx_val := to_integer(adc_stream_val_at_rx_enable (15 downto 4)) when EIGHT_BIT_MODE_EN else
770 to_integer(adc_stream_val_at_rx_enable);
771 previous_adc_stream_val_at_rx_enable := adc_stream_val_at_rx_enable;
772 end if;
773
774 if( rising_edge(fx3_pclk_pll)
775 and fx3_gpif.gpif_oe = '1'
776 and fx3_control.rx_enable = '1' ) then
777 if( EIGHT_BIT_MODE_EN = '1') then
778 -- The +-1 ch1 offset in SISO mode will not reach 128
779 both_channels_en := ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1;
780 q1_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val - 1, 8)) when both_channels_en else
781 std_logic_vector(to_signed(-((rx_val + 1) mod 128), 8));
782 i1_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val + 1, 8)) when both_channels_en else
783 std_logic_vector(to_signed((rx_val + 1) mod 128, 8));
784 q0_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val, 8));
785 i0_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val, 8));
786
787 q1_out_eight_bit_mode := fx3_gpif.gpif_out(31 downto 24);
788 i1_out_eight_bit_mode := fx3_gpif.gpif_out(23 downto 16);
789 q0_out_eight_bit_mode := fx3_gpif.gpif_out(15 downto 8);
790 i0_out_eight_bit_mode := fx3_gpif.gpif_out(7 downto 0);
791
792 if( q1_out_eight_bit_mode /= q1_expected_eight_bit_mode or
793 i1_out_eight_bit_mode /= i1_expected_eight_bit_mode or
794 q0_out_eight_bit_mode /= q0_expected_eight_bit_mode or
795 i0_out_eight_bit_mode /= i0_expected_eight_bit_mode) then
796 fail_count := fail_count + 1;
797 report "-----------------------------";
798 if( fail_count > 3 ) then
799 report "rx fail count tolerance exceeded" severity failure;
800 end if;
801 end if;
802
803 assert ( q1_out_eight_bit_mode = q1_expected_eight_bit_mode )
804 report "data_q1: " & to_hstring(q1_out_eight_bit_mode) & " | " &
805 "expected: " & to_hstring(q1_expected_eight_bit_mode)
806 severity warning;
807 assert ( i1_out_eight_bit_mode = i1_expected_eight_bit_mode )
808 report "data_i1: " & to_hstring(i1_out_eight_bit_mode) & " | " &
809 "expected: " & to_hstring(i1_expected_eight_bit_mode)
810 severity warning;
811 assert ( q0_out_eight_bit_mode = q0_expected_eight_bit_mode )
812 report "data_q0: " & to_hstring(q0_out_eight_bit_mode) & " | " &
813 "expected: " & to_hstring(q0_expected_eight_bit_mode)
814 severity warning;
815 assert ( i0_out_eight_bit_mode = i0_expected_eight_bit_mode )
816 report "data_i0: " & to_hstring(i0_out_eight_bit_mode) & " | " &
817 "expected: " & to_hstring(i0_expected_eight_bit_mode)
818 severity warning;
819
820 -- 128 limit set by gen_adc_controls above
821 rx_val := (rx_val + 2) mod 128;
822 else
823 q_expected := std_logic_vector(to_signed(-rx_val, 16));
824 i_expected := std_logic_vector(to_signed(rx_val, 16));
825 q_out := fx3_gpif.gpif_out(31 downto 16);
826 i_out := fx3_gpif.gpif_out(15 downto 0);
827
828 assert(q_out = q_expected)
829 report "data_q: " & to_hstring(q_out) & " | " &
830 "expected: " & to_hstring(q_expected)
831 severity failure;
832 assert(i_out = i_expected)
833 report "data_i: " & to_hstring(i_out) & " | " &
834 "expected: " & to_hstring(i_expected)
835 severity failure;
836
837 -- 2047 limit set by gen_adc_controls above
838 rx_val := (rx_val + 1) mod 2048;
839 end if;
840 end if;
841 end process look_for_dropped_rx_samples;
842
843 end architecture;