Debian Codegraph @

hdl/fpga/platforms/bladerf-micro/vhdl/tb/fx3_gpif_packet_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 fx3_gpif_packet_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 );
45 end entity;
46
47 architecture arch of fx3_gpif_packet_tb is
48
49 -- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock
50 constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0);
51
52 -- For reasons unknown, simulation of this system in ModelSim requires that
53 -- wrreq and data be asserted shortly before the rising clock edge. Sigh...
54 constant FIFO_WORKAROUND : time := 1 ps;
55
56 type fx3_control_t is record
57 usb_speed : std_logic;
58 tx_enable : std_logic;
59 rx_enable : std_logic;
60 meta_enable : std_logic;
61 packet : std_logic;
62 end record;
63
64 type fx3_gpif_t is record
65 gpif_in : std_logic_vector(31 downto 0);
66 gpif_out : std_logic_vector(31 downto 0);
67 gpif_oe : std_logic;
68 ctl_in : std_logic_vector(12 downto 0);
69 ctl_out : std_logic_vector(12 downto 0);
70 ctl_oe : std_logic_vector(12 downto 0);
71 end record;
72
73 signal sys_rst : std_logic := '1';
74 signal done : boolean := false;
75
76 signal fx3_pclk : std_logic := '1';
77 signal fx3_pclk_pll : std_logic := '1';
78 signal sys_clk : std_logic := '1';
79
80 signal pll_reset : std_logic := '0';
81 signal pll_locked : std_logic := '0';
82 signal fx3_control : fx3_control_t;
83 signal fx3_gpif : fx3_gpif_t;
84 signal fx3_gpif_i : std_logic_vector(31 downto 0);
85 signal fx3_ctl_i : std_logic_vector(12 downto 0);
86
87 -- Control mapping
88 alias dma0_rx_ack is fx3_ctl_i( 0);
89 alias dma1_rx_ack is fx3_ctl_i( 1);
90 alias dma2_tx_ack is fx3_ctl_i( 2);
91 alias dma3_tx_ack is fx3_ctl_i( 3);
92 alias dma_rx_enable is fx3_ctl_i( 4);
93 alias dma_tx_enable is fx3_ctl_i( 5);
94 alias dma_idle is fx3_ctl_i( 6);
95 alias system_reset is fx3_ctl_i( 7);
96 alias dma0_rx_reqx is fx3_ctl_i( 8);
97 alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk
98 alias dma2_tx_reqx is fx3_ctl_i(10);
99 alias dma3_tx_reqx is fx3_ctl_i(11);
100
101 signal loopback_i : signed(15 downto 0) := (others =>'0');
102 signal loopback_q : signed(15 downto 0) := (others =>'0');
103 signal loopback_valid : std_logic := '0';
104 signal loopback_enabled : std_logic := '0';
105
106 signal tx_clock : std_logic := '1' ;
107 signal rx_clock : std_logic := '1' ;
108
109 signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT;
110 signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT;
111 signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT;
112 signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT;
113 signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT;
114
115 signal rx_mux_i : signed(15 downto 0);
116 signal rx_mux_q : signed(15 downto 0);
117 signal rx_mux_valid : std_logic;
118
119 signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' );
120 signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' );
121
122 constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ;
123 constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
124 constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
125
126 signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
127 signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE);
128 signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
129 signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE);
130
131 signal tx_reset : std_logic := '0';
132 signal tx_ts_reset : std_logic := '0';
133 signal rx_reset : std_logic := '0';
134 signal rx_ts_reset : std_logic := '0';
135
136 signal meta_en_tx : std_logic := '0';
137 signal meta_en_rx : std_logic := '0';
138
139 signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT;
140 signal tx_packet_control : packet_control_t;
141 signal tx_packet_len : signed(7 downto 0);
142 signal rx_packet_len : signed(7 downto 0);
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 <= '1';
241 fx3_control.packet <= '1';
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_packet_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 done => done
298 );
299
300 -- Generate phase-shifted PLL clock
301 U_fx3_pll : entity rtl_work.fx3_pll
302 port map (
303 inclk0 => fx3_pclk,
304 areset => pll_reset,
305 c0 => fx3_pclk_pll,
306 locked => pll_locked
307 );
308
309 tx_clock <= not tx_clock after TX_HALF_PERIOD ;
310 rx_clock <= not rx_clock after RX_HALF_PERIOD ;
311
312
313 -- Reset handler
314 sys_rst <= '0' after 100 ns;
315
316 -- Generate system clock
317 sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0';
318
319
320 tx_reset <= sys_rst;
321 tx_ts_reset <= sys_rst;
322 rx_reset <= sys_rst;
323 rx_ts_reset <= sys_rst;
324
325 meta_en_tx <= fx3_control.meta_enable;
326 meta_en_rx <= fx3_control.meta_enable;
327
328 -- TX Submodule
329 U_tx : entity work.tx
330 generic map (
331 NUM_STREAMS => dac_controls'length
332 )
333 port map (
334 tx_reset => tx_reset,
335 tx_clock => tx_clock,
336 tx_enable => fx3_control.tx_enable,
337
338 meta_en => meta_en_tx,
339 timestamp_reset => tx_ts_reset,
340 usb_speed => fx3_control.usb_speed,
341 tx_underflow_led => open,
342 tx_timestamp => tx_timestamp,
343
344 -- Triggering
345 trigger_arm => '0',
346 trigger_fire => '0',
347 trigger_master => '0',
348 trigger_line => open,
349
350 -- Packet FIFO
351 packet_en => fx3_control.packet,
352 packet_empty => open,
353 packet_control => tx_packet_control,
354 packet_ready => '1',
355
356 -- Samples from host via FX3
357 sample_fifo_wclock => fx3_pclk_pll,
358 sample_fifo_wreq => tx_sample_fifo.wreq,
359 sample_fifo_wdata => tx_sample_fifo.wdata,
360 sample_fifo_wempty => tx_sample_fifo.wempty,
361 sample_fifo_wfull => tx_sample_fifo.wfull,
362 sample_fifo_wused => tx_sample_fifo.wused,
363
364 -- Metadata from host via FX3
365 meta_fifo_wclock => fx3_pclk_pll,
366 meta_fifo_wreq => tx_meta_fifo.wreq,
367 meta_fifo_wdata => tx_meta_fifo.wdata,
368 meta_fifo_wempty => tx_meta_fifo.wempty,
369 meta_fifo_wfull => tx_meta_fifo.wfull,
370 meta_fifo_wused => tx_meta_fifo.wused,
371
372 -- Digital Loopback Interface
373 loopback_enabled => '0',
374 loopback_fifo_wdata => loopback_fifo.wdata,
375 loopback_fifo_wreq => loopback_fifo.wreq,
376 loopback_fifo_wfull => loopback_fifo.wfull,
377 loopback_fifo_wused => loopback_fifo.wused,
378
379 -- RFFE Interface
380 dac_controls => dac_controls,
381 dac_streams => dac_streams
382 );
383
384 -- RX Submodule
385 U_rx : entity work.rx
386 generic map (
387 NUM_STREAMS => adc_controls'length
388 )
389 port map (
390 rx_reset => rx_reset,
391 rx_clock => rx_clock,
392 rx_enable => fx3_control.rx_enable,
393
394 meta_en => meta_en_rx,
395 timestamp_reset => rx_ts_reset,
396 usb_speed => fx3_control.usb_speed,
397 rx_mux_sel => to_unsigned(0, 3),
398 rx_overflow_led => open,
399 rx_timestamp => rx_timestamp,
400
401 -- Triggering
402 trigger_arm => '0',
403 trigger_fire => '0',
404 trigger_master => '0',
405 trigger_line => open,
406 trigger_signal_sync_tb => trigger_signal_sync_tb,
407
408 -- Packet FIFO
409 packet_en => fx3_control.packet,
410 packet_control => rx_packet_control,
411 packet_ready => rx_packet_ready,
412
413 -- Samples to host via FX3
414 sample_fifo_rclock => fx3_pclk_pll,
415 sample_fifo_raclr => not fx3_control.rx_enable,
416 sample_fifo_rreq => rx_sample_fifo.rreq,
417 sample_fifo_rdata => rx_sample_fifo.rdata,
418 sample_fifo_rempty => rx_sample_fifo.rempty,
419 sample_fifo_rfull => rx_sample_fifo.rfull,
420 sample_fifo_rused => rx_sample_fifo.rused,
421
422 -- Mini expansion signals
423 mini_exp => "00",
424
425 -- Metadata to host via FX3
426 meta_fifo_rclock => fx3_pclk_pll,
427 meta_fifo_raclr => not fx3_control.rx_enable,
428 meta_fifo_rreq => rx_meta_fifo.rreq,
429 meta_fifo_rdata => rx_meta_fifo.rdata,
430 meta_fifo_rempty => rx_meta_fifo.rempty,
431 meta_fifo_rfull => rx_meta_fifo.rfull,
432 meta_fifo_rused => rx_meta_fifo.rused,
433
434 -- Digital Loopback Interface
435 loopback_fifo_wenabled => open,
436 loopback_fifo_wreset => tx_reset,
437 loopback_fifo_wclock => tx_clock,
438 loopback_fifo_wdata => loopback_fifo.wdata,
439 loopback_fifo_wreq => loopback_fifo.wreq,
440 loopback_fifo_wfull => loopback_fifo.wfull,
441 loopback_fifo_wused => loopback_fifo.wused,
442
443 -- RFFE Interface
444 adc_controls => adc_controls,
445 adc_streams => adc_streams
446 );
447
448 -- ========================================================================
449 -- Data converters
450 -- ========================================================================
451
452 gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate
453 -- The TX side of the AD9361 HDL is a FIFO pull interface
454 -- that expects a readahead FIFO. It toggles the data request
455 -- signal every other cycle. This behavior is mimicked here.
456 process( tx_clock, sys_rst )
457 begin
458 if( sys_rst = '1' ) then
459 dac_controls <= (
460 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
461 1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
462 );
463 elsif( rising_edge(tx_clock) ) then
464 for i in dac_controls'range loop
465 dac_controls(i) <= (
466 enable => dac_controls(i).enable,
467 data_req => not dac_controls(i).data_req );
468 end loop;
469 end if;
470 end process;
471 else generate
472 dac_controls <= (others => SAMPLE_CONTROL_ENABLE);
473 end generate;
474
475 gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate
476 process( rx_clock, sys_rst )
477 constant COUNT_RESET : integer := 0;
478 variable count : integer range -2047 to 2047 := COUNT_RESET;
479 begin
480 if( sys_rst = '1' ) then
481 count := COUNT_RESET;
482 adc_controls <= (
483 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
484 1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
485 );
486 elsif( rising_edge(rx_clock) ) then
487 for i in adc_controls'range loop
488 adc_controls(i) <= (
489 enable => adc_controls(i).enable,
490 data_req => not adc_controls(i).data_req );
491 if( adc_controls(i).enable = '1') then
492 if( adc_streams(i).data_v = '1' ) then
493 adc_streams(i).data_i <= to_signed(count, 16);
494 adc_streams(i).data_q <= to_signed(-count, 16);
495 if( count < 2047 ) then
496 count := count + 1;
497 else
498 count := COUNT_RESET;
499 end if;
500 end if;
501 adc_streams(i).data_v <= not adc_streams(i).data_v;
502 end if;
503 end loop;
504 end if;
505 end process;
506 else generate
507 adc_controls <= (others => SAMPLE_CONTROL_ENABLE);
508 end generate;
509
510 -- ========================================================================
511 -- Processes
512 -- ========================================================================
513
514 -- FX3 GPIF bidirectional signal control
515 -- Adapted from same process in bladerf-hosted.vhd
516 register_gpif : process(sys_rst, fx3_pclk_pll)
517 begin
518 if( sys_rst = '1' ) then
519 fx3_gpif_i <= (others => 'Z');
520 fx3_gpif.gpif_in <= (others => 'Z');
521 elsif( rising_edge(fx3_pclk_pll) ) then
522 fx3_gpif.gpif_in <= fx3_gpif_i;
523
524 if( fx3_gpif.gpif_oe = '1' ) then
525 fx3_gpif_i <= fx3_gpif.gpif_out;
526 else
527 fx3_gpif_i <= (others =>'Z');
528 end if;
529 end if;
530 end process;
531
532 -- FX3 CTL bidirectional signals
533 -- Adapted from same generator in bladerf-hosted.vhd
534 generate_ctl : for i in fx3_ctl_i'range generate
535 fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z';
536 end generate;
537
538 fx3_gpif.ctl_in <= fx3_ctl_i;
539
540 -- Controller for loopback FIFO
541 -- Stripped-down version of same process from rx.vhd
542 loopback_fifo_control : process( sys_rst, loopback_fifo.rclock )
543 begin
544 if( sys_rst = '1' ) then
545 loopback_enabled <= '0';
546 loopback_fifo.rreq <= '0';
547 loopback_i <= (others => '0');
548 loopback_q <= (others => '0');
549 loopback_valid <= '0';
550 elsif( rising_edge(loopback_fifo.rclock) ) then
551 loopback_enabled <= '0';
552 loopback_fifo.rreq <= '0';
553 loopback_i <= loopback_i;
554 loopback_q <= loopback_q;
555 loopback_valid <= '0';
556
557 -- Is loopback enabled?
558 loopback_enabled <= fx3_control.rx_enable;
559
560 -- Do the loopback
561 loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length);
562 loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length);
563 loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty;
564
565 -- Read from the FIFO if req'd
566 loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty);
567 end if;
568 end process;
569
570 -- RX multiplexer
571 -- Stripped-down version of same process from rx.vhd
572 rx_mux : process(sys_rst, sys_clk)
573 begin
574 if( sys_rst = '1' ) then
575 rx_mux_i <= (others =>'0');
576 rx_mux_q <= (others =>'0');
577 rx_mux_valid <= '0';
578 elsif( rising_edge(sys_clk) ) then
579 rx_mux_i <= loopback_i;
580 rx_mux_q <= loopback_q;
581 rx_mux_valid <= loopback_valid;
582 end if;
583 end process;
584
585 -- TX multiplexer
586 -- Stripped-down version of mimo_channel_sel_mux from tx.vhd
587 --tx_mux : process( sys_clk )
588 --begin
589 -- if( rising_edge(sys_clk) ) then
590 -- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty;
591
592 -- loopback_fifo.wdata <= tx_sample_fifo.rdata;
593 -- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty;
594 -- end if;
595 --end process;
596
597
598 -- ========================================================================
599 -- Verification
600 -- ========================================================================
601
602 -- Check for metavalues
603 -- We should never see metavalues written to the FIFOs
604 check_fifo_write: process(fx3_pclk_pll) is
605 begin
606 if( rising_edge(fx3_pclk_pll) ) then
607 if( tx_sample_fifo.wreq = '1' and fx3_control.meta_enable = '0' ) then
608 for i in tx_sample_fifo.wdata'range loop
609 assert tx_sample_fifo.wdata(i) = '0' or tx_sample_fifo.wdata(i) = '1'
610 severity failure;
611 end loop;
612 end if;
613 end if;
614 end process;
615
616 check_fifo_read: process(fx3_pclk_pll) is
617 begin
618 if( rising_edge(fx3_pclk_pll) ) then
619 if( rx_sample_fifo.rreq = '1' ) then
620 for i in rx_sample_fifo.rdata'range loop
621 assert rx_sample_fifo.rdata(i) = '0' or rx_sample_fifo.rdata(i) = '1'
622 severity failure;
623 end loop;
624 end if;
625 end if;
626 end process check_fifo_read;
627
628 -- Check for fullness on FIFOs
629 assert(rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning;
630 assert(tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning;
631 assert(loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning;
632
633 tx_header_check: process
634 type time_state_t is (
635 WAIT_FOR_TIMESTAMP,
636 WAIT_FOR_SAMPLE
637 );
638 variable state : time_state_t := WAIT_FOR_TIMESTAMP;
639 variable timestamp_cntr : unsigned (31 downto 0) := (others => '0');
640 variable min_time_for_save : integer := 350;
641 begin
642 case state is
643 when WAIT_FOR_TIMESTAMP =>
644 wait until rising_edge(dma3_tx_reqx);
645 if fx3_control.meta_enable = '1' then
646 wait until rising_edge(fx3_pclk);
647 tx_packet_len <= signed(fx3_gpif_i(7 downto 0));
648 report "Tx Packet Length: 0x" & to_hstring(fx3_gpif_i(7 downto 0));
649 wait until rising_edge(fx3_pclk);
650 report "Tx Packet Length Saved: " & to_string(to_integer(tx_packet_len));
651 report "Tx Timestamp: 0x" & to_hstring(fx3_gpif_i);
652 timestamp_cntr := unsigned(fx3_gpif_i);
653 report "Tx Timestamp Saved: " & to_string(to_integer(timestamp_cntr));
654 end if;
655 state := WAIT_FOR_SAMPLE;
656
657 when WAIT_FOR_SAMPLE =>
658 while ( timestamp_cntr /= tx_timestamp ) loop
659 assert(tx_timestamp < timestamp_cntr)
660 report "Tx Header timestamp is in the past. Samples " &
661 "usually ignored but considered a failure in tb."
662 severity failure;
663 assert(tx_packet_control.data_valid = '0')
664 report "Tx data being transmitted before expected tx_timestamp."
665 severity failure;
666 wait until rising_edge(tx_clock);
667 end loop;
668 report "TX TIMESTAMP = META TIMESTAMP";
669
670 if( tx_packet_control.data_valid = '1' ) then
671 assert(tx_packet_control.pkt_sop = '1')
672 report "Tx data not seen at expected tx_timestamp."
673 severity failure;
674 end if;
675 state := WAIT_FOR_TIMESTAMP;
676 wait until rising_edge(tx_clock);
677 end case;
678 end process tx_header_check;
679
680 look_for_dropped_tx_packets: process(tx_clock) is
681 constant BLOCKS_PER_ITERATION : natural := 3; --Provided in fx3_model
682 variable current_block_count : natural := 1;
683 variable num_samples_generated : integer := 0;
684 variable num_samples_outstanding : integer := 0;
685 variable iq_value : signed (15 downto 0) := x"0000";
686 variable expected_sample_q : signed (15 downto 0);
687 variable expected_sample_i : signed (15 downto 0);
688 variable expected_data : signed (31 downto 0);
689 begin
690 if( rising_edge(tx_clock) and tx_packet_control.data_valid = '1' )
691 then
692 expected_sample_i := iq_value;
693 expected_sample_q := to_signed(current_block_count, 8) & to_signed(0, 8);
694 expected_data := expected_sample_q & expected_sample_i;
695
696 assert(tx_packet_control.data = std_logic_vector(expected_data))
697 report "tx_packet_control.data: " & to_hstring(tx_packet_control.data) & " | " &
698 "expected_data: " & to_hstring(expected_data)
699 severity failure;
700
701 -- Change the iq values based on blocks received
702 -- See tx_sample_stream's encoding scheme in fx3_model.vhd
703 if( iq_value(7 downto 0) = tx_packet_len - 1 ) then
704 iq_value := x"0000";
705 if( current_block_count <= BLOCKS_PER_ITERATION ) then
706 current_block_count := current_block_count + 1;
707 else
708 current_block_count := 1;
709 end if;
710 else
711 iq_value := (iq_value + 1) mod 2048;
712 end if;
713 end if;
714
715 end process look_for_dropped_tx_packets;
716
717 look_for_dropped_rx_packets: process(fx3_pclk_pll)
718 constant RX_PACKET_LEN : natural := 500; -- Provided in rx_packet_generator.vhd
719 constant HEADER_LEN : natural := 4; -- In clk cycles
720 variable rx_fifo_clear_detected : boolean := false;
721 variable current_block_count : natural := 0;
722 variable header_downcount : natural := HEADER_LEN;
723 variable rx_val : integer := RX_PACKET_LEN; --
724 variable data_expected : std_logic_vector (31 downto 0);
725 variable msw_expected : std_logic_vector (15 downto 0);
726 variable lsw_expected : std_logic_vector (15 downto 0);
727 variable rx_en_flip_flop : std_logic := '0';
728 begin
729 if( rising_edge(fx3_pclk_pll)
730 and fx3_gpif.gpif_oe = '1'
731 and fx3_control.rx_enable = '1' ) then
732
733 rx_en_flip_flop := '1';
734 msw_expected := std_logic_vector(to_unsigned(current_block_count, 16));
735 lsw_expected := std_logic_vector(to_unsigned(rx_val, 16));
736 data_expected := msw_expected & lsw_expected;
737
738 if( header_downcount /= 0 ) then
739 header_downcount := header_downcount - 1;
740 else
741 assert(fx3_gpif.gpif_out = data_expected)
742 report "gpif_out: " & to_hstring(fx3_gpif.gpif_out) & " | " &
743 "expected: " & to_hstring(data_expected)
744 severity failure;
745
746 if( rx_val > 1 ) then
747 rx_val := rx_val - 1;
748 else
749 current_block_count := current_block_count + 1;
750 rx_val := RX_PACKET_LEN;
751 end if;
752 end if;
753 end if;
754
755 if( fx3_gpif.gpif_oe = '0' ) then
756 header_downcount := HEADER_LEN;
757 end if;
758
759 -- Increments block count given a purposely disregarded block by a clear signal
760 rx_fifo_clear_detected := fx3_control.rx_enable = '0' and rx_en_flip_flop = '1';
761 if( rx_fifo_clear_detected ) then
762 rx_en_flip_flop := '0';
763 current_block_count := current_block_count + 1;
764 end if;
765
766 end process look_for_dropped_rx_packets;
767
768 end architecture;