ARM Technical Support Knowledge Articles

USING THE _ATOMIC_ FUNCTION

Applies to: C166 C Compiler

Answer


Information in this article applies to:


QUESTION

How can I use the _atomic_ function in my programs to create atomic sections?

ANSWER

The _atomic_ and _endatomic_ library routines specify the start and end of an atomic code section. This section of code must be 4 instructions or less. Use atomic sections to protect program code from hardware interrupts. Instructions in an atomic section are executed as an atom and cannot be interrupted.

For example:

#include <intrins.h>

bit testbit;

void function (int flag)
{
_atomic_ (0);
if (flag == 1)
  testbit = 1;
_endatomic_ ();
}

Generates the following code:

0000 D120          ATOMIC    #03H
0002 4881          CMP       R8,#01H
0004 3D01          JMPR      cc_NZ,?C0001
0006 0F00     R    BSET      testbit
0008         ?C0001:
0008 CB00          RET

which uses the ATOMIC instruction to protect the specified code.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-15 13:22:08

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential