From b9562c04e00b7bb35a61bd2123e950b614151cd7 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 19 May 2020 10:23:15 -0400 Subject: [PATCH] Add ability to add output marker via external signal For example, a script to flash the chip can use this to mark the output so that it's clear when the target was actually reset. --- itm-decode.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/itm-decode.py b/itm-decode.py index 3f2b0be..86e4b3e 100755 --- a/itm-decode.py +++ b/itm-decode.py @@ -13,6 +13,20 @@ color_lookup = { "red": 31, "green": 32, "cyan": 36, "yellow": 33 } def color(name, text): return "\033[%dm%s\033[0m" % (color_lookup[name], text); +try: + # On Unix systems, print an additional marker in the output stream + # when SIGUSR1 or SIGUSR2 is received. This is just to help clarify + # output when the chip is externally reset, etc. + import signal + def sigusr1_handler(signum, frame): + print(color("yellow", "--- mark ---")) + def sigusr2_handler(signum, frame): + print(color("yellow", "--- reset ---")) + signal.signal(signal.SIGUSR1, sigusr1_handler) + signal.signal(signal.SIGUSR2, sigusr2_handler) +except AttributeError as e: + pass + class ResyncException(Exception): pass