where to position an interrupt routine?

NikoTeen

Well-known member
My project is using the comparator within a T_3.2 or T_3.5 and CMP1 interrupts.
The functions for comparator configuration and handling are located in COMP1.h and COMP1.cpp.
COMP1.h is included in the sketch.

The function CMP1_init() is
Code:
void CMP1_Init(void) {
  NVIC_SET_PRIORITY(IRQ_CMP1, 130); // 0 = highest priority, 255 = lowest
  NVIC_ENABLE_IRQ(IRQ_CMP1); // handler is now cmp1_isr()
  // CMP1_IN0 (pin23), sicherheitshalber:
  CORE_PIN23_CONFIG = PORT_PCR_MUX(0); // set pin23 function to ALT0
}
The statement NVIC_ENABLE_IRQ(IRQ_CMP1); defines that cmp1_isr() will be called by every comparator interrupt.

My question now is: where is the best place to locate this interrupt routine?

Shall it be within COMP1.cpp or within the sketch?
Are there differences in functionality where it is located?

P.S.: if there is no definition of cmp1_isr() at all, not within COMP1.cpp and not within the sketch, then neither the compiler nor the linker is reporting an error or a warning!
But of course the programm crashes.
 
The statement NVIC_ENABLE_IRQ(IRQ_CMP1); defines that cmp1_isr() will be called by every comparator interrupt.

My question now is: where is the best place to locate this interrupt routine?

Shall it be within COMP1.cpp or within the sketch?
Are there differences in functionality where it is located?

P.S.: if there is no definition of cmp1_isr() at all, not within COMP1.cpp and not within the sketch, then neither the compiler nor the linker is reporting an error or a warning!
But of course the programm crashes.

The ISR can be anywhere in your program. There is no error when you don't define cmp1_isr() in your own program because it is defined (weak) in the Teensy3 core file mk20dx128.c. When you define your own, you "override" the default weak version. The default function does nothing, so if you enable the interrupt without providing your own ISR, the interrupts won't be cleared, and your program will hang or crash.
 
Back
Top