build.res: accept a list of clocks in ConstraintManager constructor.
authorwhitequark <cz@m-labs.hk>
Sat, 1 Jun 2019 15:41:41 +0000 (15:41 +0000)
committerwhitequark <cz@m-labs.hk>
Sat, 1 Jun 2019 15:41:41 +0000 (15:41 +0000)
nmigen/build/res.py
nmigen/test/test_build_res.py

index f447ff709f4a6bd648a3e68e4f6a1ef91debbbf2..c14efafcc047cf6d8226833f72f0fa4de7fc0a8e 100644 (file)
@@ -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:
index adc25bfd1dc074e1ca3af7d4f48db4b350252508..43dc7bda3300dec6f12891d6571be3ddd44addec 100644 (file)
@@ -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 = [