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

How to determine where function was called from

From my code I need to figure out has my function been called from the ISR or just regular application code. I do know that application is running is the User Thread mode and ISR is in privileged handler mode. Could you anyone please provide me with the sources of C-function(s) or inline assembly which will let me efficiently solve this issue.

Thanks.

Parents
  • Something like this:

    int32u __asm processor_in_user_mode(void)
    {
            STMDB   R13!, {R1}
    
            MRS     R0, CPSR
            AND     R0, R0, #0x1F   // the lowest 5 bits of CPSR respresent the processor mode
            MOV             R1, #0x10               // user mode = 0x10
            CMP             R0, R1
            BEQ             not_interrupt_context
    
            LDMIA   R13!, {R1} // restore the file name and the line number.
    
            MOV             R0,     #0x0 // indicate called while not in user mode
    
            BX              LR
    
    not_interrupt_context
    
            // restore original values of R1
            LDMIA   R13!, {R1}
    
            MOV             R0,     #0x1 // indicate called while in user mode
    
            BX              LR
    }
    

Reply
  • Something like this:

    int32u __asm processor_in_user_mode(void)
    {
            STMDB   R13!, {R1}
    
            MRS     R0, CPSR
            AND     R0, R0, #0x1F   // the lowest 5 bits of CPSR respresent the processor mode
            MOV             R1, #0x10               // user mode = 0x10
            CMP             R0, R1
            BEQ             not_interrupt_context
    
            LDMIA   R13!, {R1} // restore the file name and the line number.
    
            MOV             R0,     #0x0 // indicate called while not in user mode
    
            BX              LR
    
    not_interrupt_context
    
            // restore original values of R1
            LDMIA   R13!, {R1}
    
            MOV             R0,     #0x1 // indicate called while in user mode
    
            BX              LR
    }
    

Children