build/lattice/prjtrellis: add inout support

This commit is contained in:
Florent Kermarrec 2018-10-29 19:23:21 +01:00
parent 091ad799b0
commit d9dcad33a4
1 changed files with 23 additions and 16 deletions

View File

@ -56,12 +56,14 @@ def generate_prjtrellis_iowrapper(platform, vns):
# ios declaration # ios declaration
ios_declaration = "" ios_declaration = ""
for io_name, io_pins, _, _ in ios: for io_name, io_pins, io_others, _ in ios:
ios_declaration += "\t" + ios_direction[io_name] + " " for io_other in io_others:
if len(io_pins) > 1: if isinstance(io_other, IOStandard):
ios_declaration += "[{}:0] ".format(len(io_pins) - 1) io_standard = io_other.name
ios_declaration += io_name + "_io" for i, io_pin in enumerate(io_pins):
ios_declaration += ",\n" if io_name != last_io_name else "" ios_declaration += "(* LOC=\"{}\" *) (* IO_TYPE=\"{}\" *)\n".format(io_pin, io_standard)
ios_declaration += "\t" + ios_direction[io_name] + " " + io_name + "_io" + (str(i) if len(io_pins) > 1 else "")
ios_declaration += ",\n" if io_name != last_io_name or (i != len(io_pins) - 1) else ""
iowrapper_contents.append(ios_declaration) iowrapper_contents.append(ios_declaration)
iowrapper_contents.append(");\n") iowrapper_contents.append(");\n")
@ -78,27 +80,32 @@ def generate_prjtrellis_iowrapper(platform, vns):
# trellis_io declaration # trellis_io declaration
trellis_io_declaration = "" trellis_io_declaration = ""
for io_name, io_pins, io_others, _ in ios: for io_name, io_pins, io_others, _ in ios:
for io_other in io_others:
if isinstance(io_other, IOStandard):
io_standard = io_other.name
for i, io_pin in enumerate(io_pins): for i, io_pin in enumerate(io_pins):
trellis_io_declaration += \ io_suffix = "io" + str(i) if len(io_pins) > 1 else "io"
"(* LOC=\"{}\" *) (* IO_TYPE=\"{}\" *)\n".format(io_pin, io_standard)
if ios_direction[io_name] == "input": if ios_direction[io_name] == "input":
trellis_io_declaration += \ trellis_io_declaration += \
"TRELLIS_IO #(.DIR(\"INPUT\")) {} (.B({}), .O({}));\n".format( "TRELLIS_IO #(.DIR(\"INPUT\")) {} (.B({}), .O({}));\n".format(
io_name + "_buf" + str(i), io_name + "_io[" + str(i) + "]", io_name + "[" + str(i) + "]") io_name + "_buf" + str(i), io_name + "_" + io_suffix, io_name + "[" + str(i) + "]")
elif ios_direction[io_name] == "output": elif ios_direction[io_name] == "output":
trellis_io_declaration += \ trellis_io_declaration += \
"TRELLIS_IO #(.DIR(\"OUTPUT\")) {} (.B({}), .I({}));\n".format( "TRELLIS_IO #(.DIR(\"OUTPUT\")) {} (.B({}), .I({}));\n".format(
io_name + "_buf" + str(i), io_name + "_io[" + str(i) + "]", io_name + "[" + str(i) + "]") io_name + "_buf" + str(i), io_name + "_" + io_suffix, io_name + "[" + str(i) + "]")
else: else:
raise NotImplementedError pass # handled by Migen's Tristate
iowrapper_contents.append(trellis_io_declaration) iowrapper_contents.append(trellis_io_declaration)
# top declaration # top declaration
top_declaration = "{build_name} _{build_name}(\n" top_declaration = "{build_name} _{build_name}(\n"
for io_name, io_pins, _, _ in ios: for io_name, io_pins, _, _ in ios:
if ios_direction[io_name] == "inout":
if len(io_pins) > 1:
io_concat_name = "{{"
io_concat_name += ",".join([io_name + "_io" + str(i) for i in range(len(io_pins))])
io_concat_name += "}}"
top_declaration += "\t." + io_name + "(" + io_concat_name + ")"
else:
top_declaration += "\t." + io_name + "(" + io_name + "_io)"
else:
top_declaration += "\t." + io_name + "(" + io_name + ")" top_declaration += "\t." + io_name + "(" + io_name + ")"
top_declaration += ",\n" if io_name != last_io_name else "\n" top_declaration += ",\n" if io_name != last_io_name else "\n"
top_declaration += ");\n" top_declaration += ");\n"
@ -125,7 +132,7 @@ class LatticePrjTrellisToolchain:
"no_shreg_extract": None "no_shreg_extract": None
} }
special_overrides = common.lattice_ecpx_special_overrides special_overrides = common.lattice_ecpx_prjtrellis_special_overrides
def build(self, platform, fragment, build_dir="build", build_name="top", def build(self, platform, fragment, build_dir="build", build_name="top",
toolchain_path=None, run=True): toolchain_path=None, run=True):