Atomic operation support.
More...
Atomic operation support.
◆ __CM_SAVER
#define __CM_SAVER |
( |
|
state | ) |
|
Value: __val = (state), \
static uint32_t __cm_atomic_set(uint32_t *val)
Definition at line 171 of file cortex.h.
◆ CM_ATOMIC_BLOCK
#define CM_ATOMIC_BLOCK |
( |
| ) |
for (uint32_t __CM_SAVER(true), __my = true; __my; __my = false) |
Cortex M Atomic Declare block.
This macro disables interrupts for the next command or block of code. The interrupt mask is automatically restored after exit of the boundary of the code block. Therefore restore of interrupt is done automatically after call of return or goto control sentence jumping outside of the block.
- Warning
- The usage of sentences break or continue is prohibited in the block due to implementation of this macro!
- Note
- It is safe to use this block inside normal code and in interrupt routine.
Basic usage of atomic block
uint64_t value;
...
CM_ATOMIC_BLOCK() {
value = value * 1024 + 651;
}
Use of return inside block
uint64_t value;
...
uint64_t allocval(void)
{
value = value * 1024 + 651;
return value;
}
}
#define CM_ATOMIC_BLOCK()
Cortex M Atomic Declare block.
Definition at line 224 of file cortex.h.
◆ CM_ATOMIC_CONTEXT
#define CM_ATOMIC_CONTEXT |
( |
| ) |
uint32_t __CM_SAVER(true) |
Cortex M Atomic Declare context.
This macro disables interrupts in the current block of code from the place where it is defined to the end of the block. The interrupt mask is automatically restored after exit of the boundary of the code block. Therefore restore of interrupt is done automatically after call of return, continue, break, or goto control sentence jumping outside of the block.
- Note
- This function is intended for use in for- cycles to enable the use of break and contine sentences inside the block, and for securing the atomic reader-like functions.
-
It is safe to use this block inside normal code and in interrupt routine.
Basic usage of atomic context
uint64_t value;
...
for (int i=0;i < 100; i++) {
value += 100;
if ((value % 16) == 0) {
break;
}
}
#define CM_ATOMIC_CONTEXT()
Cortex M Atomic Declare context.
Usage of atomic context inside atomic reader fcn.
uint64_t value;
...
uint64_t getnextval(void)
{
value = value + 3;
return value;
}
Definition at line 278 of file cortex.h.
◆ __cm_atomic_set()
static uint32_t __cm_atomic_set |
( |
uint32_t * |
val | ) |
|
|
inlinestatic |