Skip to content

Commit 5698775

Browse files
committed
phy/s7pciephy: Add refclk_freq parameter and use it to support 100, 125MHz or 250MHz RefClks.
Useful when PCIe is used with a free running reference clock.
1 parent 21da327 commit 5698775

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

litepcie/phy/s7pciephy.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class S7PCIEPHY(LiteXModule):
2525
def __init__(self, platform, pads, data_width=64, cd="sys",
2626
# PCIe hardblock parameters.
2727
pcie_data_width = None,
28+
refclk_freq = 100e6,
2829
bar0_size = 0x100000,
2930
msi_type = "msi",
3031
with_ptm = False,
@@ -63,6 +64,7 @@ def __init__(self, platform, pads, data_width=64, cd="sys",
6364
self.platform = platform
6465
self.data_width = data_width
6566
self.pcie_data_width = pcie_data_width
67+
self.refclk_freq = refclk_freq
6668
self.msi_type = msi_type
6769
self.with_ptm = with_ptm
6870

@@ -82,6 +84,7 @@ def __init__(self, platform, pads, data_width=64, cd="sys",
8284
assert nlanes in [1, 2, 4, 8]
8385
assert data_width in [64, 128]
8486
assert pcie_data_width in [64, 128]
87+
assert refclk_freq in [100e6, 125e6, 250e6]
8588

8689
# Clocking / Reset -------------------------------------------------------------------------
8790
self.pcie_refclk = pcie_refclk = Signal()
@@ -94,7 +97,7 @@ def __init__(self, platform, pads, data_width=64, cd="sys",
9497
i_IB = pads.clk_n,
9598
o_O = pcie_refclk
9699
)
97-
platform.add_period_constraint(pads.clk_p, 1e9/100e6)
100+
platform.add_period_constraint(pads.clk_p, 1e9/refclk_freq)
98101
self.cd_pcie = ClockDomain()
99102

100103
# TX (FPGA --> HOST) CDC / Data Width Conversion -------------------------------------------
@@ -175,7 +178,7 @@ def convert_size(command, size, max_size):
175178
i_I = pipe_txoutclk,
176179
o_O = pipe_txoutclk_bufg,
177180
)
178-
mmcm.register_clkin(pipe_txoutclk_bufg, 100e6)
181+
mmcm.register_clkin(pipe_txoutclk_bufg, refclk_freq)
179182
mmcm.create_clkout(self.cd_clk125, 125e6, margin=0)
180183
mmcm.create_clkout(self.cd_clk250, 250e6, margin=0)
181184
mmcm.create_clkout(self.cd_userclk1, userclk1_freq, margin=0)
@@ -490,7 +493,7 @@ def add_sources(self, platform, phy_path, phy_filename=None, user_config=None):
490493
"Max_Payload_Size" : "512_bytes" if self.nlanes != 8 else "256_bytes",
491494
"Maximum_Link_Width" : f"X{self.nlanes}",
492495
"PCIe_Blk_Locn" : "X0Y0",
493-
"Ref_Clk_Freq" : "100_MHz",
496+
"Ref_Clk_Freq" : f"{int(self.refclk_freq/1e6)}_MHz",
494497
"Trans_Buf_Pipeline" : None,
495498
"Trgt_Link_Speed" : "4'h2",
496499
"User_Clk_Freq" : 125 if self.nlanes != 8 else 250,

0 commit comments

Comments
 (0)