Imported Upstream version 3.2.2
[debian/gnuradio] / gr-radar-mono / src / fpga / lib / radar_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 `include "../../../../usrp/firmware/include/fpga_regs_common.v"
23 `include "../../../../usrp/firmware/include/fpga_regs_standard.v"
24
25 module radar_rx(clk_i,rst_i,ena_i,dbg_i,pulse_num_i,rx_in_i_i,
26                 rx_in_q_i,rx_i_o,rx_q_o,rx_strobe_o);
27    
28    input clk_i;
29    input rst_i;
30    input ena_i;
31    input dbg_i;
32    
33    input [15:0] rx_in_i_i;
34    input [15:0] rx_in_q_i;
35    input [15:0] pulse_num_i;
36    
37    output [15:0] rx_i_o;
38    output [15:0] rx_q_o;
39    output reg    rx_strobe_o;
40    
41    reg [15:0] count;
42
43    always @(posedge clk_i)
44      if (rst_i | ~ena_i)
45        count <= 16'b0;
46      else
47        count <= count + 16'b1;
48
49    wire [31:0] fifo_inp = dbg_i ? {count[15:0],pulse_num_i[15:0]} : {rx_in_i_i,rx_in_q_i};
50
51    // Buffer incoming samples every clock
52    wire [31:0] fifo_out;
53    reg         fifo_ack;
54    wire        fifo_empty;
55
56 // Use model if simulating, otherwise Altera Megacell
57 `ifdef SIMULATION
58    fifo_1clk #(32, 2048) buffer(.clock(clk_i),.sclr(rst_i),
59                                 .data(fifo_inp),.wrreq(ena_i),
60                                 .rdreq(fifo_ack),.q(fifo_out),
61                                 .empty(fifo_empty));
62 `else
63    fifo32_2k buffer(.clock(clk_i),.sclr(rst_i),
64                     .data(fifo_inp),.wrreq(ena_i),
65                     .rdreq(fifo_ack),.q(fifo_out),
66                     .empty(fifo_empty));
67 `endif
68    
69    // Write samples to rx_fifo every third clock
70    `define ST_FIFO_IDLE   3'b001
71    `define ST_FIFO_STROBE 3'b010
72    `define ST_FIFO_ACK    3'b100
73
74    reg [2:0]   state;
75
76    always @(posedge clk_i)
77      if (rst_i)
78        begin
79           state <= `ST_FIFO_IDLE;
80           rx_strobe_o <= 1'b0;
81           fifo_ack <= 1'b0;
82        end
83      else
84        case (state)
85          `ST_FIFO_IDLE:
86            if (!fifo_empty)
87              begin
88                 // Tell rx_fifo sample is ready
89                 rx_strobe_o <= 1'b1;
90                 state <= `ST_FIFO_STROBE;
91              end
92          `ST_FIFO_STROBE:
93            begin
94               rx_strobe_o <= 1'b0;
95               // Ack our FIFO
96               fifo_ack <= 1'b1;
97               state <= `ST_FIFO_ACK;
98            end
99          `ST_FIFO_ACK:
100            begin
101               fifo_ack <= 1'b0;
102               state <= `ST_FIFO_IDLE;
103            end
104        endcase // case(state)
105
106    assign rx_i_o = fifo_out[31:16];
107    assign rx_q_o = fifo_out[15:0];
108    
109 endmodule // radar_rx