mibuild: get rid of Platform factory function, cleanup

This commit is contained in:
Sebastien Bourdeauducq 2015-03-13 23:17:45 +01:00
parent ff266bc2ee
commit 702d177c85
23 changed files with 177 additions and 148 deletions

View file

@ -6,7 +6,7 @@ from migen.genlib.cordic import Cordic
from mibuild.tools import mkdir_noerror from mibuild.tools import mkdir_noerror
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
class CordicImpl(Module): class CordicImpl(Module):
def __init__(self, name, **kwargs): def __init__(self, name, **kwargs):
@ -27,7 +27,7 @@ class CordicImpl(Module):
def build(self): def build(self):
self.platform.build(self, build_name=self.name) self.platform.build(self, build_name=self.name)
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
_io = [ _io = [
("clk", 0, Pins("AB13")), ("clk", 0, Pins("AB13")),
("rst", 0, Pins("V5")), ("rst", 0, Pins("V5")),
@ -38,7 +38,7 @@ class Platform(XilinxISEPlatform):
), ),
] ]
def __init__(self): 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")) lambda p: SimpleCRG(p, "clk", "rst"))
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -285,3 +285,6 @@ class GenericPlatform:
argdict = dict((k, autotype(v)) for k, v in zip(*[iter(arg)]*2)) argdict = dict((k, autotype(v)) for k, v in zip(*[iter(arg)]*2))
kwargs.update(argdict) kwargs.update(argdict)
self.build(*args, **kwargs) self.build(*args, **kwargs)
def create_programmer(self):
raise NotImplementedError

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_ios = [ _ios = [
("clk0", 0, Pins("N9"), IOStandard("LVCMOS18")), ("clk0", 0, Pins("N9"), IOStandard("LVCMOS18")),
@ -141,11 +141,12 @@ _connectors = [
"None") # 116 USBH2_CLK USB_HOST2 +2V5 PA0 "None") # 116 USBH2_CLK USB_HOST2 +2V5 PA0
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
default_clk_name = "clk0" default_clk_name = "clk0"
default_clk_period = 10 default_clk_period = 10
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc3s200a-ft256-4", _ios, XilinxPlatform.__init__(self, "xc3s200a-ft256-4", _ios,
lambda p: SimpleCRG(p, "clk0", None), _connectors) lambda p: SimpleCRG(p, "clk0", None), _connectors)
def do_finalize(self, fragment): def do_finalize(self, fragment):

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_ios = [ _ios = [
("clk3", 0, Pins("N8"), IOStandard("LVCMOS33")), ("clk3", 0, Pins("N8"), IOStandard("LVCMOS33")),
@ -168,11 +168,12 @@ _connectors = [
"None") # 140 FPGA_BANK3_POWER "None") # 140 FPGA_BANK3_POWER
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
default_clk_name = "clk3" default_clk_name = "clk3"
default_clk_period = 10.526 default_clk_period = 10.526
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc6slx9-2csg225", _ios, XilinxPlatform.__init__(self, "xc6slx9-2csg225", _ios,
lambda p: SimpleCRG(p, "clk3", None), _connectors) lambda p: SimpleCRG(p, "clk3", None), _connectors)
def do_finalize(self, fragment): def do_finalize(self, fragment):
@ -180,4 +181,3 @@ class Platform(XilinxISEPlatform):
self.add_period_constraint(self.lookup_request("clk3"), 10.526) self.add_period_constraint(self.lookup_request("clk3"), 10.526)
except ConstraintError: except ConstraintError:
pass pass

View file

@ -94,6 +94,7 @@ _io = [
class Platform(AlteraQuartusPlatform): class Platform(AlteraQuartusPlatform):
default_clk_name = "clk50" default_clk_name = "clk50"
default_clk_period = 20 default_clk_period = 20
def __init__(self): def __init__(self):
AlteraQuartusPlatform.__init__(self, "EP4CE22F17C6", _io, AlteraQuartusPlatform.__init__(self, "EP4CE22F17C6", _io,
lambda p: SimpleCRG(p, "clk50", None)) lambda p: SimpleCRG(p, "clk50", None))

View file

@ -1,9 +1,8 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG 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.common import CRG_DS
from mibuild.xilinx.ise import XilinxISEPlatform
from mibuild.xilinx.vivado import XilinxVivadoPlatform
from mibuild.xilinx.programmer import XC3SProg, VivadoProgrammer
_io = [ _io = [
("user_led", 0, Pins("AB8"), IOStandard("LVCMOS15")), ("user_led", 0, Pins("AB8"), IOStandard("LVCMOS15")),
@ -378,47 +377,41 @@ _connectors = [
) )
] ]
def Platform(*args, toolchain="vivado", programmer="xc3sprog", **kwargs): class Platform(XilinxPlatform):
if toolchain == "ise": identifier = 0x4B37
xilinx_platform = XilinxISEPlatform default_clk_name = "clk156"
elif toolchain == "vivado": default_clk_period = 6.4
xilinx_platform = XilinxVivadoPlatform
else:
raise ValueError
class RealPlatform(xilinx_platform): def __init__(self, toolchain="vivado", programmer="xc3sprog"):
identifier = 0x4B37 XilinxPlatform.__init__(self, "xc7k325t-ffg900-2", _io,
default_clk_name = "clk156" default_crg_factory=lambda p: CRG_DS(p, "clk156", "cpu_reset"),
default_clk_period = 6.4 connectors=_connectors,
bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g ConfigRate:12 -g SPI_buswidth:4" 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")): def create_programmer(self):
xilinx_platform.__init__(self, "xc7k325t-ffg900-2", _io, crg_factory, _connectors) 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): def do_finalize(self, fragment):
if programmer == "xc3sprog": try:
return XC3SProg("jtaghs1_fast", "bscan_spi_kc705.bit") self.add_period_constraint(self.lookup_request("clk156").p, 6.4)
elif programmer == "vivado": except ConstraintError:
return VivadoProgrammer() pass
else: try:
raise ValueError("{} programmer is not supported".format(programmer)) self.add_period_constraint(self.lookup_request("clk200").p, 5.0)
except ConstraintError:
def do_finalize(self, fragment): pass
try: try:
self.add_period_constraint(self.lookup_request("clk156").p, 6.4) self.add_period_constraint(self.lookup_request("eth_clocks").rx, 8.0)
except ConstraintError: except ConstraintError:
pass pass
try: if isinstance(self.toolchain, XilinxISEToolchain):
self.add_period_constraint(self.lookup_request("clk200").p, 5.0) self.add_platform_command("CONFIG DCI_CASCADE = \"33 32 34\";")
except ConstraintError: else:
pass self.add_platform_command("set_property DCI_CASCADE {{32 34}} [get_iobanks 33]")
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)

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_io = [ _io = [
("user_btn", 0, Pins("V4"), IOStandard("LVCMOS33"), ("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_name = "clk_y3"
default_clk_period = 10 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): def __init__(self):
XilinxISEPlatform.__init__(self, "xc6slx9-2csg324", _io, XilinxPlatform.__init__(self, "xc6slx9-2csg324", _io,
lambda p: SimpleCRG(p, "clk_y3", "user_btn")) lambda p: SimpleCRG(p, "clk_y3", "user_btn"))
self.add_platform_command(""" self.add_platform_command("""
CONFIG VCCAUX = "3.3"; 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): def do_finalize(self, fragment):
try: 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_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; 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) """, phy_rx_clk=eth_clocks.rx, phy_tx_clk=eth_clocks.tx)
except ContraintError: except ConstraintError:
pass pass

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
from mibuild.xilinx.programmer import UrJTAG from mibuild.xilinx.programmer import UrJTAG
_io = [ _io = [
@ -118,12 +118,13 @@ _io = [
) )
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
identifier = 0x4D31 identifier = 0x4D31
default_clk_name = "clk50" default_clk_name = "clk50"
default_clk_period = 20 default_clk_period = 20
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc6slx45-fgg484-2", _io, XilinxPlatform.__init__(self, "xc6slx45-fgg484-2", _io,
lambda p: SimpleCRG(p, "clk50", None)) lambda p: SimpleCRG(p, "clk50", None))
def create_programmer(self): def create_programmer(self):

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
from mibuild.xilinx.programmer import UrJTAG from mibuild.xilinx.programmer import UrJTAG
_io = [ _io = [
@ -154,12 +154,13 @@ _io = [
), ),
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
identifier = 0x4D58 identifier = 0x4D58
default_clk_name = "clk50" default_clk_name = "clk50"
default_clk_period = 20 default_clk_period = 20
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc6slx45-fgg484-2", _io, XilinxPlatform.__init__(self, "xc6slx45-fgg484-2", _io,
lambda p: SimpleCRG(p, "clk50", None)) lambda p: SimpleCRG(p, "clk50", None))
self.add_platform_command("CONFIG VCCAUX=\"3.3\";\n") self.add_platform_command("CONFIG VCCAUX=\"3.3\";\n")

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.xilinx.common import CRG_DS from mibuild.xilinx.common import CRG_DS
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_io = [ _io = [
# System clock (Differential 200MHz) # System clock (Differential 200MHz)
@ -51,11 +51,12 @@ _io = [
) )
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
default_clk_name = "clk200" default_clk_name = "clk200"
default_clk_period = 5 default_clk_period = 5
def __init__(self): 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")) lambda p: CRG_DS(p, "clk200", "user_btn"))
def do_finalize(self, fragment): def do_finalize(self, fragment):

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
from mibuild.xilinx.programmer import XC3SProg from mibuild.xilinx.programmer import XC3SProg
_io = [ _io = [
@ -49,12 +49,13 @@ _connectors = [
("C", "P114 P115 P116 P117 P118 P119 P120 P121 P123 P124 P126 P127 P131 P132 P133 P134") ("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 identifier = 0x5050
default_clk_name = "clk32" default_clk_name = "clk32"
default_clk_period = 31.25 default_clk_period = 31.25
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc6slx9-tqg144-2", _io, XilinxPlatform.__init__(self, "xc6slx9-tqg144-2", _io,
lambda p: SimpleCRG(p, "clk32", None), _connectors) lambda p: SimpleCRG(p, "clk32", None), _connectors)
def create_programmer(self): def create_programmer(self):

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
from mibuild.xilinx.programmer import XC3SProg from mibuild.xilinx.programmer import XC3SProg
_io = [ _io = [
@ -124,13 +124,13 @@ _connectors = [
("C", "F17 F16 E16 G16 F15 G14 F14 H14 H13 J13 G13 H12 K14 K13 K12 L12"), ("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 identifier = 0x5049
default_clk_name = "clk50" default_clk_name = "clk50"
default_clk_period = 20 default_clk_period = 20
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc6slx45-csg324-2", _io, XilinxPlatform.__init__(self, "xc6slx45-csg324-2", _io,
lambda p: SimpleCRG(p, "clk50", None), _connectors) lambda p: SimpleCRG(p, "clk50", None), _connectors)
def create_programmer(self): def create_programmer(self):

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.xilinx.common import CRG_DS from mibuild.xilinx.common import CRG_DS
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_io = [ _io = [
("user_led", 0, Pins("Y3")), ("user_led", 0, Pins("Y3")),
@ -133,11 +133,12 @@ _io = [
) )
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
default_clk_name = "clk100" default_clk_name = "clk100"
default_clk_period = 10 default_clk_period = 10
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc6slx150t-fgg676-3", _io, XilinxPlatform.__init__(self, "xc6slx150t-fgg676-3", _io,
lambda p: CRG_DS(p, "clk100", "gpio")) lambda p: CRG_DS(p, "clk100", "gpio"))
def do_finalize(self, fragment): def do_finalize(self, fragment):

View file

@ -1,5 +1,5 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_io = [ _io = [
("epb", 0, ("epb", 0,
@ -28,6 +28,6 @@ _io = [
), ),
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc5vsx95t-ff1136-1", _io) XilinxPlatform.__init__(self, "xc5vsx95t-ff1136-1", _io)

View file

@ -36,6 +36,7 @@ class Platform(VerilatorPlatform):
is_sim = True is_sim = True
default_clk_name = "sys_clk" default_clk_name = "sys_clk"
default_clk_period = 1000 # on modern computers simulate at ~ 1MHz default_clk_period = 1000 # on modern computers simulate at ~ 1MHz
def __init__(self): def __init__(self):
VerilatorPlatform.__init__(self, "SIM", _io) VerilatorPlatform.__init__(self, "SIM", _io)

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.xilinx.common import CRG_DS from mibuild.xilinx.common import CRG_DS
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_io = [ _io = [
("clk64", 0, ("clk64", 0,
@ -113,13 +113,14 @@ _io = [
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
default_clk_name = "clk64" default_clk_name = "clk64"
default_clk_period = 15.625 default_clk_period = 15.625
bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w -g UnusedPin:PullUp"
def __init__(self): 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)) 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): def do_finalize(self, fragment):
try: try:

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG 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 # Bank 34 and 35 voltage depend on J18 jumper setting
_io = [ _io = [
@ -137,11 +137,12 @@ _io = [
] ]
class Platform(XilinxISEPlatform): class Platform(XilinxPlatform):
default_clk_name = "clk100" default_clk_name = "clk100"
default_clk_period = 10 default_clk_period = 10
def __init__(self): def __init__(self):
XilinxISEPlatform.__init__(self, "xc7z020-clg484-1", _io, XilinxPlatform.__init__(self, "xc7z020-clg484-1", _io,
lambda p: SimpleCRG(p, "clk100", None)) lambda p: SimpleCRG(p, "clk100", None))
def do_finalize(self, fragment): def do_finalize(self, fragment):

View file

@ -1,6 +1,6 @@
from mibuild.generic_platform import * from mibuild.generic_platform import *
from mibuild.crg import SimpleCRG from mibuild.crg import SimpleCRG
from mibuild.xilinx.ise import XilinxISEPlatform from mibuild.xilinx import XilinxPlatform
_io = [ _io = [
("clk_fx", 0, Pins("L22"), IOStandard("LVCMOS33")), ("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): def __init__(self):
default_clk_name = "clk_if" XilinxPlatform.__init__(self, "xc6slx150-3csg484", _io,
default_clk_period = 20
XilinxISEPlatform.__init__(self, "xc6slx150-3csg484", _io,
lambda p: SimpleCRG(p, "clk_if", "rst")) lambda p: SimpleCRG(p, "clk_if", "rst"))
self.add_platform_command(""" self.add_platform_command("""
CONFIG VCCAUX = "2.5"; 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_fx2if" = FROM "GRPclk_fx" TO "GRPclk_if" 3 ns DATAPATHONLY;
TIMESPEC "TSclk_if2fx" = FROM "GRPclk_if" TO "GRPclk_fx" 3 ns DATAPATHONLY; TIMESPEC "TSclk_if2fx" = FROM "GRPclk_if" TO "GRPclk_fx" 3 ns DATAPATHONLY;
""", clk_if=clk_if, clk_fx=clk_fx) """, clk_if=clk_if, clk_fx=clk_fx)
except ContraintError: except ConstraintError:
pass pass

View file

@ -0,0 +1,2 @@
from mibuild.xilinx.platform import XilinxPlatform
from mibuild.xilinx.programmer import UrJTAG, XC3SProg, FpgaProg, VivadoProgrammer

View file

@ -4,9 +4,6 @@ from distutils.version import StrictVersion
from migen.fhdl.std import * from migen.fhdl.std import *
from migen.fhdl.specials import SynthesisDirective from migen.fhdl.specials import SynthesisDirective
from migen.genlib.cdc import * 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 from mibuild import tools
def settings(path, ver=None, sub=None): def settings(path, ver=None, sub=None):
@ -30,7 +27,7 @@ def settings(path, ver=None, sub=None):
if os.path.exists(settings): if os.path.exists(settings):
return settings return settings
raise ValueError("no settings file found") raise OSError("no settings file found")
class CRG_DS(Module): class CRG_DS(Module):
def __init__(self, platform, clk_name, rst_name, rst_invert=False): def __init__(self, platform, clk_name, rst_name, rst_invert=False):
@ -100,20 +97,3 @@ class XilinxDifferentialOutput:
@staticmethod @staticmethod
def lower(dr): def lower(dr):
return XilinxDifferentialOutputImpl(dr.i, dr.o_p, dr.o_n) 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)

View file

@ -120,50 +120,51 @@ bitgen {bitgen_opt} {build_name}.ncd {build_name}.bit
if r != 0: if r != 0:
raise OSError("Subprocess failed") raise OSError("Subprocess failed")
class XilinxISEPlatform(common.XilinxGenericPlatform): class XilinxISEToolchain:
xst_opt = """-ifmt MIXED def __init__(self):
self.xst_opt = """-ifmt MIXED
-opt_mode SPEED -opt_mode SPEED
-register_balancing yes""" -register_balancing yes"""
map_opt = "-ol high -w" self.map_opt = "-ol high -w"
par_opt = "-ol high -w" self.par_opt = "-ol high -w"
ngdbuild_opt = "" self.ngdbuild_opt = ""
bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w" self.bitgen_opt = "-g LCK_cycle:6 -g Binary:Yes -w"
ise_commands = "" 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"): ise_path="/opt/Xilinx", source=True, run=True, mode="xst"):
tools.mkdir_noerror(build_dir) tools.mkdir_noerror(build_dir)
os.chdir(build_dir) os.chdir(build_dir)
if not isinstance(fragment, _Fragment): if not isinstance(fragment, _Fragment):
fragment = fragment.get_fragment() fragment = fragment.get_fragment()
self.finalize(fragment) platform.finalize(fragment)
ngdbuild_opt = self.ngdbuild_opt ngdbuild_opt = self.ngdbuild_opt
vns = None vns = None
if mode == "xst" or mode == "yosys": if mode == "xst" or mode == "yosys":
v_src, vns = self.get_verilog(fragment) v_src, vns = platform.get_verilog(fragment)
named_sc, named_pc = self.resolve_signals(vns) named_sc, named_pc = platform.resolve_signals(vns)
v_file = build_name + ".v" v_file = build_name + ".v"
tools.write_to_file(v_file, v_src) tools.write_to_file(v_file, v_src)
sources = self.sources + [(v_file, "verilog")] sources = platform.sources + [(v_file, "verilog")]
if mode == "xst": 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" isemode = "xst"
else: 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" isemode = "edif"
ngdbuild_opt += "-p " + self.device ngdbuild_opt += "-p " + platform.device
if mode == "mist": if mode == "mist":
from mist import synthesize 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": if mode == "edif" or mode == "mist":
e_src, vns = self.get_edif(fragment) e_src, vns = platform.get_edif(fragment)
named_sc, named_pc = self.resolve_signals(vns) named_sc, named_pc = platform.resolve_signals(vns)
e_file = build_name + ".edif" e_file = build_name + ".edif"
tools.write_to_file(e_file, e_src) tools.write_to_file(e_file, e_src)
isemode = "edif" isemode = "edif"
@ -178,6 +179,6 @@ class XilinxISEPlatform(common.XilinxGenericPlatform):
return vns return vns
def add_period_constraint(self, clk, period): def add_period_constraint(self, platform, clk, period):
self.add_platform_command("""NET "{clk}" TNM_NET = "GRP{clk}"; platform.add_platform_command("""NET "{clk}" TNM_NET = "GRP{clk}";
TIMESPEC "TS{clk}" = PERIOD "GRP{clk}" """+str(period)+""" ns HIGH 50%;""", clk=clk) TIMESPEC "TS{clk}" = PERIOD "GRP{clk}" """+str(period)+""" ns HIGH 50%;""", clk=clk)

View file

@ -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)

View file

@ -93,26 +93,25 @@ def _run_vivado(build_name, vivado_path, source, ver=None):
if r != 0: if r != 0:
raise OSError("Subprocess failed") raise OSError("Subprocess failed")
class XilinxVivadoPlatform(common.XilinxGenericPlatform): class XilinxVivadoToolchain:
def __init__(self, *args, **kwargs): def __init__(self):
common.XilinxGenericPlatform.__init__(self, *args, **kwargs)
self.bitstream_commands = [] self.bitstream_commands = []
self.additional_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): vivado_path="/opt/Xilinx/Vivado", source=True, run=True):
tools.mkdir_noerror(build_dir) tools.mkdir_noerror(build_dir)
os.chdir(build_dir) os.chdir(build_dir)
if not isinstance(fragment, _Fragment): if not isinstance(fragment, _Fragment):
fragment = fragment.get_fragment() fragment = fragment.get_fragment()
self.finalize(fragment) platform.finalize(fragment)
v_src, vns = self.get_verilog(fragment) v_src, vns = platform.get_verilog(fragment)
named_sc, named_pc = self.resolve_signals(vns) named_sc, named_pc = platform.resolve_signals(vns)
v_file = build_name + ".v" v_file = build_name + ".v"
tools.write_to_file(v_file, v_src) tools.write_to_file(v_file, v_src)
sources = self.sources + [(v_file, "verilog")] sources = platform.sources + [(v_file, "verilog")]
_build_files(self.device, sources, self.verilog_include_paths, build_name, _build_files(platform.device, sources, platform.verilog_include_paths, build_name,
self.bitstream_commands, self.additional_commands) self.bitstream_commands, self.additional_commands)
tools.write_to_file(build_name + ".xdc", _build_xdc(named_sc, named_pc)) tools.write_to_file(build_name + ".xdc", _build_xdc(named_sc, named_pc))
if run: if run:
@ -122,6 +121,6 @@ class XilinxVivadoPlatform(common.XilinxGenericPlatform):
return vns return vns
def add_period_constraint(self, clk, period): def add_period_constraint(self, platform, clk, period):
self.add_platform_command("""create_clock -name {clk} -period """ +\ platform.add_platform_command("""create_clock -name {clk} -period """ + \
str(period) + """ [get_ports {clk}]""", clk=clk) str(period) + """ [get_ports {clk}]""", clk=clk)