Skip to content

Add support for ATOMIC_BLOCK #2838

@V10git

Description

@V10git

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions