3 // USRP - Universal Software Radio Peripheral
5 // Copyright (C) 2003,2004 Matt Ettus
6 // Copyright 2007 Free Software Foundation, Inc.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA
25 `include "../../../firmware/include/fpga_regs_common.v"
26 `include "../../../firmware/include/fpga_regs_standard.v"
28 module usrp_inband_usb
29 (output MYSTERY_SIGNAL,
40 input wire [11:0] rx_a_a,
41 input wire [11:0] rx_b_a,
42 input wire [11:0] rx_a_b,
43 input wire [11:0] rx_b_b,
45 output wire [13:0] tx_a,
46 output wire [13:0] tx_b,
53 input wire [2:0] usbctl,
54 output wire [1:0] usbrdy,
55 inout [15:0] usbdata, // NB Careful, inout
57 // These are the general purpose i/o's that go to the daughterboard slots
58 inout wire [15:0] io_tx_a,
59 inout wire [15:0] io_tx_b,
60 inout wire [15:0] io_rx_a,
61 inout wire [15:0] io_rx_b
63 wire [15:0] debugdata,debugctrl;
64 assign MYSTERY_SIGNAL = 1'b0;
72 wire have_space, have_pkt_rdy;
73 assign usbrdy[0] = have_space;
74 assign usbrdy[1] = have_pkt_rdy;
76 wire tx_underrun, rx_overrun;
77 wire clear_status = FX2_1;
78 assign FX2_2 = rx_overrun;
79 assign FX2_3 = tx_underrun;
81 wire [15:0] usbdata_out;
83 wire [3:0] dac0mux,dac1mux,dac2mux,dac3mux;
86 wire [3:0] rx_numchan;
87 wire [2:0] tx_numchan;
89 wire [7:0] interp_rate, decim_rate;
90 wire [15:0] tx_debugbus, rx_debugbus;
92 wire enable_tx, enable_rx;
93 wire tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
96 // Tri-state bus macro
97 bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
99 assign clk64 = master_clk;
101 wire [15:0] ch0tx,ch1tx,ch2tx,ch3tx; //,ch4tx,ch5tx,ch6tx,ch7tx;
102 wire [15:0] ch0rx,ch1rx,ch2rx,ch3rx,ch4rx,ch5rx,ch6rx,ch7rx;
105 wire [15:0] i_out_0,i_out_1,q_out_0,q_out_1;
106 wire [15:0] bb_tx_i0,bb_tx_q0,bb_tx_i1,bb_tx_q1; // bb_tx_i2,bb_tx_q2,bb_tx_i3,bb_tx_q3;
108 wire strobe_interp, tx_sample_strobe;
112 wire [6:0] serial_addr;
113 wire [31:0] serial_data;
115 reg [15:0] debug_counter;
116 reg [15:0] loopback_i_0,loopback_q_0;
118 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121 assign bb_tx_i0 = ch0tx;
122 assign bb_tx_q0 = ch1tx;
123 assign bb_tx_i1 = ch2tx;
124 assign bb_tx_q1 = ch3tx;
127 tx_buffer_inband tx_buffer
128 ( .usbclk(usbclk),.bus_reset(tx_bus_reset),.reset(tx_dsp_reset),
129 .usbdata(usbdata),.WR(WR),.have_space(have_space),.tx_underrun(tx_underrun),
130 .channels({tx_numchan,1'b0}),
131 .tx_i_0(ch0tx),.tx_q_0(ch1tx),
132 .tx_i_1(ch2tx),.tx_q_1(ch3tx),
135 .txclk(clk64),.txstrobe(strobe_interp),
136 .clear_status(clear_status),
138 .debugbus(tx_debugbus) );
141 ( .usbclk(usbclk),.bus_reset(tx_bus_reset),.reset(tx_dsp_reset),
142 .usbdata(usbdata),.WR(WR),.have_space(have_space),.tx_underrun(tx_underrun),
143 .channels({tx_numchan,1'b0}),
144 .tx_i_0(ch0tx),.tx_q_0(ch1tx),
145 .tx_i_1(ch2tx),.tx_q_1(ch3tx),
148 .txclk(clk64),.txstrobe(strobe_interp),
149 .clear_status(clear_status),
151 .debugbus(tx_debugbus) );
156 ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
157 .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
158 .interpolator_strobe(strobe_interp),.freq(),
159 .i_in(bb_tx_i0),.q_in(bb_tx_q0),.i_out(i_out_0),.q_out(q_out_0) );
161 assign i_out_0=16'd0;
162 assign q_out_0=16'd0;
167 ( .clock(clk64),.reset(tx_dsp_reset),.enable(enable_tx),
168 .interp_rate(interp_rate),.sample_strobe(tx_sample_strobe),
169 .interpolator_strobe(strobe_interp),.freq(),
170 .i_in(bb_tx_i1),.q_in(bb_tx_q1),.i_out(i_out_1),.q_out(q_out_1) );
172 assign i_out_1=16'd0;
173 assign q_out_1=16'd0;
176 setting_reg #(`FR_TX_MUX)
177 sr_txmux(.clock(clk64),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
178 .out({dac3mux,dac2mux,dac1mux,dac0mux,tx_realsignals,tx_numchan}));
180 wire [15:0] tx_a_a = dac0mux[3] ? (dac0mux[1] ? (dac0mux[0] ? q_out_1 : i_out_1) : (dac0mux[0] ? q_out_0 : i_out_0)) : 16'b0;
181 wire [15:0] tx_b_a = dac1mux[3] ? (dac1mux[1] ? (dac1mux[0] ? q_out_1 : i_out_1) : (dac1mux[0] ? q_out_0 : i_out_0)) : 16'b0;
182 wire [15:0] tx_a_b = dac2mux[3] ? (dac2mux[1] ? (dac2mux[0] ? q_out_1 : i_out_1) : (dac2mux[0] ? q_out_0 : i_out_0)) : 16'b0;
183 wire [15:0] tx_b_b = dac3mux[3] ? (dac3mux[1] ? (dac3mux[0] ? q_out_1 : i_out_1) : (dac3mux[0] ? q_out_0 : i_out_0)) : 16'b0;
185 wire txsync = tx_sample_strobe;
186 assign TXSYNC_A = txsync;
187 assign TXSYNC_B = txsync;
189 assign tx_a = txsync ? tx_b_a[15:2] : tx_a_a[15:2];
190 assign tx_b = txsync ? tx_b_b[15:2] : tx_a_b[15:2];
191 `endif // `ifdef TX_ON
193 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
196 wire rx_sample_strobe,strobe_decim,hb_strobe;
197 wire [15:0] bb_rx_i0,bb_rx_q0,bb_rx_i1,bb_rx_q1,
198 bb_rx_i2,bb_rx_q2,bb_rx_i3,bb_rx_q3;
200 wire loopback = settings[0];
201 wire counter = settings[1];
203 always @(posedge clk64)
205 debug_counter <= #1 16'd0;
207 debug_counter <= #1 16'd0;
209 debug_counter <=#1 debug_counter + 16'd2;
211 always @(posedge clk64)
214 loopback_i_0 <= #1 ch0tx;
215 loopback_q_0 <= #1 ch1tx;
218 assign ch0rx = counter ? debug_counter : loopback ? loopback_i_0 : bb_rx_i0;
219 assign ch1rx = counter ? debug_counter + 16'd1 : loopback ? loopback_q_0 : bb_rx_q0;
220 assign ch2rx = bb_rx_i1;
221 assign ch3rx = bb_rx_q1;
222 assign ch4rx = bb_rx_i2;
223 assign ch5rx = bb_rx_q2;
224 assign ch6rx = bb_rx_i3;
225 assign ch7rx = bb_rx_q3;
227 wire [15:0] ddc0_in_i,ddc0_in_q,ddc1_in_i,ddc1_in_q,ddc2_in_i,ddc2_in_q,ddc3_in_i,ddc3_in_q;
228 wire [31:0] rssi_0,rssi_1,rssi_2,rssi_3;
230 adc_interface adc_interface(.clock(clk64),.reset(rx_dsp_reset),.enable(1'b1),
231 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
232 .rx_a_a(rx_a_a),.rx_b_a(rx_b_a),.rx_a_b(rx_a_b),.rx_b_b(rx_b_b),
233 .rssi_0(rssi_0),.rssi_1(rssi_1),.rssi_2(rssi_2),.rssi_3(rssi_3),
234 .ddc0_in_i(ddc0_in_i),.ddc0_in_q(ddc0_in_q),
235 .ddc1_in_i(ddc1_in_i),.ddc1_in_q(ddc1_in_q),
236 .ddc2_in_i(ddc2_in_i),.ddc2_in_q(ddc2_in_q),
237 .ddc3_in_i(ddc3_in_i),.ddc3_in_q(ddc3_in_q),.rx_numchan(rx_numchan) );
240 ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset),
241 .reset_regs(rx_dsp_reset),
242 .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
243 .channels(rx_numchan),
244 .ch_0(ch0rx),.ch_1(ch1rx),
245 .ch_2(ch2rx),.ch_3(ch3rx),
246 .ch_4(ch4rx),.ch_5(ch5rx),
247 .ch_6(ch6rx),.ch_7(ch7rx),
248 .rxclk(clk64),.rxstrobe(hb_strobe),
249 .clear_status(clear_status),
250 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
251 .debugbus(rx_debugbus) );
254 rx_chain #(`FR_RX_FREQ_0,`FR_RX_PHASE_0) rx_chain_0
255 ( .clock(clk64),.reset(1'b0),.enable(enable_rx),
256 .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(hb_strobe),
257 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
258 .i_in(ddc0_in_i),.q_in(ddc0_in_q),.i_out(bb_rx_i0),.q_out(bb_rx_q0),.debugdata(debugdata),.debugctrl(debugctrl));
260 assign bb_rx_i0=16'd0;
261 assign bb_rx_q0=16'd0;
265 rx_chain #(`FR_RX_FREQ_1,`FR_RX_PHASE_1) rx_chain_1
266 ( .clock(clk64),.reset(1'b0),.enable(enable_rx),
267 .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
268 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
269 .i_in(ddc1_in_i),.q_in(ddc1_in_q),.i_out(bb_rx_i1),.q_out(bb_rx_q1));
271 assign bb_rx_i1=16'd0;
272 assign bb_rx_q1=16'd0;
276 rx_chain #(`FR_RX_FREQ_2,`FR_RX_PHASE_2) rx_chain_2
277 ( .clock(clk64),.reset(1'b0),.enable(enable_rx),
278 .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
279 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
280 .i_in(ddc2_in_i),.q_in(ddc2_in_q),.i_out(bb_rx_i2),.q_out(bb_rx_q2));
282 assign bb_rx_i2=16'd0;
283 assign bb_rx_q2=16'd0;
287 rx_chain #(`FR_RX_FREQ_3,`FR_RX_PHASE_3) rx_chain_3
288 ( .clock(clk64),.reset(1'b0),.enable(enable_rx),
289 .decim_rate(decim_rate),.sample_strobe(rx_sample_strobe),.decimator_strobe(strobe_decim),.hb_strobe(),
290 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
291 .i_in(ddc3_in_i),.q_in(ddc3_in_q),.i_out(bb_rx_i3),.q_out(bb_rx_q3));
293 assign bb_rx_i3=16'd0;
294 assign bb_rx_q3=16'd0;
297 `endif // `ifdef RX_ON
299 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
302 wire [31:0] capabilities;
303 assign capabilities[7] = `TX_CAP_HB;
304 assign capabilities[6:4] = `TX_CAP_NCHAN;
305 assign capabilities[3] = `RX_CAP_HB;
306 assign capabilities[2:0] = `RX_CAP_NCHAN;
310 ( .master_clk(clk64),.serial_clock(SCLK),.serial_data_in(SDI),
311 .enable(SEN_FPGA),.reset(1'b0),.serial_data_out(SDO),
312 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
313 .readback_0({io_rx_a,io_tx_a}),.readback_1({io_rx_b,io_tx_b}),.readback_2(capabilities),.readback_3(32'hf0f0931a),
314 .readback_4(rssi_0),.readback_5(rssi_1),.readback_6(rssi_2),.readback_7(rssi_3)
317 wire [15:0] reg_0,reg_1,reg_2,reg_3;
318 master_control master_control
319 ( .master_clk(clk64),.usbclk(usbclk),
320 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
321 .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
322 .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
323 .enable_tx(enable_tx),.enable_rx(enable_rx),
324 .interp_rate(interp_rate),.decim_rate(decim_rate),
325 .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
326 .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
328 //.debug_0(rx_a_a),.debug_1(ddc0_in_i),
329 .debug_0(rx_debugbus),.debug_1(ddc0_in_i),
330 .debug_2({rx_sample_strobe,strobe_decim,serial_strobe,serial_addr}),.debug_3({rx_dsp_reset,tx_dsp_reset,rx_bus_reset,tx_bus_reset,enable_rx,tx_underrun,rx_overrun,decim_rate}),
331 .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
334 (.io_0(io_tx_a),.io_1(io_rx_a),.io_2(io_tx_b),.io_3(io_rx_b),
335 .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3),
336 .clock(clk64),.rx_reset(rx_dsp_reset),.tx_reset(tx_dsp_reset),
337 .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe));
339 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
341 setting_reg #(`FR_MODE) sr_misc(.clock(clk64),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),.out(settings));
343 endmodule // usrp_inband_usb