This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Setting up IRQ in ARM

Hi everyone

I am new to ARM and really wanted to learn about various aspects of ARM Programming .

I have basic understanding of x86 Assembly.

So,what Specifically I wanted to know is what happens when an external device triggers an interrupt .

Let me put my basic understanding on the same, which I learnt in last few days

Offset Handler
===============
00 Reset
04 Undefined Instruction
08 Supervisor Call (SVC)
0C Prefetch Abort
10 Data Abort
14 (Reserved)
18 Interrupt (IRQ)
1C Fast Interrupt (FIQ)

Whenever Interrupt comes instruction at address 18 is executed

So is it true that it is first instruction executed when interrupts comes??

Or as I read somewhere whenever interrupts comes first it moves from user mode to IRQ mode and cpsr is copied to spsr_IRQ but it happen without an instruction .

After that current instruction is replaced with a blx 0x18

How and where we do need to set the stack for different mode e.g for IRQ mode and Supervisior mode??

In the brancged code


IRQ_HANDLER:

SUB lr, lr, #4

STMFD !sp {r14}

bl IRQ_handler_to_specific_device ;it will branch to actuall hander code.

LDMFD r13!,{r14}
mov pc, r14


Is it all We need to do for setting up Basic IRQ handling ?


Also,how PIC/CPU comes to know that interrupt is coming from which device?


Thanks

Amit Singh Tomar.


"ARM is taking over the world"

Parents
  • Getting interrupts right on ARM can be a little fiddly - you have to get quite a lot of things right, and do them in the correct order. I would highly recommend the ARM System Developers Guide as it walks through a lot of the OS-like behaviors.

    http://books.google.co.uk/books/about/ARM_System_Developer_s_Guide.html?id=vdk4ZGRqMskC&redir_esc=y

    Also note that the Cortex-M series does things totally differently with a simpler interrupt model and much more of the low level interrupt handling done in hardware.

    To answer your questions ...

    So is it true that it is first instruction executed when interrupts comes??


    Yes.


    How and where we do need to set the stack for different mode e.g for IRQ mode and Supervisior mode??


    Stacks need to be setup when your OS boots, before the first interrupt happens.


    Is it all We need to do for setting up Basic IRQ handling ?

    No. Most of the ARM registers are shared with the context of the application which was running when the system was interrupted, so you need to stack off these registers before the main part of the interrupt handler runs, or you may corrupt state. You also have to restore them at the end before you return.

    You also need a special return instruction which will restore the SPSR into the CPSR - you can't just "mov pc, r14". This link may help, although it only gives the bare essentials:

    ARM Compiler toolchain Developing Software for ARM Processors: Return from an exception handler


    Also,how PIC/CPU comes to know that interrupt is coming from which device?

    Depends on implementation. Some devices provide a vector-based interrupt handler so the device can jump directly to the correct handler, others require the interrupt handler to query the interrupt controller to find out which line was activated.

    HTH,
    Pete

Reply
  • Getting interrupts right on ARM can be a little fiddly - you have to get quite a lot of things right, and do them in the correct order. I would highly recommend the ARM System Developers Guide as it walks through a lot of the OS-like behaviors.

    http://books.google.co.uk/books/about/ARM_System_Developer_s_Guide.html?id=vdk4ZGRqMskC&redir_esc=y

    Also note that the Cortex-M series does things totally differently with a simpler interrupt model and much more of the low level interrupt handling done in hardware.

    To answer your questions ...

    So is it true that it is first instruction executed when interrupts comes??


    Yes.


    How and where we do need to set the stack for different mode e.g for IRQ mode and Supervisior mode??


    Stacks need to be setup when your OS boots, before the first interrupt happens.


    Is it all We need to do for setting up Basic IRQ handling ?

    No. Most of the ARM registers are shared with the context of the application which was running when the system was interrupted, so you need to stack off these registers before the main part of the interrupt handler runs, or you may corrupt state. You also have to restore them at the end before you return.

    You also need a special return instruction which will restore the SPSR into the CPSR - you can't just "mov pc, r14". This link may help, although it only gives the bare essentials:

    ARM Compiler toolchain Developing Software for ARM Processors: Return from an exception handler


    Also,how PIC/CPU comes to know that interrupt is coming from which device?

    Depends on implementation. Some devices provide a vector-based interrupt handler so the device can jump directly to the correct handler, others require the interrupt handler to query the interrupt controller to find out which line was activated.

    HTH,
    Pete

Children
No data