Questions of interrupt priorities.

Status
Not open for further replies.

vindar

Well-known member
Hello,

I have a couple of questions about interrupts, specifically for Teensy 4.

What is the default priority for the "interrupt at completion" of a DMA transfer. How should I proceed to adjust this priority ? There does not seems to be a method for that in the DMAChannel library so I guess it should be done by hand right ? I am a bit lost in the IMXRT manual so a snippet of code would be most welcome !

Second, looking at the code of IntervalTimer.h, it seems that all IntervalTimer objects share the same interrupt priority (which is max of all requested priorities). So this would means that another library can raise the priority of my IntervalTimer without my knowledge but I need it to stay lower than my DMA complete channel interrupt... Is there any easy way around that problem. Maybe using another timer ? My use of intervalTimer is as a one-shot timer to be called somewhere between 1ms to 100ms in the future.

Thanks for your input!
 
You can set the priority of any interrupt by
Code:
NVIC_SET_PRIORITY(irqnum, priority)
irqnum is the number of the interrupt. For T4.x you find the irq numbers in imxrt.h https://github.com/PaulStoffregen/c...568f2be30a9d9842be4c1eb7b3/teensy4/imxrt.h#L8 Standard priority is 128, lower numbers give higher priority.

Second, looking at the code of IntervalTimer.h, it seems that all IntervalTimer objects share the same interrupt priority (which is max of all requested priorities). So this would means that another library can raise the priority of my IntervalTimer without my knowledge

Yes, for the T4.x all four PIT timers share the same interrupt vector. The T3.x processors had separate vectors for the PITs. But of course you can never prevent a third party library grabbing any hardware resource....

Maybe using another timer ?
You could use one of the GPT timers. They are also 32bit and are easy to use. AFAIK GPT2 is not used by the core libraries. Manitou maintains a useful collection of snippets which I often use if I want to understand how certain peripherals are used: https://github.com/manitou48/teensy4.

If you don't want to fiddle around with low level register programming, you can also use the TeensyTimerTool which gives you high level access to most of the Teensy timers. (https://github.com/luni64/TeensyTimerTool/wiki)
 
You can set the priority of any interrupt by
Code:
NVIC_SET_PRIORITY(irqnum, priority)
irqnum is the number of the interrupt. For T4.x you find the irq numbers in imxrt.h https://github.com/PaulStoffregen/c...568f2be30a9d9842be4c1eb7b3/teensy4/imxrt.h#L8 Standard priority is 128, lower numbers give higher priority.

Ok, so setting the priority for the DMA interrupt is as simple as
Code:
NVIC_SET_PRIORITY((IRQ_DMA_CH0 + dmaobj.channel, priority)
easy ! :)

Yes, for the T4.x all four PIT timers share the same interrupt vector. The T3.x processors had separate vectors for the PITs. But of course you can never prevent a third party library grabbing any hardware resource....

Ok, that explains the weird code...

You could use one of the GPT timers. They are also 32bit and are easy to use. AFAIK GPT2 is not used by the core libraries. Manitou maintains a useful collection of snippets which I often use if I want to understand how certain peripherals are used: https://github.com/manitou48/teensy4.

Useful resource, bookmarked !

If you don't want to fiddle around with low level register programming, you can also use the TeensyTimerTool which gives you high level access to most of the Teensy timers. (https://github.com/luni64/TeensyTimerTool/wiki)

Yes, I saw the thread in the general forum about 10 minutes after posting this message... It seems like a great library and I especially like the clean C++ feel of it. I will probably end up using it as it provides greater flexibility.

By the way, do you know if the Audio library uses any timer ? I guess not but just to be on the safe side...

Thanks for your help!
 
By the way, do you know if the Audio library uses any timer ? I guess not but just to be on the safe side...
Nope, never did anything with audio but I'm sure answers will pop in quickly...
 
Which hardware the Audio library uses depends on which of its many inputs & outputs you use.

On Teensy 4, I believe the only one which currently uses a timer is the (still experimental) ADC input. It uses Quadtimer4.3.

On Teensy 3, several use the PDB timer. The PWM output uses one of the FTM timers.

Generally speaking, the ports made for specifically audio (I2S/SAI, SPDIF, MSQ) have their own ways to generate all their timing, so they don't use any of the chip's timers.
 
There does not seems to be a method for that in the DMAChannel library so I guess it should be done by hand right ?

The new cores has now a method that let you to define priority level within DMAChannel.
not sure if it is already distributed, but you can look the code up in Paul's Github repository of cores
 
Status
Not open for further replies.
Back
Top