Add support for ATOMIC_BLOCK
My code uses avr-gcc util\atomic.h. For code block should be executed with disabled irqs and restore irqs state(disable, enable) after code block ends. Example:
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
// some long time executed code irqs free
}
Can you add correct support of this to core? In my code I use this workaround(not tested):
#ifdef __ARM__
#ifndef ATOMIC_BLOCK
#define ATOMIC_BLOCK(type) for ( type, __ToDo = __iCliRetVal(); \
__ToDo ; __ToDo = 0 )
#define ATOMIC_RESTORESTATE uint8_t __primask_save \
__attribute__((__cleanup__(__iRestore))) = __get_PRIMASK()
static __inline__ uint8_t __iCliRetVal(void)
{
__disable_irq();
return 1;
}
static __inline__ void __iRestore(const uint8_t *__s)
{
__set_PRIMASK(*__s);
__asm__ volatile ("" ::: "memory");
}
#endif
#endif
This definition should correct work for code like this:
void someFunc()
{
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
// some long time executed code irqs free
} // irqs state not changed
}
void someFunc2()
{
// irq disabled
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
someFunc();
// some long time executed code irqs free
} // irq enabled
}
Hi @V10git Feel free to provides a PR.
Hi @V10git Feel free to provides a PR.
I have 0 experience with stm32, so I don’t know how it should work on it correctly. Provided code example just cutoff from my project. I not test or compile it for now.
Take a look at SimplyAtomic or the Teensy implementation