From 9eac0a43645d844e43bf1b1463fc565895b0d809 Mon Sep 17 00:00:00 2001 From: Jean THOMAS Date: Thu, 12 Dec 2024 11:43:56 +0100 Subject: [PATCH] stream: Add BFM methods --- lambdalib/interface/stream.py | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lambdalib/interface/stream.py b/lambdalib/interface/stream.py index 73b3afc..d020921 100644 --- a/lambdalib/interface/stream.py +++ b/lambdalib/interface/stream.py @@ -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):