|
| 1 | +from migen.fhdl.std import * |
| 2 | + |
| 3 | + |
| 4 | +class OInterface: |
| 5 | + def __init__(self, data_width, address_width=0, |
| 6 | + fine_ts_width=0, latency=1, suppress_nop=True): |
| 7 | + self.stb = Signal() |
| 8 | + self.busy = Signal() |
| 9 | + |
| 10 | + if data_width: |
| 11 | + self.data = Signal(data_width) |
| 12 | + if address_width: |
| 13 | + self.address = Signal(address_width) |
| 14 | + if fine_ts_width: |
| 15 | + self.fine_ts = Signal(fine_ts_width) |
| 16 | + |
| 17 | + self.latency = latency |
| 18 | + self.suppress_nop = suppress_nop |
| 19 | + |
| 20 | + |
| 21 | +class IInterface: |
| 22 | + def __init__(self, data_width, |
| 23 | + timestamped=True, fine_ts_width=0, latency=2): |
| 24 | + self.stb = Signal() |
| 25 | + |
| 26 | + if data_width: |
| 27 | + self.data = Signal(data_width) |
| 28 | + if fine_ts_width: |
| 29 | + self.fine_ts = Signal(fine_ts_width) |
| 30 | + |
| 31 | + self.latency = latency |
| 32 | + self.timestamped = timestamped |
| 33 | + assert(not fine_ts_width or timestamped) |
| 34 | + |
| 35 | + |
| 36 | +class Interface: |
| 37 | + def __init__(self, o, i=None): |
| 38 | + self.o = o |
| 39 | + self.i = i |
| 40 | + |
| 41 | + |
| 42 | +def _get_or_zero(interface, attr): |
| 43 | + if isinstance(interface, Interface): |
| 44 | + return max(_get_or_zero(interface.i, attr), |
| 45 | + _get_or_zero(interface.o, attr)) |
| 46 | + else: |
| 47 | + if hasattr(interface, attr): |
| 48 | + return flen(getattr(interface, attr)) |
| 49 | + else: |
| 50 | + return 0 |
| 51 | + |
| 52 | + |
| 53 | +def get_data_width(interface): |
| 54 | + return _get_or_zero(interface, "data") |
| 55 | + |
| 56 | + |
| 57 | +def get_address_width(interface): |
| 58 | + return _get_or_zero(interface, "address") |
| 59 | + |
| 60 | + |
| 61 | +def get_fine_ts_width(interface): |
| 62 | + return _get_or_zero(interface, "fine_ts") |
0 commit comments