Debian Codegraph @

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