mibuild: get rid of Platform factory function, cleanup
authorSebastien Bourdeauducq <sb@m-labs.hk>
Fri, 13 Mar 2015 22:17:45 +0000 (23:17 +0100)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Fri, 13 Mar 2015 22:25:15 +0000 (23:25 +0100)
23 files changed:
examples/cordic/cordic_impl.py
mibuild/generic_platform.py
mibuild/platforms/apf27.py
mibuild/platforms/apf51.py
mibuild/platforms/de0nano.py
mibuild/platforms/kc705.py
mibuild/platforms/lx9_microboard.py
mibuild/platforms/m1.py
mibuild/platforms/mixxeo.py
mibuild/platforms/ml605.py
mibuild/platforms/papilio_pro.py
mibuild/platforms/pipistrello.py
mibuild/platforms/rhino.py
mibuild/platforms/roach.py
mibuild/platforms/sim.py
mibuild/platforms/usrp_b100.py
mibuild/platforms/zedboard.py
mibuild/platforms/ztex_115d.py
mibuild/xilinx/__init__.py
mibuild/xilinx/common.py
mibuild/xilinx/ise.py
mibuild/xilinx/platform.py [new file with mode: 0644]
mibuild/xilinx/vivado.py

index a1f329b59f5160d14457bec8849203a09fcd74e0..f63418d192d4b3cff60cbea2dad42aa70bb6a5d7 100644 (file)
@@ -6,7 +6,7 @@ from migen.genlib.cordic import Cordic
 from mibuild.tools import mkdir_noerror
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 class CordicImpl(Module):
        def __init__(self, name, **kwargs):
@@ -27,7 +27,7 @@ class CordicImpl(Module):
        def build(self):
                self.platform.build(self, build_name=self.name)
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        _io = [
                ("clk", 0, Pins("AB13")),
                ("rst", 0, Pins("V5")),
@@ -38,7 +38,7 @@ class Platform(XilinxISEPlatform):
                ),
        ]
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx45-fgg484-2", self._io,
+               XilinxPlatform.__init__(self, "xc6slx45-fgg484-2", self._io,
                        lambda p: SimpleCRG(p, "clk", "rst"))
 
 if __name__ == "__main__":
index 9704e5d5dd4d097dcd8cd2547a9d604a2680af56..d8781e8a6f86655d21a38e1248828b469a584c6f 100644 (file)
@@ -285,3 +285,6 @@ class GenericPlatform:
                argdict = dict((k, autotype(v)) for k, v in zip(*[iter(arg)]*2))
                kwargs.update(argdict)
                self.build(*args, **kwargs)
+
+       def create_programmer(self):
+               raise NotImplementedError
index 3490c1c4c58036e53b7d863cbd6f5732d683066a..984dff36a5cae4b274e0e276883781416b1ce846 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _ios = [
        ("clk0", 0, Pins("N9"), IOStandard("LVCMOS18")),
@@ -141,11 +141,12 @@ _connectors = [
                "None")  # 116 USBH2_CLK USB_HOST2 +2V5 PA0
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        default_clk_name = "clk0"
        default_clk_period = 10
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc3s200a-ft256-4", _ios,
+               XilinxPlatform.__init__(self, "xc3s200a-ft256-4", _ios,
                        lambda p: SimpleCRG(p, "clk0", None), _connectors)
 
        def do_finalize(self, fragment):
index 2f7f92d601d63d3966c00f78659e4c7bcfddfd62..856f99217663367b28897b65272c177065f355d8 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _ios = [
        ("clk3", 0, Pins("N8"), IOStandard("LVCMOS33")),
@@ -168,11 +168,12 @@ _connectors = [
                        "None")  # 140 FPGA_BANK3_POWER
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        default_clk_name = "clk3"
        default_clk_period = 10.526
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx9-2csg225", _ios,
+               XilinxPlatform.__init__(self, "xc6slx9-2csg225", _ios,
                        lambda p: SimpleCRG(p, "clk3", None), _connectors)
 
        def do_finalize(self, fragment):
@@ -180,4 +181,3 @@ class Platform(XilinxISEPlatform):
                        self.add_period_constraint(self.lookup_request("clk3"), 10.526)
                except ConstraintError:
                        pass
-
index 4cab4b9cc93477f19dfeec64c1ae0f09ddfcf8e0..2ce73fc7ff7bf0b64957e2683fc7c20d15f0e6db 100644 (file)
@@ -94,6 +94,7 @@ _io = [
 class Platform(AlteraQuartusPlatform):
        default_clk_name = "clk50"
        default_clk_period = 20
+
        def __init__(self):
                AlteraQuartusPlatform.__init__(self, "EP4CE22F17C6", _io,
                        lambda p: SimpleCRG(p, "clk50", None))
index b439ce6bb3ca535c68c9c59c1a00c4c8cc80d026..4d9e923f29f43af0bbcd854a6466ee79643d5e63 100644 (file)
@@ -1,9 +1,8 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
+from mibuild.xilinx import XilinxPlatform, XC3SProg, VivadoProgrammer
+from mibuild.xilinx.ise import XilinxISEToolchain
 from mibuild.xilinx.common import CRG_DS
-from mibuild.xilinx.ise import XilinxISEPlatform
-from mibuild.xilinx.vivado import XilinxVivadoPlatform
-from mibuild.xilinx.programmer import XC3SProg, VivadoProgrammer
 
 _io = [
        ("user_led", 0, Pins("AB8"), IOStandard("LVCMOS15")),
@@ -378,47 +377,41 @@ _connectors = [
        )
 ]
 
-def Platform(*args, toolchain="vivado", programmer="xc3sprog", **kwargs):
-       if toolchain == "ise":
-               xilinx_platform = XilinxISEPlatform
-       elif toolchain == "vivado":
-               xilinx_platform = XilinxVivadoPlatform
-       else:
-               raise ValueError
+class Platform(XilinxPlatform):
+       identifier = 0x4B37
+       default_clk_name = "clk156"
+       default_clk_period = 6.4
 
-       class RealPlatform(xilinx_platform):
-               identifier = 0x4B37
-               default_clk_name = "clk156"
-               default_clk_period = 6.4
-               bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g ConfigRate:12 -g SPI_buswidth:4"
+       def __init__(self, toolchain="vivado", programmer="xc3sprog"):
+               XilinxPlatform.__init__(self, "xc7k325t-ffg900-2", _io, 
+                       default_crg_factory=lambda p: CRG_DS(p, "clk156", "cpu_reset"),
+                       connectors=_connectors,
+                       toolchain=toolchain)
+               self.bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g ConfigRate:12 -g SPI_buswidth:4"
+               self.programmer = programmer
 
-               def __init__(self, crg_factory=lambda p: CRG_DS(p, "clk156", "cpu_reset")):
-                       xilinx_platform.__init__(self, "xc7k325t-ffg900-2", _io, crg_factory, _connectors)
+       def create_programmer(self):
+               if self.programmer == "xc3sprog":
+                       return XC3SProg("jtaghs1_fast", "bscan_spi_kc705.bit")
+               elif self.programmer == "vivado":
+                       return VivadoProgrammer()
+               else:
+                       raise ValueError("{} programmer is not supported".format(programmer))
 
-               def create_programmer(self):
-                       if programmer == "xc3sprog":
-                               return XC3SProg("jtaghs1_fast", "bscan_spi_kc705.bit")
-                       elif programmer == "vivado":
-                               return VivadoProgrammer()
-                       else:
-                               raise ValueError("{} programmer is not supported".format(programmer))
-
-               def do_finalize(self, fragment):
-                       try:
-                               self.add_period_constraint(self.lookup_request("clk156").p, 6.4)
-                       except ConstraintError:
-                               pass
-                       try:
-                               self.add_period_constraint(self.lookup_request("clk200").p, 5.0)
-                       except ConstraintError:
-                               pass
-                       try:
-                               self.add_period_constraint(self.lookup_request("eth_clocks").rx, 8.0)
-                       except ConstraintError:
-                               pass
-                       if isinstance(self, XilinxISEPlatform):
-                               self.add_platform_command("CONFIG DCI_CASCADE = \"33 32 34\";")
-                       else:
-                               self.add_platform_command("set_property DCI_CASCADE {{32 34}} [get_iobanks 33]")
-
-       return RealPlatform(*args, **kwargs)
+       def do_finalize(self, fragment):
+               try:
+                       self.add_period_constraint(self.lookup_request("clk156").p, 6.4)
+               except ConstraintError:
+                       pass
+               try:
+                       self.add_period_constraint(self.lookup_request("clk200").p, 5.0)
+               except ConstraintError:
+                       pass
+               try:
+                       self.add_period_constraint(self.lookup_request("eth_clocks").rx, 8.0)
+               except ConstraintError:
+                       pass
+               if isinstance(self.toolchain, XilinxISEToolchain):
+                       self.add_platform_command("CONFIG DCI_CASCADE = \"33 32 34\";")
+               else:
+                       self.add_platform_command("set_property DCI_CASCADE {{32 34}} [get_iobanks 33]")
index 8dbf01e86fa889bc4fc7e24768a28540490e9d31..e47a0f53354276ba66e395981c735ecc5782d808 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _io = [
                ("user_btn", 0, Pins("V4"), IOStandard("LVCMOS33"),
@@ -102,19 +102,20 @@ _io = [
                ]
 
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        default_clk_name = "clk_y3"
        default_clk_period = 10
-       bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g SPI_buswidth:4"
-       ise_commands = """
-promgen -w -spi -c FF -p mcs -o {build_name}.mcs -u 0 {build_name}.bit
-"""
+       
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx9-2csg324", _io,
+               XilinxPlatform.__init__(self, "xc6slx9-2csg324", _io,
                                lambda p: SimpleCRG(p, "clk_y3", "user_btn"))
                self.add_platform_command("""
 CONFIG VCCAUX = "3.3";
 """)
+               self.bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g SPI_buswidth:4"
+               self.ise_commands = """
+promgen -w -spi -c FF -p mcs -o {build_name}.mcs -u 0 {build_name}.bit
+"""
 
        def do_finalize(self, fragment):
                try:
@@ -130,5 +131,5 @@ CONFIG VCCAUX = "3.3";
 TIMESPEC "TS{phy_tx_clk}_io" = FROM "GRP{phy_tx_clk}" TO "PADS" 10 ns;
 TIMESPEC "TS{phy_rx_clk}_io" = FROM "PADS" TO "GRP{phy_rx_clk}" 10 ns;
 """, phy_rx_clk=eth_clocks.rx, phy_tx_clk=eth_clocks.tx)
-               except ContraintError:
+               except ConstraintError:
                        pass
index 5dfffb1c4e26630cb0048e321706aa87ab59f296..7884d3d9251bf573fc93ba659143ab575fa175ee 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 from mibuild.xilinx.programmer import UrJTAG
 
 _io = [
@@ -118,12 +118,13 @@ _io = [
        )
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        identifier = 0x4D31
        default_clk_name = "clk50"
        default_clk_period = 20
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx45-fgg484-2", _io,
+               XilinxPlatform.__init__(self, "xc6slx45-fgg484-2", _io,
                        lambda p: SimpleCRG(p, "clk50", None))
 
        def create_programmer(self):
index 4c5f0944cc48b36bcb04d5ccc8451a35e276efa0..e571f944d3d462f6d841a7b523714f2ef888130d 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 from mibuild.xilinx.programmer import UrJTAG
 
 _io = [
@@ -154,12 +154,13 @@ _io = [
        ),
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        identifier = 0x4D58
        default_clk_name = "clk50"
        default_clk_period = 20
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx45-fgg484-2", _io,
+               XilinxPlatform.__init__(self, "xc6slx45-fgg484-2", _io,
                        lambda p: SimpleCRG(p, "clk50", None))
                self.add_platform_command("CONFIG VCCAUX=\"3.3\";\n")
 
index 0812a7fc801aefd5d5e96ebd5494c712de53eb23..1bdea3bf7a31262a9139db75326b1fccf5d082d7 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.xilinx.common import CRG_DS
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _io = [
        # System clock (Differential 200MHz)
@@ -51,11 +51,12 @@ _io = [
        )
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        default_clk_name = "clk200"
        default_clk_period = 5
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6vlx240t-ff1156-1", _io,
+               XilinxPlatform.__init__(self, "xc6vlx240t-ff1156-1", _io,
                        lambda p: CRG_DS(p, "clk200", "user_btn"))
 
        def do_finalize(self, fragment):
index 545b7518b3510999ba6a9f139f582cce343b10ed..bd54ac51101b14c908a950036576c0d3bdb0b97f 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 from mibuild.xilinx.programmer import XC3SProg
 
 _io = [
@@ -49,12 +49,13 @@ _connectors = [
        ("C", "P114 P115 P116 P117 P118 P119 P120 P121 P123 P124 P126 P127 P131 P132 P133 P134")
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        identifier = 0x5050
        default_clk_name = "clk32"
        default_clk_period = 31.25
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx9-tqg144-2", _io,
+               XilinxPlatform.__init__(self, "xc6slx9-tqg144-2", _io,
                        lambda p: SimpleCRG(p, "clk32", None), _connectors)
 
        def create_programmer(self):
index 84c4b87ceada1c318874e962749b8fb84f270e15..831285e85a1b24537a93afa3cb873b4c1323220c 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 from mibuild.xilinx.programmer import XC3SProg
 
 _io = [
@@ -124,13 +124,13 @@ _connectors = [
        ("C", "F17 F16 E16 G16 F15 G14 F14 H14 H13 J13 G13 H12 K14 K13 K12 L12"),
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        identifier = 0x5049
        default_clk_name = "clk50"
        default_clk_period = 20
 
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx45-csg324-2", _io,
+               XilinxPlatform.__init__(self, "xc6slx45-csg324-2", _io,
                        lambda p: SimpleCRG(p, "clk50", None), _connectors)
 
        def create_programmer(self):
index 64ec2d41a8a38b92449ef8a89516c21ac49d9a5f..77993cc7230383dcb6b624a4f5ff7d8b7b2f4276 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.xilinx.common import CRG_DS
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _io = [
        ("user_led", 0, Pins("Y3")),
@@ -133,11 +133,12 @@ _io = [
        )
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        default_clk_name = "clk100"
        default_clk_period = 10
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc6slx150t-fgg676-3", _io,
+               XilinxPlatform.__init__(self, "xc6slx150t-fgg676-3", _io,
                        lambda p: CRG_DS(p, "clk100", "gpio"))
 
        def do_finalize(self, fragment):
index d20d611b05037075d8a369aec1b644a48bcc1914..37e391f257963f40c100fb747b78caee6cbfc577 100644 (file)
@@ -1,5 +1,5 @@
 from mibuild.generic_platform import *
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _io = [
        ("epb", 0,
@@ -28,6 +28,6 @@ _io = [
        ),
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc5vsx95t-ff1136-1", _io)
+               XilinxPlatform.__init__(self, "xc5vsx95t-ff1136-1", _io)
index 64b032036f923ebfa17ba55406e9556fd123cf21..697edaa3cfd1a85fd75c5141996e0d3936a48b96 100644 (file)
@@ -36,6 +36,7 @@ class Platform(VerilatorPlatform):
        is_sim = True
        default_clk_name = "sys_clk"
        default_clk_period = 1000 # on modern computers simulate at ~ 1MHz
+
        def __init__(self):
                VerilatorPlatform.__init__(self, "SIM", _io)
 
index d8af1667b53f403dfca444abd9a00117cf90841b..be4b2130a6d93d32fbf4bf9ab6f5b73914cc8228 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.xilinx.common import CRG_DS
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _io = [
                ("clk64", 0,
@@ -113,13 +113,14 @@ _io = [
 ]
 
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        default_clk_name = "clk64"
        default_clk_period = 15.625
-       bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g UnusedPin:PullUp"
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc3s1400a-ft256-4", _io,
+               XilinxPlatform.__init__(self, "xc3s1400a-ft256-4", _io,
                        lambda p: CRG_DS(p, "clk64", "reset_n", rst_invert=True))
+               self.bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g UnusedPin:PullUp"
 
        def do_finalize(self, fragment):
                try:
index 5604a1f9d73a158517c378affb9cf311526f3990..74ba5d818c9c9663c326787f166f1334560e83e4 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 # Bank 34 and 35 voltage depend on J18 jumper setting
 _io = [
@@ -137,11 +137,12 @@ _io = [
 ]
 
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
        default_clk_name = "clk100"
        default_clk_period = 10
+
        def __init__(self):
-               XilinxISEPlatform.__init__(self, "xc7z020-clg484-1", _io,
+               XilinxPlatform.__init__(self, "xc7z020-clg484-1", _io,
                        lambda p: SimpleCRG(p, "clk100", None))
 
        def do_finalize(self, fragment):
index 8513f96cfa9ad6d4d558c0e7ca12dd6198e5f748..a6880ef110ef09c4d9b65ff869434236dd575c8b 100644 (file)
@@ -1,6 +1,6 @@
 from mibuild.generic_platform import *
 from mibuild.crg import SimpleCRG
-from mibuild.xilinx.ise import XilinxISEPlatform
+from mibuild.xilinx import XilinxPlatform
 
 _io = [
                ("clk_fx", 0, Pins("L22"), IOStandard("LVCMOS33")),
@@ -81,11 +81,12 @@ _io = [
 
 ]
 
-class Platform(XilinxISEPlatform):
+class Platform(XilinxPlatform):
+       default_clk_name = "clk_if"
+       default_clk_period = 20
+
        def __init__(self):
-               default_clk_name = "clk_if"
-               default_clk_period = 20
-               XilinxISEPlatform.__init__(self, "xc6slx150-3csg484", _io,
+               XilinxPlatform.__init__(self, "xc6slx150-3csg484", _io,
                                lambda p: SimpleCRG(p, "clk_if", "rst"))
                self.add_platform_command("""
 CONFIG VCCAUX = "2.5";
@@ -108,5 +109,5 @@ TIMESPEC "TSclk_if" = PERIOD "GRPclk_if" 20 ns HIGH 50%;
 TIMESPEC "TSclk_fx2if" = FROM "GRPclk_fx" TO "GRPclk_if" 3 ns DATAPATHONLY;
 TIMESPEC "TSclk_if2fx" = FROM "GRPclk_if" TO "GRPclk_fx" 3 ns DATAPATHONLY;
 """, clk_if=clk_if, clk_fx=clk_fx)
-               except ContraintError:
+               except ConstraintError:
                        pass
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8f67a642eede7b7a6d885993a26b734a88d1e16f 100644 (file)
@@ -0,0 +1,2 @@
+from mibuild.xilinx.platform import XilinxPlatform
+from mibuild.xilinx.programmer import UrJTAG, XC3SProg, FpgaProg, VivadoProgrammer
index 0966d223d9dc03efa537136275afd9345c7f2836..9b5d994344cc4ff5c87f96707e1cc6927e4112e5 100644 (file)
@@ -4,9 +4,6 @@ from distutils.version import StrictVersion
 from migen.fhdl.std import *
 from migen.fhdl.specials import SynthesisDirective
 from migen.genlib.cdc import *
-from migen.genlib.resetsync import AsyncResetSynchronizer
-from migen.genlib.io import *
-from mibuild.generic_platform import GenericPlatform
 from mibuild import tools
 
 def settings(path, ver=None, sub=None):
@@ -30,7 +27,7 @@ def settings(path, ver=None, sub=None):
                if os.path.exists(settings):
                        return settings
 
-       raise ValueError("no settings file found")
+       raise OSError("no settings file found")
 
 class CRG_DS(Module):
        def __init__(self, platform, clk_name, rst_name, rst_invert=False):
@@ -100,20 +97,3 @@ class XilinxDifferentialOutput:
        @staticmethod
        def lower(dr):
                return XilinxDifferentialOutputImpl(dr.i, dr.o_p, dr.o_n)
-
-class XilinxGenericPlatform(GenericPlatform):
-       bitstream_ext = ".bit"
-
-       def get_verilog(self, *args, special_overrides=dict(), **kwargs):
-               so = {
-                       NoRetiming:                                     XilinxNoRetiming,
-                       MultiReg:                                       XilinxMultiReg,
-                       AsyncResetSynchronizer:         XilinxAsyncResetSynchronizer,
-                       DifferentialInput:                      XilinxDifferentialInput,
-                       DifferentialOutput:                     XilinxDifferentialOutput,
-               }
-               so.update(special_overrides)
-               return GenericPlatform.get_verilog(self, *args, special_overrides=so, **kwargs)
-
-       def get_edif(self, fragment, **kwargs):
-               return GenericPlatform.get_edif(self, fragment, "UNISIMS", "Xilinx", self.device, **kwargs)
index 5935c1a02af4f0e0b132836b7775f4bad0d8ae62..acebf6052c43e57b6e71e8f093332dd7a889d1b2 100644 (file)
@@ -120,50 +120,51 @@ bitgen {bitgen_opt} {build_name}.ncd {build_name}.bit
        if r != 0:
                raise OSError("Subprocess failed")
 
-class XilinxISEPlatform(common.XilinxGenericPlatform):
-       xst_opt = """-ifmt MIXED
+class XilinxISEToolchain:
+       def __init__(self):
+               self.xst_opt = """-ifmt MIXED
 -opt_mode SPEED
 -register_balancing yes"""
-       map_opt = "-ol high -w"
-       par_opt = "-ol high -w"
-       ngdbuild_opt = ""
-       bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w"
-       ise_commands = ""
+               self.map_opt = "-ol high -w"
+               self.par_opt = "-ol high -w"
+               self.ngdbuild_opt = ""
+               self.bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w"
+               self.ise_commands = ""
 
-       def build(self, fragment, build_dir="build", build_name="top",
+       def build(self, platform, fragment, build_dir="build", build_name="top",
                        ise_path="/opt/Xilinx", source=True, run=True, mode="xst"):
                tools.mkdir_noerror(build_dir)
                os.chdir(build_dir)
 
                if not isinstance(fragment, _Fragment):
                        fragment = fragment.get_fragment()
-               self.finalize(fragment)
+               platform.finalize(fragment)
 
                ngdbuild_opt = self.ngdbuild_opt
 
                vns = None
 
                if mode == "xst" or mode == "yosys":
-                       v_src, vns = self.get_verilog(fragment)
-                       named_sc, named_pc = self.resolve_signals(vns)
+                       v_src, vns = platform.get_verilog(fragment)
+                       named_sc, named_pc = platform.resolve_signals(vns)
                        v_file = build_name + ".v"
                        tools.write_to_file(v_file, v_src)
-                       sources = self.sources + [(v_file, "verilog")]
+                       sources = platform.sources + [(v_file, "verilog")]
                        if mode == "xst":
-                               _build_xst_files(self.device, sources, self.verilog_include_paths, build_name, self.xst_opt)
+                               _build_xst_files(platform.device, sources, platform.verilog_include_paths, build_name, self.xst_opt)
                                isemode = "xst"
                        else:
-                               _run_yosys(self.device, sources, self.verilog_include_paths, build_name)
+                               _run_yosys(platform.device, sources, platform.verilog_include_paths, build_name)
                                isemode = "edif"
-                               ngdbuild_opt += "-p " + self.device
+                               ngdbuild_opt += "-p " + platform.device
 
                if mode == "mist":
                        from mist import synthesize
-                       synthesize(fragment, self.constraint_manager.get_io_signals())
+                       synthesize(fragment, platform.constraint_manager.get_io_signals())
 
                if mode == "edif" or mode == "mist":
-                       e_src, vns = self.get_edif(fragment)
-                       named_sc, named_pc = self.resolve_signals(vns)
+                       e_src, vns = platform.get_edif(fragment)
+                       named_sc, named_pc = platform.resolve_signals(vns)
                        e_file = build_name + ".edif"
                        tools.write_to_file(e_file, e_src)
                        isemode = "edif"
@@ -178,6 +179,6 @@ class XilinxISEPlatform(common.XilinxGenericPlatform):
 
                return vns
 
-       def add_period_constraint(self, clk, period):
-               self.add_platform_command("""NET "{clk}" TNM_NET = "GRP{clk}";
+       def add_period_constraint(self, platform, clk, period):
+               platform.add_platform_command("""NET "{clk}" TNM_NET = "GRP{clk}";
 TIMESPEC "TS{clk}" = PERIOD "GRP{clk}" """+str(period)+""" ns HIGH 50%;""", clk=clk)
diff --git a/mibuild/xilinx/platform.py b/mibuild/xilinx/platform.py
new file mode 100644 (file)
index 0000000..f5d3cd8
--- /dev/null
@@ -0,0 +1,39 @@
+from migen.genlib.cdc import *
+from migen.genlib.resetsync import AsyncResetSynchronizer
+from migen.genlib.io import *
+
+from mibuild.generic_platform import GenericPlatform
+from mibuild.xilinx import common, vivado, ise
+
+class XilinxPlatform(GenericPlatform):
+       bitstream_ext = ".bit"
+
+       def __init__(self, *args, toolchain="ise", **kwargs):
+               GenericPlatform.__init__(self, *args, **kwargs)
+               if toolchain == "ise":
+                       self.toolchain = ise.XilinxISEToolchain()
+               elif toolchain == "vivado":
+                       self.toolchain = vivado.XilinxVivadoToolchain()
+               else:
+                       raise ValueError("Unknown toolchain")
+
+       def get_verilog(self, *args, special_overrides=dict(), **kwargs):
+               so = {
+                       NoRetiming:                                     common.XilinxNoRetiming,
+                       MultiReg:                                       common.XilinxMultiReg,
+                       AsyncResetSynchronizer:         common.XilinxAsyncResetSynchronizer,
+                       DifferentialInput:                      common.XilinxDifferentialInput,
+                       DifferentialOutput:                     common.XilinxDifferentialOutput,
+               }
+               so.update(special_overrides)
+               return GenericPlatform.get_verilog(self, *args, special_overrides=so, **kwargs)
+
+       def get_edif(self, fragment, **kwargs):
+               return GenericPlatform.get_edif(self, fragment, "UNISIMS", "Xilinx", self.device, **kwargs)
+
+
+       def build(self, *args, **kwargs):
+               return self.toolchain.build(self, *args, **kwargs)
+
+       def add_period_constraint(self, clk, period):
+               self.toolchain.add_period_constraint(self, clk, period)
index 418ec2b3504b8d61d912bd1683d7a9bcc9996e0d..4aabb1ea36bcd422f009eb60a4c0f894289a180b 100644 (file)
@@ -93,26 +93,25 @@ def _run_vivado(build_name, vivado_path, source, ver=None):
        if r != 0:
                raise OSError("Subprocess failed")
 
-class XilinxVivadoPlatform(common.XilinxGenericPlatform):
-       def __init__(self, *args, **kwargs):
-               common.XilinxGenericPlatform.__init__(self, *args, **kwargs)
+class XilinxVivadoToolchain:
+       def __init__(self):
                self.bitstream_commands = []
                self.additional_commands = []
 
-       def build(self, fragment, build_dir="build", build_name="top",
+       def build(self, platform, fragment, build_dir="build", build_name="top",
                        vivado_path="/opt/Xilinx/Vivado", source=True, run=True):
                tools.mkdir_noerror(build_dir)
                os.chdir(build_dir)
 
                if not isinstance(fragment, _Fragment):
                        fragment = fragment.get_fragment()
-               self.finalize(fragment)
-               v_src, vns = self.get_verilog(fragment)
-               named_sc, named_pc = self.resolve_signals(vns)
+               platform.finalize(fragment)
+               v_src, vns = platform.get_verilog(fragment)
+               named_sc, named_pc = platform.resolve_signals(vns)
                v_file = build_name + ".v"
                tools.write_to_file(v_file, v_src)
-               sources = self.sources + [(v_file, "verilog")]
-               _build_files(self.device, sources, self.verilog_include_paths, build_name,
+               sources = platform.sources + [(v_file, "verilog")]
+               _build_files(platform.device, sources, platform.verilog_include_paths, build_name,
                        self.bitstream_commands, self.additional_commands)
                tools.write_to_file(build_name + ".xdc", _build_xdc(named_sc, named_pc))
                if run:
@@ -122,6 +121,6 @@ class XilinxVivadoPlatform(common.XilinxGenericPlatform):
 
                return vns
 
-       def add_period_constraint(self, clk, period):
-               self.add_platform_command("""create_clock -name {clk} -period """ +\
+       def add_period_constraint(self, platform, clk, period):
+               platform.add_platform_command("""create_clock -name {clk} -period """ + \
                        str(period) + """ [get_ports {clk}]""", clk=clk)