pico-examples icon indicating copy to clipboard operation
pico-examples copied to clipboard

Add isr example with the pio

Open dangarbri opened this issue 3 years ago • 3 comments

Someone on the pico forum asked how interrupts work with only 2 interrupt lines and 4 state machines.

I put together this example, which only runs with one isr line, but shows how you could identify which state machine the irq is coming from.

The pio program simply stalls waiting for input to the tx fifo from firmware, and then fires an interrupt when it gets anything.

From main.c, I load the program into each pio and fire the interrupts one by one. The code shows how you can identify the state machine the interrupt came from and then dispatch some action.

dangarbri avatar Aug 25 '22 01:08 dangarbri

Nice, thanks for addressing my comments :+1: Would you mind also adding this new example to https://github.com/raspberrypi/pico-examples/blob/master/README.md#pio please?

lurch avatar Aug 25 '22 23:08 lurch

Nice, thanks for addressing my comments +1 Would you mind also adding this new example to https://github.com/raspberrypi/pico-examples/blob/master/README.md#pio please?

done

dangarbri avatar Aug 26 '22 02:08 dangarbri

@lurch I made your requested review changes, and also a couple more.

I renamed it to IRQ since that's a more standard name. I'm used to calling them ISR (interrupt service routine) which gets confusing because in pico world, ISR means Input Shift Register. So I renamed everything to IRQ.

Also I updated my IRQ handler to use the lower level read/clear method. In this case I think it really does make it simpler for this use case than pio_interrupt_get. It becomes one read to check the IRQ flags instead of iterating over each bit checking if its set.

dangarbri avatar Aug 26 '22 11:08 dangarbri