I'm trying to set interrupt priorities on the teensy 4.0 and I don't get the expected result. Here is a test sketch that sets the priority on an external pin inteerupt and three interval timers,
In reading the fine print I can now see that the gpio pins share a common priority value. Same for the timer 0-3 per this document starting on page 43.
i.MX RT1060 Processor Reference Manual
Document Number: IMXRT1060RM, Rev. 3, 07/2021
I want to confirm that there is no way to set each of the 4 teensy timer interrupts to a different value,
The result of my test:
IrqNr:122 PRIO:160 PIT Timer0-3 < rounded all of my priorities (162, 255, 249) down to 160
IrqNr:157 PRIO:112 GPIO 6/7/8/9 > rounded down from 127 to 112
Some of the online documentation states priorities go from 0-255 with 0 being the highest. What I'm seeing is the valid values are multiples of 16 (rounded down, Ex 127 for GPIO ended up as 112). In the case of the three timers, it seems to max out at 160.
What are the valid values for priority 0,16,32,48,64...or am I doing something wrong to be able to use all values 0-255.
Does the interval timer restrict the maximum value as I saw in my test, to 160?
Code:
#include "IntervalTimer.h"
int MPR121_irqPin = 20; // irq pin for Adafruit MPR121 breakout board, GPIO6-2
volatile double audioInterval =1000000; //set by using playing freq as index to audioRateA440 or audioRateA220
volatile uint32_t controlInterval = 10000; // The fingerholes will be scanned for external changes 100 times per second
volatile uint32_t clockInterval = 250000; // interval timer = 1/4 second.
/********************************************************************************
variables related to the interrupt handler interval control timers
********************************************************************************/
IntervalTimer audioTimer; //control time for sound production. The frequency will be adjusted by varying the interval
IntervalTimer controlTimer; //used to scan for external changes to environment
IntervalTimer clockTimer; //timer to keep track of 1/4 second intervals
void setup() {
unsigned long delayStart = millis();
Serial.begin(115200);
while (!Serial && (millis() - delayStart) <= 1000);
Serial.println("Serial Started");
pinMode(MPR121_irqPin, INPUT); //set irq pin as input
attachInterrupt(MPR121_irqPin,readTouchInputs,FALLING);
NVIC_SET_PRIORITY(IRQ_GPIO6789,127);
controlTimer.begin(scanInputs, controlInterval);
controlTimer.priority(162);
audioTimer.begin(audioOscillator, audioInterval);
audioTimer.priority(255);
clockTimer.begin(clockRoutine, clockInterval);
clockTimer.priority(249);
for (int irqNr = 0; irqNr < NVIC_NUM_INTERRUPTS; irqNr++)
{
Serial.printf("IrqNr:%d PRIO:%d\n",irqNr, NVIC_GET_PRIORITY(irqNr));
}
}
void scanInputs()
{
}
void readTouchInputs()
{
}
void audioOscillator()
{
}
void clockRoutine()
{
}
void loop() {
// put your main code here, to run repeatedly:
}
In reading the fine print I can now see that the gpio pins share a common priority value. Same for the timer 0-3 per this document starting on page 43.
i.MX RT1060 Processor Reference Manual
Document Number: IMXRT1060RM, Rev. 3, 07/2021
I want to confirm that there is no way to set each of the 4 teensy timer interrupts to a different value,
Code:
attachInterrupt(MPR121_irqPin,readTouchInputs,FALLING);
NVIC_SET_PRIORITY(IRQ_GPIO6789,127);
controlTimer.begin(scanInputs, controlInterval);
controlTimer.priority(162);
audioTimer.begin(audioOscillator, audioInterval);
audioTimer.priority(255);
clockTimer.begin(clockRoutine, clockInterval);
clockTimer.priority(249);
The result of my test:
IrqNr:122 PRIO:160 PIT Timer0-3 < rounded all of my priorities (162, 255, 249) down to 160
IrqNr:157 PRIO:112 GPIO 6/7/8/9 > rounded down from 127 to 112
Some of the online documentation states priorities go from 0-255 with 0 being the highest. What I'm seeing is the valid values are multiples of 16 (rounded down, Ex 127 for GPIO ended up as 112). In the case of the three timers, it seems to max out at 160.
What are the valid values for priority 0,16,32,48,64...or am I doing something wrong to be able to use all values 0-255.
Does the interval timer restrict the maximum value as I saw in my test, to 160?