Software Interrupt Setup for the Teensy 4.x

Neal

Well-known member
I want to implement a simple software interrupt so I can initiate an ISR using a software command. Other microprocessors I have used have dedicated interrupt vectors for this purpose, but I could not find an IRQ_NUMBER_t in the i.MX RT1060 Processor Reference Manual or the imxrt.h.

Has anyone implemented a software interrupt for the T4.x?

Or any suggestions on how to accomplish this?

Appreciate any help offered.
 
I want to implement a simple software interrupt so I can initiate an ISR using a software command. Other microprocessors I have used have dedicated interrupt vectors for this purpose, but I could not find an IRQ_NUMBER_t in the i.MX RT1060 Processor Reference Manual or the imxrt.h.

Has anyone implemented a software interrupt for the T4.x?

Or any suggestions on how to accomplish this?

Appreciate any help offered.

You can use any.
All are can be used as software interrupt, too. Just make sure they are not used otherwise.
There are some unused.. IRQ_SOFTWARE is used by the audio library (yeah I don't like this name, as it says nothing about it's function. Tried to rename it, but, as usual, PRs got ignored)
IRQ_Reserved1 .. IRQ_Reserved6 are not used by the hardware and are safe to use.

A table is here: https://github.com/PaulStoffregen/c...2bcfe143c99657e3d/teensy4/imxrt.h#L8C20-L8C20
Reference manual is here: https://www.pjrc.com/teensy/datasheets.html
 
There are some useful macros:

Code:
#define NVIC_ENABLE_IRQ(n)      (*(&NVIC_ISER0 + ((n) >> 5)) = (1 << ((n) & 31)))
#define NVIC_DISABLE_IRQ(n)     (*(&NVIC_ICER0 + ((n) >> 5)) = (1 << ((n) & 31)))
#define NVIC_SET_PENDING(n)     (*((volatile uint32_t *)0xE000E200 + ((n) >> 5)) = (1 << ((n) & 31)))
#define NVIC_CLEAR_PENDING(n)   (*((volatile uint32_t *)0xE000E280 + ((n) >> 5)) = (1 << ((n) & 31)))
#define NVIC_IS_ENABLED(n)      (*(&NVIC_ISER0 + ((n) >> 5)) & (1 << ((n) & 31)))
#define NVIC_IS_PENDING(n)      (*((volatile uint32_t *)0xE000E200 + ((n) >> 5)) & (1 << ((n) & 31)))
#define NVIC_IS_ACTIVE(n)       (*((volatile uint32_t *)0xE000E300 + ((n) >> 5)) & (1 << ((n) & 31)))
#define NVIC_TRIGGER_IRQ(n)     NVIC_STIR=(n)

You can use NVIC_SET_PENDING or NVIC_TRIGGER_IRQ to trigger the interrupt. NVIC_TRIGGER_IRQ is faster.
 
Rather than using an existing hardware interrupt, the ARM CPU supports two software controlled exceptions.
First is the supervisor call (exception #11) triggered by the "SVC" instruction.
Second is PendSV (exception #14) triggered by setting the PENDSVSET bit in the ICSR register. This is used by the EventResponder framework in TeensyDuino, which could probably do what you want without manually hooking an ISR.
 
The eventresponder is evil. It disables the interrupts (unnecessarily) and makes the timing of the system more unpredictable. Even if you don't use it at all.
 
Thanks for the responses. It is probably easier for me to use one of the IRQ_Reservedx vectors. I didn't realize they were useable.

Also, somehow I missed the IRQ_SOFTWARE (70) vector in imxrt.h probably because it is listed as RESERVED in the reference manual.

Thanks again for the help. I will try using one of the IRQ_Reservedx IRQ numbers.
 
Be aware that the audio library uses at least one of them (possibly the one marked as IRQ_SOFTWARE) for its own puposes.
 
Interesting. Do you @jmarsh know what it is used for in the Audio Library?

I did get if working with IRQ_SOFTWARE (70) in a simple test I did. But it didn't use any of the Audio Library for this test. If the Audio Library uses one of the IRQ vectors, it would be good to know which one and for what if anyone knows that information.
 
Interesting. Do you @jmarsh know what it is used for in the Audio Library?

I did get if working with IRQ_SOFTWARE (70) in a simple test I did. But it didn't use any of the Audio Library for this test. If the Audio Library uses one of the IRQ vectors, it would be good to know which one and for what if anyone knows that information.

You already had this information:)
As I wrote in my first answer: Yes, IRQ_SOFTWARE is used by the audio libary.

My (mp3,acc etc) Audio-codecs library uses IRQ_Reserved1 in additon.
 
Sorry, my misunderstanding @Mcu32. When you said "IRQ_SOFTWARE is used by the audio library " I thought you meant it was included in the imxrt.h file that is in the Audio Library. I didn't realize it was actually being used.

Thanks for the clarification. I will use one of the IRQ_Reservedx vectors.
 
Back
Top