Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: How to create ISR routines?

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    16

    How to create ISR routines?

    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

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,440
    Quote Originally Posted by Franky_74 View Post
    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.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,226
    Quote Originally Posted by Franky_74 View Post
    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...

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,348
    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...

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    16
    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...

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,348
    If you are talking about: https://github.com/chrisstaite/Teens.../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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •