Skip to content

Commit

Permalink
Merge mov_status_count & _param into mov_status_n
Browse files Browse the repository at this point in the history
.. and correct .mov_status irq prev and range handling
  • Loading branch information
jepler committed Sep 10, 2024
1 parent 86f02e8 commit b379f05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
20 changes: 10 additions & 10 deletions adafruit_pioasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b379f05

Please sign in to comment.