Debian Codegraph @

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

raw
1 -- Copyright (c) 2024 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_packed_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_packed_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 highly_packed_mode : 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 dac_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' );
146
147 function data_gen (count : natural) return std_logic_vector is
148 variable msw, lsw : std_logic_vector(15 downto 0);
149 begin
150 msw := std_logic_vector(to_signed(count, 16));
151 lsw := std_logic_vector(to_signed(-count, 16));
152
153 return (msw & lsw);
154 end function data_gen;
155
156 signal rx_packet_ready : std_logic;
157
158 begin
159
160 -- ========================================================================
161 -- Brief summary of data flow
162 -- ========================================================================
163 --
164 -- Simulated samples flow from fx3_model's TX side to its RX side. The
165 -- validity of the data is checked there.
166 --
167 -- entity U_fx3_model FX3 model, TX process
168 -- signal fx3_gpif_i fx3_gpif.gpif_oe is '0'
169 -- process register_gpif
170 -- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA)
171 -- entity U_fx3_gpif GPIF implementation, write side
172 -- signal tx_sample_fifo.w* TX fifo, write side
173 -- entity U_tx_sample_fifo
174 -- signal tx_sample_fifo.r* TX fifo, read side
175 -- process tx_mux
176 -- signal loopback_fifo.w* Loopback fifo, write side
177 -- entity U_rx_loopback_fifo
178 -- signal loopback_fifo.r* Loopback fifo, read side
179 -- process loopback_fifo_control
180 -- signal loopback_{i,q,valid}
181 -- process rx_mux
182 -- signal rx_mux_{i,q,valid}
183 -- entity U_fifo_writer
184 -- signal rx_sample_fifo.w* RX fifo, write side
185 -- entity U_rx_sample_fifo
186 -- signal rx_sample_fifo.r* RX fifo, read side
187 -- entity U_fx3_gpif GPIF implementation, read side
188 -- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3)
189 -- process register_gpif
190 -- signal fx3_gpif_i fx3_gpif.gpif_oe is '1'
191 -- entity U_fx3_model FX3 model, RX process
192
193
194 -- ========================================================================
195 -- Instantiations
196 -- ========================================================================
197
198 -- Unit under test
199 -- Clock domain: fx3_pclk_pll
200 U_fx3_gpif : entity nuand.fx3_gpif
201 port map (
202 pclk => fx3_pclk_pll,
203 reset => sys_rst,
204 usb_speed => fx3_control.usb_speed,
205 gpif_in => fx3_gpif.gpif_in,
206 gpif_out => fx3_gpif.gpif_out,
207 gpif_oe => fx3_gpif.gpif_oe,
208 ctl_in => fx3_gpif.ctl_in,
209 ctl_out => fx3_gpif.ctl_out,
210 ctl_oe => fx3_gpif.ctl_oe,
211 tx_enable => fx3_control.tx_enable,
212 rx_enable => fx3_control.rx_enable,
213 meta_enable => fx3_control.meta_enable,
214 packet_enable => fx3_control.packet,
215 tx_fifo_write => tx_sample_fifo.wreq,
216 tx_fifo_full => tx_sample_fifo.wfull,
217 tx_fifo_empty => tx_sample_fifo.wempty,
218 tx_fifo_usedw => tx_sample_fifo.wused,
219 tx_fifo_data => tx_sample_fifo.wdata,
220 tx_timestamp => tx_timestamp,
221 tx_meta_fifo_write => tx_meta_fifo.wreq,
222 tx_meta_fifo_full => tx_meta_fifo.wfull,
223 tx_meta_fifo_empty => tx_meta_fifo.wempty,
224 tx_meta_fifo_usedw => tx_meta_fifo.wused,
225 tx_meta_fifo_data => tx_meta_fifo.wdata,
226 rx_fifo_read => rx_sample_fifo.rreq,
227 rx_fifo_full => rx_sample_fifo.rfull,
228 rx_fifo_empty => rx_sample_fifo.rempty,
229 rx_fifo_usedw => rx_sample_fifo.rused,
230 rx_fifo_data => rx_sample_fifo.rdata,
231 rx_meta_fifo_read => rx_meta_fifo.rreq,
232 rx_meta_fifo_full => rx_meta_fifo.rfull,
233 rx_meta_fifo_empty => rx_meta_fifo.rempty,
234 rx_meta_fifo_usedr => rx_meta_fifo.rused,
235 rx_meta_fifo_data => rx_meta_fifo.rdata
236 );
237
238 -- Discrete control signals for fx3_gpif
239 fx3_control.usb_speed <= '0';
240 fx3_control.meta_enable <= '0';
241 fx3_control.packet <= '0';
242 fx3_control.highly_packed_mode <= '1';
243
244 U_pkt_gen : entity nuand.rx_packet_generator
245 port map(
246 rx_clock => rx_clock,
247 rx_reset => rx_reset,
248 rx_enable => fx3_control.rx_enable,
249 rx_packet_enable => fx3_control.packet,
250 rx_packet_ready => rx_packet_ready,
251 rx_packet_control => rx_packet_control
252 );
253
254
255 meta_en_tx <= fx3_control.meta_enable;
256 meta_en_rx <= fx3_control.meta_enable;
257
258 increment_tx_ts : process(tx_clock)
259 variable ping : boolean := true ;
260 begin
261 if( rising_edge(tx_clock) ) then
262 ping := not ping ;
263 if( ping = true ) then
264 tx_timestamp <= tx_timestamp + 1 ;
265 end if ;
266 end if ;
267 end process ;
268
269 increment_rx_ts : process(rx_clock)
270 variable ping : boolean := true ;
271 begin
272 if( rising_edge(rx_clock) ) then
273 ping := not ping ;
274 if( ping = true ) then
275 rx_timestamp <= rx_timestamp + 1 ;
276 end if ;
277 end if ;
278 end process ;
279
280 -- Model of FX3's GPIF interface
281 -- Clock domain: fx3_pclk (source)
282 U_fx3_model : entity nuand.fx3_model(micro_dma)
283 port map (
284 fx3_pclk => fx3_pclk,
285 fx3_gpif => fx3_gpif_i,
286 fx3_ctl => fx3_ctl_i,
287 fx3_uart_rxd => '0',
288 fx3_uart_txd => open,
289 fx3_uart_cts => open,
290 fx3_rx_en => '1',
291 fx3_rx_meta_en => meta_en_rx,
292 fx3_tx_en => '1',
293 fx3_tx_meta_en => meta_en_tx,
294 packed_mode_en => fx3_control.highly_packed_mode,
295 done => done
296 );
297
298 -- Generate phase-shifted PLL clock
299 U_fx3_pll : entity rtl_work.fx3_pll
300 port map (
301 inclk0 => fx3_pclk,
302 areset => pll_reset,
303 c0 => fx3_pclk_pll,
304 locked => pll_locked
305 );
306
307 tx_clock <= not tx_clock after TX_HALF_PERIOD ;
308 rx_clock <= not rx_clock after RX_HALF_PERIOD ;
309
310
311 -- Reset handler
312 sys_rst <= '0' after 100 ns;
313
314 -- Generate system clock
315 sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0';
316
317
318 tx_reset <= sys_rst;
319 tx_ts_reset <= sys_rst;
320 rx_reset <= sys_rst;
321 rx_ts_reset <= sys_rst;
322
323 meta_en_tx <= fx3_control.meta_enable;
324 meta_en_rx <= fx3_control.meta_enable;
325
326 -- TX Submodule
327 U_tx : entity work.tx
328 generic map (
329 NUM_STREAMS => dac_controls'length
330 )
331 port map (
332 tx_reset => tx_reset,
333 tx_clock => tx_clock,
334 tx_enable => fx3_control.tx_enable,
335
336 meta_en => meta_en_tx,
337 timestamp_reset => tx_ts_reset,
338 usb_speed => fx3_control.usb_speed,
339 tx_underflow_led => open,
340 tx_timestamp => tx_timestamp,
341
342 -- Packing modes
343 highly_packed_mode_en => fx3_control.highly_packed_mode,
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 -- Samples from host via FX3
358 sample_fifo_wclock => fx3_pclk_pll,
359 sample_fifo_wreq => tx_sample_fifo.wreq,
360 sample_fifo_wdata => tx_sample_fifo.wdata,
361 sample_fifo_wempty => tx_sample_fifo.wempty,
362 sample_fifo_wfull => tx_sample_fifo.wfull,
363 sample_fifo_wused => tx_sample_fifo.wused,
364
365 -- Metadata from host via FX3
366 meta_fifo_wclock => fx3_pclk_pll,
367 meta_fifo_wreq => tx_meta_fifo.wreq,
368 meta_fifo_wdata => tx_meta_fifo.wdata,
369 meta_fifo_wempty => tx_meta_fifo.wempty,
370 meta_fifo_wfull => tx_meta_fifo.wfull,
371 meta_fifo_wused => tx_meta_fifo.wused,
372
373 -- Digital Loopback Interface
374 loopback_enabled => '0',
375 loopback_fifo_wdata => loopback_fifo.wdata,
376 loopback_fifo_wreq => loopback_fifo.wreq,
377 loopback_fifo_wfull => loopback_fifo.wfull,
378 loopback_fifo_wused => loopback_fifo.wused,
379
380 -- RFFE Interface
381 dac_controls => dac_controls,
382 dac_streams => dac_streams
383 );
384
385 -- RX Submodule
386 U_rx : entity work.rx
387 generic map (
388 NUM_STREAMS => adc_controls'length
389 )
390 port map (
391 highly_packed_mode_en => fx3_control.highly_packed_mode,
392 rx_reset => rx_reset,
393 rx_clock => rx_clock,
394 rx_enable => fx3_control.rx_enable,
395
396 meta_en => meta_en_rx,
397 timestamp_reset => rx_ts_reset,
398 usb_speed => fx3_control.usb_speed,
399 rx_mux_sel => to_unsigned(0, 3),
400 rx_overflow_led => open,
401 rx_timestamp => rx_timestamp,
402
403 -- Triggering
404 trigger_arm => '0',
405 trigger_fire => '0',
406 trigger_master => '0',
407 trigger_line => open,
408 trigger_signal_sync_tb => trigger_signal_sync_tb,
409
410 -- Packet FIFO
411 packet_en => fx3_control.packet,
412 packet_control => rx_packet_control,
413 packet_ready => rx_packet_ready,
414
415 -- Samples to host via FX3
416 sample_fifo_rclock => fx3_pclk_pll,
417 sample_fifo_raclr => not fx3_control.rx_enable,
418 sample_fifo_rreq => rx_sample_fifo.rreq,
419 sample_fifo_rdata => rx_sample_fifo.rdata,
420 sample_fifo_rempty => rx_sample_fifo.rempty,
421 sample_fifo_rfull => rx_sample_fifo.rfull,
422 sample_fifo_rused => rx_sample_fifo.rused,
423
424 -- Mini expansion signals
425 mini_exp => "00",
426
427 -- Metadata to host via FX3
428 meta_fifo_rclock => fx3_pclk_pll,
429 meta_fifo_raclr => not fx3_control.rx_enable,
430 meta_fifo_rreq => rx_meta_fifo.rreq,
431 meta_fifo_rdata => rx_meta_fifo.rdata,
432 meta_fifo_rempty => rx_meta_fifo.rempty,
433 meta_fifo_rfull => rx_meta_fifo.rfull,
434 meta_fifo_rused => rx_meta_fifo.rused,
435
436 -- Digital Loopback Interface
437 loopback_fifo_wenabled => open,
438 loopback_fifo_wreset => tx_reset,
439 loopback_fifo_wclock => tx_clock,
440 loopback_fifo_wdata => loopback_fifo.wdata,
441 loopback_fifo_wreq => loopback_fifo.wreq,
442 loopback_fifo_wfull => loopback_fifo.wfull,
443 loopback_fifo_wused => loopback_fifo.wused,
444
445 -- RFFE Interface
446 adc_controls => adc_controls,
447 adc_streams => adc_streams
448 );
449
450 -- ========================================================================
451 -- Data converters
452 -- ========================================================================
453
454 gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate
455 -- The TX side of the AD9361 HDL is a FIFO pull interface
456 -- that expects a readahead FIFO. It toggles the data request
457 -- signal every other cycle. This behavior is mimicked here.
458 process( tx_clock, sys_rst )
459 begin
460 if( sys_rst = '1' ) then
461 dac_controls <= (
462 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
463 1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
464 );
465 elsif( rising_edge(tx_clock) ) then
466 for i in dac_controls'range loop
467 dac_controls(i) <= (
468 enable => dac_controls(i).enable,
469 data_req => not dac_controls(i).data_req );
470 end loop;
471 end if;
472 end process;
473 else generate
474 dac_controls <= (others => SAMPLE_CONTROL_ENABLE);
475 end generate;
476
477 gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate
478 process( rx_clock, sys_rst )
479 constant COUNT_RESET : integer := 0;
480 variable count : integer range -2047 to 2047 := COUNT_RESET;
481 begin
482 if( sys_rst = '1' ) then
483 count := COUNT_RESET;
484 adc_controls <= (
485 0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
486 1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
487 );
488 elsif( rising_edge(rx_clock) ) then
489 for i in adc_controls'range loop
490 adc_controls(i) <= (
491 enable => adc_controls(i).enable,
492 data_req => not adc_controls(i).data_req );
493 if( adc_controls(i).enable = '1') then
494 if( adc_streams(i).data_v = '1' ) then
495 adc_streams(i).data_i <= to_signed(count, 16);
496 adc_streams(i).data_q <= to_signed(-count, 16);
497 if( count < 2047 ) then
498 count := count + 1;
499 else
500 count := COUNT_RESET;
501 end if;
502 end if;
503 adc_streams(i).data_v <= not adc_streams(i).data_v;
504 end if;
505 end loop;
506 end if;
507 end process;
508 else generate
509 adc_controls <= (others => SAMPLE_CONTROL_ENABLE);
510 end generate;
511
512 -- ========================================================================
513 -- Processes
514 -- ========================================================================
515
516 -- FX3 GPIF bidirectional signal control
517 -- Adapted from same process in bladerf-hosted.vhd
518 register_gpif : process(sys_rst, fx3_pclk_pll)
519 begin
520 if( sys_rst = '1' ) then
521 fx3_gpif_i <= (others => 'Z');
522 fx3_gpif.gpif_in <= (others => 'Z');
523 elsif( rising_edge(fx3_pclk_pll) ) then
524 fx3_gpif.gpif_in <= fx3_gpif_i;
525
526 if( fx3_gpif.gpif_oe = '1' ) then
527 fx3_gpif_i <= fx3_gpif.gpif_out;
528 else
529 fx3_gpif_i <= (others =>'Z');
530 end if;
531 end if;
532 end process;
533
534 -- FX3 CTL bidirectional signals
535 -- Adapted from same generator in bladerf-hosted.vhd
536 generate_ctl : for i in fx3_ctl_i'range generate
537 fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z';
538 end generate;
539
540 fx3_gpif.ctl_in <= fx3_ctl_i;
541
542 -- Controller for loopback FIFO
543 -- Stripped-down version of same process from rx.vhd
544 loopback_fifo_control : process( sys_rst, loopback_fifo.rclock )
545 begin
546 if( sys_rst = '1' ) then
547 loopback_enabled <= '0';
548 loopback_fifo.rreq <= '0';
549 loopback_i <= (others => '0');
550 loopback_q <= (others => '0');
551 loopback_valid <= '0';
552 elsif( rising_edge(loopback_fifo.rclock) ) then
553 loopback_enabled <= '0';
554 loopback_fifo.rreq <= '0';
555 loopback_i <= loopback_i;
556 loopback_q <= loopback_q;
557 loopback_valid <= '0';
558
559 -- Is loopback enabled?
560 loopback_enabled <= fx3_control.rx_enable;
561
562 -- Do the loopback
563 loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length);
564 loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length);
565 loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty;
566
567 -- Read from the FIFO if req'd
568 loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty);
569 end if;
570 end process;
571
572 -- RX multiplexer
573 -- Stripped-down version of same process from rx.vhd
574 rx_mux : process(sys_rst, sys_clk)
575 begin
576 if( sys_rst = '1' ) then
577 rx_mux_i <= (others =>'0');
578 rx_mux_q <= (others =>'0');
579 rx_mux_valid <= '0';
580 elsif( rising_edge(sys_clk) ) then
581 rx_mux_i <= loopback_i;
582 rx_mux_q <= loopback_q;
583 rx_mux_valid <= loopback_valid;
584 end if;
585 end process;
586
587 -- TX multiplexer
588 -- Stripped-down version of mimo_channel_sel_mux from tx.vhd
589 --tx_mux : process( sys_clk )
590 --begin
591 -- if( rising_edge(sys_clk) ) then
592 -- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty;
593
594 -- loopback_fifo.wdata <= tx_sample_fifo.rdata;
595 -- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty;
596 -- end if;
597 --end process;
598
599
600 -- ========================================================================
601 -- Verification
602 -- ========================================================================
603
604 --
605 -- Check for fullness on FIFOs
606 --
607 assert (rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning;
608 assert (tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning;
609 assert (loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning;
610
611 -- Every three gpif transfers will contain 4 samples.
612 -- Let's fill and check a 4 sample buffer every 3 pclk cycles.
613 --
614 -- Note: Failure expected after each fx3_model iteration since we lose
615 -- sample continuity when fifo writer is disabled.
616 look_for_dropped_rx_samples: process(fx3_pclk_pll)
617 variable rx_val : integer;
618 variable gpif_buffer_idx : integer range 0 to 2 := 0;
619 variable buf_sc12q11 : std_logic_vector(3*fx3_gpif.gpif_out'length-1 downto 0) := (others => '0');
620 begin
621 -- Init rx_val
622 if sys_rst = '1' then
623 rx_val := 16#172# when ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1 else 16#B9#;
624 end if;
625
626 if (rising_edge(fx3_pclk_pll)
627 and fx3_gpif.gpif_oe = '1'
628 and fx3_control.rx_enable = '1') then
629
630 -- Shift in the new samples
631 buf_sc12q11 := fx3_gpif.gpif_out & buf_sc12q11(buf_sc12q11'length-1 downto fx3_gpif.gpif_out'length);
632
633 -- Checks the 4 sample buffer every 3 pclk cycles
634 if gpif_buffer_idx = 2 then
635 for i in 0 to 3 loop
636 assert(signed(buf_sc12q11(11+24*i downto 24*i))) = to_signed(rx_val, 12)
637 report "I expected: " & integer'image(rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(11+24*i downto 24*i))))
638 severity failure;
639 assert(signed(buf_sc12q11(23+24*i downto 12+24*i))) = to_signed(-1*rx_val, 12)
640 report "Q expected: " & integer'image(-1*rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(23+24*i downto 12+24*i))))
641 severity failure;
642 rx_val := (rx_val + 1) mod 2048;
643 end loop;
644 end if;
645
646 gpif_buffer_idx := (gpif_buffer_idx + 1) mod 3;
647 end if;
648 end process look_for_dropped_rx_samples;
649
650 look_for_dropped_tx_samples: process(tx_clock)
651 variable tx_val : integer := 0;
652 variable message_count : integer := 1;
653 variable q_expected : integer := 0;
654 variable valid_tx_count : integer := 0;
655 begin
656 if rising_edge(tx_clock) then
657 for i in dac_controls'range loop
658 if dac_streams(i).data_v = '1' then
659 q_expected := tx_val+1 when fx3_control.highly_packed_mode = '1'
660 else to_integer(to_signed(message_count,8) & to_signed(tx_val+1, 8));
661
662 assert(dac_streams(i).data_i = to_signed(tx_val, 16))
663 report "TX("&integer'image(i)&") I expected: " & integer'image(tx_val) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_i)))
664 severity failure;
665 assert(dac_streams(i).data_q = q_expected)
666 report "TX("&integer'image(i)&") Q expected: " & integer'image(q_expected) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_q)))
667 severity failure;
668
669 -- A new message is received every 2048 samples
670 valid_tx_count := valid_tx_count + 1;
671 if valid_tx_count mod 2048 = 0 then
672 message_count := message_count + 1;
673 end if;
674
675 tx_val := (tx_val + 2) when tx_val < 2046 else -2048;
676 end if;
677 end loop;
678 end if;
679 end process look_for_dropped_tx_samples;
680
681 end architecture;