Merged r5945:6012 from jcorgan/radar into trunk. Updates gr-radar-mono component...
[debian/gnuradio] / gr-radar-mono / src / fpga / lib / radar_control.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 "../lib/radar_config.vh"
23
24 module radar_control(clk_i,saddr_i,sdata_i,s_strobe_i,
25                      reset_o,tx_strobe_o,tx_ctrl_o,rx_ctrl_o,
26                      ampl_o,fstart_o,fincr_o);
27
28    // System interface
29    input         clk_i;         // Master clock @ 64 MHz
30    input  [6:0]  saddr_i;       // Configuration bus address
31    input  [31:0] sdata_i;       // Configuration bus data
32    input         s_strobe_i;    // Configuration bus write
33
34    // Control and configuration outputs
35    output        reset_o;
36    output        tx_strobe_o;
37    output        tx_ctrl_o;
38    output        rx_ctrl_o;
39    output [15:0] ampl_o;
40    output [31:0] fstart_o;
41    output [31:0] fincr_o;
42    
43    // Internal configuration
44    wire          lp_ena;
45    wire          dr_ena;
46    wire          md_ena;
47    wire   [1:0]  chirps;
48    wire   [15:0] t_on;
49    wire   [15:0] t_sw;
50    wire   [15:0] t_look;
51    wire   [31:0] t_idle;
52
53    // Configuration from host
54    setting_reg #(`FR_RADAR_MODE)   sr_mode(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
55                                            .out({chirps,md_ena,dr_ena,lp_ena,reset_o}));
56                                      
57    setting_reg #(`FR_RADAR_TON)    sr_ton(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
58                                           .out(t_on));
59    
60    setting_reg #(`FR_RADAR_TSW)    sr_tsw(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
61                                           .out(t_sw));
62                                      
63    setting_reg #(`FR_RADAR_TLOOK)  sr_tlook(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
64                                             .out(t_look));
65                                      
66    setting_reg #(`FR_RADAR_TIDLE)  sr_tidle(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
67                                             .out(t_idle));
68                                      
69    setting_reg #(`FR_RADAR_AMPL)   sr_ampl(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
70                                            .out(ampl_o));
71
72    setting_reg #(`FR_RADAR_FSTART) sr_fstart(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
73                                              .out(fstart_o));
74
75    setting_reg #(`FR_RADAR_FINCR)  sr_fincr(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
76                                             .out(fincr_o));
77
78    // Pulse state machine
79    `define ST_ON   4'b0001
80    `define ST_SW   4'b0010
81    `define ST_LOOK 4'b0100
82    `define ST_IDLE 4'b1000
83
84    reg [3:0]  state;
85    reg [31:0] count;
86
87    always @(posedge clk_i)
88      if (reset_o)
89        begin
90           state <= `ST_ON;
91           count <= 32'b0;
92        end
93      else
94        case (state)
95          `ST_ON:
96            if (count == {16'b0,t_on})
97              begin
98                 state <= `ST_SW;
99                 count <= 32'b0;
100              end
101            else
102              count <= count + 32'b1;
103          
104          `ST_SW:
105            if (count == {16'b0,t_sw})
106              begin
107                 state <= `ST_LOOK;
108                 count <= 32'b0;
109              end
110            else
111              count <= count + 24'b1;
112
113          `ST_LOOK:
114            if (count == {16'b0,t_look})
115              begin
116                 state <= `ST_IDLE;
117                 count <= 32'b0;
118              end
119            else
120              count <= count + 32'b1;
121
122          `ST_IDLE:
123            if (count == t_idle)
124              begin
125                 state <= `ST_ON;
126                 count <= 24'b0;
127              end
128            else
129              count <= count + 32'b1;
130
131          default:                 // Invalid state, reset state machine
132            begin
133               state <= `ST_ON;
134               count <= 32'b0;
135            end
136        endcase
137    
138    assign tx_strobe_o = count[0]; // Drive DAC inputs at 32 MHz
139    assign tx_ctrl_o = (state == `ST_ON);
140    assign rx_ctrl_o = (state == `ST_LOOK);
141    
142 endmodule // radar_control