Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » MSPGCC
  • » [Mspgcc-users] Is there an alternative to __BIC_SR_ISR(.)? [RSS Feed]

#1 Dec. 31, 2010 16:28:20

Alex S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] Is there an alternative to __BIC_SR_ISR(.)?


Hi everybody!

I noticed that when I use __BIC_SR_ISR in an interrupt handler right
after calling a function and immediately before returning from the
interrupt handler, the optimizer delays popping the function's
arguments off the stack. In this case __BIC_SR_ISR is useless since it
simply changes a value on the stack at a fixed offset, which is now in
the wrong place.

So the code below

...

if ( condition ) {

func(a, b, c);
__BIC_SR_ISR(LPM4_bits);

return;

}

might not wake the chip (depending on your optimization settings).

Is there a different, preferred way of handling this, other than
saving the address of future SR as in:

interrupt blah_blah() {

uint16_t *sr;
sr = ( uint16_t *)GET_FRAME_ADDR_F( __FUNCTION__ );

...

if ( condition ) {

func(a, b, c);
*sr &= ~LPM4_bits;

return;

}

I do need to wake up the chip conditionally and I do have to call an
outside function (I know, these things are frowned upon in interrupt
handlers but I have no choice).

Thanks.

Alex


Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/mspgcc-users

Offline

#2 Dec. 31, 2010 17:29:56

Peter B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] Is there an alternative to __BIC_SR_ISR(.)?


Which version of mspgcc, what optimizer flags? I can't find a
definition for __BIC_SR_ISR anywhere.

I generally use __bic_SR_register_on_exit, which does the same thing
as _BIC_SR_IRQ. I haven't noticed any problems, but may not be
invoking external functions in a way that confuses the optimizer.

Peter

On Fri, Dec 31, 2010 at 10:26 AM, Alex Shibakov <alex***@*mail.com> wrote:
> Hi everybody!
>
> I noticed that when I use __BIC_SR_ISR in an interrupt handler right
> after calling a function and immediately before returning from the
> interrupt handler, the optimizer delays popping the function's
> arguments off the stack. In this case __BIC_SR_ISR is useless since it
> simply changes a value on the stack at a fixed offset, which is now in
> the wrong place.
>
> So the code below
>
> ...
>
> if ( condition ) {
>
>  func(a, b, c);
>  __BIC_SR_ISR(LPM4_bits);
>
>  return;
>
> }
>
> might not wake the chip (depending on your optimization settings).
>
> Is there a different, preferred way of handling this, other than
> saving the address of future SR as in:
>
> interrupt blah_blah() {
>
>  uint16_t *sr;
>  sr = ( uint16_t *)GET_FRAME_ADDR_F( __FUNCTION__ );
>
>  ...
>
> if ( condition ) {
>
>  func(a, b, c);
>  *sr &= ~LPM4_bits;
>
>  return;
>
> }
>
> I do need to wake up the chip conditionally and I do have to call an
> outside function (I know, these things are frowned upon in interrupt
> handlers but I have no choice).
>
> Thanks.
>
> Alex
>
>
> Mspgcc-users mailing list
> Mspgcc-us***@*ists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/mspgcc-users>


Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/mspgcc-users

Offline

#3 Jan. 4, 2011 13:50:22

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] Is there an alternative to __BIC_SR_ISR(.)?


Yes, it's a known behavior, that the optimization delays popping function
arguments from stack. This way, there is only one single SP correction
at the end of a function instead of several.
I noticed it when having several SPRINTF calls on the 1232, which has
only 256 bytes ram - I got immediate stack overflows.
besides the increased stack usage, it will break compiler intrinsics
like the __BICs as it is outside C language and therefore not considered
when doing the optimizations

The solution is to cover the function call in a code block.

do { function(); } while(0);

This way, the stack is corrected at the end of the code block.
And no additoinal code is generated by the 'loop'.

JMGross

----- Ursprüngliche Nachricht -----
Von: Alex Shibakov
Gesendet am: 31 Dez 2010 17:26:57

Hi everybody!

I noticed that when I use __BIC_SR_ISR in an interrupt handler right
after calling a function and immediately before returning from the
interrupt handler, the optimizer delays popping the function's
arguments off the stack. In this case __BIC_SR_ISR is useless since it
simply changes a value on the stack at a fixed offset, which is now in
the wrong place.



Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/mspgcc-users

Offline

  • Root
  • » MSPGCC
  • » [Mspgcc-users] Is there an alternative to __BIC_SR_ISR(.)? [RSS Feed]

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support