]> git.gag.com Git - debian/gnuradio/blob - gr-radar-mono/src/fpga/lib/radar_rx.v
1ca546134079cd31849f02220a5e6b12a4c75280
[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,
26                 rx_in_i_i,rx_in_q_i,
27                 rx_i_o,rx_q_o,rx_strobe_o);
28    
29    input clk_i;
30    input rst_i;
31    input ena_i;
32    input dbg_i;
33    
34    input [15:0] rx_in_i_i;
35    input [15:0] rx_in_q_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_data = dbg_i ? {count[15:0],16'hAA55} : {rx_in_i_i,rx_in_q_i};
50
51    // Need to buffer received samples as they come in at 32 bits per cycle
52    // but the rx_buffer.v fifo is only 16 bits wide.
53    //
54    reg         fifo_read;
55    wire [31:0] fifo_out;
56    wire        fifo_empty;
57    
58    fifo32_4k fifo(.clock(clk_i),.sclr(rst_i),
59                   .data(fifo_data),.wrreq(ena_i),
60                   .q(fifo_out),.rdreq(fifo_read),
61                   .empty(fifo_empty) );
62
63    `define ST_RD_IDLE     4'b0001
64    `define ST_RD_REQ      4'b0010
65    `define ST_WR_FIFO     4'b0100
66    `define ST_RD_DELAY    4'b1000
67
68    reg [3:0] state;
69    reg [3:0] delay;
70    
71    always @(posedge clk_i)
72      if (rst_i | ~ena_i)
73        begin
74           state <= `ST_RD_IDLE;
75           delay <= 4'd0;
76           rx_strobe_o <= 1'b0;
77           fifo_read <= 1'b0;
78        end
79      else
80        case (state)
81          `ST_RD_IDLE:
82            begin
83               if (!fifo_empty)
84                 begin
85                    fifo_read <= 1'b1;
86                    state <= `ST_RD_REQ;
87                 end
88            end
89
90          `ST_RD_REQ:
91            begin
92               fifo_read <= 1'b0;
93               rx_strobe_o <= 1'b1;
94               state <= `ST_WR_FIFO;
95            end
96
97          `ST_WR_FIFO:
98            begin
99               rx_strobe_o <= 1'b0;
100               state <= `ST_RD_DELAY;
101            end
102
103          `ST_RD_DELAY:
104            if (delay == 7)
105              begin
106                 delay <= 0;
107                 state <= `ST_RD_IDLE;
108              end
109            else
110              delay <= delay + 1'b1;
111
112        endcase // case(state)
113    
114    assign rx_i_o = fifo_out[31:16];
115    assign rx_q_o = fifo_out[15:0];
116    
117 endmodule // radar_rx