build.plat: add default_clk{,_constraint,_frequency}.
authorwhitequark <cz@m-labs.hk>
Sat, 3 Aug 2019 16:18:46 +0000 (16:18 +0000)
committerwhitequark <cz@m-labs.hk>
Sat, 3 Aug 2019 16:18:46 +0000 (16:18 +0000)
This is the equivalent of oMigen's default_clk and default_clk_period
except the period is taken from the resource.

nmigen/build/plat.py

index f4c5cd5cc88ac615bc9d0e0e42a75fe59417fd60..ef39d23004c854c29f6ccbd6dfb3d79e5213efb3 100644 (file)
@@ -18,8 +18,9 @@ __all__ = ["Platform", "TemplatedPlatform"]
 
 
 class Platform(ResourceManager, metaclass=ABCMeta):
-    resources  = abstractproperty()
-    connectors = abstractproperty()
+    resources   = abstractproperty()
+    connectors  = abstractproperty()
+    default_clk = None
 
     def __init__(self):
         super().__init__(self.resources, self.connectors)
@@ -28,6 +29,21 @@ class Platform(ResourceManager, metaclass=ABCMeta):
 
         self._prepared   = False
 
+    @property
+    def default_clk_constraint(self):
+        if self.default_clk is None:
+            raise AttributeError("Platform '{}' does not define a default clock"
+                                 .format(self.__class__.__name__))
+        return self.lookup(self.default_clk).clock
+
+    @property
+    def default_clk_frequency(self):
+        constraint = self.default_clk_constraint
+        if constraint is None:
+            raise AttributeError("Platform '{}' does not constrain its default clock"
+                                 .format(self.__class__.__name__))
+        return constraint.frequency
+
     def add_file(self, filename, content):
         if not isinstance(filename, str):
             raise TypeError("File name must be a string")