EmbDev.net

Forum: ARM programming with GCC/GNU tools STR9 - how to mutex in thumb mode?


Author: Dan Miller (gorlash)
Posted on:

Rate this post
0 useful
not useful
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?

Author: Spencer Oliver (ntfreak)
Posted on:

Rate this post
0 useful
not useful
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

Author: Dan Miller (gorlash)
Posted on:

Rate this post
0 useful
not useful
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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.