From: Florent Kermarrec Date: Tue, 2 Dec 2014 19:02:43 +0000 (+0100) Subject: link: add CRC check to BFM X-Git-Tag: 24jan2021_ls180~2572^2~159 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed97f378ff701c3a102758fed20f9bb845a71a5f;p=litex.git link: add CRC check to BFM --- diff --git a/lib/sata/link/test/bfm.py b/lib/sata/link/test/bfm.py index db276c0f..7587f489 100644 --- a/lib/sata/link/test/bfm.py +++ b/lib/sata/link/test/bfm.py @@ -102,8 +102,18 @@ class BFM(Module): return p def check_crc(self, packet): - # Todo from C Code or Python Code - return packet[:-1] + stdin = "" + for v in packet[:-1]: + stdin += "0x%08x " %v + stdin += "exit" + with subprocess.Popen("./crc", stdin=subprocess.PIPE, stdout=subprocess.PIPE) as process: + process.stdin.write(stdin.encode("ASCII")) + out, err = process.communicate() + crc = int(out.decode("ASCII"), 16) + if packet[-1] != crc: + return [] + else: + return packet[:-1] def packet_callback(self, packet): packet = self.descramble(packet)