updated wiki url
[debian/gnuradio] / usrp2 / fpga / top / u2plus / u2plus.v
1 `timescale 1ns / 1ps
2 //////////////////////////////////////////////////////////////////////////////////
3
4 module u2plus
5   (
6    // Misc, debug
7    output [4:0] leds,  // LED4 is shared w/INIT_B
8    input [3:0] dipsw,
9    output [31:0] debug,
10    output [1:0] debug_clk,
11    output uart_tx_o,
12    input uart_rx_i,
13    
14    // Expansion
15    input exp_pps_in_p, // Diff
16    input exp_pps_in_n, // Diff
17    output exp_pps_out_p, // Diff 
18    output exp_pps_out_n, // Diff 
19    
20    // GMII
21    //   GMII-CTRL
22    input GMII_COL,
23    input GMII_CRS,
24
25    //   GMII-TX
26    output reg [7:0] GMII_TXD,
27    output reg GMII_TX_EN,
28    output reg GMII_TX_ER,
29    output GMII_GTX_CLK,
30    input GMII_TX_CLK,  // 100mbps clk
31
32    //   GMII-RX
33    input [7:0] GMII_RXD,
34    input GMII_RX_CLK,
35    input GMII_RX_DV,
36    input GMII_RX_ER,
37
38    //   GMII-Management
39    inout MDIO,
40    output MDC,
41    input PHY_INTn,   // open drain
42    output PHY_RESETn,
43    input PHY_CLK,   // possibly use on-board osc
44    input clk_to_mac,
45    output eth_led,
46    
47    // SERDES
48    output ser_enable,
49    output ser_prbsen,
50    output ser_loopen,
51    output ser_rx_en,
52    
53    output ser_tx_clk,
54    output reg [15:0] ser_t,
55    output reg ser_tklsb,
56    output reg ser_tkmsb,
57
58    input ser_rx_clk,
59    input [15:0] ser_r,
60    input ser_rklsb,
61    input ser_rkmsb,
62    
63    // ADC
64    input [13:0] adc_a,
65    input adc_ovf_a,
66    output adc_oen_a,
67    output adc_pdn_a,
68    
69    input [13:0] adc_b,
70    input adc_ovf_b,
71    output adc_oen_b,
72    output adc_pdn_b,
73    
74    // DAC
75    output [15:0] dac_a,
76    output [15:0] dac_b,
77    input dac_lock,     // unused for now
78    
79    // I2C
80    inout SCL,
81    inout SDA,
82
83    // Clock Gen Control
84    output [1:0] clk_en,
85    output [1:0] clk_sel,
86    input clk_func,        // FIXME is an input to control the 9510
87    input clk_status,
88
89    // Clocks
90    input clk_fpga_p,  // Diff
91    input clk_fpga_n,  // Diff
92    input pps_in,
93    input POR,
94    
95    // AD9510 SPI
96    output sclk,
97    output sen_clk,
98    output sdi,
99    input sdo,
100
101    // TX side SPI -- tx_db, tx_adc, tx_dac, 9777
102    output sen_dac,
103    output sen_tx_db,
104    output sen_tx_adc,
105    output sen_tx_dac,
106    output mosi_tx,
107    input miso_dac,
108    input miso_tx_db,
109    input miso_tx_adc,
110    output sclk_tx,
111
112    // RX side SPI
113    output sen_rx_db,
114    output sclk_rx_db,
115    input sdo_rx_db,
116    output sdi_rx_db,
117
118    output sen_rx_adc,
119    output sclk_rx_adc,
120    input sdo_rx_adc,
121    output sdi_rx_adc,
122
123    output sen_rx_dac,
124    output sclk_rx_dac,
125    output sdi_rx_dac,
126
127    // DB IO Pins
128    inout [15:0] io_tx,
129    inout [15:0] io_rx,
130
131    // SPI Flash
132    output flash_cs,
133    output flash_clk,
134    output flash_mosi,
135    input flash_miso
136    );
137
138    // FPGA-specific pins connections
139    wire         aux_clk = PHY_CLK;
140
141    wire         clk_fpga, dsp_clk, clk_div, dcm_out, wb_clk, clock_ready;
142
143    IBUFGDS clk_fpga_pin (.O(clk_fpga),.I(clk_fpga_p),.IB(clk_fpga_n));
144    defparam     clk_fpga_pin.IOSTANDARD = "LVPECL_25";
145    
146    wire         exp_pps_in;
147    IBUFDS exp_pps_in_pin (.O(exp_pps_in),.I(exp_pps_in_p),.IB(exp_pps_in_n));
148    defparam     exp_pps_in_pin.IOSTANDARD = "LVDS_25";
149    
150    wire         exp_pps_out;
151    OBUFDS exp_pps_out_pin (.O(exp_pps_out_p),.OB(exp_pps_out_n),.I(exp_pps_out));
152    defparam     exp_pps_out_pin.IOSTANDARD = "LVDS_25";
153
154    reg [5:0]    clock_ready_d;
155    always @(posedge aux_clk)
156      clock_ready_d[5:0] <= {clock_ready_d[4:0],clock_ready};
157
158    wire         dcm_rst = ~&clock_ready_d & |clock_ready_d;
159    wire         clk_muxed = clock_ready ? clk_fpga : aux_clk;
160
161    wire         adc_on_a, adc_on_b, adc_oe_a, adc_oe_b;
162    assign       adc_oen_a = ~adc_oe_a;
163    assign       adc_oen_b = ~adc_oe_b;
164    assign       adc_pdn_a = ~adc_on_a;  
165    assign       adc_pdn_b = ~adc_on_b;  
166
167    // Handle Clocks
168    DCM DCM_INST (.CLKFB(dsp_clk), 
169                  .CLKIN(clk_muxed), 
170                  .DSSEN(0), 
171                  .PSCLK(0), 
172                  .PSEN(0), 
173                  .PSINCDEC(0), 
174                  .RST(dcm_rst), 
175                  .CLKDV(clk_div), 
176                  .CLKFX(), 
177                  .CLKFX180(), 
178                  .CLK0(dcm_out), 
179                  .CLK2X(), 
180                  .CLK2X180(), 
181                  .CLK90(), 
182                  .CLK180(), 
183                  .CLK270(), 
184                  .LOCKED(LOCKED_OUT), 
185                  .PSDONE(), 
186                  .STATUS());
187    defparam DCM_INST.CLK_FEEDBACK = "1X";
188    defparam DCM_INST.CLKDV_DIVIDE = 2.0;
189    defparam DCM_INST.CLKFX_DIVIDE = 1;
190    defparam DCM_INST.CLKFX_MULTIPLY = 4;
191    defparam DCM_INST.CLKIN_DIVIDE_BY_2 = "FALSE";
192    defparam DCM_INST.CLKIN_PERIOD = 10.000;
193    defparam DCM_INST.CLKOUT_PHASE_SHIFT = "NONE";
194    defparam DCM_INST.DESKEW_ADJUST = "SYSTEM_SYNCHRONOUS";
195    defparam DCM_INST.DFS_FREQUENCY_MODE = "LOW";
196    defparam DCM_INST.DLL_FREQUENCY_MODE = "LOW";
197    defparam DCM_INST.DUTY_CYCLE_CORRECTION = "TRUE";
198    defparam DCM_INST.FACTORY_JF = 16'h8080;
199    defparam DCM_INST.PHASE_SHIFT = 0;
200    defparam DCM_INST.STARTUP_WAIT = "FALSE";
201
202    BUFG dspclk_BUFG (.I(dcm_out), .O(dsp_clk));
203    BUFG wbclk_BUFG (.I(clk_div), .O(wb_clk));
204
205    // I2C -- Don't use external transistors for open drain, the FPGA implements this
206    IOBUF scl_pin(.O(scl_pad_i), .IO(SCL), .I(scl_pad_o), .T(scl_pad_oen_o));
207    IOBUF sda_pin(.O(sda_pad_i), .IO(SDA), .I(sda_pad_o), .T(sda_pad_oen_o));
208
209    // LEDs are active low outputs
210    wire [4:0] leds_int;
211    assign     leds = ~leds_int;  // drive low to turn on leds
212    
213    // SPI
214    wire         miso, mosi, sclk_int;
215    assign       {sclk,sdi} = (~sen_clk | ~sen_dac) ? {sclk_int,mosi} : 2'b0;
216    assign       {sclk_tx_db,sdi_tx_db} = ~sen_tx_db ? {sclk_int,mosi} : 2'b0;
217    assign       {sclk_tx_dac,sdi_tx_dac} = ~sen_tx_dac ? {sclk_int,mosi} : 2'b0;
218    assign       {sclk_tx_adc,sdi_tx_adc} = ~sen_tx_adc ? {sclk_int,mosi} : 2'b0;
219    assign       {sclk_rx_db,sdi_rx_db} = ~sen_rx_db ? {sclk_int,mosi} : 2'b0;
220    assign       {sclk_rx_dac,sdi_rx_dac} = ~sen_rx_dac ? {sclk_int,mosi} : 2'b0;
221    assign       {sclk_rx_adc,sdi_rx_adc} = ~sen_rx_adc ? {sclk_int,mosi} : 2'b0;
222    
223    assign       miso = (~sen_clk & sdo) | (~sen_dac & sdo) | 
224                 (~sen_tx_db & sdo_tx_db) | (~sen_tx_adc & sdo_tx_adc) |
225                 (~sen_rx_db & sdo_rx_db) | (~sen_rx_adc & sdo_rx_adc);
226
227    wire         GMII_TX_EN_unreg, GMII_TX_ER_unreg;
228    wire [7:0]   GMII_TXD_unreg;
229    wire         GMII_GTX_CLK_int;
230    
231    always @(posedge GMII_GTX_CLK_int)
232      begin
233         GMII_TX_EN <= GMII_TX_EN_unreg;
234         GMII_TX_ER <= GMII_TX_ER_unreg;
235         GMII_TXD <= GMII_TXD_unreg;
236      end
237
238    OFDDRRSE OFDDRRSE_gmii_inst 
239      (.Q(GMII_GTX_CLK),      // Data output (connect directly to top-level port)
240       .C0(GMII_GTX_CLK_int),    // 0 degree clock input
241       .C1(~GMII_GTX_CLK_int),    // 180 degree clock input
242       .CE(1),    // Clock enable input
243       .D0(0),    // Posedge data input
244       .D1(1),    // Negedge data input
245       .R(0),      // Synchronous reset input
246       .S(0)       // Synchronous preset input
247       );
248    
249    wire ser_tklsb_unreg, ser_tkmsb_unreg;
250    wire [15:0] ser_t_unreg;
251    wire        ser_tx_clk_int;
252    
253    always @(posedge ser_tx_clk_int)
254      begin
255         ser_tklsb <= ser_tklsb_unreg;
256         ser_tkmsb <= ser_tkmsb_unreg;
257         ser_t <= ser_t_unreg;
258      end
259
260    assign ser_tx_clk = clk_fpga;
261
262    reg [15:0] ser_r_int;
263    reg        ser_rklsb_int, ser_rkmsb_int;
264
265    always @(posedge ser_rx_clk)
266      begin
267         ser_r_int <= ser_r;
268         ser_rklsb_int <= ser_rklsb;
269         ser_rkmsb_int <= ser_rkmsb;
270      end
271    
272    /*
273    OFDDRRSE OFDDRRSE_serdes_inst 
274      (.Q(ser_tx_clk),      // Data output (connect directly to top-level port)
275       .C0(ser_tx_clk_int),    // 0 degree clock input
276       .C1(~ser_tx_clk_int),    // 180 degree clock input
277       .CE(1),    // Clock enable input
278       .D0(0),    // Posedge data input
279       .D1(1),    // Negedge data input
280       .R(0),      // Synchronous reset input
281       .S(0)       // Synchronous preset input
282       );
283    */
284    u2_core u2_core(.dsp_clk           (dsp_clk),
285                      .wb_clk            (wb_clk),
286                      .clock_ready       (clock_ready),
287                      .clk_to_mac        (clk_to_mac),
288                      .pps_in            (pps_in),
289                      .leds              (leds_int),
290                      .debug             (debug[31:0]),
291                      .debug_clk         (debug_clk[1:0]),
292                      .exp_pps_in        (exp_pps_in),
293                      .exp_pps_out       (exp_pps_out),
294                      .GMII_COL          (GMII_COL),
295                      .GMII_CRS          (GMII_CRS),
296                      .GMII_TXD          (GMII_TXD_unreg[7:0]),
297                      .GMII_TX_EN        (GMII_TX_EN_unreg),
298                      .GMII_TX_ER        (GMII_TX_ER_unreg),
299                      .GMII_GTX_CLK      (GMII_GTX_CLK_int),
300                      .GMII_TX_CLK       (GMII_TX_CLK),
301                      .GMII_RXD          (GMII_RXD[7:0]),
302                      .GMII_RX_CLK       (GMII_RX_CLK),
303                      .GMII_RX_DV        (GMII_RX_DV),
304                      .GMII_RX_ER        (GMII_RX_ER),
305                      .MDIO              (MDIO),
306                      .MDC               (MDC),
307                      .PHY_INTn          (PHY_INTn),
308                      .PHY_RESETn        (PHY_RESETn),
309                      .PHY_CLK           (PHY_CLK),
310                      .ser_enable        (ser_enable),
311                      .ser_prbsen        (ser_prbsen),
312                      .ser_loopen        (ser_loopen),
313                      .ser_rx_en         (ser_rx_en),
314                      .ser_tx_clk        (ser_tx_clk_int),
315                      .ser_t             (ser_t_unreg[15:0]),
316                      .ser_tklsb         (ser_tklsb_unreg),
317                      .ser_tkmsb         (ser_tkmsb_unreg),
318                      .ser_rx_clk        (ser_rx_clk),
319                      .ser_r             (ser_r_int[15:0]),
320                      .ser_rklsb         (ser_rklsb_int),
321                      .ser_rkmsb         (ser_rkmsb_int),
322                      .cpld_start        (cpld_start),
323                      .cpld_mode         (cpld_mode),
324                      .cpld_done         (cpld_done),
325                      .cpld_din          (cpld_din),
326                      .cpld_clk          (cpld_clk),
327                      .cpld_detached     (cpld_detached),
328                      .adc_a             (adc_a[13:0]),
329                      .adc_ovf_a         (adc_ovf_a),
330                      .adc_on_a          (adc_on_a),
331                      .adc_oe_a          (adc_oe_a),
332                      .adc_b             (adc_b[13:0]),
333                      .adc_ovf_b         (adc_ovf_b),
334                      .adc_on_b          (adc_on_b),
335                      .adc_oe_b          (adc_oe_b),
336                      .dac_a             (dac_a[15:0]),
337                      .dac_b             (dac_b[15:0]),
338                      .scl_pad_i         (scl_pad_i),
339                      .scl_pad_o         (scl_pad_o),
340                      .scl_pad_oen_o     (scl_pad_oen_o),
341                      .sda_pad_i         (sda_pad_i),
342                      .sda_pad_o         (sda_pad_o),
343                      .sda_pad_oen_o     (sda_pad_oen_o),
344                      .clk_en            (clk_en[1:0]),
345                      .clk_sel           (clk_sel[1:0]),
346                      .clk_func          (clk_func),
347                      .clk_status        (clk_status),
348                      .sclk              (sclk_int),
349                      .mosi              (mosi),
350                      .miso              (miso),
351                      .sen_clk           (sen_clk),
352                      .sen_dac           (sen_dac),
353                      .sen_tx_db         (sen_tx_db),
354                      .sen_tx_adc        (sen_tx_adc),
355                      .sen_tx_dac        (sen_tx_dac),
356                      .sen_rx_db         (sen_rx_db),
357                      .sen_rx_adc        (sen_rx_adc),
358                      .sen_rx_dac        (sen_rx_dac),
359                      .io_tx             (io_tx[15:0]),
360                      .io_rx             (io_rx[15:0]),
361                      .RAM_D             (RAM_D),
362                      .RAM_A             (RAM_A),
363                      .RAM_CE1n          (RAM_CE1n),
364                      .RAM_CENn          (RAM_CENn),
365                      .RAM_CLK           (RAM_CLK),
366                      .RAM_WEn           (RAM_WEn),
367                      .RAM_OEn           (RAM_OEn),
368                      .RAM_LDn           (RAM_LDn), 
369                      .uart_tx_o         (uart_tx_o),
370                      //.uart_rx_i         (uart_rx_i),
371                      .uart_rx_i         (),
372                      .uart_baud_o       (),
373                      .sim_mode          (1'b0),
374                      .clock_divider     (2)
375                      );
376    
377 endmodule // u2plus