Skip to content

Commit

Permalink
stream: Add BFM methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean THOMAS committed Dec 12, 2024
1 parent 07c8a03 commit 9eac0a4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lambdalib/interface/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,46 @@ def __getattr__(self, name):
except AttributeError:
return self.fields["payload"][name]

def bfm_send(self, pkts, timeout=100):
len_pkts = len(pkts)
for i, pkt in enumerate(pkts):
yield Settle()
yield self.valid.eq(1)
yield self.first.eq(i == 0)
yield self.last .eq(i == len_pkts - 1)
for key, val in pkt.items():
yield getattr(self, key).eq(val)

yield
elapsed = 1

yield Settle()
while not (yield self.ready):
yield
yield Settle()
elapsed += 1
if elapsed >= timeout:
raise Exception("timeout")

yield self.valid.eq(0)

def bfm_read(self, timeout=100):
elapsed = 0

yield self.ready.eq(1)
yield Settle()
while not (yield self.valid):
yield
yield Settle()
elapsed += 1
if elapsed >= timeout:
raise Exception("timeout")

yield
yield self.ready.eq(0)

return {key: getattr(self, key) for key, _ in self.description}


class _FIFOWrapper:
def __init__(self, payload_layout):
Expand Down

0 comments on commit 9eac0a4

Please sign in to comment.