3 // USRP - Universal Software Radio Peripheral
5 // Copyright (C) 2003 Matt Ettus
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.
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.
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
22 // Interface to Cypress FX2 bus
23 // A packet is 512 Bytes, the fifo has 4096 lines of 18 bits each
25 `include "../../firmware/include/fpga_regs_common.v"
26 `include "../../firmware/include/fpga_regs_standard.v"
32 output [15:0] usbdata,
34 output reg have_pkt_rdy,
35 output reg rx_overrun,
39 input reset, // DSP side reset (used here), do not reset registers
41 input wire [3:0] channels,
42 input wire [15:0] ch_0,
43 input wire [15:0] ch_1,
44 input wire [15:0] ch_2,
45 input wire [15:0] ch_3,
46 input wire [15:0] ch_4,
47 input wire [15:0] ch_5,
48 input wire [15:0] ch_6,
49 input wire [15:0] ch_7,
50 // Settings, on rxclk also
51 input [6:0] serial_addr, input [31:0] serial_data, input serial_strobe,
52 input reset_regs, //Only reset registers
53 output [31:0] debugbus
56 wire [15:0] fifodata, fifodata_8;
57 reg [15:0] fifodata_16;
59 wire [11:0] rxfifolevel;
62 wire bypass_hb, want_q;
66 setting_reg #(`FR_RX_FORMAT) sr_rxformat(.clock(rxclk),.reset(reset_regs),
67 .strobe(serial_strobe),.addr(serial_addr),.in(serial_data),
68 .out({bypass_hb,want_q,bitwidth,bitshift}));
70 // USB Read Side of FIFO
71 always @(negedge usbclk)
72 have_pkt_rdy <= (rxfifolevel >= 256);
76 always @(negedge usbclk)
80 read_count <= read_count + 1;
85 wire ch0_in, ch0_out, iq_out;
86 assign ch0_in = (phase == 1);
90 .data ( {ch0_in, phase[0], fifodata} ),
91 .wrreq (~rx_full & (phase != 0)),
97 .q ( {ch0_out,iq_out,usbdata} ),
98 .rdreq ( RD & ~read_count[8] ),
102 .rdusedw ( rxfifolevel ),
106 // DSP Write Side of FIFO
116 always @(posedge rxclk)
130 always @(posedge rxclk)
139 if(phase == ((bitwidth == 5'd8) ? (channels>>1) : channels))
142 phase <= phase + 4'd1;
144 assign fifodata = (bitwidth == 5'd8) ? fifodata_8 : fifodata_16;
146 assign fifodata_8 = {round_8(top),round_8(bottom)};
147 reg [15:0] top,bottom;
149 function [7:0] round_8;
152 round_8 = in_val[15:8] + (in_val[15] & |in_val[7:0]);
153 endfunction // round_8
177 endcase // case(phase)
181 4'd1 : fifodata_16 = ch_0_reg;
182 4'd2 : fifodata_16 = ch_1_reg;
183 4'd3 : fifodata_16 = ch_2_reg;
184 4'd4 : fifodata_16 = ch_3_reg;
185 4'd5 : fifodata_16 = ch_4_reg;
186 4'd6 : fifodata_16 = ch_5_reg;
187 4'd7 : fifodata_16 = ch_6_reg;
188 4'd8 : fifodata_16 = ch_7_reg;
189 default : fifodata_16 = 16'hFFFF;
190 endcase // case(phase)
193 reg clear_status_dsp, rx_overrun_dsp;
194 always @(posedge rxclk)
195 clear_status_dsp <= clear_status;
197 always @(negedge usbclk)
198 rx_overrun <= rx_overrun_dsp;
200 always @(posedge rxclk)
202 rx_overrun_dsp <= 1'b0;
203 else if(rxstrobe & (phase != 0))
204 rx_overrun_dsp <= 1'b1;
205 else if(clear_status_dsp)
206 rx_overrun_dsp <= 1'b0;
210 // 15:0 rxclk domain => TXA 15:0
211 // 31:16 usbclk domain => RXA 15:0
213 assign debugbus[0] = reset;
214 assign debugbus[1] = reset_regs;
215 assign debugbus[2] = rxstrobe;
216 assign debugbus[6:3] = channels;
217 assign debugbus[7] = rx_full;
218 assign debugbus[11:8] = phase;
219 assign debugbus[12] = ch0_in;
220 assign debugbus[13] = clear_status_dsp;
221 assign debugbus[14] = rx_overrun_dsp;
222 assign debugbus[15] = rxclk;
224 assign debugbus[16] = bus_reset;
225 assign debugbus[17] = RD;
226 assign debugbus[18] = have_pkt_rdy;
227 assign debugbus[19] = rx_overrun;
228 assign debugbus[20] = read_count[0];
229 assign debugbus[21] = read_count[8];
230 assign debugbus[22] = ch0_out;
231 assign debugbus[23] = iq_out;
232 assign debugbus[24] = clear_status;
233 assign debugbus[30:25] = 0;
234 assign debugbus[31] = usbclk;
236 endmodule // rx_buffer