litex/verilog/m1crg/m1crg.v

312 lines
5.3 KiB
Coq
Raw Normal View History

2012-02-16 12:02:37 -05:00
module m1crg #(
parameter in_period = 0.0,
parameter f_mult = 0,
parameter f_div = 0,
parameter clk2x_period = (in_period*f_div)/(2.0*f_mult)
) (
2013-02-11 12:23:06 -05:00
input clk50_pad,
2012-02-16 12:02:37 -05:00
input trigger_reset,
output sys_clk,
output reg sys_rst,
2013-02-11 12:23:06 -05:00
/* Reset NOR flash */
output norflash_rst_n,
2012-02-16 12:02:37 -05:00
2012-02-19 12:43:42 -05:00
/* DDR PHY clocks */
2012-02-20 17:55:20 -05:00
output clk2x_270,
2012-02-19 12:43:42 -05:00
output clk4x_wr,
output clk4x_wr_strb,
output clk4x_rd,
2012-05-19 18:30:03 -04:00
output clk4x_rd_strb,
2013-02-11 12:23:06 -05:00
/* DDR off-chip clocking */
output ddr_clk_pad_p,
output ddr_clk_pad_n,
2012-05-19 18:30:03 -04:00
2013-02-11 12:23:06 -05:00
/* Ethernet PHY clocks */
output reg eth_phy_clk_pad,
input eth_rx_clk_pad,
input eth_tx_clk_pad,
output eth_rx_clk,
output eth_tx_clk,
2012-06-17 07:41:26 -04:00
/* VGA clock */
output vga_clk, /* < buffered, to internal clock network */
output vga_clk_pad, /* < forwarded through ODDR2, to I/O */
/* VGA clock control */
input vga_progclk,
input vga_progdata,
input vga_progen,
output vga_progdone,
output vga_locked
2012-02-16 12:02:37 -05:00
);
/*
* Reset
*/
reg [19:0] rst_debounce;
2012-02-19 12:43:42 -05:00
always @(posedge sys_clk) begin
if(trigger_reset)
2012-02-16 12:02:37 -05:00
rst_debounce <= 20'hFFFFF;
2012-02-19 12:43:42 -05:00
else if(rst_debounce != 20'd0)
rst_debounce <= rst_debounce - 20'd1;
sys_rst <= rst_debounce != 20'd0;
2012-02-16 12:02:37 -05:00
end
/*
* We must release the Flash reset before the system reset
* because the Flash needs some time to come out of reset
* and the CPU begins fetching instructions from it
* as soon as the system reset is released.
* From datasheet, minimum reset pulse width is 100ns
* and reset-to-read time is 150ns.
*/
reg [7:0] flash_rstcounter;
2012-02-19 12:43:42 -05:00
always @(posedge sys_clk) begin
if(trigger_reset)
2012-02-16 12:02:37 -05:00
flash_rstcounter <= 8'd0;
2012-02-19 12:43:42 -05:00
else if(~flash_rstcounter[7])
flash_rstcounter <= flash_rstcounter + 8'd1;
2012-02-16 12:02:37 -05:00
end
2013-02-11 12:23:06 -05:00
assign norflash_rst_n = flash_rstcounter[7];
2012-02-16 12:02:37 -05:00
/*
2012-02-19 12:43:42 -05:00
* Clock management. Inspired by the NWL reference design.
2012-02-16 12:02:37 -05:00
*/
2012-02-19 12:43:42 -05:00
2013-02-11 12:23:06 -05:00
wire sdr_clk50;
2012-02-16 12:02:37 -05:00
wire clkdiv;
IBUF #(
.IOSTANDARD("DEFAULT")
) clk2_iob (
2013-02-11 12:23:06 -05:00
.I(clk50_pad),
.O(sdr_clk50)
2012-02-16 12:02:37 -05:00
);
BUFIO2 #(
.DIVIDE(1),
.DIVIDE_BYPASS("FALSE"),
.I_INVERT("FALSE")
) bufio2_inst2 (
2013-02-11 12:23:06 -05:00
.I(sdr_clk50),
2012-02-16 12:02:37 -05:00
.IOCLK(),
.DIVCLK(clkdiv),
.SERDESSTROBE()
);
2012-02-19 12:43:42 -05:00
wire pll_lckd;
wire buf_pll_fb_out;
wire pllout0;
wire pllout1;
wire pllout2;
wire pllout3;
2012-05-19 18:30:03 -04:00
wire pllout4;
wire pllout5;
2012-02-16 12:02:37 -05:00
PLL_ADV #(
.BANDWIDTH("OPTIMIZED"),
.CLKFBOUT_MULT(4*f_mult),
.CLKFBOUT_PHASE(0.0),
.CLKIN1_PERIOD(in_period),
.CLKIN2_PERIOD(in_period),
2012-02-16 12:02:37 -05:00
.CLKOUT0_DIVIDE(f_div),
.CLKOUT0_DUTY_CYCLE(0.5),
.CLKOUT0_PHASE(0.0),
2012-02-16 12:02:37 -05:00
.CLKOUT1_DIVIDE(f_div),
.CLKOUT1_DUTY_CYCLE(0.5),
.CLKOUT1_PHASE(0.0),
2012-02-19 12:43:42 -05:00
.CLKOUT2_DIVIDE(2*f_div),
2012-02-16 12:02:37 -05:00
.CLKOUT2_DUTY_CYCLE(0.5),
2012-02-20 17:55:20 -05:00
.CLKOUT2_PHASE(270.0),
2012-02-19 12:43:42 -05:00
.CLKOUT3_DIVIDE(4*f_div),
2012-02-16 12:02:37 -05:00
.CLKOUT3_DUTY_CYCLE(0.5),
2012-02-19 12:43:42 -05:00
.CLKOUT3_PHASE(0.0),
2012-05-19 18:30:03 -04:00
.CLKOUT4_DIVIDE(4*f_mult),
2012-02-16 12:02:37 -05:00
.CLKOUT4_DUTY_CYCLE(0.5),
.CLKOUT4_PHASE(0.0),
.CLKOUT5_DIVIDE(2*f_div),
2012-02-16 12:02:37 -05:00
.CLKOUT5_DUTY_CYCLE(0.5),
.CLKOUT5_PHASE(250.0),
2012-02-16 12:02:37 -05:00
.COMPENSATION("INTERNAL"),
.DIVCLK_DIVIDE(1),
.REF_JITTER(0.100),
.CLK_FEEDBACK("CLKFBOUT"),
.SIM_DEVICE("SPARTAN6")
2012-02-19 12:43:42 -05:00
) pll (
2012-02-16 12:02:37 -05:00
.CLKFBDCM(),
2012-02-19 12:43:42 -05:00
.CLKFBOUT(buf_pll_fb_out),
.CLKOUT0(pllout0), /* < x4 clock for writes */
.CLKOUT1(pllout1), /* < x4 clock for reads */
.CLKOUT2(pllout2), /* < x2 270 clock for DQS, memory address and control signals */
2012-02-19 12:43:42 -05:00
.CLKOUT3(pllout3), /* < x1 clock for system and memory controller */
2013-02-11 12:23:06 -05:00
.CLKOUT4(pllout4), /* < buffered clk50 */
.CLKOUT5(pllout5), /* < x2 clock to off-chip DDR */
2012-02-16 12:02:37 -05:00
.CLKOUTDCM0(),
.CLKOUTDCM1(),
.CLKOUTDCM2(),
.CLKOUTDCM3(),
.CLKOUTDCM4(),
.CLKOUTDCM5(),
.DO(),
.DRDY(),
2012-02-19 12:43:42 -05:00
.LOCKED(pll_lckd),
.CLKFBIN(buf_pll_fb_out),
2012-02-16 12:02:37 -05:00
.CLKIN1(clkdiv),
.CLKIN2(1'b0),
.CLKINSEL(1'b1),
.DADDR(5'b00000),
.DCLK(1'b0),
.DEN(1'b0),
.DI(16'h0000),
.DWE(1'b0),
.RST(1'b0),
.REL(1'b0)
);
BUFPLL #(
.DIVIDE(4)
2012-02-19 12:43:42 -05:00
) wr_bufpll (
.PLLIN(pllout0),
2012-02-16 12:02:37 -05:00
.GCLK(sys_clk),
2012-02-19 12:43:42 -05:00
.LOCKED(pll_lckd),
.IOCLK(clk4x_wr),
2012-02-16 12:02:37 -05:00
.LOCK(),
2012-02-19 12:43:42 -05:00
.SERDESSTROBE(clk4x_wr_strb)
2012-02-16 12:02:37 -05:00
);
BUFPLL #(
.DIVIDE(4)
2012-02-19 12:43:42 -05:00
) rd_bufpll (
.PLLIN(pllout1),
2012-02-16 12:02:37 -05:00
.GCLK(sys_clk),
2012-02-19 12:43:42 -05:00
.LOCKED(pll_lckd),
.IOCLK(clk4x_rd),
2012-02-16 12:02:37 -05:00
.LOCK(),
2012-02-19 12:43:42 -05:00
.SERDESSTROBE(clk4x_rd_strb)
2012-02-16 12:02:37 -05:00
);
BUFG bufg_x2_2(
2012-02-19 12:43:42 -05:00
.I(pllout2),
2012-02-20 17:55:20 -05:00
.O(clk2x_270)
2012-02-16 12:02:37 -05:00
);
2012-02-19 12:43:42 -05:00
BUFG bufg_x1(
.I(pllout3),
.O(sys_clk)
2012-02-16 12:02:37 -05:00
);
2012-05-19 18:30:03 -04:00
wire clk50g;
BUFG bufg_50(
.I(pllout4),
.O(clk50g)
);
wire clk2x_off;
BUFG bufg_x2_offclk(
.I(pllout5),
.O(clk2x_off)
);
2013-02-11 12:23:06 -05:00
/*
* SDRAM clock
*/
ODDR2 #(
.DDR_ALIGNMENT("NONE"),
.INIT(1'b0),
.SRTYPE("SYNC")
) sd_clk_forward_p (
2013-02-13 17:59:35 -05:00
.Q(ddr_clk_pad_p),
.C0(clk2x_off),
.C1(~clk2x_off),
2013-02-11 12:23:06 -05:00
.CE(1'b1),
.D0(1'b1),
.D1(1'b0),
.R(1'b0),
.S(1'b0)
);
ODDR2 #(
.DDR_ALIGNMENT("NONE"),
.INIT(1'b0),
.SRTYPE("SYNC")
) sd_clk_forward_n (
2013-02-13 17:59:35 -05:00
.Q(ddr_clk_pad_n),
.C0(clk2x_off),
.C1(~clk2x_off),
2013-02-11 12:23:06 -05:00
.CE(1'b1),
.D0(1'b0),
.D1(1'b1),
.R(1'b0),
.S(1'b0)
);
/*
* Ethernet PHY
*/
always @(posedge clk50g)
2013-02-13 17:59:35 -05:00
eth_phy_clk_pad <= ~eth_phy_clk_pad;
2012-06-17 07:41:26 -04:00
2013-02-11 12:23:06 -05:00
/* Let the synthesizer insert the appropriate buffers */
assign eth_rx_clk = eth_rx_clk_pad;
assign eth_tx_clk = eth_tx_clk_pad;
/*
* VGA clock
*/
2012-06-17 07:41:26 -04:00
DCM_CLKGEN #(
.CLKFXDV_DIVIDE(2),
.CLKFX_DIVIDE(4),
2013-03-28 15:45:42 -04:00
.CLKFX_MD_MAX(3.0),
2012-06-17 07:41:26 -04:00
.CLKFX_MULTIPLY(2),
.CLKIN_PERIOD(20.0),
2012-06-17 07:41:26 -04:00
.SPREAD_SPECTRUM("NONE"),
.STARTUP_WAIT("FALSE")
) vga_clock_gen (
.CLKFX(vga_clk),
.CLKFX180(),
.CLKFXDV(),
.STATUS(),
.CLKIN(clk50g),
2012-06-17 07:41:26 -04:00
.FREEZEDCM(1'b0),
.PROGCLK(vga_progclk),
.PROGDATA(vga_progdata),
.PROGEN(vga_progen),
.PROGDONE(vga_progdone),
.LOCKED(vga_locked),
2013-03-29 12:14:48 -04:00
.RST(~pll_lckd | sys_rst)
2012-06-17 07:41:26 -04:00
);
ODDR2 #(
.DDR_ALIGNMENT("NONE"),
.INIT(1'b0),
.SRTYPE("SYNC")
) vga_clock_forward (
.Q(vga_clk_pad),
.C0(vga_clk),
.C1(~vga_clk),
.CE(1'b1),
.D0(1'b1),
.D1(1'b0),
.R(1'b0),
.S(1'b0)
);
2012-02-16 12:02:37 -05:00
endmodule