From b379f05b29b310e1cece677847c131c5f08f022c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 10 Sep 2024 11:20:48 -0500 Subject: [PATCH] Merge mov_status_count & _param into mov_status_n .. and correct .mov_status irq prev and range handling --- adafruit_pioasm.py | 20 ++++++++++---------- tests/test_version.py | 22 +++++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/adafruit_pioasm.py b/adafruit_pioasm.py index 1ddcb1b..3b83347 100644 --- a/adafruit_pioasm.py +++ b/adafruit_pioasm.py @@ -63,8 +63,7 @@ def __init__(self, text_program: str, *, build_debuginfo: bool = False) -> None: pio_version = 0 fifo_type = None mov_status_type = None - mov_status_count = None - mov_status_param = None + mov_status_n = None in_count = None in_shift_right = None auto_push = None @@ -139,24 +138,26 @@ def parse_rxfifo_brackets(arg, fifo_dir): elif line.startswith(".mov_status"): require_before_instruction() required_version = 0 - mov_status_param = 0 + mov_status_n = 0 mov_status_type = words[1] if words[1] in ("txfifo", "rxfifo"): if words[2] != "<": raise RuntimeError(f"Invalid {line}") - mov_status_count = int_in_range(words[3], 0, 16, words[1]) + mov_status_n = int_in_range(words[3], 0, 32, words[1]) elif words[1] == "irq": required_version = 1 idx = 2 if words[idx] == "next": - mov_status_param = 2 + mov_status_n = 0x10 idx += 1 - if words[idx] == "next": - mov_status_param = 1 + elif words[idx] == "prev": + mov_status_n = 0x8 idx += 1 + else: + mov_status_n = 0 if words[idx] != "set": raise RuntimeError(f"Invalid {line})") - mov_status_count = int(words[idx + 1]) + mov_status_n |= int_in_range(words[idx + 1], 0, 8, "mov_status irq") require_version(required_version, line) elif words[0] == ".out": require_before_instruction() @@ -447,8 +448,7 @@ def parse_rxfifo_brackets(arg, fifo_dir): if mov_status_type is not None: self.pio_kwargs["mov_status_type"] = mov_status_type - self.pio_kwargs["mov_status_count"] = mov_status_count - self.pio_kwargs["mov_status_param"] = mov_status_param + self.pio_kwargs["mov_status_n"] = mov_status_n if set_count not in (None, 32): self.pio_kwargs["set_count"] = set_count diff --git a/tests/test_version.py b/tests/test_version.py index 380d5aa..cf015a6 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -32,35 +32,39 @@ def test_mov_status() -> None: ".mov_status txfifo < 5", sideset_enable=0, mov_status_type="txfifo", - mov_status_count=5, - mov_status_param=0, + mov_status_n=5, ) assert_pio_kwargs( ".mov_status rxfifo < 8", sideset_enable=0, mov_status_type="rxfifo", - mov_status_count=8, - mov_status_param=0, + mov_status_n=8, ) assert_assembly_fails(".mov_status rxfifo < -1") - assert_assembly_fails(".mov_status rxfifo < 16") + assert_assembly_fails(".mov_status rxfifo < 33") assert_assembly_fails(".mov_status irq next set 3") + assert_pio_kwargs( + ".pio_version 1\n.mov_status irq prev set 3", + pio_version=1, + sideset_enable=0, + mov_status_type="irq", + mov_status_n=3 | 0x8, + ) assert_pio_kwargs( ".pio_version 1\n.mov_status irq next set 3", pio_version=1, sideset_enable=0, mov_status_type="irq", - mov_status_count=3, - mov_status_param=2, + mov_status_n=3 | 0x10, ) assert_pio_kwargs( ".pio_version 1\n.mov_status irq set 3", pio_version=1, sideset_enable=0, mov_status_type="irq", - mov_status_count=3, - mov_status_param=0, + mov_status_n=3, ) + assert_assembly_fails(".pio_version 1\n.mov_status irq prev set 9") def test_dot_in() -> None: