How to create ISR routines?

Status
Not open for further replies.

Franky_74

Member
In the past ( Arduino 1.0.5.r2) i used modified ISR routines for serial reception.
This routines are realised by modify existing code in serial1.c in my case.

It can be done by this way - but it is really unflexible because everytime the hardwaredriver changed this files must be modified again.

My question is how is possible to extend /replace existing ISR routines by writing the code in the sketch file or additional driver c-files?

Any advice would be really nice.

Thank you,
Frank Muenzner
 
In the past ( Arduino 1.0.5.r2) i used modified ISR routines for serial reception.
This routines are realised by modify existing code in serial1.c in my case.

It can be done by this way - but it is really unflexible because everytime the hardwaredriver changed this files must be modified again.

My question is how is possible to extend /replace existing ISR routines by writing the code in the sketch file or additional driver c-files?

Any advice would be really nice.

Thank you,
Frank Muenzner

For attaching interrupts (here my own DMA as example) I use
Code:
void DMA_attachInterrupt(DMA_STRUCT *dma, void (*isr)(void)) 
{
	_VectorsRam[IRQ_DMA_CH0 + 16 + dma->channel % 16] = isr;	// on T3.6 are only 16 interrupt slots
	NVIC_ENABLE_IRQ(IRQ_DMA_CH0 + dma->channel % 16);
}

void DMA_detachInterrupt(DMA_STRUCT *dma) 
{
	NVIC_DISABLE_IRQ(IRQ_DMA_CH0 + dma->channel % 16);
}

You simply replace the _VectorsRam array entry with a pointer to your own ISR
This should work also with uart or any other interrupt.
 
My question is how is possible to extend /replace existing ISR routines by writing the code in the sketch file or additional driver c-files?

You can use attachInterruptVector(), or just write into the RAM-based interrupt table.

Because the table is in RAM, it's easy to override and take control of any interrupt. Use this power wisely...
 
There is a function attachInterruptVector(IRQ, function)

That allows you to setup your own functions for specific interrupt, without having to know about the internals of _VectorsRam...
 
I found some code for serial isr modification.... i found it's really elegant - because it extend an existing isr - therefore this solution should be backward compatible...
I did'nt know that a way like this exist...
The attachInterrupt is known to me - but i used only for systick or eventbased.



The code i have found in TeensyDMX.cpp it's from Paul

But this is not the attachInterrupt Method- how did it work - special how did it works with the backreference?




void uart2_status_isr(); // Back reference to serial3.c
void UART2TxStatus()
{
if ((UART2_C2 & UART_C2_TCIE) && (UART2_S1 & UART_S1_TC)) {
// TX complete
uartInstances[2]->nextTx();
}
// Call standard ISR too
uart2_status_isr();
}

Many thanks for your help to expand my understanding...
 
If you are talking about: https://github.com/chrisstaite/TeensyDmx/blob/master/TeensyDmx.cpp
If you look down at about line 326 you will see things like: attachInterruptVector(IRQ_UART0_STATUS, UART0TxStatus);
Which is where it hooks the ISR.

It also knew the names of the default ISRs for these interrupts.
You can find the names in the kinetis.h file and these names are used in the default interrupt vector, which you can find in mk20dx128.c
 
Status
Not open for further replies.
Back
Top