mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
clock/gowin_gw1n: Add Initial On-Chip Oscillator support.
Ex: self.submodules.osc = GW1NOSC(device="GW1N9K", freq=10e6)
This commit is contained in:
parent
6fc87f7c85
commit
756503ab92
1 changed files with 35 additions and 1 deletions
|
@ -11,7 +11,41 @@ from litex.soc.cores.clock.common import *
|
|||
|
||||
class Open(Signal): pass
|
||||
|
||||
# GoWin / GW1N -------------------------------------------------------------------------------------
|
||||
# GoWin / GW1NOSC ----------------------------------------------------------------------------------
|
||||
|
||||
class GW1NOSC(Module):
|
||||
osc_div_range = (2, 128)
|
||||
def __init__(self, device, freq, margin=1e-2):
|
||||
self.logger = logging.getLogger("GW1NOSC")
|
||||
self.logger.info("Creating GW1NOSC.".format())
|
||||
self.clk = Signal()
|
||||
|
||||
# # #
|
||||
|
||||
# Oscillator frequency.
|
||||
osc_freq = 250e6
|
||||
if device in ["GW1N-4", "GW1NR-4", "GW1N-4B", "GW1NR-4B", "GW1NRF-4B", "GW1N-4C", "GW1NR-4C"]:
|
||||
osc_freq = 210e6
|
||||
|
||||
# Oscillator divider.
|
||||
osc_div = None
|
||||
osc_div_min, osc_div_max = self.osc_div_range
|
||||
for div in range(osc_div_min, osc_div_max):
|
||||
clk_freq = osc_freq/div
|
||||
if (clk_freq >= freq*(1 - margin) and clk_freq <= freq*(1 + margin)):
|
||||
osc_div = div
|
||||
if osc_div is None:
|
||||
raise ValueError("No OSC config found")
|
||||
self.logger.info(f"Configured to {(osc_freq/osc_div)/1e6:3.2f}MHz (div={osc_div}).")
|
||||
|
||||
# Oscillator instance.
|
||||
self.specials += Instance("OSC",
|
||||
p_DEVICE = device,
|
||||
p_FREQ_DIV = osc_div,
|
||||
o_OSCOUT = self.clk
|
||||
)
|
||||
|
||||
# GoWin / GW1NPLL ----------------------------------------------------------------------------------
|
||||
|
||||
class GW1NPLL(Module):
|
||||
nclkouts_max = 1
|
||||
|
|
Loading…
Reference in a new issue