From 1c73a3d7bff58bd7a8f4eb2ef691972099ed95f6 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Sun, 16 Oct 2022 16:15:02 +0800 Subject: [PATCH] SAMD21 IRQ priority exploration --- DCCTimerSAMD.cpp | 6 +++--- I2CManager_SAMD.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DCCTimerSAMD.cpp b/DCCTimerSAMD.cpp index 481f623..7f10169 100644 --- a/DCCTimerSAMD.cpp +++ b/DCCTimerSAMD.cpp @@ -30,8 +30,6 @@ #include "DCCTimer.h" #include -#include -#include INTERRUPT_CALLBACK interruptHandler=0; @@ -71,7 +69,9 @@ void DCCTimer::begin(INTERRUPT_CALLBACK callback) { // Set the interrupt condition, priority and enable it in the NVIC TCC0->INTENSET.reg = TCC_INTENSET_OVF; // Only interrupt on overflow - NVIC_SetPriority((IRQn_Type)TCC0_IRQn, 0); // Make this highest priority + int USBprio = NVIC_GetPriority((IRQn_Type) USB_IRQn); // Fetch the USB priority + NVIC_SetPriority((IRQn_Type)TCC0_IRQn, USBprio); // Match the USB priority +// NVIC_SetPriority((IRQn_Type)TCC0_IRQn, 0); // Make this highest priority NVIC_EnableIRQ((IRQn_Type)TCC0_IRQn); // Enable the interrupt interrupts(); } diff --git a/I2CManager_SAMD.h b/I2CManager_SAMD.h index 4dd2790..cd57507 100644 --- a/I2CManager_SAMD.h +++ b/I2CManager_SAMD.h @@ -113,7 +113,8 @@ void I2CManagerClass::I2C_init() #if defined(I2C_USE_INTERRUPTS) // Setting NVIC NVIC_EnableIRQ(SERCOM3_IRQn); - NVIC_SetPriority (SERCOM3_IRQn, 0); /* set Priority */ + NVIC_SetPriority (SERCOM3_IRQn, SERCOM_NVIC_PRIORITY); // Match default SERCOM priorities +// NVIC_SetPriority (SERCOM3_IRQn, 0); // Set highest priority // Enable all interrupts s->I2CM.INTENSET.reg = SERCOM_I2CM_INTENSET_MB | SERCOM_I2CM_INTENSET_SB | SERCOM_I2CM_INTENSET_ERROR;