I'm porting some existing (running) code from IAR to GnuArm (Yagarto). The existing project has some shared data that it protected by using enable/disable IRQs for mutual exclusion. Unfortunately, the functions that IAR used to enable/disable interrupts were intrinsic functions (get_cpsr/set_cpsr). When I try to convert these functions to explicit code, I have troubles switching to/from thumb mode. I'm still finding the discussions of this process very confusing!! In any case, we really should be using a true mutex method for this, rather than mucking with interrupts (since our project has numerous interrupt sources), but I haven't found any sources yet that describe a thumb mode mutex mechanism. Has anyone ever managed this?? Could you give some hints?? Or, better still, a working example?
Dan Miller wrote: > I'm porting some existing (running) code from IAR to GnuArm (Yagarto). > The existing project has some shared data that it protected by using > enable/disable IRQs for mutual exclusion. Unfortunately, the functions > that IAR used to enable/disable interrupts were intrinsic functions > (get_cpsr/set_cpsr). When I try to convert these functions to explicit > code, I have troubles switching to/from thumb mode. I'm still finding > the discussions of this process very confusing!! > > In any case, we really should be using a true mutex method for this, > rather than mucking with interrupts (since our project has numerous > interrupt sources), but I haven't found any sources yet that describe a > thumb mode mutex mechanism. > > Has anyone ever managed this?? Could you give some hints?? Or, better > still, a working example? other than using a rtos you probably do not have much choice about disabling ints - the rtos will probably do that as well. This is similar code from FreeRTOS for disabling ints. void vPortDisableInterruptsFromThumb( void ) _attribute_ ((naked)); void vPortEnableInterruptsFromThumb( void ) _attribute_ ((naked)); void vPortDisableInterruptsFromThumb( void ) _attribute_ ((naked)); void vPortEnableInterruptsFromThumb( void ) _attribute_ ((naked)); void vPortDisableInterruptsFromThumb( void ) { asm volatile ( "STMDB SP!, {R0} \n\t" /* Push R0. */ "MRS R0, CPSR \n\t" /* Get CPSR. */ "ORR R0, R0, #0xC0 \n\t" /* Disable IRQ, FIQ. */ "MSR CPSR, R0 \n\t" /* Write back modified value. */ "LDMIA SP!, {R0} \n\t" /* Pop R0. */ "BX R14" ); /*Return back to thumb. */ } void vPortEnableInterruptsFromThumb( void ) { asm volatile ( "STMDB SP!, {R0} \n\t" /* Push R0. */ "MRS R0, CPSR \n\t" /* Get CPSR. */ "BIC R0, R0, #0xC0 \n\t" /* Enable IRQ, FIQ. */ "MSR CPSR, R0 \n\t" /* Write back modified value. */ "LDMIA SP!, {R0} \n\t" /* Pop R0. */ "BX R14" ); /* Return back to thumb. */ } Cheers Spen
Spencer Oliver wrote: > Dan Miller wrote: >> I'm porting some existing (running) code from IAR to GnuArm (Yagarto). > > other than using a rtos you probably do not have much choice about > disabling ints - the rtos will probably do that as well. > Okay, let me try this out. Thanks!! BTW, we are using no RTOS here, just startup.s calling main.c
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.