What is the difference between FIQ and IRQ interrupt system?

后端 未结 11 1179
北海茫月
北海茫月 2020-11-28 01:48

I want to know the difference between FIQ and IRQ interrupt system in any microprocessor, e.g: ARM926EJ.

11条回答
  •  悲&欢浪女
    2020-11-28 02:25

    FIQ or fast interrupt is often referred to as Soft DMA in some ARM references.
    Features of the FIQ are,

    1. Separate mode with banked register including stack, link register and R8-R12.
    2. Separate FIQ enable/disable bit.
    3. Tail of vector table (which is always in cache and mapped by MMU).

    The last feature also gives a slight advantage over an IRQ which must branch.

    A speed demo in 'C'

    Some have quoted the difficulty of coding in assembler to handle the FIQ. gcc has annotations to code a FIQ handler. Here is an example,

    void  __attribute__ ((interrupt ("FIQ"))) fiq_handler(void)
    {
        /* registers set previously by FIQ setup. */
        register volatile char *src asm ("r8");  /* A source buffer to transfer. */
        register char *uart asm ("r9");          /* pointer to uart tx register. */
        register int size asm ("r10");           /* Size of buffer remaining. */
        if(size--) {
            *uart = *src++;
        }
    }
    

    This translates to the following almost good assembler,

    00000000 :
       0:   e35a0000        cmp     sl, #0
       4:   e52d3004        push    {r3}            ; use r11, r12, etc as scratch.
       8:   15d83000        ldrbne  r3, [r8]
       c:   15c93000        strbne  r3, [r9]
      10:   e49d3004        pop     {r3}            ; same thing.
      14:   e25ef004        subs    pc, lr, #4
    

    The assembler routine at 0x1c might look like,

       tst     r10, #0    ; counter zero?
       ldrbne  r11, [r8]  ; get character.
       subne   r10, #1    ; decrement count
       strbne  r11, [r9]  ; write to uart
       subs    pc, lr, #4 ; return from FIQ.
    

    A real UART probably has a ready bit, but the code to make a high speed soft DMA with the FIQ would only be 10-20 instructions. The main code needs to poll the FIQ r10 to determine when the buffer is finished. Main (non-interrupt code) may transfer and setup the banked FIQ registers by using the msr instruction to switch to FIQ mode and transfer non-banked R0-R7 to the banked R8-R13 registers.

    Typically RTOS interrupt latency will be 500-1000 instructions. For Linux, it maybe 2000-10000 instructions. Real DMA is always preferable, however, for high frequency simple interrupts (like a buffer transfer), the FIQ can provide a solution.

    As the FIQ is about speed, you shouldn't consider it if you aren't secure in coding in assembler (or willing to dedicate the time). Assembler written by an infinitely running programmer will be faster than a compiler. Having GCC assist can help a novice.

    Latency

    As the FIQ has a separate mask bit it is almost ubiquitously enabled. On earlier ARM CPUs (such as the ARM926EJ), some atomic operations had to be implemented by masking interrupts. Still even with the most advanced Cortex CPUs, there are occasions where an OS will mask interrupts. Often the service time is not critical for an interrupt, but the time between signalling and servicing. Here, the FIQ also has an advantage.

    Weakness

    The FIQ is not scalable. In order to use multiple FIQ sources, the banked registers must be shared among interrupt routines. Also, code must be added to determine what caused the interrupt/FIQ. The FIQ is generally a one trick pony.

    If your interrupt is highly complex (network driver, USB, etc), then the FIQ probably makes little sense. This is basically the same statement as multiplexing the interrupts. The banked registers give 6 free variables to use which never load from memory. Register are faster than memory. Registers are faster than L2-cache. Registers are faster than L1-cache. Registers are fast. If you can not write a routine that runs with 6 variables, then the FIQ is not suitable. Note: You can double duty some register with shifts and rotates which are free on the ARM, if you use 16 bit values.

    Obviously the FIQ is more complex. OS developers want to support multiple interrupt sources. Customer requirements for a FIQ will vary and often they realize they should just let the customer roll their own. Usually support for a FIQ is limited as any support is likely to detract from the main benefit, SPEED.

    Summary

    Don't bash my friend the FIQ. It is a system programers one trick against stupid hardware. It is not for everyone, but it has its place. When all other attempts to reduce latency and increase ISR service frequency has failed, the FIQ can be your only choice (or a better hardware team).

    It also possible to use as a panic interrupt in some safety critical applications.

提交回复
热议问题