Skip to content

Commit

Permalink
soc/cores/clock/lattice_nx.py: added clk contraints for OSCA output
Browse files Browse the repository at this point in the history
  • Loading branch information
trabucayre committed Jul 22, 2024
1 parent ecd0f0e commit b8cb6da
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions litex/soc/cores/clock/lattice_nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ class NXOSCA(LiteXModule):
clk_hf_freq_range = (1.76, 450e6)
clk_hf_freq = 450e6

def __init__(self):
def __init__(self, platform=None):
self.logger = logging.getLogger("NXOSCA")
self.logger.info("Creating NXOSCA.")

self.hf_clk_out = {}
self.hfsdc_clk_out = {}
self.lf_clk_out = None
self.params = {}
self.platform = platform

def create_hf_clk(self, cd, freq, margin=.05):
"""450 - 1.7 Mhz Clk"""
Expand Down Expand Up @@ -86,21 +87,29 @@ def compute_divisor(self, freq, margin):

def do_finalize(self):
if self.hf_clk_out:
divisor = self.compute_divisor(self.hf_clk_out[1], self.hf_clk_out[2])
clk_freq = self.hf_clk_out[1]
divisor = self.compute_divisor(clk_freq, self.hf_clk_out[2])
self.params["i_HFOUTEN"] = 0b1
self.params["p_HF_CLK_DIV"] = divisor
self.params["o_HFCLKOUT"] = self.hf_clk_out[0]
self.params["p_HF_OSC_EN"] = "ENABLED"
if self.platform:
self.platform.add_platform_command("create_clock -period {} -name OSCA_HFCLKOUT [get_pins OSCA.OSCA_inst/HFCLKOUT]".format(str(1e9/clk_freq)))

if self.hfsdc_clk_out:
divisor = self.compute_divisor(self.hfsdc_clk_out[1], self.hfsdc_clk_out[2])
clk_freq = self.hf_clk_out[1]
divisor = self.compute_divisor(clk_freq, self.hfsdc_clk_out[2])
self.params["i_HFSDSCEN"] = 0b1
self.params["p_HF_SED_SEC_DIV"] = divisor
self.params["o_HFSDCOUT"] = self.hfsdc_clk_out[0]
if self.platform:
self.platform.add_platform_command("create_clock -period {} -name OSCA_HFSDCOUT [get_pins OSCA.OSCA_inst/HFSDCOUT]".format(str(1e9/clk_freq)))

if self.lf_clk_out is not None:
self.params["o_LFCLKOUT"] = self.lf_clk_out[0]
self.params["p_LF_OUTPUT_EN"] = "ENABLED"
if self.platform:
self.platform.add_platform_command("create_clock -period {} -name OSCA_LF_OUTPUT_EN [get_pins OSCA.OSCA_inst/LF_OUTPUT_EN]".format(str(1e9/128e3)))

self.specials += Instance("OSCA", **self.params)

Expand Down

0 comments on commit b8cb6da

Please sign in to comment.