Debian Codegraph @

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