~ubuntu-branches/ubuntu/trusty/gnuradio/trusty

« back to all changes in this revision

Viewing changes to gr-radar-mono/src/fpga/lib/radar_control.v

  • Committer: Bazaar Package Importer
  • Author(s): Kamal Mostafa
  • Date: 2010-03-13 07:46:01 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100313074601-zjsa893a87bozyh7
Tags: 3.2.2.dfsg-1ubuntu1
* Fix build for Ubuntu lucid (LP: #260406)
  - add binary package dep for libusrp0, libusrp2-0: adduser
  - debian/rules clean: remove pre-built Qt moc files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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,reset_o,
 
25
                     tx_side_o,dbg_o,tx_strobe_o,tx_ctrl_o,rx_ctrl_o,
 
26
                     ampl_o,fstart_o,fincr_o,pulse_num_o,io_tx_ena_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_side_o;
 
37
   output        dbg_o;
 
38
   output        tx_strobe_o;
 
39
   output        tx_ctrl_o;
 
40
   output        rx_ctrl_o;
 
41
   output [15:0] ampl_o;
 
42
   output [31:0] fstart_o;
 
43
   output [31:0] fincr_o;
 
44
   output [15:0] pulse_num_o;
 
45
   output        io_tx_ena_o;
 
46
   
 
47
   // Internal configuration
 
48
   wire          lp_ena;
 
49
   wire          md_ena;
 
50
   wire          dr_ena;
 
51
   wire   [1:0]  chirps;
 
52
   wire   [15:0] t_on;
 
53
   wire   [15:0] t_sw;
 
54
   wire   [15:0] t_look;
 
55
   wire   [31:0] t_idle;
 
56
   wire   [31:0] atrdel;
 
57
   
 
58
   // Configuration from host
 
59
   wire [31:0]   mode;
 
60
   setting_reg #(`FR_RADAR_MODE)   sr_mode(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
61
                                           .out(mode));
 
62
   assign reset_o   = mode[0];
 
63
   assign tx_side_o = mode[1];
 
64
   assign lp_ena    = mode[2];
 
65
   assign md_ena    = mode[3];
 
66
   assign dr_ena    = mode[4];
 
67
   assign chirps    = mode[6:5];
 
68
   assign dbg_o     = mode[7];
 
69
   
 
70
   setting_reg #(`FR_RADAR_TON)    sr_ton(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
71
                                          .out(t_on));
 
72
   
 
73
   setting_reg #(`FR_RADAR_TSW)    sr_tsw(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
74
                                          .out(t_sw));
 
75
                                     
 
76
   setting_reg #(`FR_RADAR_TLOOK)  sr_tlook(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
77
                                            .out(t_look));
 
78
                                     
 
79
   setting_reg #(`FR_RADAR_TIDLE)  sr_tidle(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
80
                                            .out(t_idle));
 
81
                                     
 
82
   setting_reg #(`FR_RADAR_AMPL)   sr_ampl(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
83
                                           .out(ampl_o));
 
84
 
 
85
   setting_reg #(`FR_RADAR_FSTART) sr_fstart(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
86
                                             .out(fstart_o));
 
87
 
 
88
   setting_reg #(`FR_RADAR_FINCR)  sr_fincr(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
89
                                            .out(fincr_o));
 
90
 
 
91
   setting_reg #(`FR_RADAR_ATRDEL)  sr_atrdel(.clock(clk_i),.reset(1'b0),.strobe(s_strobe_i),.addr(saddr_i),.in(sdata_i),
 
92
                                            .out(atrdel));
 
93
   
 
94
   // Pulse state machine
 
95
   `define ST_ON   4'b0001
 
96
   `define ST_SW   4'b0010
 
97
   `define ST_LOOK 4'b0100
 
98
   `define ST_IDLE 4'b1000
 
99
 
 
100
   reg [3:0]  state;
 
101
   reg [31:0] count;
 
102
   reg [15:0] pulse_num_o;
 
103
   
 
104
   always @(posedge clk_i)
 
105
     if (reset_o)
 
106
       begin
 
107
          state <= `ST_ON;
 
108
          count <= 32'b0;
 
109
          pulse_num_o <= 16'b0;
 
110
       end
 
111
     else
 
112
       case (state)
 
113
         `ST_ON:
 
114
           if (count == {16'b0,t_on})
 
115
             begin
 
116
                state <= `ST_SW;
 
117
                count <= 32'b0;
 
118
                pulse_num_o <= pulse_num_o + 16'b1;
 
119
             end
 
120
           else
 
121
             count <= count + 32'b1;
 
122
         
 
123
         `ST_SW:
 
124
           if (count == {16'b0,t_sw})
 
125
             begin
 
126
                state <= `ST_LOOK;
 
127
                count <= 32'b0;
 
128
             end
 
129
           else
 
130
             count <= count + 32'b1;
 
131
 
 
132
         `ST_LOOK:
 
133
           if (count == {16'b0,t_look})
 
134
             begin
 
135
                state <= `ST_IDLE;
 
136
                count <= 32'b0;
 
137
             end
 
138
           else
 
139
             count <= count + 32'b1;
 
140
 
 
141
         `ST_IDLE:
 
142
           if (count == t_idle)
 
143
             begin
 
144
                state <= `ST_ON;
 
145
                count <= 32'b0;
 
146
             end
 
147
           else
 
148
             count <= count + 32'b1;
 
149
 
 
150
         default:                 // Invalid state, reset state machine
 
151
           begin
 
152
              state <= `ST_ON;
 
153
              count <= 32'b0;
 
154
           end
 
155
       endcase
 
156
   
 
157
   assign tx_strobe_o = count[0]; // Drive DAC inputs at 32 MHz
 
158
   assign tx_ctrl_o = (state == `ST_ON);
 
159
   assign rx_ctrl_o = (state == `ST_LOOK);
 
160
 
 
161
   // Create delayed version of tx_ctrl_o to drive mixers and TX/RX switch
 
162
   atr_delay atr_delay(.clk_i(clk_i),.rst_i(reset_o),.ena_i(1'b1),.tx_empty_i(!tx_ctrl_o),
 
163
                       .tx_delay_i(atrdel[27:16]),.rx_delay_i(atrdel[11:0]),
 
164
                       .atr_tx_o(io_tx_ena_o));
 
165
   
 
166
endmodule // radar_control