Skip to content

Commit a2beb99

Browse files
soypatdeadprogram
authored andcommitted
add IRQ instructions to AssemblerV1
1 parent da356ef commit a2beb99

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

rp2-pio/instr.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,18 @@ const (
314314
type IRQIndexMode uint8
315315

316316
const (
317+
// Direct: the three LSBs are used directly to index the IRQ flags in this PIO block.
318+
IRQDirect IRQIndexMode = 0b00 // direct
317319
// Prev: the instruction references an IRQ flag from the next-lower-numbered PIO in the system, wrapping to
318320
// the highest-numbered PIO if this is PIO0. Available on RP2350 only.
319-
IRQPrev IRQIndexMode = 0b01
321+
IRQPrev IRQIndexMode = 0b01 // prev
320322
// Rel: the state machine ID (0…3) is added to the IRQ flag index, by way of modulo-4 addition on the two
321323
// LSBs. For example, state machine 2 with a flag value of '0x11' will wait on flag 3, and a flag value of '0x13' will
322324
// wait on flag 1. This allows multiple state machines running the same program to synchronise with each other.
323-
IRQRel IRQIndexMode = 0b10
325+
IRQRel IRQIndexMode = 0b10 // rel
324326
// Next: the instruction references an IRQ flag from the next-higher-numbered PIO in the system, wrapping to
325327
// PIO0 if this is the highest-numbered PIO. Available on RP2350 only.
326-
IRQNext IRQIndexMode = 0b11
328+
IRQNext IRQIndexMode = 0b11 // next
327329
)
328330

329331
// EncodeInstr encodes an arbitrary PIO instruction with the given arguments.

rp2-pio/instrv1.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (asm AssemblerV1) MovReverse(dest MovDest, src MovSrc) instructionV0 {
8181
// MovOSRFromRx reads the selected RX FIFO entry into the OSR. The PIO state machine can read the FIFO entries in any order, indexed
8282
// either by the Y register, or an immediate Index in the instruction. Requires the SHIFTCTRL_FJOIN_RX_GET configuration field
8383
// to be set, otherwise its operation is undefined.
84-
// - If IdxI (index by immediate) is set, the RX FIFO’s registers are indexed by the two least-significant bits of the Index
84+
// - If idxByImmediate (index by immediate) is set, the RX FIFO’s registers are indexed by the two least-significant bits of the Index
8585
// operand. Otherwise, they are indexed by the two least-significant bits of the Y register. When IdxI is clear, all non-zero
8686
// values of Index are reserved encodings, and their operation is undefined.
8787
func (asm AssemblerV1) MovOSRFromRx(idxByImmediate bool, RxFifoIndex uint8) instructionV0 {
@@ -106,5 +106,26 @@ func (asm AssemblerV1) Set(dest SetDest, value uint8) instructionV0 {
106106
return asm.v0().Set(dest, value)
107107
}
108108

109+
// IRQSet sets the IRQ flag selected by irqIndex.
110+
func (asm AssemblerV1) IRQSet(irqIndex uint8, idxMode IRQIndexMode) instructionV0 {
111+
return asm.irq(false, false, irqIndex, idxMode)
112+
}
113+
114+
// IRQClear clears the IRQ flag selected by irqIndex argument. See [AssemblerV1.IRQSet].
115+
func (asm AssemblerV1) IRQClear(irqIndex uint8, idxMode IRQIndexMode) instructionV0 {
116+
return asm.irq(true, false, irqIndex, idxMode)
117+
}
118+
119+
// IRQWait sets the IRQ flag selected by irqIndex and waits for it to be cleared before proceeding.
120+
// If Wait is set, Delay cycles do not begin until after the wait period elapses.
121+
func (asm AssemblerV1) IRQWait(irqIndex uint8, idxMode IRQIndexMode) instructionV0 {
122+
return asm.irq(false, true, irqIndex, idxMode)
123+
}
124+
125+
func (asm AssemblerV1) irq(clear, wait bool, irqIndex uint8, idxMode IRQIndexMode) instructionV0 {
126+
instr := _INSTR_BITS_IRQ | uint16(boolAsU8(clear))<<6 | uint16(boolAsU8(wait))<<6 | uint16(idxMode)<<3 | uint16(irqIndex&0b111)
127+
return asm.v0().instr(instr)
128+
}
129+
109130
// Nop instruction unchanged from [AssemblerV0.Nop].
110131
func (asm AssemblerV1) Nop() instructionV0 { return asm.v0().Nop() }

0 commit comments

Comments
 (0)