From d85d2b7b9bad25eae8f26195ee123b6c2b61bd61 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 27 Nov 2015 19:36:23 +0100 Subject: [PATCH] soc/interconnect/stream_packet: add check of field's width vs signal's width in Header.get_field --- litex/soc/interconnect/stream_packet.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/litex/soc/interconnect/stream_packet.py b/litex/soc/interconnect/stream_packet.py index 60fcd5cf..f892fedf 100644 --- a/litex/soc/interconnect/stream_packet.py +++ b/litex/soc/interconnect/stream_packet.py @@ -118,13 +118,15 @@ class Header: field = getattr(obj, name.replace("_msb", ""))[width:2*width] else: field = getattr(obj, name) + if len(field) != width: + raise ValueError("Width mismatch on " + name + " field") return field def encode(self, obj, signal): r = [] for k, v in sorted(self.fields.items()): - start = v.byte*8+v.offset - end = start+v.width + start = v.byte*8 + v.offset + end = start + v.width field = self.get_field(obj, k, v.width) if self.swap_field_bytes: field = reverse_bytes(field) @@ -134,8 +136,8 @@ class Header: def decode(self, signal, obj): r = [] for k, v in sorted(self.fields.items()): - start = v.byte*8+v.offset - end = start+v.width + start = v.byte*8 + v.offset + end = start + v.width field = self.get_field(obj, k, v.width) if self.swap_field_bytes: r.append(field.eq(reverse_bytes(signal[start:end]))) -- 2.30.2