From dc9109030ae9d07301253d73aca06c47c0ded75f Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 3 Sep 2020 13:16:32 +0200 Subject: [PATCH] software/driver/analyzer/add_trigger: add support for binary/hexa expressions with x support. ex: litescope_cli -v sig1 0b111x0 ex: litescope_cli -v sig2 0x1234567x --- litescope/software/driver/analyzer.py | 24 +++++++++++++++++++++--- litescope/software/litescope_cli.py | 1 - 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/litescope/software/driver/analyzer.py b/litescope/software/driver/analyzer.py index e78eaa0..e432cb0 100644 --- a/litescope/software/driver/analyzer.py +++ b/litescope/software/driver/analyzer.py @@ -8,7 +8,7 @@ import os import sys - +import re from migen import * @@ -82,8 +82,26 @@ class LiteScopeAnalyzerDriver: raise ValueError("Trigger memory full, too much conditions") if cond is not None: for k, v in cond.items(): - value |= getattr(self, k + "_o")*v - mask |= getattr(self, k + "_m") + # Check for binary/hexa expressions + mb = re.match("0b([01x]+)", v) + mx = re.match("0x([0-fx]+)", v) + m = mb or mx + if m is not None: + b = m.group(1) + v = 0 + m = 0 + for c in b: + v <<= 4 if mx is not None else 1 + m <<= 4 if mx is not None else 1 + if c != "x": + v |= int(c) + m |= 0xf if mx is not None else 0b1 + value |= getattr(self, k + "_o")*v + mask |= getattr(self, k + "_m") & (getattr(self, k + "_o")*m) + # Else convert to int + else: + value |= getattr(self, k + "_o")*int(v, 0) + mask |= getattr(self, k + "_m") self.trigger_mem_mask.write(mask) self.trigger_mem_value.write(value) self.trigger_mem_write.write(1) diff --git a/litescope/software/litescope_cli.py b/litescope/software/litescope_cli.py index 35b5f9d..d10e4fc 100755 --- a/litescope/software/litescope_cli.py +++ b/litescope/software/litescope_cli.py @@ -85,7 +85,6 @@ def add_triggers(args, analyzer, signals): cond = {} for signal, value in args.value_trigger or []: name = finder[signal] - value = int(value, 0) cond[finder[signal]] = value print(f"Condition: {name} == {value}") if cond: