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.

How to write assembly Interrupt handler code ?

Hello everyone, for programming in C  for TMS570 HDK boards, I know that when interrupts occur, the program will run the instructions in C interrupt functions( for example: rtiNotification(), gioNotification()..v.v). However, for my purpose, I want to write a interrupt handler by assembly code, so what should I do? Do I need to change some thing in file "sys_intvecs.asm"? and which files should I change their values?. Thank you

  • Dzung,

    If you want to use your own ISR, you will need to modify sys_vim.c file and put the address of your function into the right place in the VIMRAM table.

    I do not recommend you to write ISR in assembly because it involve too many low level details. You can create an ISR in C as follows.

    #pragma INTERRUPT (GIO_ISR,IRQ)
    #pragma CODE_STATE (GIO_ISR,32)
    void GIO_ISR()
    {
    register GIO_ST *GIO_ptr = (GIO_ST *)GIO1;
    register volatile unsigned char gio_temp;
    gio_temp = GIO_ptr->OffB_UB; /* read the GIO int offset*/
    if(!gio_temp)
    while(1);
    GIO_TestCount++;
    GIO_TestFlag = 1;
    }

    If you really want to do it in assembly, you can take a look at the following example. In this example, I save all the registers because I do not know how many will be used in GIO_Proc() function.

    .global _GIO_ISR_Proc
    .global _GIO_ISR

    .align 4

    _GIO_ISR:
    push {R0-R12,LR}
    sub SP,SP,#4
    BL _GIO_Proc
    add SP,SP,#4
    pop {R0-R12,LR}
    SUBS PC,LR,#4

    Thanks and regards,

    Zhaohong
  • Hi Zhaohong,, thanks for your reply. So I only need to modify sys_vim.c file when write code in assembly, am I right?. Do I need to modify sys_invects file? Since I see that in sys_invects file, it includes interrupt vector table?
  • Dzung,

    If the hardware vector mode is enabled, CPU will not jump to the default interrupt table defined in sys_invects.c file. The VIM module will fetch the IRQ ISR address from VIMRAM table and CPU will directly branch to that address.

    Thanks and regards,

    Zhaohong