litex/verilog/m1crg/m1crg.v

212 lines
4.3 KiB
Coq
Raw Normal View History

2012-02-16 12:02:37 -05:00
/*
* Milkymist-NG SoC
* Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Sebastien Bourdeauducq
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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)
) (
input clkin,
input trigger_reset,
output sys_clk,
output reg sys_rst,
/* Reset off-chip devices */
output ac97_rst_n,
output videoin_rst_n,
output flash_rst_n,
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,
/* Ethernet PHY clock */
output reg phy_clk
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
assign ac97_rst_n = ~sys_rst;
assign videoin_rst_n = ~sys_rst;
/*
* 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
assign flash_rst_n = flash_rstcounter[7];
/*
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
2012-02-16 12:02:37 -05:00
wire sdr_clkin;
wire clkdiv;
IBUF #(
.IOSTANDARD("DEFAULT")
) clk2_iob (
.I(clkin),
.O(sdr_clkin)
);
BUFIO2 #(
.DIVIDE(1),
.DIVIDE_BYPASS("FALSE"),
.I_INVERT("FALSE")
) bufio2_inst2 (
.I(sdr_clkin),
.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;
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),
.CLKOUT0_DIVIDE(f_div),
.CLKOUT0_DUTY_CYCLE(0.5),
.CLKOUT0_PHASE(0),
.CLKOUT1_DIVIDE(f_div),
.CLKOUT1_DUTY_CYCLE(0.5),
.CLKOUT1_PHASE(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),
.CLKOUT5_DIVIDE(7),
.CLKOUT5_DUTY_CYCLE(0.5),
.CLKOUT5_PHASE(0.0),
.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 90 clock to generate memory clock, clock DQS and memory address and control signals. */
.CLKOUT3(pllout3), /* < x1 clock for system and memory controller */
2012-05-19 18:30:03 -04:00
.CLKOUT4(pllout4), /* < buffered clkin */
2012-02-16 12:02:37 -05:00
.CLKOUT5(),
.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
/* Ethernet PHY */
always @(posedge pllout4)
phy_clk <= ~phy_clk;
2012-02-16 12:02:37 -05:00
endmodule