Imported Upstream version 3.2.2
[debian/gnuradio] / gr-sounder / src / fpga / lib / sounder_ctrl.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_ctrl(clk_i,rst_i,saddr_i,sdata_i,s_strobe_i,
26                     reset_o,transmit_o,receive_o,loopback_o,
27                     degree_o,ampl_o,mask_o,
28                     tx_strobe_o,rx_strobe_o,sum_strobe_o,ref_strobe_o);
29
30    input         clk_i;         // Master clock @ 64 MHz
31    input         rst_i;         // Master synchronous reset
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    output        reset_o;
36    output        transmit_o;
37    output        receive_o;
38    output        loopback_o;
39    output [4:0]  degree_o;
40    output [13:0] ampl_o;
41    output [15:0] mask_o;
42    output        tx_strobe_o;
43    output        rx_strobe_o;
44    output        sum_strobe_o;
45    output        ref_strobe_o;
46    
47    setting_reg #(`FR_USER_0) sr_mode
48      ( .clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
49        .out({loopback_o,receive_o,transmit_o,reset_o}) );
50
51    setting_reg #(`FR_USER_1) sr_lfsr_degree
52      ( .clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
53        .out(degree_o) );
54    
55    setting_reg #(`FR_USER_2) sr_lfsr_ampl
56      ( .clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
57        .out(ampl_o) );
58    
59    wire [16:0] len;
60    lfsr_constants constants
61      (.clk_i(clk_i),.rst_i(rst_i),.degree_i(degree_o),.mask_o(mask_o),
62       .len_o(len) );
63
64    reg [15:0] phase;
65    assign tx_strobe_o = ~phase[0];
66    assign ref_strobe_o = tx_strobe_o & !(phase>>1 == len>>1);
67    assign sum_strobe_o = (phase == len);
68    
69    reg    rx_strobe_o;
70    always @(posedge clk_i)
71      if (rst_i)
72        begin
73           phase <= #5 16'hFFFF;
74           rx_strobe_o <= #5 0;
75        end
76      else
77        if (sum_strobe_o)
78          begin
79             phase <= #5 0;
80             rx_strobe_o <= #5 1'b1;
81          end
82        else
83          begin
84             phase <= #5 phase + 16'b1;
85             rx_strobe_o <= #5 0;
86          end
87
88
89
90
91
92
93
94
95
96    
97 endmodule // sounder_ctrl