Get NVIC IRQ # from Pin #

Status
Not open for further replies.

gfvalvo

Well-known member
Hi.

Wondering if there’s a macro or function defined in Teensyduino that will map a T3.x pin number to its entry in the NVIC IRQ table. For example, Pin 3 (what I know) on a T3.2 is PTA12. So, its NVIC IRQ (what I want to know) is ‘IRQ_PORTA’ (87 decimal).

Thanks.
 
As supported Pin interrupts are pulled from an interrupt to the PORT they are on when AttachInterrupt( pin ) is used.
 
I wasn't sure it did because it isn't clear what the end use is - but that is the supported mechanism. Each pin interrupt is parsed from an interrupt to the PORT interrupt. There isn't a supported NVIC entry for each pin.

It follows this : Reference > Language > Functions > External interrupts > Attachinterrupt

Except on Teensy the pin# can be given directly like >> attachInterrupt(pin, ISR, mode); (not recommended Arduino Due, Zero, MKR1000, 101 only). The ISR code will be called when the case for 'mode' happens.
 
As stated in my original post, I wanted to know the NVIC IRQ entry given the pin number.

After poking around in pins_teensy.c, I just found a technique implemented in getIsrTable().

Thanks anyway.
 
Some libraries can change the priority based on the given critical tasks, essentially like, "whats your rank? your demoted im in charge! ok here's your badge back sir."
 
As stated in my original post, I wanted to know the NVIC IRQ entry given the pin number.

After poking around in pins_teensy.c, I just found a technique implemented in getIsrTable().

Thanks anyway.

Thanks Anyway?

You'll please note that void attachInterrupt(uint8_t pin, void (*function)(void), int mode) is where that getIsrTable() code is used!
 
Paul or others posted about the way pin interrupts are handled by a PORT interrupt that was the basis of my notes above. Reading the code it is clear that is the case. AttachInterrupt() registers the function to call when the port interrupt is detected. Each pin is not provided an NVIC entry - but the PORT interrupt is processed and when a function was registered - that code is then called. getIsrTable() is just the mapping tool to connect the provided pin# to the PORT where the interrupt will appear.
 
After poking around in pins_teensy.c, I just found a technique implemented in getIsrTable().

Yes, using the macros that translate the pin number to its unique config register is the best way. There simply isn't a define that gives exactly what you want, but this approach can do it and (probably) can be evaluated completely at compile time if your pin number is a compile time constant.

And yeah, you clearly do seem to understand the pins/ports relationship, even though that's what most of this thread turned out to discuss....
 
Status
Not open for further replies.
Back
Top