Debian Codegraph @

hdl/fpga/platforms/bladerf-micro/vhdl/bladerf-hosted.vhd

raw
1 -- Copyright (c) 2017 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 use ieee.math_real.all;
25 use ieee.math_complex.all;
26
27 library work;
28 use work.bladerf;
29 use work.bladerf_p.all;
30 use work.fifo_readwrite_p.all;
31
32 architecture hosted_bladerf of bladerf is
33
34 attribute noprune : boolean;
35 attribute keep : boolean;
36
37 alias sys_reset_async : std_logic is fx3_ctl(7);
38 signal sys_reset_pclk : std_logic;
39 signal sys_reset : std_logic;
40
41 signal sys_clock : std_logic;
42 signal sys_clock_out : std_logic;
43 signal sys_pll_locked : std_logic;
44 signal sys_pll_reset : std_logic;
45
46 signal fx3_pclk_pll : std_logic;
47 signal fx3_pclk_pll_out : std_logic;
48 signal fx3_pclk_pll_locked : std_logic;
49 signal fx3_pclk_pll_reset : std_logic;
50
51 signal rx_mux_sel : unsigned(2 downto 0);
52
53 signal nios_xb_gpio_in : std_logic_vector(31 downto 0) := (others => '0');
54 signal nios_xb_gpio_out : std_logic_vector(31 downto 0) := (others => '0');
55 signal nios_xb_gpio_oe : std_logic_vector(31 downto 0) := (others => '0');
56
57 signal nios_gpio : nios_gpio_t;
58 signal nios_gpo_slv : std_logic_vector(31 downto 0);
59
60 signal i2c_scl_in : std_logic;
61 signal i2c_scl_out : std_logic;
62 signal i2c_scl_oen : std_logic;
63
64 signal i2c_sda_in : std_logic;
65 signal i2c_sda_out : std_logic;
66 signal i2c_sda_oen : std_logic;
67
68 signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT;
69 signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT;
70 signal tx_loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT;
71
72 signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT;
73 signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT;
74
75 signal usb_speed_pclk : std_logic;
76 signal usb_speed_rx : std_logic;
77 signal usb_speed_tx : std_logic;
78
79 signal tx_reset : std_logic;
80 signal rx_reset : std_logic;
81
82 signal tx_enable_pclk : std_logic;
83 signal rx_enable_pclk : std_logic;
84
85 signal tx_enable : std_logic;
86 signal rx_enable : std_logic;
87
88 signal meta_en_pclk : std_logic;
89 signal meta_en_tx : std_logic;
90 signal meta_en_rx : std_logic;
91
92 signal eightbit_en_pclk : std_logic;
93 signal eightbit_en_tx : std_logic;
94 signal eightbit_en_rx : std_logic;
95
96 signal highly_packed_en_txrx : std_logic;
97
98 signal packet_en_pclk : std_logic;
99 signal packet_en_tx : std_logic;
100 signal packet_en_rx : std_logic;
101
102 signal tx_timestamp : unsigned(63 downto 0);
103 signal rx_timestamp : unsigned(63 downto 0);
104 signal timestamp_sync : std_logic;
105
106 signal tx_loopback_enabled : std_logic := '0';
107
108 signal fx3_gpif_in : std_logic_vector(31 downto 0);
109 signal fx3_gpif_out : std_logic_vector(31 downto 0);
110 signal fx3_gpif_oe : std_logic;
111
112 signal fx3_ctl_in : std_logic_vector(12 downto 0);
113 signal fx3_ctl_out : std_logic_vector(12 downto 0);
114 signal fx3_ctl_oe : std_logic_vector(12 downto 0);
115
116 signal tx_underflow_led : std_logic := '1';
117 signal rx_overflow_led : std_logic := '1';
118
119 signal led1_blink : std_logic;
120
121 signal nios_sdo : std_logic;
122 signal nios_sdio : std_logic;
123 signal nios_sclk : std_logic;
124 signal nios_ss_n : std_logic_vector(1 downto 0);
125
126 signal command_serial_in : std_logic;
127 signal command_serial_out : std_logic;
128
129 signal timestamp_req : std_logic;
130 signal timestamp_ack : std_logic;
131 signal fx3_timestamp : unsigned(63 downto 0);
132
133 signal rx_ts_reset : std_logic;
134 signal tx_ts_reset : std_logic;
135
136 signal rx_trigger_ctl_i : std_logic_vector(7 downto 0);
137 signal rx_trigger_ctl : trigger_t := TRIGGER_T_DEFAULT;
138 alias rx_trigger_line : std_logic is mini_exp1;
139
140 signal tx_trigger_ctl_i : std_logic_vector(7 downto 0);
141 signal tx_trigger_ctl : trigger_t := TRIGGER_T_DEFAULT;
142 alias tx_trigger_line : std_logic is mini_exp1;
143
144 signal rffe_gpio : rffe_gpio_t := (
145 i => RFFE_GPI_DEFAULT,
146 o => pack(RFFE_GPO_DEFAULT)
147 );
148
149 signal ad9361 : mimo_2r2t_t := MIMO_2R2T_T_DEFAULT;
150 alias tx_clock is ad9361.clock;
151 alias rx_clock is ad9361.clock;
152
153 signal mimo_rx_enables : std_logic_vector(RFFE_GPO_DEFAULT.mimo_rx_en'range) := RFFE_GPO_DEFAULT.mimo_rx_en;
154 signal mimo_tx_enables : std_logic_vector(RFFE_GPO_DEFAULT.mimo_tx_en'range) := RFFE_GPO_DEFAULT.mimo_tx_en;
155
156 signal dac_controls : sample_controls_t(ad9361.ch'range) := (others => SAMPLE_CONTROL_DISABLE);
157 signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE);
158 signal adc_controls : sample_controls_t(ad9361.ch'range) := (others => SAMPLE_CONTROL_DISABLE);
159 signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE);
160 signal adc_streams_last_v : std_logic_vector(adc_controls'range) := (others => '0');
161
162 signal ps_sync : std_logic_vector(0 downto 0) := (others => '0');
163
164
165 signal tx_packet_control : packet_control_t ;
166 signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT ;
167
168 signal rx_packet_ready : std_logic;
169
170 signal tx_packet_ready : std_logic;
171 signal tx_packet_empty : std_logic;
172
173
174 signal wbm_wb_clk_i : std_logic;
175 signal wbm_wb_rst_i : std_logic;
176 signal wbm_wb_adr_o : std_logic_vector(31 downto 0);
177 signal wbm_wb_dat_o : std_logic_vector(31 downto 0);
178 signal wbm_wb_dat_i : std_logic_vector(31 downto 0);
179 signal wbm_wb_we_o : std_logic;
180 signal wbm_wb_sel_o : std_logic;
181 signal wbm_wb_stb_o : std_logic;
182 signal wbm_wb_ack_i : std_logic;
183 signal wbm_wb_cyc_o : std_logic;
184 begin
185
186 U_rx_pkt_gen : entity work.rx_packet_generator
187 port map(
188 rx_clock => rx_clock,
189 rx_reset => rx_reset,
190
191 rx_packet_ready => rx_packet_ready,
192
193 rx_enable => rx_enable,
194 rx_packet_enable => packet_en_rx,
195
196 rx_packet_control => rx_packet_control
197 ) ;
198
199
200 -- ========================================================================
201 -- PLLs
202 -- ========================================================================
203
204 -- Create 80 MHz system clock from 38.4 MHz
205 U_system_pll : component system_pll
206 port map (
207 refclk => c5_clock2,
208 rst => sys_pll_reset,
209 outclk_0 => sys_clock_out,
210 locked => sys_pll_locked
211 );
212
213 U_system_pll_ctrl : component clk_ctrl
214 port map (
215 inclk => sys_clock_out,
216 ena => sys_pll_locked,
217 outclk => sys_clock
218 );
219
220 U_pll_reset_pll : entity work.pll_reset
221 generic map (
222 SYS_CLOCK_FREQ_HZ => 38_400_000,
223 DEVICE_FAMILY => "Cyclone V"
224 )
225 port map (
226 sys_clock => c5_clock2,
227 pll_locked => sys_pll_locked,
228 pll_reset => sys_pll_reset
229 );
230
231 -- Use PLL to adjust the phase of the FX3 PCLK to
232 -- retime the FX3 GPIF interface for timing closure.
233 U_fx3_pll : component fx3_pll
234 port map (
235 refclk => fx3_pclk,
236 rst => fx3_pclk_pll_reset,
237 outclk_0 => fx3_pclk_pll_out,
238 locked => fx3_pclk_pll_locked
239 );
240
241 U_fx3_pll_ctrl : component clk_ctrl
242 port map (
243 inclk => fx3_pclk_pll_out,
244 ena => fx3_pclk_pll_locked,
245 outclk => fx3_pclk_pll
246 );
247
248 U_pll_reset_fx3_pll : entity work.pll_reset
249 generic map (
250 SYS_CLOCK_FREQ_HZ => 100_000_000,
251 DEVICE_FAMILY => "Cyclone V"
252 )
253 port map (
254 sys_clock => fx3_pclk,
255 pll_locked => fx3_pclk_pll_locked,
256 pll_reset => fx3_pclk_pll_reset
257 );
258
259
260 -- ========================================================================
261 -- POWER SUPPLY SYNCHRONIZATION
262 -- ========================================================================
263
264 U_ps_sync : entity work.ps_sync
265 generic map (
266 OUTPUTS => 1,
267 USE_LFSR => true,
268 HOP_LIST => adp2384_sync_divisors( REFCLK_HZ => 38.4e6,
269 n_divisors => 7 ),
270 HOP_RATE => 100
271 )
272 port map (
273 refclk => c5_clock2,
274 sync => ps_sync
275 );
276
277 ps_sync_1p1 <= ps_sync(0);
278 ps_sync_1p8 <= ps_sync(0);
279
280 -- ========================================================================
281 -- FX3 GPIF
282 -- ========================================================================
283
284 -- FX3 GPIF
285 U_fx3_gpif : entity work.fx3_gpif
286 port map (
287 pclk => fx3_pclk_pll,
288 reset => sys_reset_pclk,
289
290 usb_speed => usb_speed_pclk,
291
292 meta_enable => meta_en_pclk,
293 packet_enable => packet_en_pclk,
294 rx_enable => rx_enable_pclk,
295 tx_enable => tx_enable_pclk,
296
297 gpif_in => fx3_gpif_in,
298 gpif_out => fx3_gpif_out,
299 gpif_oe => fx3_gpif_oe,
300 ctl_in => fx3_ctl_in,
301 ctl_out => fx3_ctl_out,
302 ctl_oe => fx3_ctl_oe,
303
304 tx_fifo_write => tx_sample_fifo.wreq,
305 tx_fifo_full => tx_sample_fifo.wfull,
306 tx_fifo_empty => tx_sample_fifo.wempty,
307 tx_fifo_usedw => tx_sample_fifo.wused,
308 tx_fifo_data => tx_sample_fifo.wdata,
309
310 tx_timestamp => fx3_timestamp,
311 tx_meta_fifo_write => tx_meta_fifo.wreq,
312 tx_meta_fifo_full => tx_meta_fifo.wfull,
313 tx_meta_fifo_empty => tx_meta_fifo.wempty,
314 tx_meta_fifo_usedw => tx_meta_fifo.wused,
315 tx_meta_fifo_data => tx_meta_fifo.wdata,
316
317 rx_fifo_read => rx_sample_fifo.rreq,
318 rx_fifo_full => rx_sample_fifo.rfull,
319 rx_fifo_empty => rx_sample_fifo.rempty,
320 rx_fifo_usedw => rx_sample_fifo.rused,
321 rx_fifo_data => rx_sample_fifo.rdata,
322
323 rx_meta_fifo_read => rx_meta_fifo.rreq,
324 rx_meta_fifo_full => rx_meta_fifo.rfull,
325 rx_meta_fifo_empty => rx_meta_fifo.rempty,
326 rx_meta_fifo_usedr => rx_meta_fifo.rused,
327 rx_meta_fifo_data => rx_meta_fifo.rdata
328 );
329
330 -- FX3 GPIF bidirectional signal control
331 register_gpif : process(sys_reset_pclk, fx3_pclk_pll)
332 begin
333 if( sys_reset_pclk = '1' ) then
334 fx3_gpif <= (others =>'Z');
335 fx3_gpif_in <= (others =>'0');
336 elsif( rising_edge(fx3_pclk_pll) ) then
337 fx3_gpif_in <= fx3_gpif;
338 if( fx3_gpif_oe = '1' ) then
339 fx3_gpif <= fx3_gpif_out;
340 else
341 fx3_gpif <= (others =>'Z');
342 end if;
343 end if;
344 end process;
345
346 -- FX3 CTL bidirectional signal control
347 generate_ctl : for i in fx3_ctl'range generate
348 fx3_ctl(i) <= fx3_ctl_out(i) when fx3_ctl_oe(i) = '1' else 'Z';
349 end generate;
350
351 fx3_ctl_in <= fx3_ctl;
352
353 toggle_led1 : process(fx3_pclk_pll)
354 variable count : natural range 0 to 10_000_000 := 10_000_000;
355 begin
356 if( rising_edge(fx3_pclk_pll) ) then
357 count := count - 1;
358 if( count = 0 ) then
359 count := 10_000_000;
360 led1_blink <= not led1_blink;
361 end if;
362 end if;
363 end process;
364
365
366 -- ========================================================================
367 -- NIOS SYSTEM
368 -- ========================================================================
369
370 U_nios_system : component nios_system
371 port map (
372 clk_clk => sys_clock,
373 reset_reset_n => '1',
374 dac_MISO => nios_sdo,
375 dac_MOSI => nios_sdio,
376 dac_SCLK => nios_sclk,
377 dac_SS_n => nios_ss_n,
378 spi_MISO => adi_spi_sdo,
379 spi_MOSI => adi_spi_sdi,
380 spi_SCLK => adi_spi_sclk,
381 spi_SS_n => adi_spi_csn,
382 gpio_in_port => pack(nios_gpio.i, '0'),
383 gpio_out_port => nios_gpo_slv,
384 gpio_rffe_0_in_port => pack(rffe_gpio),
385 gpio_rffe_0_out_port => rffe_gpio.o,
386 ad9361_dac_sync_in_sync => '0',
387 ad9361_dac_sync_out_sync => adi_sync_in,
388 ad9361_data_clock_clk => ad9361.clock, -- out std_logic;
389 ad9361_data_reset_reset => ad9361.reset, -- out std_logic;
390 ad9361_device_if_rx_clk_in_p => adi_rx_clock,
391 ad9361_device_if_rx_clk_in_n => '0',
392 ad9361_device_if_rx_frame_in_p => adi_rx_frame,
393 ad9361_device_if_rx_frame_in_n => '0',
394 ad9361_device_if_rx_data_in_p => adi_rx_data,
395 ad9361_device_if_rx_data_in_n => (others => '0'),
396 ad9361_device_if_tx_clk_out_p => adi_tx_clock,
397 ad9361_device_if_tx_clk_out_n => open,
398 ad9361_device_if_tx_frame_out_p => adi_tx_frame,
399 ad9361_device_if_tx_frame_out_n => open,
400 ad9361_device_if_tx_data_out_p => adi_tx_data,
401 ad9361_device_if_tx_data_out_n => open,
402 ad9361_adc_i0_enable => ad9361.ch(0).adc.i.enable, -- out sl
403 ad9361_adc_i0_valid => ad9361.ch(0).adc.i.valid, -- out sl
404 ad9361_adc_i0_data => ad9361.ch(0).adc.i.data, -- out slv(15:0)
405 ad9361_adc_i1_enable => ad9361.ch(1).adc.i.enable, -- out sl
406 ad9361_adc_i1_valid => ad9361.ch(1).adc.i.valid, -- out sl
407 ad9361_adc_i1_data => ad9361.ch(1).adc.i.data, -- out slv(15:0)
408 ad9361_adc_overflow_ovf => ad9361.adc_overflow, -- in sl
409 ad9361_adc_q0_enable => ad9361.ch(0).adc.q.enable, -- out sl
410 ad9361_adc_q0_valid => ad9361.ch(0).adc.q.valid, -- out sl
411 ad9361_adc_q0_data => ad9361.ch(0).adc.q.data, -- out slv(15:0)
412 ad9361_adc_q1_enable => ad9361.ch(1).adc.q.enable, -- out sl
413 ad9361_adc_q1_valid => ad9361.ch(1).adc.q.valid, -- out sl
414 ad9361_adc_q1_data => ad9361.ch(1).adc.q.data, -- out slv(15:0)
415 ad9361_adc_underflow_unf => ad9361.adc_underflow, -- in sl
416 ad9361_dac_i0_enable => ad9361.ch(0).dac.i.enable, -- out sl
417 ad9361_dac_i0_valid => ad9361.ch(0).dac.i.valid, -- out sl
418 ad9361_dac_i0_data => ad9361.ch(0).dac.i.data, -- in slv(15:0)
419 ad9361_dac_i1_enable => ad9361.ch(1).dac.i.enable, -- out sl
420 ad9361_dac_i1_valid => ad9361.ch(1).dac.i.valid, -- out sl
421 ad9361_dac_i1_data => ad9361.ch(1).dac.i.data, -- in slv(15:0)
422 ad9361_dac_overflow_ovf => ad9361.dac_overflow, -- in sl
423 ad9361_dac_q0_enable => ad9361.ch(0).dac.q.enable, -- out sl
424 ad9361_dac_q0_valid => ad9361.ch(0).dac.q.valid, -- out sl
425 ad9361_dac_q0_data => ad9361.ch(0).dac.q.data, -- in slv(15:0)
426 ad9361_dac_q1_enable => ad9361.ch(1).dac.q.enable, -- out sl
427 ad9361_dac_q1_valid => ad9361.ch(1).dac.q.valid, -- out sl
428 ad9361_dac_q1_data => ad9361.ch(1).dac.q.data, -- in slv(15:0)
429 ad9361_dac_underflow_unf => ad9361.dac_underflow, -- in sl
430 xb_gpio_in_port => nios_xb_gpio_in,
431 xb_gpio_out_port => nios_xb_gpio_out,
432 xb_gpio_dir_export => nios_xb_gpio_oe,
433 command_serial_in => command_serial_in,
434 command_serial_out => command_serial_out,
435 oc_i2c_arst_i => '0',
436 oc_i2c_scl_pad_i => i2c_scl_in,
437 oc_i2c_scl_pad_o => i2c_scl_out,
438 oc_i2c_scl_padoen_o => i2c_scl_oen,
439 oc_i2c_sda_pad_i => i2c_sda_in,
440 oc_i2c_sda_pad_o => i2c_sda_out,
441 oc_i2c_sda_padoen_o => i2c_sda_oen,
442 rx_tamer_ts_sync_in => '0',
443 rx_tamer_ts_sync_out => open,
444 rx_tamer_ts_pps => '0',
445 rx_tamer_ts_clock => rx_clock,
446 rx_tamer_ts_reset => rx_ts_reset,
447 unsigned(rx_tamer_ts_time) => rx_timestamp,
448 tx_tamer_ts_sync_in => '0',
449 tx_tamer_ts_sync_out => open,
450 tx_tamer_ts_pps => '0',
451 tx_tamer_ts_clock => tx_clock,
452 tx_tamer_ts_reset => tx_ts_reset,
453 unsigned(tx_tamer_ts_time) => tx_timestamp,
454 rx_trigger_ctl_out_port => rx_trigger_ctl_i,
455 tx_trigger_ctl_out_port => tx_trigger_ctl_i,
456 rx_trigger_ctl_in_port => pack(rx_trigger_ctl),
457 tx_trigger_ctl_in_port => pack(tx_trigger_ctl),
458 wbm_wb_clk_i => wbm_wb_clk_i,
459 wbm_wb_rst_i => wbm_wb_rst_i,
460 wbm_wb_adr_o => wbm_wb_adr_o,
461 wbm_wb_dat_o => wbm_wb_dat_o,
462 wbm_wb_dat_i => wbm_wb_dat_i,
463 wbm_wb_we_o => wbm_wb_we_o,
464 wbm_wb_sel_o => wbm_wb_sel_o,
465 wbm_wb_stb_o => wbm_wb_stb_o,
466 wbm_wb_ack_i => wbm_wb_ack_i,
467 wbm_wb_cyc_o => wbm_wb_cyc_o
468 );
469
470 -- FX3 UART
471 command_serial_in <= fx3_uart_txd when sys_reset = '0' else '1';
472 fx3_uart_rxd <= command_serial_out when sys_reset = '0' else 'Z';
473
474 -- FX3 UART CTS and Flash SPI CSx are tied to the same signal.
475 -- Allow SPI accesses when FPGA is in reset
476 fx3_uart_cts <= '1' when sys_reset_pclk = '0' else 'Z';
477
478 -- Unpack the Nios general-purpose outputs into a record
479 nios_gpio.o <= unpack(nios_gpo_slv);
480
481 -- Readback of Nios general-purpose outputs
482 nios_gpio.i.gpo_readback <= nios_gpio.o;
483
484 -- RFFE GPIO outputs
485 adi_ctrl_in <= unpack(rffe_gpio.o).ctrl_in;
486 adi_tx_spdt2_v <= unpack(rffe_gpio.o).tx_spdt2;
487 adi_tx_spdt1_v <= unpack(rffe_gpio.o).tx_spdt1;
488 tx_bias_en <= unpack(rffe_gpio.o).tx_bias_en;
489 adi_rx_spdt2_v <= unpack(rffe_gpio.o).rx_spdt2;
490 adi_rx_spdt1_v <= unpack(rffe_gpio.o).rx_spdt1;
491 rx_bias_en <= unpack(rffe_gpio.o).rx_bias_en;
492 --adi_sync_in <= unpack(rffe_gpio.o).sync_in;
493 adi_en_agc <= unpack(rffe_gpio.o).en_agc;
494 adi_txnrx <= unpack(rffe_gpio.o).txnrx;
495 adi_enable <= unpack(rffe_gpio.o).enable;
496 adi_reset_n <= unpack(rffe_gpio.o).reset_n;
497
498 -- Unpack trigger GPIO bits into records
499 rx_trigger_ctl <= unpack(rx_trigger_ctl_i, rx_trigger_line);
500 tx_trigger_ctl <= unpack(tx_trigger_ctl_i, tx_trigger_line);
501
502 -- LEDs
503 led(1) <= led1_blink when nios_gpio.o.led_mode = '0' else not nios_gpio.o.leds(1);
504 led(2) <= tx_underflow_led when nios_gpio.o.led_mode = '0' else not nios_gpio.o.leds(2);
505 led(3) <= rx_overflow_led when nios_gpio.o.led_mode = '0' else not nios_gpio.o.leds(3);
506
507 -- DAC SPI (data latched on falling edge)
508 dac_sclk <= not nios_sclk when nios_gpio.o.adf_chip_enable = '0' else '0';
509 dac_sdi <= nios_sdio when nios_gpio.o.adf_chip_enable = '0' else '0';
510 dac_csn <= nios_ss_n(0) when nios_gpio.o.adf_chip_enable = '0' else '1';
511
512 -- ADF SPI (data latched on rising edge)
513 adf_sclk <= nios_sclk when nios_gpio.o.adf_chip_enable = '1' else '0';
514 adf_sdi <= nios_sdio when nios_gpio.o.adf_chip_enable = '1' else '0';
515 adf_csn <= nios_ss_n(1) when nios_gpio.o.adf_chip_enable = '1' else '1';
516 adf_ce <= nios_gpio.o.adf_chip_enable;
517
518 nios_sdo <= adf_muxout when ((nios_ss_n(1) = '0') and (nios_gpio.o.adf_chip_enable = '1'))
519 else '0';
520
521 -- Power monitor I2C
522 pwr_scl <= i2c_scl_out when i2c_scl_oen = '0' else 'Z';
523 pwr_sda <= i2c_sda_out when i2c_sda_oen = '0' else 'Z';
524
525 i2c_scl_in <= pwr_scl;
526 i2c_sda_in <= pwr_sda;
527
528 -- TPS2115A status
529 nios_gpio.i.pwr_status <= pwr_status;
530
531 -- SI53304 controls / clock output enables
532 si_clock_sel <= nios_gpio.o.si_clock_sel;
533 c5_clock2_oe <= '1';
534 exp_clock_oe <= exp_present and exp_clock_req;
535 ufl_clock_oe <= nios_gpio.o.ufl_clock_oe;
536
537 -- Expansion I2C
538 exp_i2c_scl <= 'Z';
539 exp_i2c_sda <= 'Z';
540
541 -- Expansion GPIO outputs
542 generate_xb_gpio_out : for i in exp_gpio'range generate
543 exp_gpio(i) <= nios_xb_gpio_out(i) when nios_xb_gpio_oe(i) = '1' else 'Z';
544 end generate;
545
546 tx_packet_ready <= '1';
547
548 -- TX Submodule
549 U_tx : entity work.tx
550 generic map (
551 NUM_STREAMS => dac_controls'length
552 )
553 port map (
554 tx_reset => tx_reset,
555 tx_clock => tx_clock,
556 tx_enable => tx_enable,
557
558 meta_en => meta_en_tx,
559 timestamp_reset => tx_ts_reset,
560 usb_speed => usb_speed_tx,
561 tx_underflow_led => tx_underflow_led,
562 tx_timestamp => tx_timestamp,
563
564 -- Triggering
565 trigger_arm => tx_trigger_ctl.arm,
566 trigger_fire => tx_trigger_ctl.fire,
567 trigger_master => tx_trigger_ctl.master,
568 trigger_line => tx_trigger_line,
569
570 -- Eightbit mode
571 eight_bit_mode_en => eightbit_en_tx,
572 highly_packed_mode_en => highly_packed_en_txrx,
573
574 -- Packet FIFO
575 packet_en => packet_en_tx,
576 packet_empty => tx_packet_empty,
577 packet_control => tx_packet_control,
578 packet_ready => tx_packet_ready,
579
580 -- Samples from host via FX3
581 sample_fifo_wclock => fx3_pclk_pll,
582 sample_fifo_wreq => tx_sample_fifo.wreq,
583 sample_fifo_wdata => tx_sample_fifo.wdata,
584 sample_fifo_wempty => tx_sample_fifo.wempty,
585 sample_fifo_wfull => tx_sample_fifo.wfull,
586 sample_fifo_wused => tx_sample_fifo.wused,
587
588 -- Metadata from host via FX3
589 meta_fifo_wclock => fx3_pclk_pll,
590 meta_fifo_wreq => tx_meta_fifo.wreq,
591 meta_fifo_wdata => tx_meta_fifo.wdata,
592 meta_fifo_wempty => tx_meta_fifo.wempty,
593 meta_fifo_wfull => tx_meta_fifo.wfull,
594 meta_fifo_wused => tx_meta_fifo.wused,
595
596 -- Digital Loopback Interface
597 loopback_enabled => tx_loopback_enabled,
598 loopback_fifo_wclock => tx_loopback_fifo.wclock,
599 loopback_fifo_wdata => tx_loopback_fifo.wdata,
600 loopback_fifo_wreq => tx_loopback_fifo.wreq,
601 loopback_fifo_wfull => tx_loopback_fifo.wfull,
602 loopback_fifo_wused => tx_loopback_fifo.wused,
603
604 -- RFFE Interface
605 dac_controls => dac_controls,
606 dac_streams => dac_streams
607 );
608
609 dac_assignment_proc : process( all )
610 begin
611 for i in dac_controls'range loop
612 dac_controls(i).enable <= (ad9361.ch(i).dac.i.enable or ad9361.ch(i).dac.q.enable or tx_loopback_enabled) and
613 mimo_tx_enables(i);
614 dac_controls(i).data_req <= (ad9361.ch(i).dac.i.valid or ad9361.ch(i).dac.q.valid or tx_loopback_enabled) and
615 mimo_tx_enables(i);
616
617 if (rising_edge(tx_clock) and dac_streams(i).data_v = '1') then
618 ad9361.ch(i).dac.i.data <= std_logic_vector(dac_streams(i).data_i(11 downto 0)) & "0000";
619 ad9361.ch(i).dac.q.data <= std_logic_vector(dac_streams(i).data_q(11 downto 0)) & "0000";
620 end if;
621 end loop;
622 end process;
623
624 -- RX Submodule
625 U_rx : entity work.rx
626 generic map (
627 NUM_STREAMS => adc_controls'length
628 )
629 port map (
630 rx_reset => rx_reset,
631 rx_clock => rx_clock,
632 rx_enable => rx_enable,
633
634 meta_en => meta_en_rx,
635 timestamp_reset => rx_ts_reset,
636 usb_speed => usb_speed_rx,
637 rx_mux_sel => rx_mux_sel,
638 rx_overflow_led => rx_overflow_led,
639 rx_timestamp => rx_timestamp,
640
641 -- Triggering
642 trigger_arm => rx_trigger_ctl.arm,
643 trigger_fire => rx_trigger_ctl.fire,
644 trigger_master => rx_trigger_ctl.master,
645 trigger_line => rx_trigger_line,
646
647 -- Packed modes
648 eight_bit_mode_en => eightbit_en_rx,
649 highly_packed_mode_en => highly_packed_en_txrx,
650
651 -- Packet FIFO
652 packet_en => packet_en_rx,
653 packet_control => rx_packet_control,
654 packet_ready => rx_packet_ready,
655
656 -- Samples to host via FX3
657 sample_fifo_rclock => fx3_pclk_pll,
658 sample_fifo_raclr => not rx_enable_pclk,
659 sample_fifo_rreq => rx_sample_fifo.rreq,
660 sample_fifo_rdata => rx_sample_fifo.rdata,
661 sample_fifo_rempty => rx_sample_fifo.rempty,
662 sample_fifo_rfull => rx_sample_fifo.rfull,
663 sample_fifo_rused => rx_sample_fifo.rused,
664
665 -- Mini expansion signals
666 mini_exp => mini_exp2 & mini_exp1,
667
668 -- Metadata to host via FX3
669 meta_fifo_rclock => fx3_pclk_pll,
670 meta_fifo_raclr => not rx_enable_pclk,
671 meta_fifo_rreq => rx_meta_fifo.rreq,
672 meta_fifo_rdata => rx_meta_fifo.rdata,
673 meta_fifo_rempty => rx_meta_fifo.rempty,
674 meta_fifo_rfull => rx_meta_fifo.rfull,
675 meta_fifo_rused => rx_meta_fifo.rused,
676
677 -- Digital Loopback Interface
678 loopback_fifo_wenabled => tx_loopback_enabled,
679 loopback_fifo_wreset => tx_reset,
680 loopback_fifo_wclock => tx_loopback_fifo.wclock,
681 loopback_fifo_wdata => tx_loopback_fifo.wdata,
682 loopback_fifo_wreq => tx_loopback_fifo.wreq,
683 loopback_fifo_wfull => tx_loopback_fifo.wfull,
684 loopback_fifo_wused => tx_loopback_fifo.wused,
685
686 -- RFFE Interface
687 adc_controls => adc_controls,
688 adc_streams => adc_streams
689 );
690
691 adc_assignment_proc : process( all )
692 begin
693 for i in adc_controls'range loop
694 adc_controls(i).enable <= (ad9361.ch(i).adc.i.enable or ad9361.ch(i).adc.q.enable) and mimo_rx_enables(i);
695 adc_controls(i).data_req <= '1';
696 adc_streams(i).data_i <= signed(ad9361.ch(i).adc.i.data);
697 adc_streams(i).data_q <= signed(ad9361.ch(i).adc.q.data);
698 adc_streams(i).data_v <= (ad9361.ch(i).adc.i.valid or ad9361.ch(i).adc.q.valid) and not adc_streams_last_v(i);
699 end loop;
700 end process;
701
702 process(rx_clock)
703 begin
704 if( rx_reset = '1' ) then
705 adc_streams_last_v <= ( others => '0' ) ;
706 elsif( rising_edge( rx_clock ) ) then
707 for i in adc_controls'range loop
708 adc_streams_last_v(i) <= ad9361.ch(i).adc.i.valid or ad9361.ch(i).adc.q.valid;
709 end loop;
710 end if;
711 end process;
712
713 -- ========================================================================
714 -- RESET SYNCHRONIZERS
715 -- ========================================================================
716
717 U_reset_sync_pclk : entity work.reset_synchronizer
718 generic map (
719 INPUT_LEVEL => '1',
720 OUTPUT_LEVEL => '1'
721 )
722 port map (
723 clock => fx3_pclk_pll,
724 async => sys_reset_async,
725 sync => sys_reset_pclk
726 );
727
728 U_reset_sync_sys : entity work.reset_synchronizer
729 generic map (
730 INPUT_LEVEL => '1',
731 OUTPUT_LEVEL => '1'
732 )
733 port map (
734 clock => sys_clock,
735 async => sys_reset_async,
736 sync => sys_reset
737 );
738
739 U_reset_sync_rx : entity work.reset_synchronizer
740 generic map (
741 INPUT_LEVEL => '1',
742 OUTPUT_LEVEL => '1'
743 )
744 port map (
745 clock => rx_clock,
746 async => sys_reset_pclk,
747 sync => rx_reset
748 );
749
750 U_reset_sync_tx : entity work.reset_synchronizer
751 generic map (
752 INPUT_LEVEL => '1',
753 OUTPUT_LEVEL => '1'
754 )
755 port map (
756 clock => tx_clock,
757 async => sys_reset_pclk,
758 sync => tx_reset
759 );
760
761
762 -- ========================================================================
763 -- SYNCHRONIZERS
764 -- ========================================================================
765
766 U_sync_usb_speed_pclk : entity work.synchronizer
767 generic map (
768 RESET_LEVEL => '0'
769 )
770 port map (
771 reset => '0',
772 clock => fx3_pclk_pll,
773 async => nios_gpio.o.usb_speed,
774 sync => usb_speed_pclk
775 );
776
777 U_sync_usb_speed_rx : entity work.synchronizer
778 generic map (
779 RESET_LEVEL => '0'
780 )
781 port map (
782 reset => '0',
783 clock => rx_clock,
784 async => nios_gpio.o.usb_speed,
785 sync => usb_speed_rx
786 );
787
788 U_sync_usb_speed_tx : entity work.synchronizer
789 generic map (
790 RESET_LEVEL => '0'
791 )
792 port map (
793 reset => '0',
794 clock => tx_clock,
795 async => nios_gpio.o.usb_speed,
796 sync => usb_speed_tx
797 );
798
799
800 U_sync_meta_en_pclk : entity work.synchronizer
801 generic map (
802 RESET_LEVEL => '0'
803 )
804 port map (
805 reset => '0',
806 clock => fx3_pclk_pll,
807 async => nios_gpio.o.meta_sync,
808 sync => meta_en_pclk
809 );
810
811 U_sync_meta_en_rx : entity work.synchronizer
812 generic map (
813 RESET_LEVEL => '0'
814 )
815 port map (
816 reset => '0',
817 clock => rx_clock,
818 async => nios_gpio.o.meta_sync,
819 sync => meta_en_rx
820 );
821
822 U_sync_meta_en_tx : entity work.synchronizer
823 generic map (
824 RESET_LEVEL => '0'
825 )
826 port map (
827 reset => '0',
828 clock => tx_clock,
829 async => nios_gpio.o.meta_sync,
830 sync => meta_en_tx
831 );
832
833 U_sync_eightbit_en_pclk : entity work.synchronizer
834 generic map (
835 RESET_LEVEL => '0'
836 )
837 port map (
838 reset => '0',
839 clock => fx3_pclk_pll,
840 async => nios_gpio.o.eightbit_en,
841 sync => eightbit_en_pclk
842 );
843
844 U_sync_eightbit_en_rx : entity work.synchronizer
845 generic map (
846 RESET_LEVEL => '0'
847 )
848 port map (
849 reset => '0',
850 clock => rx_clock,
851 async => nios_gpio.o.eightbit_en,
852 sync => eightbit_en_rx
853 );
854
855 U_sync_eightbit_en_tx : entity work.synchronizer
856 generic map (
857 RESET_LEVEL => '0'
858 )
859 port map (
860 reset => '0',
861 clock => tx_clock,
862 async => nios_gpio.o.eightbit_en,
863 sync => eightbit_en_tx
864 );
865
866 U_sync_highly_packed_en_txrx : entity work.synchronizer
867 generic map (
868 RESET_LEVEL => '0'
869 )
870 port map (
871 reset => '0',
872 clock => ad9361.clock,
873 async => nios_gpio.o.highly_packed_en,
874 sync => highly_packed_en_txrx
875 );
876
877 U_sync_packet_en_pclk : entity work.synchronizer
878 generic map (
879 RESET_LEVEL => '0'
880 )
881 port map (
882 reset => '0',
883 clock => fx3_pclk_pll,
884 async => nios_gpio.o.packet_en,
885 sync => packet_en_pclk
886 );
887
888 U_sync_packet_en_rx : entity work.synchronizer
889 generic map (
890 RESET_LEVEL => '0'
891 )
892 port map (
893 reset => '0',
894 clock => rx_clock,
895 async => nios_gpio.o.packet_en,
896 sync => packet_en_rx
897 );
898
899 U_sync_packet_en_tx : entity work.synchronizer
900 generic map (
901 RESET_LEVEL => '0'
902 )
903 port map (
904 reset => '0',
905 clock => tx_clock,
906 async => nios_gpio.o.packet_en,
907 sync => packet_en_tx
908 );
909
910 generate_sync_rx_mux_sel : for i in rx_mux_sel'range generate
911 U_sync_rx_mux_sel : entity work.synchronizer
912 generic map (
913 RESET_LEVEL => '0'
914 )
915 port map (
916 reset => '0',
917 clock => rx_clock,
918 async => nios_gpio.o.rx_mux_sel(i),
919 sync => rx_mux_sel(i)
920 );
921 end generate;
922
923 generate_sync_mimo_rx_en : for i in mimo_rx_enables'range generate
924 U_sync_mimo_rx_en : entity work.synchronizer
925 generic map (
926 RESET_LEVEL => '0'
927 )
928 port map (
929 reset => '0',
930 clock => rx_clock,
931 async => unpack(rffe_gpio.o).mimo_rx_en(i),
932 sync => mimo_rx_enables(i)
933 );
934 end generate;
935
936 generate_sync_mimo_tx_en : for i in mimo_tx_enables'range generate
937 U_sync_mimo_tx_en : entity work.synchronizer
938 generic map (
939 RESET_LEVEL => '0'
940 )
941 port map (
942 reset => '0',
943 clock => tx_clock,
944 async => unpack(rffe_gpio.o).mimo_tx_en(i),
945 sync => mimo_tx_enables(i)
946 );
947 end generate;
948
949 generate_sync_adi_ctrl_out : for i in adi_ctrl_out'range generate
950 U_sync_adi_ctrl_out : entity work.synchronizer
951 generic map (
952 RESET_LEVEL => '0'
953 )
954 port map (
955 reset => '0',
956 clock => sys_clock,
957 async => adi_ctrl_out(i),
958 sync => rffe_gpio.i.ctrl_out(i)
959 );
960 end generate;
961
962 U_sync_adf_muxout : entity work.synchronizer
963 generic map (
964 RESET_LEVEL => '0'
965 )
966 port map (
967 reset => '0',
968 clock => sys_clock,
969 async => adf_muxout,
970 sync => rffe_gpio.i.adf_muxout
971 );
972
973 generate_sync_xb_gpio_in : for i in exp_gpio'range generate
974 U_sync_xb_gpio_in : entity work.synchronizer
975 generic map (
976 RESET_LEVEL => '0'
977 ) port map (
978 reset => '0',
979 clock => sys_clock,
980 async => exp_gpio(i),
981 sync => nios_xb_gpio_in(i)
982 );
983 end generate;
984
985 U_sync_rx_enable : entity work.synchronizer
986 generic map (
987 RESET_LEVEL => '0'
988 )
989 port map (
990 reset => rx_reset,
991 clock => rx_clock,
992 async => rx_enable_pclk,
993 sync => rx_enable
994 );
995
996 U_sync_tx_enable : entity work.synchronizer
997 generic map (
998 RESET_LEVEL => '0'
999 )
1000 port map (
1001 reset => tx_reset,
1002 clock => tx_clock,
1003 async => tx_enable_pclk,
1004 sync => tx_enable
1005 );
1006
1007
1008 -- ========================================================================
1009 -- HANDSHAKES
1010 -- ========================================================================
1011
1012 drive_handshake_timestamp : process( fx3_pclk_pll, sys_reset_pclk )
1013 begin
1014 if( sys_reset_pclk = '1' ) then
1015 timestamp_req <= '0';
1016 elsif( rising_edge(fx3_pclk_pll) ) then
1017 if( meta_en_pclk = '0' ) then
1018 timestamp_req <= '0';
1019 else
1020 if( timestamp_ack = '0' ) then
1021 timestamp_req <= '1';
1022 elsif( timestamp_ack = '1' ) then
1023 timestamp_req <= '0';
1024 end if;
1025 end if;
1026 end if;
1027 end process;
1028
1029 U_handshake_timestamp : entity work.handshake
1030 generic map (
1031 DATA_WIDTH => tx_timestamp'length
1032 )
1033 port map (
1034 source_clock => tx_clock,
1035 source_reset => tx_reset,
1036 source_data => std_logic_vector(tx_timestamp),
1037
1038 dest_clock => fx3_pclk_pll,
1039 dest_reset => sys_reset_pclk,
1040 unsigned(dest_data) => fx3_timestamp,
1041 dest_req => timestamp_req,
1042 dest_ack => timestamp_ack
1043 );
1044
1045 end architecture;