Why FIQ interrupt is enabled if TX_ENABLE_FIQ_SUPPORT is not defined in __tx_thread_preempt_restore function?

Aniruddha Patel 36 Reputation points
2020-09-04T20:43:20.517+00:00

I am looking at the port files for Azure RTOS for Cortex R5-F processor. I was looking at the tx_thread_context_restore.S file and I have following question.

In the function __tx_thread_preempt_restore, processor mode is temporarily changed from IRQ mode to SVC mode to save the registers on the stack of a thread which is being switched out. While changing the mode to SVC mode it seems that FIQ interrupts are enabled if macro TX_ENABLE_FIQ_SUPPORT is not defined, which seems wrong to me. In this case shouldn't it just change the processor mode and not modify FIQ bit of CPSR registers?

Following is the snippet of a function __tx_thread_preempt_restore for your reference.

__tx_thread_preempt_restore:
@
    LDMIA   sp!, {r3, r10, r12, lr}         @ Recover temporarily saved registers
    MOV     r1, lr                          @ Save lr (point of interrupt)
    MOV     r2, #SVC_MODE                   @ Build SVC mode CPSR
    MSR     CPSR_c, r2                      @ Enter SVC mode
    STR     r1, [sp, #-4]!                  @ Save point of interrupt
    STMDB   sp!, {r4-r12, lr}               @ Save upper half of registers
    MOV     r4, r3                          @ Save SPSR in r4
    MOV     r2, #IRQ_MODE                   @ Build IRQ mode CPSR
    MSR     CPSR_c, r2                      @ Enter IRQ mode
    LDMIA   sp!, {r0-r3}                    @ Recover r0-r3
    MOV     r5, #SVC_MODE                   @ Build SVC mode CPSR
    MSR     CPSR_c, r5                      @ Enter SVC mode
    STMDB   sp!, {r0-r3}                    @ Save r0-r3 on thread's stack
    ...
    ...

SVC_MODE and IRQ_MODE are defined as follows in the same file.

#ifdef TX_ENABLE_FIQ_SUPPORT
SVC_MODE        =     0xD3               @ Disable IRQ/FIQ, SVC mode
IRQ_MODE        =     0xD2               @ Disable IRQ/FIQ, IRQ mode
#else
SVC_MODE        =     0xD3               @ Disable IRQ, SVC mode
IRQ_MODE        =     0xD2               @ Disable IRQ, IRQ mode
#endif

It would be great if someone can clarify on this.

Thanks.

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
341 questions
{count} vote

Accepted answer
  1. Scott Azure RTOS 4,051 Reputation points
    2020-09-11T04:00:09.69+00:00

    FIQ will remain enabled because no ThreadX APIs will be called in an FIQ (because TX_ENABLE_FIQ_SUPPORT is NOT defined). Remember: FIQs are still allowed to happen - ThreadX does not care what the user does in the FIQ (as long as the user does not call any ThreadX API).

    Though I agree with you - the F bit should not be touched. I'll get our team to fix this.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Scott Azure RTOS 4,051 Reputation points
    2020-09-09T17:35:58.873+00:00

    Hello,

    For ARM Compiler 6, I see the following in this file (https://github.com/azure-rtos/threadx/blob/master/ports/cortex_r5/ac6/src/tx_thread_context_restore.S):

    #ifdef TX_ENABLE_FIQ_SUPPORT
    SVC_MODE        =     0xD3               @ Disable IRQ/FIQ, SVC mode
    IRQ_MODE        =     0xD2               @ Disable IRQ/FIQ, IRQ mode
    #else
    SVC_MODE        =     0x93               @ Disable IRQ, SVC mode
    IRQ_MODE        =     0x92               @ Disable IRQ, IRQ mode
    #endif
    

    So FIQ should be disabled.
    What version are you looking at? What I linked to above is 6.0.1.

    Thanks,
    Scott

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.