Imported Upstream version 3.2.2
[debian/gnuradio] / gr-sounder / src / fpga / top / usrp_sounder.v
1 // -*- verilog -*-
2 //
3 //  USRP - Universal Software Radio Peripheral
4 //
5 //  Copyright (C) 2003,2004 Matt Ettus
6 //  Copyright (C) 2007 Corgan Enterprises LLC
7 //
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.
12 //
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.
17 //
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
21 //
22
23 // Top level module for a full setup with DUCs and DDCs
24
25 // Define DEBUG_OWNS_IO_PINS if we're using the daughterboard i/o pins
26 // for debugging info.  NB, This can kill the m'board and/or d'board if you
27 // have anything except basic d'boards installed.
28
29 // Uncomment the following to include optional circuitry
30
31 module usrp_sounder
32 (output MYSTERY_SIGNAL,
33  input master_clk,
34  input SCLK,
35  input SDI,
36  inout SDO,
37  input SEN_FPGA,
38
39  input FX2_1,
40  output FX2_2,
41  output FX2_3,
42  
43  input wire [11:0] rx_a_a,
44  input wire [11:0] rx_b_a,
45  input wire [11:0] rx_a_b,
46  input wire [11:0] rx_b_b,
47
48  output wire [13:0] tx_a,
49  output wire [13:0] tx_b,
50
51  output wire TXSYNC_A,
52  output wire TXSYNC_B,
53  
54   // USB interface
55  input usbclk,
56  input wire [2:0] usbctl,
57  output wire [1:0] usbrdy,
58  inout [15:0] usbdata,  // NB Careful, inout
59
60  // These are the general purpose i/o's that go to the daughterboard slots
61  inout wire [15:0] io_tx_a,
62  inout wire [15:0] io_tx_b,
63  inout wire [15:0] io_rx_a,
64  inout wire [15:0] io_rx_b
65  );     
66    wire [15:0] debugdata,debugctrl;
67    assign MYSTERY_SIGNAL = 1'b0;
68    
69    wire clk64;
70    
71    // wire WR = usbctl[0];
72    wire RD = usbctl[1];
73    wire OE = usbctl[2];
74
75    wire have_pkt_rdy;
76    assign usbrdy[0] = 1'b0; // have_space;
77    assign usbrdy[1] = have_pkt_rdy;
78
79    wire   tx_underrun, rx_overrun;    
80    wire   clear_status = FX2_1;
81    assign FX2_2 = rx_overrun;
82    assign FX2_3 = 1'b0; // tx_underrun;
83       
84    wire [15:0] usbdata_out;
85    
86    wire [3:0]  rx_numchan;
87    wire        enable_tx, enable_rx;
88    wire        tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
89    
90    // Tri-state bus macro
91    bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
92
93    assign      clk64 = master_clk;
94
95    // TX
96    wire        tx_sample_strobe;
97    wire        tx_empty;
98    
99    wire        serial_strobe;
100    wire [6:0]  serial_addr;
101    wire [31:0] serial_data;
102
103    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
104    // Transmit Side
105    
106    wire [13:0] tx_i, tx_q;
107    wire [13:0] tx_dac;
108    
109    dac_interface dac(.clk_i(clk64),.rst_i(tx_dsp_reset),.ena_i(enable_tx),
110                      .strobe_i(tx_sample_strobe),.tx_i_i(tx_i),.tx_q_i(tx_q),
111                      .tx_data_o(tx_dac),.tx_sync_o(TXSYNC_A));
112
113    assign tx_a = tx_dac;
114
115    // Wedge DAC #2 at zero
116    assign TXSYNC_B = 1'b0;
117    assign tx_b = 14'b0;
118    
119    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120    // Receive Side
121    wire        rx_sample_strobe, rx_strobe;
122    wire [15:0] rx_adc0_i, rx_adc0_q;
123    wire [15:0] rx_buf_i, rx_buf_q;
124    
125    adc_interface adc_interface(.clock(clk64),.reset(rx_dsp_reset),.enable(enable_rx),
126                                .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
127                                .rx_a_a(rx_a_a),.rx_b_a(rx_b_a),.rx_a_b(),.rx_b_b(),
128                                .rssi_0(),.rssi_1(),.rssi_2(),.rssi_3(),
129                                .ddc0_in_i(rx_adc0_i),.ddc0_in_q(rx_adc0_q),
130                                .ddc1_in_i(),.ddc1_in_q(),
131                                .ddc2_in_i(),.ddc2_in_q(),
132                                .ddc3_in_i(),.ddc3_in_q(),.rx_numchan(rx_numchan) );
133
134    rx_buffer rx_buffer
135      ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset),
136        .reset_regs(rx_dsp_reset),
137        .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
138        .channels(rx_numchan),
139        .ch_0(rx_buf_i),.ch_1(rx_buf_q),
140        .ch_2(),.ch_3(),
141        .ch_4(),.ch_5(),
142        .ch_6(),.ch_7(),
143        .rxclk(clk64),.rxstrobe(rx_strobe),
144        .clear_status(clear_status),
145        .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
146        .debugbus() );
147    
148
149    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
150    // Top level application
151
152    sounder sounder
153      ( .clk_i(clk64),.saddr_i(serial_addr),.sdata_i(serial_data),.s_strobe_i(serial_strobe),
154        .tx_strobe_o(tx_sample_strobe),.tx_dac_i_o(tx_i),.tx_dac_q_o(tx_q),
155        .rx_adc_i_i(rx_adc0_i),.rx_adc_q_i(rx_adc0_q),
156        .rx_strobe_o(rx_strobe),.rx_imp_i_o(rx_buf_i),.rx_imp_q_o(rx_buf_q)
157        );
158
159    
160    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
161    // Control Functions
162
163    wire [31:0] capabilities;
164    assign capabilities[7]   = 0;  // `TX_CAP_HB;
165    assign capabilities[6:4] = 2;  // `TX_CAP_NCHAN;
166    assign capabilities[3]   = 0;  // `RX_CAP_HB;
167    assign capabilities[2:0] = 2;  // `RX_CAP_NCHAN;
168
169    serial_io serial_io
170      ( .master_clk(clk64),.serial_clock(SCLK),.serial_data_in(SDI),
171        .enable(SEN_FPGA),.reset(1'b0),.serial_data_out(SDO),
172        .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
173        .readback_0({io_rx_a,io_tx_a}),.readback_1({io_rx_b,io_tx_b}),.readback_2(capabilities),.readback_3(32'hf0f0931a),
174        .readback_4(),.readback_5(),.readback_6(),.readback_7()
175        );
176
177    wire [15:0] reg_0,reg_1,reg_2,reg_3;
178    master_control master_control
179      ( .master_clk(clk64),.usbclk(usbclk),
180        .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
181        .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
182        .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
183        .enable_tx(enable_tx),.enable_rx(enable_rx),
184        .interp_rate(),.decim_rate(),
185        .tx_sample_strobe(),.strobe_interp(),
186        .rx_sample_strobe(rx_sample_strobe),.strobe_decim(),
187        .tx_empty(tx_empty),
188        .debug_0(),.debug_1(),
189        .debug_2(),.debug_3(),
190        .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3) );
191    
192    io_pins io_pins
193      (.io_0(io_tx_a),.io_1(io_rx_a),.io_2(io_tx_b),.io_3(io_rx_b),
194       .reg_0(reg_0),.reg_1(reg_1),.reg_2(reg_2),.reg_3(reg_3),
195       .clock(clk64),.rx_reset(rx_dsp_reset),.tx_reset(tx_dsp_reset),
196       .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe));
197    
198 endmodule // usrp_sounder