This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Interrupt service routines in separate assembly files

I am having trouble keeping an i2c ISR in a separate file in assembly and getting good isr response time.  The goal is to keep this file separate from the main file.  Anyone know a better way to do this?  I am using IAR.

This is what I have tried and did not work out for i2c...

<in main.s43 file>

EXTERN   rxifg_isr

EXTERN   txifg_isr

COMMON  INTVEC

                 org  0x005a           ;ucb1 interrupt vector

                 dw  ucb1_isr         ;ucb1 interrupt service routine

                 org   0x005c          ;some other vector

                 dw    other_isr

RSEG  MCODE

 

ucb1_isr:  add.w   &ucb1iv,pc              ; Add offset to PC

                 reti                            ; Vector 0: No interrupt 

                 reti                            ; Vector 2: ALIFG

                 reti                            ; Vector 4: NACKIFG

                 reti                            ; Vector 6: STTIFG        

                 reti                            ; Vector 8: STPIFG       

                 bra   #rxifg_isr          ; Vector 10: RXIFG

                 bra   #txifg_isr          ; Vector 12: TXIFG

 

<in i2c.s43 file>

RSEG  MCODE

PUBLIC rxifg_isr

rxifg_isr:  stuff bytes into buffer

                reti

PUBLIC txifg_isr

txifg_isr:  transmit bytes

                reti

-----------------------------------------------------------------------------------------------

I have also tried below but didn't work...

<in main.s43 file>

COMMON  INTVEC

                 ;org  0x005a           ;ucb1 interrupt vector *COMMENTED to use isr in another file

                 ;dw  ucb1_isr         ;ucb1 interrupt service routine *COMMENTED to use isr in another file

                 org   0x005c          ;some other vector

                 dw    other_isr

 

<in i2c.s43 file>

COMMON  INTVEC

                 org  0x005a           ;ucb1 interrupt vector

                 dw  ucb1_isr         ;ucb1 interrupt service routine

RSEG   MCODE

ucb1_isr:  add.w   &ucb1iv,pc    ; Add offset to PC

                 reti                            ; Vector 0: No interrupt

                 reti                            ; Vector 2: ALIFG

                 reti                            ; Vector 4: NACKIFG

                 reti                            ; Vector 6: STTIFG        

                 reti                            ; Vector 8: STPIFG       

                 jmp   #rxifg_isr          ; Vector 10: RXIFG

                 jmp   #txifg_isr          ; Vector 12: TXIFG

 

rxifg_isr:  stuff bytes into buffer

                reti

txifg_isr:  transmit bytes

                reti

  • Simon Yuen1 said:
    I am having trouble keeping an i2c ISR in a separate file in assembly and getting good isr response time. 

    Then you're doing something wrong. It is totally unimportant in which source file the ISRs are. The linekr will put them, togehter into the same flash of the same MSP and the response times are the same.

    If you have an ISR:X in one file, then all you need is to also add this ISR to the proper vector.

    However, you cannot branch to code oin a different source file from within an IV-jumptable:

    Simon Yuen1 said:

    ucb1_isr:  add.w   &ucb1iv,pc              ; Add offset to PC
                     reti                            ; Vector 0: No interrupt
                     [...]
                     bra   #rxifg_isr          ; Vector 10: RXIFG
                     bra   #txifg_isr          ; Vector 12: TXIFG

    bra is a 32 bit instruciton (instruction word and destination workd). But the jumptable mechanism has only 2 bytes per vector. Your 'Vector 12' is 14 bytes behind the add instruciotn, not 12. So in case of a TX interrupt, you're jumping on the second half of the RXIFG branch instruction. Which will cause any kind of unexpected behaviour, but most likely not to a jump to the TX ISR.

    The second verson should work, assuming that there are no more than +.1024 bytes between the jmp and the destination of the jump. Which means, if your rxifg_isr is >1k, the secodn jump would be unable to readch the txifg_isr.

    However i'm not sure whether the assembler allows splitting the entries into the vector table across multiple segemnts. If not, you should declare ucb1_isr as extern in main and add all ISRs to the INTVEC segment inside main.

**Attention** This is a public forum