From e110ac1c575051ce5522835e2a038173bc832754 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 1 Jun 2019 15:41:41 +0000 Subject: [PATCH] build.res: accept a list of clocks in ConstraintManager constructor. --- nmigen/build/res.py | 6 +++++- nmigen/test/test_build_res.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/nmigen/build/res.py b/nmigen/build/res.py index f447ff7..c14efaf 100644 --- a/nmigen/build/res.py +++ b/nmigen/build/res.py @@ -15,7 +15,7 @@ class ConstraintError(Exception): class ConstraintManager: - def __init__(self, resources): + def __init__(self, resources, clocks): self.resources = OrderedDict() self.requested = OrderedDict() self.clocks = OrderedDict() @@ -25,6 +25,10 @@ class ConstraintManager: self._diffpairs = [] self.add_resources(resources) + for name_number, frequency in clocks: + if not isinstance(name_number, tuple): + name_number = (name_number, 0) + self.add_clock(*name_number, frequency) def add_resources(self, resources): for r in resources: diff --git a/nmigen/test/test_build_res.py b/nmigen/test/test_build_res.py index adc25bf..43dc7bd 100644 --- a/nmigen/test/test_build_res.py +++ b/nmigen/test/test_build_res.py @@ -17,15 +17,24 @@ class ConstraintManagerTestCase(FHDLTestCase): Subsignal("sda", Pins("N11")) ) ] - self.cm = ConstraintManager(self.resources) + self.cm = ConstraintManager(self.resources, []) def test_basic(self): + self.clocks = [ + ("clk100", 100), + (("clk50", 0), 50), + ] + self.cm = ConstraintManager(self.resources, self.clocks) self.assertEqual(self.cm.resources, { ("clk100", 0): self.resources[0], ("clk50", 0): self.resources[1], ("user_led", 0): self.resources[2], ("i2c", 0): self.resources[3] }) + self.assertEqual(self.cm.clocks, { + ("clk100", 0): 100, + ("clk50", 0): 50, + }) def test_add_resources(self): new_resources = [ -- 2.30.2