Function attribute to inhibe interrupts

Asked by Cyrille

Hi all,
I'm using the arm-none-eabi GNU toolchain for developpment on a STM32 Cortes M3.
I was looking for a function attribute to make sure a function can't be interrupted. I know an some target there is a function attribute __attribute__((disinterrupt)) but this seems to be ignored on the toolchain (message while compiling).

Is there another attribute that can be used ?
Is there a pdf or website where I can see all possible attributes for my toolchain and my cpu ?

Thanks all.
Regards.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Cyrille
Solved:
Last query:
Last reply:
Revision history for this message
Terry Guo (terry.guo) said :
#1

Your requirement sounds reasonable to me but unfortunately this attribute isn't enabled for ARM targets yet. Let me discuss this feature internally first.

To get all available function attributes, please find gcc.pdf in tool chain or go to gcc official website http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Function-Attributes.html#Function-Attributes. There is no new attributes that haven't been upstreamed in this tool chain.

Revision history for this message
Terry Guo (terry.guo) said :
#2

Hi Cyrille,

I am evaluating your requirement. Could you please share experiences or opinions on following questions?

1) In which scenario the function will need this attribute? Is this requirement popular in embedded development world?

2) Have you tried out the __disable_irq() and __enable_irq() functions from CMSIS? Do they meet your requirement? The CMSIS can be found at http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-software-interface-standard.php.

Thanks.

BR,
Terry

Revision history for this message
Cyrille (cbertrand) said :
#3

Hi Terry,

Thanks for your concern on my request.
It's an easier way to disable and enable interrupt for a complete
function (like monitor functions in RTOS). Thanks to this attribute,
interrupts are disabled before local variables declaration.
This attribute is present in IAR tool chain for example and can be
sometime useful to manage critical code sections.

For the moment, I use the __disable_irq() and __enable_irq() before and
after calling these specific functions.

Thanks to keep me informed on the result of your evaluation.

Regards.
Cyrille

Le 31/03/2014 16:31, Terry Guo a écrit :
> Your question #246175 on GCC ARM Embedded changed:
> https://answers.launchpad.net/gcc-arm-embedded/+question/246175
>
> Terry Guo requested more information:
> Hi Cyrille,
>
> I am evaluating your requirement. Could you please share experiences or
> opinions on following questions?
>
> 1) In which scenario the function will need this attribute? Is this
> requirement popular in embedded development world?
>
> 2) Have you tried out the __disable_irq() and __enable_irq() functions
> from CMSIS? Do they meet your requirement? The CMSIS can be found at
> http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-
> software-interface-standard.php.
>
> Thanks.
>
> BR,
> Terry
>

--

Cordialement, Best regards

**

*EVELIA - Cyrille BERTRAND*

*7, rue Vieille Levée*

*45100 Orléans*

*France*

/Tél : +33.2.38.56.38.56/

/www.evelia.eu <http://www.evelia.eu/>/

/Before printing, th//ink about our Environment/

---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com

Revision history for this message
Terry Guo (terry.guo) said :
#4

Hi Cyrille,

I read the IAR toolchain user guide from ftp://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_DevelopmentGuide.ENU.pdf. And couldn't find that the disinterrupt attribute is supported by IAR tool chain. Compared to GNU tool chain, the most interesting thing is that IAR has intrinsic functions: __disable_interrupt and __enable_interrupt which equal normal functions: __disable_irq and __enable_irq from CMSIS. The IAR intrinsic functions: __disable_irq and __enable_irq are for other targets, not for the Cortex-M targets. So currently we have three approaches to deal with irq:

1) enable disinterrupt attribute to get a function level control.
2) implement disable_irq/enable_irq as intrinsic functions to gain a more fine level control, such as we can apply them to just a piece of code.
3) the last approach is to use CMSIS functions __disable_irq and __enable_irq. Compared to approach 1) and 2), this one can make your code independent of tool chain.

Meanwhile please be careful to use such functions. Below code may give you a surprise:

void foo()
{
   __disable_irq();
   .....
   bar();
  ......
  __enable_irq();
}

void bar()
{
   __disable_irq();
   .....
  __enable_irq();
}

After the call of function bar, the code in foo can be interrupted which violate the initial intention that no interrupt across function bar. Probably the best way is to define foo and bar as below

void foo()
{
  uint32 old_state = __get_PRIMASK();
  __disable_irq();
  .....
  __set_PRIMASK(old_state);
}

void bar()
{
  uint32 old_state = __get_PRIMASK();
  __disable_irq();
  .....
  __set_PRIMASK(old_state);
}

Revision history for this message
Terry Guo (terry.guo) said :
#5

A small typ0 in statement "After the call of function bar, the code in foo can be interrupted which violate the initial intention that no interrupt across function bar. ". I mean "across function foo".

Revision history for this message
Cyrille (cbertrand) said :
#6

Thanks Terry for your answer,

The IAR function attribute name is normally __monitor but exist on classic 8/16bits microcontroller (not in ARM).
Anyway, I'l use your proposal with the __get_PRIMASK and __set_PRIMASK functions.

Regards.
Cyrille