Skip to content

Commit

Permalink
build: efinix: use constant output option
Browse files Browse the repository at this point in the history
use constant output option, when the output is a `Constant`

Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Oct 23, 2024
1 parent 2d96e99 commit 54973eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
43 changes: 36 additions & 7 deletions litex/build/efinix/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@
def assert_is_signal_or_clocksignal(obj):
assert isinstance(obj, (ClockSignal, Signal)), f"Object {obj} is not a ClockSignal or Signal"

def const_output_calc(o, io):
if o.value == 0:
const_output = 0
elif len(o) == 1:
const_output = 1
else:
const_output = []
for bit in range(len(io)):
if o.value & (1 << bit):
const_output.append(1)
else:
const_output.append(0)
return const_output

# Efinix AsyncResetSynchronizer --------------------------------------------------------------------

class EfinixAsyncResetSynchronizerImpl(LiteXModule):
Expand Down Expand Up @@ -142,12 +156,16 @@ def __init__(self, io, o, oe, i=None):
io_pad = platform.get_pins_location(io)
io_prop = platform.get_pin_properties(io[0])
io_prop_dict = dict(io_prop)
io_data_i = platform.add_iface_io(io_name + "_OUT", len(io))
io_data_o = platform.add_iface_io(io_name + "_IN", len(io))
if isinstance(o, Constant):
const_output = const_output_calc(o, io)
else:
const_output = "NONE"
io_data_i = platform.add_iface_io(io_name + "_OUT", len(io))
self.comb += io_data_i.eq(o)
io_data_e = platform.add_iface_io(io_name + "_OE", len(io))
self.comb += io_data_i.eq(o)
self.comb += io_data_e.eq(oe)
if i is not None:
io_data_o = platform.add_iface_io(io_name + "_IN", len(io))
self.comb += i.eq(io_data_o)
block = {
"type" : "GPIO",
Expand All @@ -156,6 +174,7 @@ def __init__(self, io, o, oe, i=None):
"location" : io_pad,
"properties" : io_prop,
"size" : len(io),
"const_output" : const_output,
"drive_strength" : io_prop_dict.get("DRIVE_STRENGTH", "4")
}
platform.toolchain.ifacewriter.blocks.append(block)
Expand Down Expand Up @@ -326,10 +345,14 @@ def __init__(self, io, o, oe, i, clk):
io_pad = platform.get_pin_location(io)
io_prop = platform.get_pin_properties(io)
io_prop_dict = dict(io_prop)
io_data_i = platform.add_iface_io(io_name + "_OUT")
if isinstance(o, Constant):
const_output = const_output_calc(o, io)
else:
const_output = "NONE"
io_data_i = platform.add_iface_io(io_name + "_OUT")
self.comb += io_data_i.eq(o)
io_data_o = platform.add_iface_io(io_name + "_IN")
io_data_e = platform.add_iface_io(io_name + "_OE")
self.comb += io_data_i.eq(o)
self.comb += io_data_e.eq(oe)
self.comb += i.eq(io_data_o)
block = {
Expand All @@ -343,6 +366,7 @@ def __init__(self, io, o, oe, i, clk):
"in_clk_pin" : clk,
"out_reg" : "REG",
"out_clk_pin" : clk,
"const_output" : const_output,
"oe_reg" : "REG",
"in_clk_inv" : 0,
"out_clk_inv" : 0,
Expand All @@ -367,8 +391,12 @@ def __init__(self, i, o, clk):
io_pad = platform.get_pin_location(o)
io_prop = platform.get_pin_properties(o)
io_prop_dict = dict(io_prop)
io_data_i = platform.add_iface_io(io_name)
self.comb += io_data_i.eq(i)
if isinstance(i, Constant):
const_output = const_output_calc(i, o)
else:
const_output = "NONE"
io_data_i = platform.add_iface_io(io_name)
self.comb += io_data_i.eq(i)
block = {
"type" : "GPIO",
"mode" : "OUTPUT",
Expand All @@ -378,6 +406,7 @@ def __init__(self, i, o, clk):
"size" : 1,
"out_reg" : "REG",
"out_clk_pin" : clk,
"const_output" : const_output,
"out_clk_inv" : 0,
"drive_strength" : io_prop_dict.get("DRIVE_STRENGTH", "4")
}
Expand Down
6 changes: 6 additions & 0 deletions litex/build/efinix/ifacewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ def generate_gpio(self, block, verbose=True):
cmd += 'design.set_property("{}","DRIVE_STRENGTH","{}")\n'.format(name, block["drive_strength"])
if "slewrate" in block:
cmd += 'design.set_property("{}","SLEWRATE","{}")\n'.format(name, block["slewrate"])
if "const_output" in block:
if not isinstance(block["const_output"], list):
cmd += f'design.set_property("{name}","CONST_OUTPUT","{block["const_output"]}")\n'
else:
for i, val in enumerate(block["const_output"]):
cmd += f'design.set_property("{name}[{i}]","CONST_OUTPUT","{val}")\n'

if mode == "INOUT" or mode == "INPUT" or mode == "OUTPUT":
if prop:
Expand Down

0 comments on commit 54973eb

Please sign in to comment.