Debian Codegraph @

hdl/fpga/platforms/bladerf-micro/vhdl/tb/rx_timestamp_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 rx_timestamp_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 := '0';
45 EIGHT_BIT_MODE_EN : std_logic := '1'
46 );
47 end entity;
48
49 architecture arch of rx_timestamp_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 <= '1';
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
612 meta_verify: process
613 type timestamp_arr is array (natural range <>) of unsigned(63 downto 0);
614 constant HEADER_LEN : integer := 4;
615 variable timestamp : timestamp_arr(1 downto 0);
616 variable delta : unsigned(63 downto 0) := (others => '0');
617 variable delta_expected : unsigned(63 downto 0);
618 variable iteration : natural := 1;
619 -- variable timestamp : unsigned(63 downto 0) := (others => '0');
620 begin
621 wait for 1 ns;
622 delta_expected := to_unsigned(GPIF_BUF_SIZE_SS-HEADER_LEN, 64) when not EIGHT_BIT_MODE_EN
623 else to_unsigned(2*(GPIF_BUF_SIZE_SS-HEADER_LEN), 64);
624
625 if (ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1) then
626 delta_expected := delta_expected/2;
627 end if;
628
629 for j in 0 to 1 loop
630 wait until rising_edge(fx3_gpif.gpif_oe);
631 for i in 0 to HEADER_LEN-1 loop
632 wait until rising_edge(fx3_pclk_pll);
633 if (i = 1) then
634 timestamp(j)(31 downto 0) := unsigned(fx3_gpif.gpif_out);
635 end if;
636 if (i = 2) then
637 timestamp(j)(63 downto 32) := unsigned(fx3_gpif.gpif_out);
638 end if;
639 -- report "Header ["& integer'image(i) &"] "& to_hstring(fx3_gpif.gpif_out);
640 end loop;
641 report "Timestamp: " & integer'image(to_integer(timestamp(j)));
642 end loop;
643
644 delta := timestamp(1) - timestamp(0);
645 report "Timestamp Delta: " & integer'image(to_integer(delta));
646
647 iteration := iteration + 1;
648 if (iteration mod 3 /= 0) then
649 assert (delta = delta_expected)
650 report lf&"Unexpected Timestamp Delta"&lf&
651 "Expected " & integer'image(to_integer(delta_expected))
652 &" ("& integer'image(to_integer(timestamp(0)) + to_integer(delta_expected)) &")"&lf&
653 "Actual " & integer'image(to_integer(delta))
654 &" ("& integer'image(to_integer(timestamp(1))) &")"
655 severity failure;
656 else
657 report "rst timestamp ignored";
658 end if;
659 end process meta_verify;
660
661 end architecture;