Debian Codegraph @

hdl/fpga/platforms/bladerf-micro/vhdl/bladerf_p.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
26 library work;
27 use work.common_dcfifo_p.all;
28
29 package bladerf_p is
30
31 -- ========================================================================
32 -- Component declarations for Verilog files
33 -- ========================================================================
34
35 component system_pll is
36 port (
37 refclk : in std_logic;
38 rst : in std_logic;
39 outclk_0 : out std_logic;
40 locked : out std_logic
41 );
42 end component;
43
44 component fx3_pll is
45 port (
46 refclk : in std_logic;
47 rst : in std_logic;
48 outclk_0 : out std_logic;
49 locked : out std_logic
50 );
51 end component;
52
53 component clk_ctrl
54 port (
55 inclk :in std_logic;
56 ena :in std_logic;
57 outclk :out std_logic
58 );
59 end component;
60
61 component nios_system is
62 port (
63 clk_clk : in std_logic := 'X';
64 reset_reset_n : in std_logic := 'X';
65 dac_MISO : in std_logic := 'X';
66 dac_MOSI : out std_logic;
67 dac_SCLK : out std_logic;
68 dac_SS_n : out std_logic_vector(1 downto 0);
69 spi_MISO : in std_logic := 'X';
70 spi_MOSI : out std_logic;
71 spi_SCLK : out std_logic;
72 spi_SS_n : out std_logic;
73 gpio_in_port : in std_logic_vector(31 downto 0);
74 gpio_out_port : out std_logic_vector(31 downto 0);
75 gpio_rffe_0_in_port : in std_logic_vector(31 downto 0);
76 gpio_rffe_0_out_port : out std_logic_vector(31 downto 0);
77 ad9361_dac_sync_in_sync : in std_logic;
78 ad9361_dac_sync_out_sync : out std_logic;
79 ad9361_data_clock_clk : out std_logic;
80 ad9361_data_reset_reset : out std_logic;
81 ad9361_device_if_rx_clk_in_p : in std_logic;
82 ad9361_device_if_rx_clk_in_n : in std_logic;
83 ad9361_device_if_rx_frame_in_p : in std_logic;
84 ad9361_device_if_rx_frame_in_n : in std_logic;
85 ad9361_device_if_rx_data_in_p : in std_logic_vector(5 downto 0);
86 ad9361_device_if_rx_data_in_n : in std_logic_vector(5 downto 0);
87 ad9361_device_if_tx_clk_out_p : out std_logic;
88 ad9361_device_if_tx_clk_out_n : out std_logic;
89 ad9361_device_if_tx_frame_out_p : out std_logic;
90 ad9361_device_if_tx_frame_out_n : out std_logic;
91 ad9361_device_if_tx_data_out_p : out std_logic_vector(5 downto 0);
92 ad9361_device_if_tx_data_out_n : out std_logic_vector(5 downto 0);
93 ad9361_adc_i0_enable : out std_logic;
94 ad9361_adc_i0_valid : out std_logic;
95 ad9361_adc_i0_data : out std_logic_vector(15 downto 0);
96 ad9361_adc_i1_enable : out std_logic;
97 ad9361_adc_i1_valid : out std_logic;
98 ad9361_adc_i1_data : out std_logic_vector(15 downto 0);
99 ad9361_adc_overflow_ovf : in std_logic;
100 ad9361_adc_q0_enable : out std_logic;
101 ad9361_adc_q0_valid : out std_logic;
102 ad9361_adc_q0_data : out std_logic_vector(15 downto 0);
103 ad9361_adc_q1_enable : out std_logic;
104 ad9361_adc_q1_valid : out std_logic;
105 ad9361_adc_q1_data : out std_logic_vector(15 downto 0);
106 ad9361_adc_underflow_unf : in std_logic;
107 ad9361_dac_i0_enable : out std_logic;
108 ad9361_dac_i0_valid : out std_logic;
109 ad9361_dac_i0_data : in std_logic_vector(15 downto 0);
110 ad9361_dac_i1_enable : out std_logic;
111 ad9361_dac_i1_valid : out std_logic;
112 ad9361_dac_i1_data : in std_logic_vector(15 downto 0);
113 ad9361_dac_overflow_ovf : in std_logic;
114 ad9361_dac_q0_enable : out std_logic;
115 ad9361_dac_q0_valid : out std_logic;
116 ad9361_dac_q0_data : in std_logic_vector(15 downto 0);
117 ad9361_dac_q1_enable : out std_logic;
118 ad9361_dac_q1_valid : out std_logic;
119 ad9361_dac_q1_data : in std_logic_vector(15 downto 0);
120 ad9361_dac_underflow_unf : in std_logic;
121 oc_i2c_arst_i : in std_logic;
122 oc_i2c_scl_pad_i : in std_logic;
123 oc_i2c_scl_pad_o : out std_logic;
124 oc_i2c_scl_padoen_o : out std_logic;
125 oc_i2c_sda_pad_i : in std_logic;
126 oc_i2c_sda_pad_o : out std_logic;
127 oc_i2c_sda_padoen_o : out std_logic;
128 xb_gpio_in_port : in std_logic_vector(31 downto 0) := (others => 'X');
129 xb_gpio_out_port : out std_logic_vector(31 downto 0);
130 xb_gpio_dir_export : out std_logic_vector(31 downto 0);
131 command_serial_in : in std_logic;
132 command_serial_out : out std_logic;
133 rx_tamer_ts_sync_in : in std_logic;
134 rx_tamer_ts_sync_out : out std_logic;
135 rx_tamer_ts_pps : in std_logic;
136 rx_tamer_ts_clock : in std_logic;
137 rx_tamer_ts_reset : in std_logic;
138 rx_tamer_ts_time : out std_logic_vector(63 downto 0);
139 tx_tamer_ts_sync_in : in std_logic;
140 tx_tamer_ts_sync_out : out std_logic;
141 tx_tamer_ts_pps : in std_logic;
142 tx_tamer_ts_clock : in std_logic;
143 tx_tamer_ts_reset : in std_logic;
144 tx_tamer_ts_time : out std_logic_vector(63 downto 0);
145 tx_trigger_ctl_in_port : in std_logic_vector(7 downto 0);
146 tx_trigger_ctl_out_port : out std_logic_vector(7 downto 0);
147 rx_trigger_ctl_in_port : in std_logic_vector(7 downto 0);
148 rx_trigger_ctl_out_port : out std_logic_vector(7 downto 0);
149 arbiter_request : in std_logic_vector(1 downto 0) := (others => 'X');
150 arbiter_granted : out std_logic_vector(1 downto 0);
151 arbiter_ack : in std_logic_vector(1 downto 0) := (others => 'X');
152 wbm_wb_clk_i : in std_logic := 'X';
153 wbm_wb_rst_i : in std_logic := 'X';
154 wbm_wb_adr_o : out std_logic_vector(31 downto 0);
155 wbm_wb_dat_o : out std_logic_vector(31 downto 0);
156 wbm_wb_dat_i : in std_logic_vector(31 downto 0) := (others => 'X');
157 wbm_wb_we_o : out std_logic;
158 wbm_wb_sel_o : out std_logic;
159 wbm_wb_stb_o : out std_logic;
160 wbm_wb_ack_i : in std_logic := 'X';
161 wbm_wb_cyc_o : out std_logic
162 );
163 end component;
164
165 -- ========================================================================
166 -- TYPEDEFS
167 -- ========================================================================
168
169 constant TX_FIFO_WWIDTH : natural := 32; -- write side data width
170 constant TX_FIFO_RWIDTH : natural := 64; -- read side data width
171 constant TX_FIFO_LENGTH : natural := 8192; -- samples
172
173 constant RX_FIFO_WWIDTH : natural := 64; -- write side data width
174 constant RX_FIFO_RWIDTH : natural := 32; -- read side data width
175 constant RX_FIFO_LENGTH : natural := 8192; -- samples
176
177 constant ADSB_FIFO_WWIDTH : natural := 128; -- write side data width
178 constant ADSB_FIFO_RWIDTH : natural := 32; -- read side data width
179 constant ADSB_FIFO_LENGTH : natural := 1024; -- samples
180
181 constant LOOPBACK_FIFO_WWIDTH : natural := 64; -- write side data width
182 constant LOOPBACK_FIFO_RWIDTH : natural := 64; -- read side data width
183 constant LOOPBACK_FIFO_LENGTH : natural := 512; -- samples
184
185 constant META_FIFO_TX_WWIDTH : natural := 32; -- write side data width
186 constant META_FIFO_TX_RWIDTH : natural := 128; -- read side data width
187 constant META_FIFO_TX_LENGTH : natural := 2048; -- 32-bit words
188
189 constant META_FIFO_RX_WWIDTH : natural := 128; -- write side data width
190 constant META_FIFO_RX_RWIDTH : natural := 32; -- read side data width
191 constant META_FIFO_RX_LENGTH : natural := 2048; -- 32-bit words
192
193 type tx_fifo_t is record
194 aclr : std_logic;
195
196 wclock : std_logic;
197 wdata : std_logic_vector(TX_FIFO_WWIDTH-1 downto 0);
198 wreq : std_logic;
199 wempty : std_logic;
200 wfull : std_logic;
201 wused : std_logic_vector(compute_wrusedw_high(TX_FIFO_LENGTH, "OFF") downto 0);
202
203 rclock : std_logic;
204 rdata : std_logic_vector(TX_FIFO_RWIDTH-1 downto 0);
205 rreq : std_logic;
206 rempty : std_logic;
207 rfull : std_logic;
208 rused : std_logic_vector(compute_rdusedw_high(TX_FIFO_LENGTH, TX_FIFO_WWIDTH,
209 TX_FIFO_RWIDTH, "OFF") downto 0);
210 end record;
211
212 type rx_fifo_t is record
213 aclr : std_logic;
214
215 wclock : std_logic;
216 wdata : std_logic_vector(RX_FIFO_WWIDTH-1 downto 0);
217 wreq : std_logic;
218 wempty : std_logic;
219 wfull : std_logic;
220 wused : std_logic_vector(compute_wrusedw_high(RX_FIFO_LENGTH, "OFF") downto 0);
221
222 rclock : std_logic;
223 rdata : std_logic_vector(RX_FIFO_RWIDTH-1 downto 0);
224 rreq : std_logic;
225 rempty : std_logic;
226 rfull : std_logic;
227 rused : std_logic_vector(compute_rdusedw_high(RX_FIFO_LENGTH, RX_FIFO_WWIDTH,
228 RX_FIFO_RWIDTH, "OFF") downto 0);
229 end record;
230
231 type adsb_fifo_t is record
232 aclr : std_logic;
233
234 wclock : std_logic;
235 wdata : std_logic_vector(ADSB_FIFO_WWIDTH-1 downto 0);
236 wreq : std_logic;
237 wempty : std_logic;
238 wfull : std_logic;
239 wused : std_logic_vector(compute_wrusedw_high(ADSB_FIFO_LENGTH, "OFF") downto 0);
240
241 rclock : std_logic;
242 rdata : std_logic_vector(ADSB_FIFO_RWIDTH-1 downto 0);
243 rreq : std_logic;
244 rempty : std_logic;
245 rfull : std_logic;
246 rused : std_logic_vector(compute_rdusedw_high(ADSB_FIFO_LENGTH, ADSB_FIFO_WWIDTH,
247 ADSB_FIFO_RWIDTH, "OFF") downto 0);
248 end record;
249
250 type loopback_fifo_t is record
251 aclr : std_logic;
252
253 wclock : std_logic;
254 wdata : std_logic_vector(LOOPBACK_FIFO_WWIDTH-1 downto 0);
255 wreq : std_logic;
256 wempty : std_logic;
257 wfull : std_logic;
258 wused : std_logic_vector(compute_wrusedw_high(LOOPBACK_FIFO_LENGTH, "OFF") downto 0);
259
260 rclock : std_logic;
261 rdata : std_logic_vector(LOOPBACK_FIFO_RWIDTH-1 downto 0);
262 rreq : std_logic;
263 rempty : std_logic;
264 rfull : std_logic;
265 rused : std_logic_vector(compute_rdusedw_high(LOOPBACK_FIFO_LENGTH, LOOPBACK_FIFO_WWIDTH,
266 LOOPBACK_FIFO_RWIDTH, "OFF") downto 0);
267 end record;
268
269 type meta_fifo_tx_t is record
270 aclr : std_logic;
271
272 wclock : std_logic;
273 wdata : std_logic_vector(META_FIFO_TX_WWIDTH-1 downto 0);
274 wreq : std_logic;
275 wempty : std_logic;
276 wfull : std_logic;
277 wused : std_logic_vector(compute_wrusedw_high(META_FIFO_TX_LENGTH, "OFF") downto 0);
278
279 rclock : std_logic;
280 rdata : std_logic_vector(META_FIFO_TX_RWIDTH-1 downto 0);
281 rreq : std_logic;
282 rempty : std_logic;
283 rfull : std_logic;
284 rused : std_logic_vector(compute_rdusedw_high(META_FIFO_TX_LENGTH, META_FIFO_TX_WWIDTH,
285 META_FIFO_TX_RWIDTH, "OFF") downto 0);
286 end record;
287
288 type meta_fifo_rx_t is record
289 aclr : std_logic;
290
291 wclock : std_logic;
292 wdata : std_logic_vector(META_FIFO_RX_WWIDTH-1 downto 0);
293 wreq : std_logic;
294 wempty : std_logic;
295 wfull : std_logic;
296 wused : std_logic_vector(compute_wrusedw_high(META_FIFO_RX_LENGTH, "OFF") downto 0);
297
298 rclock : std_logic;
299 rdata : std_logic_vector(META_FIFO_RX_RWIDTH-1 downto 0);
300 rreq : std_logic;
301 rempty : std_logic;
302 rfull : std_logic;
303 rused : std_logic_vector(compute_rdusedw_high(META_FIFO_RX_LENGTH, META_FIFO_RX_WWIDTH,
304 META_FIFO_RX_RWIDTH, "OFF") downto 0);
305 end record;
306
307 type nios_gpo_t is record
308 xb_mode : std_logic_vector(1 downto 0);
309 eightbit_en : std_logic;
310 highly_packed_en: std_logic;
311 packet_en : std_logic;
312 si_clock_sel : std_logic;
313 ufl_clock_oe : std_logic;
314 meta_sync : std_logic;
315 led_mode : std_logic;
316 leds : std_logic_vector(3 downto 1);
317 adf_chip_enable : std_logic;
318 rx_mux_sel : std_logic_vector(2 downto 0);
319 usb_speed : std_logic;
320 end record;
321
322 type nios_gpi_t is record
323 -- Actual inputs
324 pwr_status : std_logic;
325 -- Readback of Nios GPIO outputs
326 gpo_readback : nios_gpo_t;
327 end record;
328
329 type nios_gpio_t is record
330 i : nios_gpi_t;
331 o : nios_gpo_t;
332 end record;
333
334 type sky13374_397lf_t is (
335 DISABLED,
336 RF1_TO_RF2,
337 RF1_TO_RF3,
338 UNDEFINED
339 );
340
341 type rffe_gpo_t is record
342 reset_n : std_logic;
343 enable : std_logic;
344 txnrx : std_logic;
345 en_agc : std_logic;
346 sync_in : std_logic;
347 rx_bias_en : std_logic;
348 rx_spdt1 : std_logic_vector(2 downto 1);
349 rx_spdt2 : std_logic_vector(2 downto 1);
350 tx_bias_en : std_logic;
351 tx_spdt1 : std_logic_vector(2 downto 1);
352 tx_spdt2 : std_logic_vector(2 downto 1);
353 mimo_rx_en : std_logic_vector(1 downto 0);
354 mimo_tx_en : std_logic_vector(1 downto 0);
355 ctrl_in : std_logic_vector(3 downto 0);
356 end record;
357
358 type rffe_gpi_t is record
359 ctrl_out : std_logic_vector(7 downto 0);
360 adf_muxout : std_logic;
361 end record;
362
363 type rffe_gpio_t is record
364 i : rffe_gpi_t;
365 o : std_logic_vector(31 downto 0);
366 end record;
367
368 type datastream_t is record
369 enable : std_logic;
370 valid : std_logic;
371 data : std_logic_vector(15 downto 0);
372 end record;
373
374 type sample_t is record
375 i : datastream_t;
376 q : datastream_t;
377 end record;
378
379 type channel_t is record
380 dac : sample_t;
381 adc : sample_t;
382 end record;
383
384 type channels_t is array( natural range <> ) of channel_t;
385
386 type mimo_2r2t_t is record
387 clock : std_logic;
388 reset : std_logic;
389 adc_overflow : std_logic;
390 adc_underflow : std_logic;
391 dac_overflow : std_logic;
392 dac_underflow : std_logic;
393 ch : channels_t(0 to 1);
394 end record;
395
396 type trigger_t is record
397 arm : std_logic;
398 fire : std_logic;
399 master : std_logic;
400 trig_line : std_logic;
401 end record;
402
403
404 -- ========================================================================
405 -- PACK FUNCTIONS -- pack a human-readable record/type into bits
406 -- ========================================================================
407
408 function pack( x : sky13374_397lf_t ) return std_logic_vector;
409 function pack( x : rffe_gpo_t ) return std_logic_vector;
410 function pack( x : rffe_gpio_t ) return std_logic_vector;
411 function pack( x : trigger_t ) return std_logic_vector;
412 function pack( x : nios_gpo_t ) return std_logic_vector;
413 function pack( x : nios_gpi_t;
414 core_present : std_logic) return std_logic_vector;
415
416
417 -- ========================================================================
418 -- UNPACK FUNCTIONS -- unpack bits into a human-readable record/type
419 -- ========================================================================
420
421 function unpack( x : std_logic_vector(1 downto 0) ) return sky13374_397lf_t;
422 function unpack( x : std_logic_vector(31 downto 0) ) return rffe_gpo_t;
423 function unpack( trig_gpo : std_logic_vector(7 downto 0);
424 trig_line : std_logic ) return trigger_t;
425 function unpack( x : std_logic_vector(31 downto 0) ) return nios_gpo_t;
426
427
428 -- ========================================================================
429 -- Utility functions
430 -- ========================================================================
431
432 function adp2384_sync_divisors( constant REFCLK_HZ : real := 38.4e6;
433 n_divisors : natural
434 ) return integer_vector;
435
436 -- ========================================================================
437 -- TYPEDEF RESET CONSTANTS -- deferred to permit use of pack/unpack
438 -- ========================================================================
439
440 constant RFFE_GPO_DEFAULT : rffe_gpo_t;
441 constant RFFE_GPI_DEFAULT : rffe_gpi_t;
442 constant TX_FIFO_T_DEFAULT : tx_fifo_t;
443 constant RX_FIFO_T_DEFAULT : rx_fifo_t;
444 constant ADSB_FIFO_T_DEFAULT : adsb_fifo_t;
445 constant LOOPBACK_FIFO_T_DEFAULT : loopback_fifo_t;
446 constant META_FIFO_TX_T_DEFAULT : meta_fifo_tx_t;
447 constant META_FIFO_RX_T_DEFAULT : meta_fifo_rx_t;
448 constant MIMO_2R2T_T_DEFAULT : mimo_2r2t_t;
449 constant TRIGGER_T_DEFAULT : trigger_t;
450
451 end package;
452
453 package body bladerf_p is
454
455 -- ========================================================================
456 -- PACK FUNCTIONS
457 -- ========================================================================
458
459 function pack( x : sky13374_397lf_t ) return std_logic_vector is
460 variable rv : unsigned(2 downto 1) := (others => '0');
461 begin
462 case x is
463 when DISABLED => rv := "00";
464 when RF1_TO_RF2 => rv := "01";
465 when RF1_TO_RF3 => rv := "10";
466 when others => rv := "00";
467 end case;
468 return std_logic_vector(rv);
469 end function;
470
471 function pack( x : rffe_gpo_t ) return std_logic_vector is
472 variable rv : std_logic_vector(31 downto 0) := (others => '0');
473 begin
474 --rv(31 downto 24) := x.ctrl_out; -- Reserved as inputs
475 rv(23 downto 20) := x.ctrl_in;
476 --rv(19) := x.adf_muxout; -- Reserved as input
477 rv(18) := x.mimo_tx_en(1);
478 rv(17) := x.mimo_rx_en(1);
479 rv(16) := x.mimo_tx_en(0);
480 rv(15) := x.mimo_rx_en(0);
481 rv(14 downto 13) := x.tx_spdt2;
482 rv(12 downto 11) := x.tx_spdt1;
483 rv(10) := x.tx_bias_en;
484 rv(9 downto 8) := x.rx_spdt2;
485 rv(7 downto 6) := x.rx_spdt1;
486 rv(5) := x.rx_bias_en;
487 rv(4) := x.sync_in;
488 rv(3) := x.en_agc;
489 rv(2) := x.txnrx;
490 rv(1) := x.enable;
491 rv(0) := x.reset_n;
492 return rv;
493 end function;
494
495 function pack( x : rffe_gpio_t ) return std_logic_vector is
496 variable rv : std_logic_vector(31 downto 0);
497 begin
498 -- Physical inputs
499 rv(31 downto 24) := x.i.ctrl_out;
500 rv(19) := x.i.adf_muxout;
501 -- Output readback
502 rv(23 downto 20) := x.o(23 downto 20);
503 rv(18 downto 0) := x.o(18 downto 0);
504 return rv;
505 end function;
506
507 function pack( x : trigger_t ) return std_logic_vector is
508 variable rv : std_logic_vector(7 downto 0);
509 begin
510 rv(7 downto 4) := (others => '0');
511 rv(3) := x.trig_line;
512 rv(2) := x.master;
513 rv(1) := x.fire;
514 rv(0) := x.arm;
515 return rv;
516 end function;
517
518 function pack( x : nios_gpo_t ) return std_logic_vector is
519 variable rv : std_logic_vector(31 downto 0) := (others => 'U');
520 begin
521 rv(31 downto 30) := x.xb_mode;
522 rv(21) := x.highly_packed_en;
523 rv(20) := x.eightbit_en;
524 rv(19) := x.packet_en;
525 rv(18) := x.si_clock_sel;
526 rv(17) := x.ufl_clock_oe;
527 rv(16) := x.meta_sync;
528 rv(15) := x.led_mode;
529 rv(14 downto 12) := x.leds;
530 rv(11) := x.adf_chip_enable;
531 rv(10 downto 8) := x.rx_mux_sel;
532 rv(7) := x.usb_speed;
533 --rv(0) := x.pwr_status; -- Reserved as input
534 return rv;
535 end function;
536
537 function pack( x : nios_gpi_t; core_present : std_logic ) return std_logic_vector is
538 variable rv : std_logic_vector(31 downto 0) := (others => 'U');
539 begin
540 -- Readback of outputs
541 rv := pack(x.gpo_readback);
542 -- Physical inputs
543 rv(0) := x.pwr_status;
544 rv(28) := core_present;
545 return rv;
546 end function;
547
548
549 -- ========================================================================
550 -- UNPACK FUNCTIONS
551 -- ========================================================================
552
553 function unpack( x : std_logic_vector(1 downto 0) ) return sky13374_397lf_t is
554 variable rv : sky13374_397lf_t;
555 begin
556 case x is
557 when "00" => rv := DISABLED;
558 when "01" => rv := RF1_TO_RF2;
559 when "10" => rv := RF1_TO_RF3;
560 when others => rv := UNDEFINED;
561 end case;
562 return rv;
563 end function;
564
565 function unpack( x : std_logic_vector(31 downto 0) ) return rffe_gpo_t is
566 variable rv : rffe_gpo_t := RFFE_GPO_DEFAULT;
567 begin
568 --rv.ctrl_out := x(31 downto 24); -- Reserved as input
569 rv.ctrl_in := x(23 downto 20);
570 --rv.adf_muxout := x(19); -- Reserved as input
571 rv.mimo_tx_en := x(18) & x(16); -- channel 1 & channel 0
572 rv.mimo_rx_en := x(17) & x(15); -- channel 1 & channel 0
573 rv.tx_spdt2 := x(14 downto 13);
574 rv.tx_spdt1 := x(12 downto 11);
575 rv.tx_bias_en := x(10);
576 rv.rx_spdt2 := x(9 downto 8);
577 rv.rx_spdt1 := x(7 downto 6);
578 rv.rx_bias_en := x(5);
579 rv.sync_in := x(4);
580 rv.en_agc := x(3);
581 rv.txnrx := x(2);
582 rv.enable := x(1);
583 rv.reset_n := x(0);
584 return rv;
585 end function;
586
587 function unpack( trig_gpo : std_logic_vector(7 downto 0);
588 trig_line : std_logic ) return trigger_t is
589 variable rv : trigger_t := TRIGGER_T_DEFAULT;
590 begin
591 rv.trig_line := trig_line;
592 rv.master := trig_gpo(2);
593 rv.fire := trig_gpo(1);
594 rv.arm := trig_gpo(0);
595 return rv;
596 end function;
597
598 function unpack( x : std_logic_vector(31 downto 0) ) return nios_gpo_t is
599 variable rv : nios_gpo_t;
600 begin
601 rv.xb_mode := x(31 downto 30);
602 rv.highly_packed_en:= x(21);
603 rv.eightbit_en := x(20);
604 rv.packet_en := x(19);
605 rv.si_clock_sel := x(18);
606 rv.ufl_clock_oe := x(17);
607 rv.meta_sync := x(16);
608 rv.led_mode := x(15);
609 rv.leds := x(14 downto 12);
610 rv.adf_chip_enable := x(11);
611 rv.rx_mux_sel := x(10 downto 8);
612 rv.usb_speed := x(7);
613 --rv.pwr_status := x(0); -- Reserved as input
614 return rv;
615 end function;
616
617
618 -- ========================================================================
619 -- Utility functions
620 -- ========================================================================
621
622 -- ADP2384 SYNC divisor calculator
623 -- The ADP2384 supports a synchronization frequency within +/-10% of the
624 -- switching frequency set by the RT resistor. Given the frequency of the
625 --- reference clock (the clock that will be divided down), and the number
626 -- of divisors requested, this function will compute and return an array
627 -- of equally-spaced divisors producing valid SYNC frequencies.
628 --
629 -- Parameters:
630 -- refclk_hz: Frequency of the reference clock to be divided down
631 -- n_sync_freqs: Number of divisors to compute
632 function adp2384_sync_divisors( constant REFCLK_HZ : real := 38.4e6;
633 n_divisors : natural
634 ) return integer_vector is
635
636 -- Because Quartus 16.0 doesn't support this function from VHDL 2008
637 function minimum( x : real; y : real ) return real is
638 variable rv : real;
639 begin
640 if( x < y ) then
641 rv := x;
642 else
643 rv := y;
644 end if;
645 return rv;
646 end function;
647
648 -- Because Quartus 16.0 doesn't support this function from VHDL 2008
649 function maximum( x : real; y : real ) return real is
650 variable rv : real;
651 begin
652 if( x > y ) then
653 rv := x;
654 else
655 rv := y;
656 end if;
657 return rv;
658 end function;
659
660 -- Convert to kHz for ease of calculations
661 constant REFCLK_KHZ : real := REFCLK_HZ / 1.0e3;
662
663 -- Min/max switching frequency of ADP2384
664 constant FSW_KHZ_MIN : real := 200.0;
665 constant FSW_KHZ_MAX : real := 1400.0;
666
667 -- RT resistor value and tolerance
668 constant RT_KOHM : real := 332.0;
669 constant RT_TOL : real := 0.01;
670
671
672 -- Given the RT resistor value and tolerance, compute the min/max
673 -- and convert to kohm.
674 constant RT_KOHM_MIN : real := RT_KOHM * (1.0 - RT_TOL);
675 constant RT_KOHM_MAX : real := RT_KOHM * (1.0 + RT_TOL);
676
677 -- Compute the min/max switching frequencies (kHz) dictated by RT
678 constant RT_FSW_KHZ_MIN : real := 69120.0 / (RT_KOHM_MAX + 15.0);
679 constant RT_FSW_KHZ_MAX : real := 69120.0 / (RT_KOHM_MIN + 15.0);
680
681 -- The SYNC pin frequency can be +/- 10% of the frequency set by RT.
682 -- Due to tolerances, use -10% of fsw_max, and +10% of fsw_min. This
683 -- will guarantee a compatible fsync across all board variations.
684 constant FSYNC_TOL : real := 0.10;
685 constant FSYNC_KHZ_MIN : real := (1.0 - FSYNC_TOL) * RT_FSW_KHZ_MAX;
686 constant FSYNC_KHZ_MAX : real := (1.0 + FSYNC_TOL) * RT_FSW_KHZ_MIN;
687
688 -- Compute the max/min divisors, keeping the sync frequency within the valid
689 -- window of the ADP2384. Divide by two due to the 50% duty cycle.
690 constant DIVISOR_MIN : real := ceil( (REFCLK_KHZ / minimum(FSYNC_KHZ_MAX, FSW_KHZ_MAX)) / 2.0 );
691 constant DIVISOR_MAX : real := floor( (REFCLK_KHZ / maximum(FSYNC_KHZ_MIN, FSW_KHZ_MIN)) / 2.0 );
692
693 -- Compute the number of cycles between divisors to create an equally
694 -- spaced array of divisors of the requested length.
695 constant DIVISOR_INCR : real := (DIVISOR_MAX - DIVISOR_MIN) / real(n_divisors - 1);
696
697 variable rv : integer_vector(0 to n_divisors-1);
698 variable fsync_khz : real;
699
700 begin
701
702 assert (DIVISOR_INCR >= 1.0)
703 report "ERROR: Too many divisors requested for range " &
704 real'image(DIVISOR_MIN) & " to " & real'image(DIVISOR_MAX) & "."
705 severity failure;
706
707 for i in 0 to (n_divisors - 1) loop
708 rv(i) := integer(floor(DIVISOR_MAX - (real(i) * DIVISOR_INCR)));
709 fsync_khz := REFCLK_KHZ / real( rv(i) * 2 );
710
711 report "ADP2384 SYNC frequency " & integer'image(i) & " = " &
712 real'image(fsync_khz) & " kHz."
713 severity note;
714
715 assert ( fsync_khz >= FSW_KHZ_MIN ) and ( fsync_khz <= FSW_KHZ_MAX )
716 report "ERROR: ADP2384 SYNC frequency " & real'image(fsync_khz) &
717 " is outside of valid range (" & real'image(FSW_KHZ_MIN) & " kHz to " &
718 real'image(FSW_KHZ_MAX) & "kHz."
719 severity failure;
720 end loop;
721
722 return rv;
723
724 end function;
725
726 -- ========================================================================
727 -- TYPEDEF RESET CONSTANTS
728 -- ========================================================================
729
730 constant RFFE_GPO_DEFAULT : rffe_gpo_t := (
731 reset_n => '0',
732 enable => '0',
733 txnrx => '0',
734 en_agc => '0',
735 sync_in => '0',
736 rx_bias_en => '0',
737 rx_spdt1 => pack(DISABLED),
738 rx_spdt2 => pack(DISABLED),
739 tx_bias_en => '0',
740 tx_spdt1 => pack(DISABLED),
741 tx_spdt2 => pack(DISABLED),
742 mimo_rx_en => (others => '0'),
743 mimo_tx_en => (others => '0'),
744 ctrl_in => (others => '0')
745 );
746
747 constant RFFE_GPI_DEFAULT : rffe_gpi_t := (
748 ctrl_out => (others => '0'),
749 adf_muxout => '0'
750 );
751
752 constant TX_FIFO_T_DEFAULT : tx_fifo_t := (
753 aclr => '1',
754 wclock => '0',
755 wdata => (others => '0'),
756 wreq => '0',
757 wempty => '1',
758 wfull => '0',
759 wused => (others => '0'),
760 rclock => '0',
761 rdata => (others => '0'),
762 rreq => '0',
763 rempty => '1',
764 rfull => '0',
765 rused => (others => '0')
766 );
767
768 constant RX_FIFO_T_DEFAULT : rx_fifo_t := (
769 aclr => '1',
770 wclock => '0',
771 wdata => (others => '0'),
772 wreq => '0',
773 wempty => '1',
774 wfull => '0',
775 wused => (others => '0'),
776 rclock => '0',
777 rdata => (others => '0'),
778 rreq => '0',
779 rempty => '1',
780 rfull => '0',
781 rused => (others => '0')
782 );
783
784 constant ADSB_FIFO_T_DEFAULT : adsb_fifo_t := (
785 aclr => '1',
786 wclock => '0',
787 wdata => (others => '0'),
788 wreq => '0',
789 wempty => '1',
790 wfull => '0',
791 wused => (others => '0'),
792 rclock => '0',
793 rdata => (others => '0'),
794 rreq => '0',
795 rempty => '1',
796 rfull => '0',
797 rused => (others => '0')
798 );
799
800 constant LOOPBACK_FIFO_T_DEFAULT : loopback_fifo_t := (
801 aclr => '1',
802 wclock => '0',
803 wdata => (others => '0'),
804 wreq => '0',
805 wempty => '1',
806 wfull => '0',
807 wused => (others => '0'),
808 rclock => '0',
809 rdata => (others => '0'),
810 rreq => '0',
811 rempty => '1',
812 rfull => '0',
813 rused => (others => '0')
814 );
815
816 constant META_FIFO_TX_T_DEFAULT : meta_fifo_tx_t := (
817 aclr => '1',
818 wclock => '0',
819 wdata => (others => '0'),
820 wreq => '0',
821 wempty => '1',
822 wfull => '0',
823 wused => (others => '0'),
824 rclock => '0',
825 rdata => (others => '0'),
826 rreq => '0',
827 rempty => '1',
828 rfull => '0',
829 rused => (others => '0')
830 );
831
832 constant META_FIFO_RX_T_DEFAULT : meta_fifo_rx_t := (
833 aclr => '1',
834 wclock => '0',
835 wdata => (others => '0'),
836 wreq => '0',
837 wempty => '1',
838 wfull => '0',
839 wused => (others => '0'),
840 rclock => '0',
841 rdata => (others => '0'),
842 rreq => '0',
843 rempty => '1',
844 rfull => '0',
845 rused => (others => '0')
846 );
847
848 constant MIMO_2R2T_T_DEFAULT : mimo_2r2t_t := (
849 clock => '0',
850 reset => '1',
851 adc_overflow => '0',
852 adc_underflow => '0',
853 dac_overflow => '0',
854 dac_underflow => '0',
855 ch => (others => (
856 dac => (i => (enable => '0',
857 valid => '0',
858 data => (others => '0')),
859 q => (enable => '0',
860 valid => '0',
861 data => (others => '0'))),
862 adc => (i => (enable => '0',
863 valid => '0',
864 data => (others => '0')),
865 q => (enable => '0',
866 valid => '0',
867 data => (others => '0')))
868 ))
869 );
870
871 constant TRIGGER_T_DEFAULT : trigger_t := (
872 arm => '0',
873 fire => '0',
874 master => '0',
875 trig_line => '0'
876 );
877
878 end package body;