Imported Upstream version 3.0
[debian/gnuradio] / usrp / fpga / toplevel / mrfm / mrfm.v
1 // -*- verilog -*-
2 //
3 //  USRP - Universal Software Radio Peripheral
4 //
5 //  Copyright (C) 2006 Matt Ettus
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 2 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
20 //
21
22 // Top level module for a full setup with DUCs and DDCs
23
24 // Uncomment the following to include optional circuitry
25
26 `include "mrfm.vh"
27 `include "../../../firmware/include/fpga_regs_common.v"
28 `include "../../../firmware/include/fpga_regs_standard.v"
29
30 module mrfm
31 (output MYSTERY_SIGNAL,
32  input master_clk,
33  input SCLK,
34  input SDI,
35  inout SDO,
36  input SEN_FPGA,
37
38  input FX2_1,
39  output FX2_2,
40  output FX2_3,
41  
42  input wire [11:0] rx_a_a,
43  input wire [11:0] rx_b_a,
44  input wire [11:0] rx_a_b,
45  input wire [11:0] rx_b_b,
46  
47  output wire [13:0] tx_a,
48  output wire [13:0] tx_b,
49  
50  output wire TXSYNC_A,
51  output wire TXSYNC_B,
52  
53  // USB interface
54  input usbclk,
55  input wire [2:0] usbctl,
56  output wire [1:0] usbrdy,
57  inout [15:0] usbdata,  // NB Careful, inout
58  
59  // These are the general purpose i/o's that go to the daughterboard slots
60  inout wire [15:0] io_tx_a,
61  inout wire [15:0] io_tx_b,
62  inout wire [15:0] io_rx_a,
63  inout wire [15:0] io_rx_b
64  );     
65    wire [15:0] debugdata,debugctrl;
66    assign MYSTERY_SIGNAL = 1'b0;
67    
68    wire clk64;
69    
70    wire WR = usbctl[0];
71    wire RD = usbctl[1];
72    wire OE = usbctl[2];
73
74    wire have_space, have_pkt_rdy;
75    assign usbrdy[0] = have_space;
76    assign usbrdy[1] = have_pkt_rdy;
77
78    wire   tx_underrun, rx_overrun;    
79    wire   clear_status = FX2_1;
80    assign FX2_2 = rx_overrun;
81    assign FX2_3 = tx_underrun;
82       
83    wire [15:0] usbdata_out;
84    
85    wire [3:0]  dac0mux,dac1mux,dac2mux,dac3mux;
86    
87    wire        tx_realsignals;
88    wire [3:0]  rx_numchan;
89    
90    wire [15:0] tx_debugbus, rx_debugbus;
91    
92    wire        enable_tx, enable_rx;
93    wire        tx_dsp_reset, rx_dsp_reset, tx_bus_reset, rx_bus_reset;
94    wire [7:0]  settings;
95    
96    // Tri-state bus macro
97    bustri bustri( .data(usbdata_out),.enabledt(OE),.tridata(usbdata) );
98
99    assign      clk64 = master_clk;
100
101    wire [15:0] ch0tx,ch1tx,ch2tx,ch3tx; 
102    wire [15:0] ch0rx,ch1rx,ch2rx,ch3rx,ch4rx,ch5rx,ch6rx,ch7rx;
103    
104    wire        serial_strobe;
105    wire [6:0]  serial_addr;
106    wire [31:0] serial_data;
107    
108    /////////////////////////////////////////////////////////////////////////////////////////////////////
109    
110    setting_reg #(`FR_TX_MUX) 
111      sr_txmux(.clock(clk64),.reset(tx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
112               .out({dac3mux,dac2mux,dac1mux,dac0mux,tx_realsignals,tx_numchan}));
113       
114    //////////////////////////////////////////////////////////////////////////////////////////////////////
115    // Signal Processing Chain
116
117    reg [15:0]  adc0;
118    wire [15:0] dac0;
119    wire [15:0] i,q,ip,qp;
120    wire        strobe_out;
121    wire        sync_out;
122    
123    always @(posedge clk64)
124      adc0 <= #1 {rx_a_a[11],rx_a_a[11:0],3'b0};
125
126    wire [15:0] adc0_corr;
127    rx_dcoffset #(0)rx_dcoffset0(.clock(clk64),.enable(1'b1),.reset(reset),.adc_in(adc0),.adc_out(adc0_corr),
128         .serial_addr(7'd0),.serial_data(32'd0),.serial_strobe(1'b0));
129
130    //wire [63:0] filt_debug = 64'd0;
131    
132    mrfm_proc mrfm_proc(.clock(clk64),.reset(rx_dsp_reset),.enable(enable_rx),
133                        .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
134                        .signal_in(adc0_corr),.signal_out(dac0),.sync_out(sync_out),
135                        .i(i),.q(q),.ip(ip),.qp(qp),.strobe_out(strobe_out),
136                        .debugbus( /* filt_debug */ ));
137           
138    wire txsync = 1'b0;
139    assign TXSYNC_A = txsync;
140    assign TXSYNC_B = txsync;
141
142    assign tx_a = dac0[15:2];
143
144    //////////////////////////////////////////////////////////////////////////////////////////////////
145    //  Data Collection on RX Buffer
146
147    assign     rx_numchan[0] = 1'b0;
148    setting_reg #(`FR_RX_MUX) sr_rxmux(.clock(clk64),.reset(rx_dsp_reset),.strobe(serial_strobe),.addr(serial_addr),
149                                       .in(serial_data),.out(rx_numchan[3:1]));
150    
151    rx_buffer rx_buffer
152      ( .usbclk(usbclk),.bus_reset(rx_bus_reset),.reset(rx_dsp_reset),
153        .usbdata(usbdata_out),.RD(RD),.have_pkt_rdy(have_pkt_rdy),.rx_overrun(rx_overrun),
154        .channels(rx_numchan),
155        .ch_0(i),.ch_1(q),
156        .ch_2(ip),.ch_3(qp),
157        .ch_4(16'd0),.ch_5(16'd0),
158        .ch_6(16'd0),.ch_7(16'd0),
159        .rxclk(clk64),.rxstrobe(strobe_out),
160        .clear_status(clear_status),
161        .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
162        .debugbus(rx_debugbus) );
163    
164    //////////////////////////////////////////////////////////////////////////////
165    // Control Functions
166        
167    wire [31:0] capabilities = 32'd2;
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
175    wire [15:0] reg_0,reg_1,reg_2,reg_3;
176    master_control master_control
177      ( .master_clk(clk64),.usbclk(usbclk),
178        .serial_addr(serial_addr),.serial_data(serial_data),.serial_strobe(serial_strobe),
179        .tx_bus_reset(tx_bus_reset),.rx_bus_reset(rx_bus_reset),
180        .tx_dsp_reset(tx_dsp_reset),.rx_dsp_reset(rx_dsp_reset),
181        .enable_tx(enable_tx),.enable_rx(enable_rx),
182        .interp_rate(interp_rate),.decim_rate(decim_rate),
183        .tx_sample_strobe(tx_sample_strobe),.strobe_interp(strobe_interp),
184        .rx_sample_strobe(rx_sample_strobe),.strobe_decim(strobe_decim),
185        .tx_empty(tx_empty),
186        .debug_0({15'd0,sync_out}), //filt_debug[63:48]),
187        .debug_1({15'd0,sync_out}), //filt_debug[47:32]),
188        .debug_2({15'd0,sync_out}), //filt_debug[31:16]),
189        .debug_3({15'd0,sync_out}), //filt_debug[15:0]),
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 // mrfm
199