Skip to content

Commit 86f02e8

Browse files
committed
Add wait jmppin & wait irq prev/next
1 parent 7acebc6 commit 86f02e8

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

adafruit_pioasm.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,36 @@ def parse_rxfifo_brackets(arg, fifo_dir):
278278
# instr delay p sr index
279279
assembled.append(0b001_00000_0_00_00000)
280280
polarity = int(instruction[1], 0)
281+
source = instruction[2]
281282
if not 0 <= polarity <= 1:
282283
raise RuntimeError("Invalid polarity")
283284
assembled[-1] |= polarity << 7
284-
assembled[-1] |= WAIT_SOURCES.index(instruction[2]) << 5
285-
num = int(instruction[3], 0)
286-
if not 0 <= num <= 31:
287-
raise RuntimeError("Wait num out of range")
288-
assembled[-1] |= num
289-
if instruction[-1] == "rel":
290-
assembled[-1] |= 0x10 # Set the high bit of the irq value
285+
if instruction[2] == "jmppin":
286+
require_version(1, "wait jmppin")
287+
num = 0
288+
print("wait jmppin", instruction)
289+
if len(instruction) > 3:
290+
if len(instruction) < 5 or instruction[3] != "+":
291+
raise RuntimeError("invalid wait jmppin")
292+
num = int_in_range(instruction[4], 0, 4, "wait jmppin offset")
293+
assembled[-1] |= num
294+
assembled[-1] |= 0b11 << 5 # JMPPIN wait source
295+
else:
296+
assembled[-1] |= WAIT_SOURCES.index(instruction[2]) << 5
297+
num = int(instruction[3], 0)
298+
if not 0 <= num <= 31:
299+
raise RuntimeError("Wait num out of range")
300+
assembled[-1] |= num
301+
# The flag index is decoded in the same way as the IRQ
302+
# index field, decoding down from the two MSBs
303+
if instruction[-1] == "next":
304+
require_version(1, "wait irq next")
305+
assembled[-1] |= 0b11000
306+
elif instruction[-1] == "prev":
307+
require_version(1, "wait irq prev")
308+
assembled[-1] |= 0b01000
309+
elif instruction[-1] == "rel":
310+
assembled[-1] |= 0b10000
291311
elif instruction[0] == "in":
292312
# instr delay src count
293313
assembled.append(0b010_00000_000_00000)

tests/test_version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,16 @@ def test_mov_v1() -> None:
125125

126126
assert_assembly_fails("mov pindirs, null", errtype=ValueError)
127127
assert_assembles_to(prefix + "mov pindirs, null", [0b101_00000_01100011])
128+
129+
130+
def test_wait_v1() -> None:
131+
assert_assembly_fails("wait 0 jmppin")
132+
assert_assembly_fails("wait 0 irq 5 next")
133+
prefix = ".pio_version 1\n"
134+
assert_assembly_fails(prefix + "wait 0 jmppin +")
135+
assert_assembly_fails(prefix + "wait 0 jmppin + 7")
136+
assert_assembles_to(prefix + "wait 0 jmppin + 3", [0b001_00000_0_11_00011])
137+
assert_assembles_to(prefix + "wait 1 jmppin", [0b001_00000_1_11_00000])
138+
139+
assert_assembles_to(prefix + "wait 0 irq 5 next", [0b001_00000_0_10_11_101])
140+
assert_assembles_to(prefix + "wait 1 irq 4 prev", [0b001_00000_1_10_01_100])

0 commit comments

Comments
 (0)