Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8013

SDK • Re: [PIO] bitwise AND on ISR value

$
0
0
Hi,

this might do the trick:

Code:

; osr shifts left; origin of pins at pin 18 (or the pin after A15); isr autopush, threshold = 14; instruction count = 7.wrap_targetwait 0 gpio PIN_RDjmp pin, skipmov osr, pins; osr = AAAAAAAAAAAAAAAAxxxxxxxxxxxxxxxx, A = A15-A0, x = other pinsout y, 2; y = 000000000000000000000000000000AA, A = A15-A14; osr = AAAAAAAAAAAAAAxxxxxxxxxxxxxxxx00, A = A13-A0, x = other pinsjmp y--, skip ; jump if y = AA != 00out isr, 14; isr = 00000000000000ooAAAAAAAAAAAAAA, oo = A15-A14 = 00, A = A13-A0, autopush (blocking)skip:wait 1 gpio PIN_RD.wrap
Here the pin filtering is done using osr and the push block instruction is avoided by using autopush for isr, which in itself is blocking, and the
fact that 'out isr, 14' sets the bit count of isr to 14 matching the autopush threshold. Because the physical pins are mapped to 'pins' modulo-32, putting the origin at pin 18 puts the pins of interest at bits 31-16 in 'pins' and hence in the osr.

In terms of instruction count, let us consider what needs to happen (here the instruction most closely matching the described action is chosen as a representative of the full action):

1 & 2. the state of the bus must be monitored -> it seems that 'wait 1 gpio PIN_RD' and 'wait 0 gpio PIN_RD' need to be individual instructions (i.e., they cannot be integrated to the rest of the logic or combined with each other)
3. a comparison must be made: 'jmp y--, skip'
4. pin data must be transferred to y for comparison: 'out y, 2'
5. data must be 'pushed': 'out isr, 14'

This means that we have two instructions more than is necessary from simplified interaction point of view. Of these 'mov osr, pins' is necessary as a part of the filtering process from pins to y to 'jmp y--, skip', since PIO does not allow for transfer of filtered pins directly to y (or x) or comparison with isr (or osr). This leaves 'jmp pin, skip'. If the pin-mapping is as given and the code needs to run on RP2040 then this instruction is necessary (we cannot access the state of an isolated pin without using at least one instruction). However, otherwise we have the following options:

Code:

; jmp-pin can be moved to physical pin 18 (or the pin after A15), RP2040 compatible; osr shifts left; origin of pins at pin 19 (or the pin after jmp-pin); isr autopush, threshold = 14; instruction count = 6.wrap_targetwait 0 gpio PIN_RDmov osr, pins; osr = jAAAAAAAAAAAAAAAAxxxxxxxxxxxxxxx, j = jmp-pin, A = A15-A0, x = other pinsout y, 3; y = 00000000000000000000000000000jAA, j = jmp-pin, A = A15-A14; osr = AAAAAAAAAAAAAAxxxxxxxxxxxxxxx000, j = jmp-pin, A = A13-A0, x = other pinsjmp y--, skip ; jump if y = jAA != 000out isr, 14; isr = 00000000000000ooAAAAAAAAAAAAAA, oo = A15-A14 = 00, A = A13-A0, autopush (blocking)skip:wait 1 gpio PIN_RD.wrap

Code:

; RP2350 compatible; in-pins masked to jmp-pin, A0-A15 (all other pins will read 0); origin of pins at pin 2 (or the pin containing A0); isr autopush, threshold = 14; instruction count = 6.wrap_targetwait 0 gpio PIN_RDmov osr, pins; osr = 0000000j00000000AAAAAAAAAAAAAAAA, j = jmp-pin (shown at a random location), A = A15-A0, 0 = all other pins are masked to 0out y, 18; y = 000000000000000000000j00000000AA, j = jmp-pin, A = A15-A14; osr = AAAAAAAAAAAAAA000000000000000000, A = A13-A0jmp y--, skip ; jump if y = 0000000j00000000AA != 000000000000000000out isr, 14; isr = 00000000000000ooAAAAAAAAAAAAAA, oo = A15-A14 = 00, A = A13-A0, autopush (blocking)skip:wait 1 gpio PIN_RD.wrap
Hope this helps toward a solution,

1012

Statistics: Posted by 1012 — Fri Jul 11, 2025 11:48 am



Viewing all articles
Browse latest Browse all 8013

Trending Articles