We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
What are you doing? Check the CPSR register to determine the processor's mode !
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 }
I think
STMDB R13!, {R1}
and
LDMIA R13!, {R1}
above are redundant.
Are you sure that I can run this in user non-privileged mode? I need to check it because it doesn't match my understanding.
Sounds like you plan to do this on a Cortex-M3. I don't know - this code works well on an ARM7 chip. You may need to implement this in a SVC.
Tapir,
Why do you say "I think"?
Are you still unsure of the rules for register preservation.
Let's give it a few more years.
SVC from the user space does trigger hard fault, so your plan doesn't work.
Eric, take my request as given please. Explaining it will spark more issues then bring answers.
It is possible to perform read/write operations directly to the MSP and PSP provided that you are in privileged level, you can access MSP and PSP using the MRS and MSR instructions: MRS R0, MSP ; Read Main Stack Pointer to R0 MSR MSP, R0 ; Write R0 to Main Stack Pointer MRS R0, PSP ; Read Process Stack Pointer to R0 MSR PSP, R0 ; Write R0 to Process Stack Pointer
And I'm not!!! Actually not always to be exact.