Debian Codegraph @

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