
Originally Posted by
M.Melani
No , at 45 years old what student I can be !
It is only for the pleasure to understand Learning do not have age .
That is Young... Some of us are considerably older... Learning is great at any age! 
For me, learning here, is I learn by example... For example I mentioned try using attachInterruptVector.
If you then look through the code you will find:
Code:
void attachInterruptVector(enum IRQ_NUMBER_t irq, void (*function)(void))
{
_VectorsRam[irq + 16] = function;
}
So you see that this just stuffs your function into the array: _VectorsRam and it offsets it by 16 units...
As @defragster mentioned this table is defined in mk20dx128.c
Now if you look at the datasheet for the processor you are using, which you can download from pjrc website: https://www.pjrc.com/teensy/datasheets.html
Example Teensy 3.6, and look at interrupt channel assignments, in this case it is section 3.4, you will find there are 16 ARM core system handler vectors, followed by the Non-Core vectors...
It starts out with a bunch of DMA interrupts. You will then find that Pin Detect (PORT C) is IRQ=61 Vector 77...
However one more set of complications. When your program is built, the actual interrupt vector table you see in the mk... file is actually:
Code:
__attribute__ ((section(".vectors"), used))
void (* const _VectorsFlash[NVIC_NUM_INTERRUPTS+16])(void) =
{
And then as part of the system reset handler: void ResetHandler(void)
Which is called as part of the chip Reset code,
At about line 772, you will see a couple lines of code:
Code:
// default all interrupts to medium priority level
for (i=0; i < NVIC_NUM_INTERRUPTS + 16; i++) _VectorsRam[i] = _VectorsFlash[i];
for (i=0; i < NVIC_NUM_INTERRUPTS; i++) NVIC_SET_PRIORITY(i, 128);
SCB_VTOR = (uint32_t)_VectorsRam; // use vector table in RAM
This copies the interrupt vector out of flash memory into RAM, sets the priority of all of the interrupts to 128 (mid point), and then tells the system to use the interrupt vector which is now part of RAM.
So when you have setup to have an interrupt on PORTC on some pin and the pin changes, the system will call what ever is stored in _VectorsRam[77].
When depends on what the processor is doing at that time. That is if it is running normal user code or a lower priority (higher number) interrupt it will call immediately. If it is in a higher priority interrupt it will wait until that interrupt returns (and there are not any other higher priority interrupts pending).
And as I mentioned in previous post, if you do not clear the interrupt condition, it will continue to call your function again and again...
Hope that helps some.