forked from M-Labs/artiq
1
0
Fork 0

rtio/rtlink: add 'like' methods to clone interfaces

This commit is contained in:
Sebastien Bourdeauducq 2015-04-16 13:02:39 +08:00
parent 61a6506484
commit 26003781b4
1 changed files with 22 additions and 0 deletions

View File

@ -17,6 +17,13 @@ class OInterface:
self.latency = latency self.latency = latency
self.suppress_nop = suppress_nop self.suppress_nop = suppress_nop
@classmethod
def like(cls, other):
return cls(get_data_width(other),
get_address_width(other),
get_fine_ts_width(other),
other.latency, other.suppress_nop)
class IInterface: class IInterface:
def __init__(self, data_width, def __init__(self, data_width,
@ -32,12 +39,27 @@ class IInterface:
self.timestamped = timestamped self.timestamped = timestamped
assert(not fine_ts_width or timestamped) assert(not fine_ts_width or timestamped)
@classmethod
def like(cls, other):
return cls(get_data_width(other),
other.timestamped,
get_fine_ts_width(other),
other.latency)
class Interface: class Interface:
def __init__(self, o, i=None): def __init__(self, o, i=None):
self.o = o self.o = o
self.i = i self.i = i
@classmethod
def like(cls, other):
if self.i is None:
return cls(OInterface.like(self.o))
else:
return cls(OInterface.like(self.o),
IInterface.like(self.i))
def _get_or_zero(interface, attr): def _get_or_zero(interface, attr):
if isinstance(interface, Interface): if isinstance(interface, Interface):