58b563448d98e6bbe5af30fd353f270276a0e735
[debian/gnuradio] / gr-sounder / src / fpga / lib / sounder.v
1 // -*- verilog -*-
2 //
3 //  USRP - Universal Software Radio Peripheral
4 //
5 //  Copyright (C) 2007 Corgan Enterprises LLC
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 `include "../../../../usrp/firmware/include/fpga_regs_common.v"
23 `include "../../../../usrp/firmware/include/fpga_regs_standard.v"
24
25 module sounder(clk_i, saddr_i, sdata_i, s_strobe_i,
26                tx_strobe_i, tx_dac_i_o,tx_dac_q_o,
27                rx_strobe_i, rx_adc_i_i,rx_adc_q_i,
28                rx_strobe_o, rx_imp_i_o,rx_imp_q_o);
29
30    // System interface
31    input         clk_i;         // Master clock @ 64 MHz
32    input  [6:0]  saddr_i;       // Configuration bus address
33    input  [31:0] sdata_i;       // Configuration bus data
34    input         s_strobe_i;    // Configuration bus write
35    
36    // Transmit subsystem
37    input         tx_strobe_i;   // Generate an transmitter output sample
38    output [13:0] tx_dac_i_o;    // I channel transmitter output to DAC
39    output [13:0] tx_dac_q_o;    // Q channel transmitter output to DAC
40
41    // Receive subsystem
42    input         rx_strobe_i;   // Indicates receive sample ready from ADC
43    output        rx_strobe_o;   // Indicates output samples ready for Rx FIFO
44    input  [15:0] rx_adc_i_i;    // I channel input from ADC interface module
45    input  [15:0] rx_adc_q_i;    // Q channel input from ADC interface module
46    output [15:0] rx_imp_i_o;    // I channel impulse response to Rx FIFO
47    output [15:0] rx_imp_q_o;    // Q channel impulse response to Rx FIFO
48          
49    // Internal variables
50    wire          reset;
51    wire          transmit;
52    wire          receive;
53    wire          loopback;
54
55    wire [4:0]    degree;
56    wire [15:0]   mask;
57    wire [15:0]   len;
58
59    setting_reg #(`FR_USER_0) sr_mode
60      ( .clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
61        .out({loopback,receive,transmit,reset}) );
62
63    setting_reg #(`FR_USER_1) sr_lfsr_degree
64      ( .clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),.out(degree) );
65    
66    lfsr_constants constants(.degree_i(degree),.mask_o(mask),.len_o(len));
67
68    // Loopback implementation
69    wire [13:0] tx_i, tx_q;      
70    wire [15:0] tx_i_ext, tx_q_ext;
71    wire [15:0] rx_i, rx_q; 
72
73    sign_extend #(14,16) tx_i_extender(tx_i, tx_i_ext);
74    sign_extend #(14,16) tx_q_extender(tx_q, tx_q_ext);
75
76    assign tx_dac_i_o = loopback ? 14'b0 : tx_i;
77    assign tx_dac_q_o = loopback ? 14'b0 : tx_q;
78    assign rx_i       = loopback ? tx_i_ext : rx_adc_i_i;
79    assign rx_q       = loopback ? tx_q_ext : rx_adc_q_i;
80    
81    sounder_tx transmitter
82      ( .clk_i(clk_i),.rst_i(reset),.ena_i(transmit),
83        .strobe_i(tx_strobe_i),.mask_i(mask),
84        .tx_i_o(tx_i),.tx_q_o(tx_q) );
85    
86    sounder_rx receiver
87      ( .clk_i(clk_i),.rst_i(reset),.ena_i(receive),
88        .rx_strobe_i(rx_strobe_i),.tx_strobe_i(tx_strobe_i),.mask_i(mask),.degree_i(degree),.len_i(len),
89        .rx_in_i_i(rx_i),.rx_in_q_i(rx_q),.rx_i_o(rx_imp_i_o),.rx_q_o(rx_imp_q_o),
90        .rx_strobe_o(rx_strobe_o),.loop_i(loopback));
91
92 endmodule // sounder