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