Imported Upstream version 3.2.2
[debian/gnuradio] / gr-sounder / src / fpga / lib / sounder_rx.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 module sounder_rx(clk_i,rst_i,ena_i,sum_strobe_i,ref_strobe_i,
23                   mask_i,degree_i,rx_in_i_i,rx_in_q_i,rx_i_o,rx_q_o);
24    
25    input         clk_i;         // Master clock
26    input         rst_i;         // Subsystem reset
27    input         ena_i;         // Subsystem enable
28    input         sum_strobe_i;  // Strobe on last sample per period
29    input         ref_strobe_i;  // PN code reference retarded one sample per period
30     
31    input  [15:0] mask_i;        // PN code LFSR mask
32    input  [4:0]  degree_i;      // PN code LFSR sequency degree
33    
34    input  [15:0] rx_in_i_i;     // I channel on receive
35    input  [15:0] rx_in_q_i;     // Q channel on receive
36
37    output [15:0] rx_i_o;        // I channel of impulse response
38    output [15:0] rx_q_o;        // Q channel of impulse response
39
40    reg  [31:0] sum_i, sum_q;
41    reg  [31:0] total_i, total_q;
42    wire [31:0] i_ext, q_ext;
43
44    sign_extend #(16,32) i_extender(rx_in_i_i, i_ext);
45    sign_extend #(16,32) q_extender(rx_in_q_i, q_ext);
46
47    wire pn_ref;
48    lfsr ref_code
49      ( .clk_i(clk_i),.rst_i(rst_i),.ena_i(ena_i),.strobe_i(ref_strobe_i),.mask_i(mask_i),.pn_o(pn_ref) );
50
51    wire [31:0] prod_i = pn_ref ? i_ext : -i_ext;
52    wire [31:0] prod_q = pn_ref ? q_ext : -q_ext;
53
54    always @(posedge clk_i)
55      if (rst_i | ~ena_i)
56        begin
57           sum_i <= #5 0;
58           sum_q <= #5 0;
59           total_i <= #5 0;
60           total_q <= #5 0;
61        end
62      else
63        if (sum_strobe_i)
64          begin
65             total_i <= #5 sum_i;
66             total_q <= #5 sum_q;
67             sum_i <= #5 prod_i;
68             sum_q <= #5 prod_q;
69          end
70        else
71          begin
72             sum_i <= #5 sum_i + prod_i;
73             sum_q <= #5 sum_q + prod_q;
74          end
75
76    wire [5:0]  offset = (5'd16-degree_i);
77    wire [31:0] scaled_i = total_i << offset;
78    wire [31:0] scaled_q = total_q << offset;
79    assign rx_i_o = scaled_i[31:16];
80    assign rx_q_o = scaled_q[31:16];
81    
82 endmodule // sounder_rx
83