build.{dsl,res,plat}: add PinsN and DiffPairsN.
This commit is contained in:
parent
ad1a40c934
commit
efb2d773c3
8 changed files with 169 additions and 77 deletions
|
|
@ -1,7 +1,8 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
|
||||
__all__ = ["Pins", "DiffPairs", "Attrs", "Clock", "Subsignal", "Resource", "Connector"]
|
||||
__all__ = ["Pins", "PinsN", "DiffPairs", "DiffPairsN",
|
||||
"Attrs", "Clock", "Subsignal", "Resource", "Connector"]
|
||||
|
||||
|
||||
class Pins:
|
||||
|
|
@ -22,8 +23,9 @@ class Pins:
|
|||
raise TypeError("Direction must be one of \"i\", \"o\", \"oe\", or \"io\", not {!r}"
|
||||
.format(dir))
|
||||
|
||||
self.names = names
|
||||
self.dir = dir
|
||||
self.names = names
|
||||
self.dir = dir
|
||||
self.invert = False
|
||||
|
||||
def __len__(self):
|
||||
return len(self.names)
|
||||
|
|
@ -43,7 +45,14 @@ class Pins:
|
|||
return mapped_names
|
||||
|
||||
def __repr__(self):
|
||||
return "(pins {} {})".format(self.dir, " ".join(self.names))
|
||||
return "(pins{} {} {})".format("-n" if self.invert else "",
|
||||
self.dir, " ".join(self.names))
|
||||
|
||||
|
||||
def PinsN(*args, **kwargs):
|
||||
pins = Pins(*args, **kwargs)
|
||||
pins.invert = True
|
||||
return pins
|
||||
|
||||
|
||||
class DiffPairs:
|
||||
|
|
@ -56,7 +65,8 @@ class DiffPairs:
|
|||
"and {!r} do not"
|
||||
.format(self.p, self.n))
|
||||
|
||||
self.dir = dir
|
||||
self.dir = dir
|
||||
self.invert = False
|
||||
|
||||
def __len__(self):
|
||||
return len(self.p.names)
|
||||
|
|
@ -65,10 +75,16 @@ class DiffPairs:
|
|||
return zip(self.p.names, self.n.names)
|
||||
|
||||
def __repr__(self):
|
||||
return "(diffpairs {} (p {}) (n {}))".format(
|
||||
return "(diffpairs{} {} (p {}) (n {}))".format("-n" if self.invert else "",
|
||||
self.dir, " ".join(self.p.names), " ".join(self.n.names))
|
||||
|
||||
|
||||
def DiffPairsN(*args, **kwargs):
|
||||
diff_pairs = DiffPairs(*args, **kwargs)
|
||||
diff_pairs.invert = True
|
||||
return diff_pairs
|
||||
|
||||
|
||||
class Attrs(OrderedDict):
|
||||
def __init__(self, **attrs):
|
||||
for attr_key, attr_value in attrs.items():
|
||||
|
|
|
|||
|
|
@ -66,25 +66,26 @@ class Platform(ResourceManager, metaclass=ABCMeta):
|
|||
pin_fragment.flatten = True
|
||||
fragment.add_subfragment(pin_fragment, name="pin_{}".format(pin.name))
|
||||
|
||||
for pin, port, attrs in self.iter_single_ended_pins():
|
||||
for pin, port, attrs, invert in self.iter_single_ended_pins():
|
||||
if pin.dir == "i":
|
||||
add_pin_fragment(pin, self.get_input(pin, port, attrs))
|
||||
add_pin_fragment(pin, self.get_input(pin, port, attrs, invert))
|
||||
if pin.dir == "o":
|
||||
add_pin_fragment(pin, self.get_output(pin, port, attrs))
|
||||
add_pin_fragment(pin, self.get_output(pin, port, attrs, invert))
|
||||
if pin.dir == "oe":
|
||||
add_pin_fragment(pin, self.get_tristate(pin, port, attrs))
|
||||
add_pin_fragment(pin, self.get_tristate(pin, port, attrs, invert))
|
||||
if pin.dir == "io":
|
||||
add_pin_fragment(pin, self.get_input_output(pin, port, attrs))
|
||||
add_pin_fragment(pin, self.get_input_output(pin, port, attrs, invert))
|
||||
|
||||
for pin, p_port, n_port, attrs in self.iter_differential_pins():
|
||||
for pin, p_port, n_port, attrs, invert in self.iter_differential_pins():
|
||||
if pin.dir == "i":
|
||||
add_pin_fragment(pin, self.get_diff_input(pin, p_port, n_port, attrs))
|
||||
add_pin_fragment(pin, self.get_diff_input(pin, p_port, n_port, attrs, invert))
|
||||
if pin.dir == "o":
|
||||
add_pin_fragment(pin, self.get_diff_output(pin, p_port, n_port, attrs))
|
||||
add_pin_fragment(pin, self.get_diff_output(pin, p_port, n_port, attrs, invert))
|
||||
if pin.dir == "oe":
|
||||
add_pin_fragment(pin, self.get_diff_tristate(pin, p_port, n_port, attrs))
|
||||
add_pin_fragment(pin, self.get_diff_tristate(pin, p_port, n_port, attrs, invert))
|
||||
if pin.dir == "io":
|
||||
add_pin_fragment(pin, self.get_diff_input_output(pin, p_port, n_port, attrs))
|
||||
add_pin_fragment(pin,
|
||||
self.get_diff_input_output(pin, p_port, n_port, attrs, invert))
|
||||
|
||||
return self.toolchain_prepare(fragment, name, **kwargs)
|
||||
|
||||
|
|
@ -115,23 +116,30 @@ class Platform(ResourceManager, metaclass=ABCMeta):
|
|||
raise NotImplementedError("Platform {} does not support attributes for {}"
|
||||
.format(self.__class__.__name__, feature))
|
||||
|
||||
def get_input(self, pin, port, attrs):
|
||||
@staticmethod
|
||||
def _invert_if(invert, value):
|
||||
if invert:
|
||||
return ~value
|
||||
else:
|
||||
return value
|
||||
|
||||
def get_input(self, pin, port, attrs, invert):
|
||||
self._check_feature("single-ended input", pin, attrs,
|
||||
valid_xdrs=(0,), valid_attrs=None)
|
||||
|
||||
m = Module()
|
||||
m.d.comb += pin.i.eq(port)
|
||||
m.d.comb += pin.i.eq(self._invert_if(invert, port))
|
||||
return m
|
||||
|
||||
def get_output(self, pin, port, attrs):
|
||||
def get_output(self, pin, port, attrs, invert):
|
||||
self._check_feature("single-ended output", pin, attrs,
|
||||
valid_xdrs=(0,), valid_attrs=None)
|
||||
|
||||
m = Module()
|
||||
m.d.comb += port.eq(pin.o)
|
||||
m.d.comb += port.eq(self._invert_if(invert, pin.o))
|
||||
return m
|
||||
|
||||
def get_tristate(self, pin, port, attrs):
|
||||
def get_tristate(self, pin, port, attrs, invert):
|
||||
self._check_feature("single-ended tristate", pin, attrs,
|
||||
valid_xdrs=(0,), valid_attrs=None)
|
||||
|
||||
|
|
@ -139,12 +147,12 @@ class Platform(ResourceManager, metaclass=ABCMeta):
|
|||
m.submodules += Instance("$tribuf",
|
||||
p_WIDTH=pin.width,
|
||||
i_EN=pin.oe,
|
||||
i_A=pin.o,
|
||||
i_A=self._invert_if(invert, pin.o),
|
||||
o_Y=port,
|
||||
)
|
||||
return m
|
||||
|
||||
def get_input_output(self, pin, port, attrs):
|
||||
def get_input_output(self, pin, port, attrs, invert):
|
||||
self._check_feature("single-ended input/output", pin, attrs,
|
||||
valid_xdrs=(0,), valid_attrs=None)
|
||||
|
||||
|
|
@ -152,25 +160,25 @@ class Platform(ResourceManager, metaclass=ABCMeta):
|
|||
m.submodules += Instance("$tribuf",
|
||||
p_WIDTH=pin.width,
|
||||
i_EN=pin.oe,
|
||||
i_A=pin.o,
|
||||
i_A=self._invert_if(invert, pin.o),
|
||||
o_Y=port,
|
||||
)
|
||||
m.d.comb += pin.i.eq(port)
|
||||
m.d.comb += pin.i.eq(self._invert_if(invert, port))
|
||||
return m
|
||||
|
||||
def get_diff_input(self, pin, p_port, n_port, attrs):
|
||||
def get_diff_input(self, pin, p_port, n_port, attrs, invert):
|
||||
self._check_feature("differential input", pin, attrs,
|
||||
valid_xdrs=(), valid_attrs=None)
|
||||
|
||||
def get_diff_output(self, pin, p_port, n_port, attrs):
|
||||
def get_diff_output(self, pin, p_port, n_port, attrs, invert):
|
||||
self._check_feature("differential output", pin, attrs,
|
||||
valid_xdrs=(), valid_attrs=None)
|
||||
|
||||
def get_diff_tristate(self, pin, p_port, n_port, attrs):
|
||||
def get_diff_tristate(self, pin, p_port, n_port, attrs, invert):
|
||||
self._check_feature("differential tristate", pin, attrs,
|
||||
valid_xdrs=(), valid_attrs=None)
|
||||
|
||||
def get_diff_input_output(self, pin, p_port, n_port, attrs):
|
||||
def get_diff_input_output(self, pin, p_port, n_port, attrs, invert):
|
||||
self._check_feature("differential input/output", pin, attrs,
|
||||
valid_xdrs=(), valid_attrs=None)
|
||||
|
||||
|
|
|
|||
|
|
@ -145,14 +145,14 @@ class ResourceManager:
|
|||
if pin is None:
|
||||
continue
|
||||
if isinstance(res.ios[0], Pins):
|
||||
yield pin, port.io, attrs
|
||||
yield pin, port.io, attrs, res.ios[0].invert
|
||||
|
||||
def iter_differential_pins(self):
|
||||
for res, pin, port, attrs in self._ports:
|
||||
if pin is None:
|
||||
continue
|
||||
if isinstance(res.ios[0], DiffPairs):
|
||||
yield pin, port.p, port.n, attrs
|
||||
yield pin, port.p, port.n, attrs, res.ios[0].invert
|
||||
|
||||
def should_skip_port_component(self, port, attrs, component):
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue