Add wait jmppin & wait irq prev/next
This commit is contained in:
parent
7acebc63b0
commit
86f02e8b83
2 changed files with 40 additions and 7 deletions
|
|
@ -278,16 +278,36 @@ class Program: # pylint: disable=too-few-public-methods
|
|||
# instr delay p sr index
|
||||
assembled.append(0b001_00000_0_00_00000)
|
||||
polarity = int(instruction[1], 0)
|
||||
source = instruction[2]
|
||||
if not 0 <= polarity <= 1:
|
||||
raise RuntimeError("Invalid polarity")
|
||||
assembled[-1] |= polarity << 7
|
||||
assembled[-1] |= WAIT_SOURCES.index(instruction[2]) << 5
|
||||
num = int(instruction[3], 0)
|
||||
if not 0 <= num <= 31:
|
||||
raise RuntimeError("Wait num out of range")
|
||||
assembled[-1] |= num
|
||||
if instruction[-1] == "rel":
|
||||
assembled[-1] |= 0x10 # Set the high bit of the irq value
|
||||
if instruction[2] == "jmppin":
|
||||
require_version(1, "wait jmppin")
|
||||
num = 0
|
||||
print("wait jmppin", instruction)
|
||||
if len(instruction) > 3:
|
||||
if len(instruction) < 5 or instruction[3] != "+":
|
||||
raise RuntimeError("invalid wait jmppin")
|
||||
num = int_in_range(instruction[4], 0, 4, "wait jmppin offset")
|
||||
assembled[-1] |= num
|
||||
assembled[-1] |= 0b11 << 5 # JMPPIN wait source
|
||||
else:
|
||||
assembled[-1] |= WAIT_SOURCES.index(instruction[2]) << 5
|
||||
num = int(instruction[3], 0)
|
||||
if not 0 <= num <= 31:
|
||||
raise RuntimeError("Wait num out of range")
|
||||
assembled[-1] |= num
|
||||
# The flag index is decoded in the same way as the IRQ
|
||||
# index field, decoding down from the two MSBs
|
||||
if instruction[-1] == "next":
|
||||
require_version(1, "wait irq next")
|
||||
assembled[-1] |= 0b11000
|
||||
elif instruction[-1] == "prev":
|
||||
require_version(1, "wait irq prev")
|
||||
assembled[-1] |= 0b01000
|
||||
elif instruction[-1] == "rel":
|
||||
assembled[-1] |= 0b10000
|
||||
elif instruction[0] == "in":
|
||||
# instr delay src count
|
||||
assembled.append(0b010_00000_000_00000)
|
||||
|
|
|
|||
|
|
@ -125,3 +125,16 @@ def test_mov_v1() -> None:
|
|||
|
||||
assert_assembly_fails("mov pindirs, null", errtype=ValueError)
|
||||
assert_assembles_to(prefix + "mov pindirs, null", [0b101_00000_01100011])
|
||||
|
||||
|
||||
def test_wait_v1() -> None:
|
||||
assert_assembly_fails("wait 0 jmppin")
|
||||
assert_assembly_fails("wait 0 irq 5 next")
|
||||
prefix = ".pio_version 1\n"
|
||||
assert_assembly_fails(prefix + "wait 0 jmppin +")
|
||||
assert_assembly_fails(prefix + "wait 0 jmppin + 7")
|
||||
assert_assembles_to(prefix + "wait 0 jmppin + 3", [0b001_00000_0_11_00011])
|
||||
assert_assembles_to(prefix + "wait 1 jmppin", [0b001_00000_1_11_00000])
|
||||
|
||||
assert_assembles_to(prefix + "wait 0 irq 5 next", [0b001_00000_0_10_11_101])
|
||||
assert_assembles_to(prefix + "wait 1 irq 4 prev", [0b001_00000_1_10_01_100])
|
||||
|
|
|
|||
Loading…
Reference in a new issue