Debian Codegraph @

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