19#ifndef ATOMIC_UTILS_ARCH_H
20#define ATOMIC_UTILS_ARCH_H
24#include "periph_cpu.h"
33#define HAS_ATOMIC_LOAD_U8
36 return __atomic_load_1(var, __ATOMIC_SEQ_CST);
39#define HAS_ATOMIC_LOAD_U16
42 return __atomic_load_2(var, __ATOMIC_SEQ_CST);
45#define HAS_ATOMIC_LOAD_U32
48 return __atomic_load_4(var, __ATOMIC_SEQ_CST);
51#define HAS_ATOMIC_STORE_U8
54 __atomic_store_1(dest, val, __ATOMIC_SEQ_CST);
57#define HAS_ATOMIC_STORE_U16
60 __atomic_store_2(dest, val, __ATOMIC_SEQ_CST);
63#define HAS_ATOMIC_STORE_U32
66 __atomic_store_4(dest, val, __ATOMIC_SEQ_CST);
71#if CPU_HAS_SRAM_BITBAND
79static inline void __attribute__((always_inline)) _bit_barrier_pre(
void)
81 __asm__
volatile (
"" : : :
"memory");
84static inline void __attribute__((always_inline)) _bit_barrier_post(
void)
86 __asm__
volatile (
"" : : :
"memory");
89static inline bool _is_addr_valid_for_bitbanding(
volatile void *_addr)
93 uintptr_t addr = (uintptr_t)_addr;
94 if ((addr < 0x20000000UL) || (addr > 0x400fffffUL)) {
98 if ((addr >= 0x200fffffUL) && (addr < 0x40000000UL)) {
107 assert(_is_addr_valid_for_bitbanding(dest));
113 assert(_is_addr_valid_for_bitbanding(dest));
119 assert(_is_addr_valid_for_bitbanding(dest));
125 assert(_is_addr_valid_for_bitbanding(dest));
#define assert(cond)
abort the program if assertion is false
Bit access macros with bit-banding support for Cortex-M based CPUs.
static volatile void * bitband_addr(volatile void *ptr, uintptr_t bit)
Convert bit band region address and bit number to bit band alias address.
static atomic_bit_u32_t atomic_bit_u32(volatile uint32_t *dest, uint8_t bit)
Create a reference to a bit in an uint32_t
static void atomic_store_u8(volatile uint8_t *dest, uint8_t val)
Store an uint8_t atomically.
static void atomic_set_bit_u8(atomic_bit_u8_t bit)
Atomic version of *dest |= (1 << bit)
static atomic_bit_u64_t atomic_bit_u64(volatile uint64_t *dest, uint8_t bit)
Create a reference to a bit in an uint64_t
static void atomic_clear_bit_u32(atomic_bit_u32_t bit)
Atomic version of *dest &= ~(1 << bit)
static uint32_t atomic_load_u32(const volatile uint32_t *var)
Load an uint32_t atomically.
static uint16_t atomic_load_u16(const volatile uint16_t *var)
Load an uint16_t atomically.
static void atomic_set_bit_u64(atomic_bit_u64_t bit)
Atomic version of *dest |= (1 << bit)
static void atomic_clear_bit_u8(atomic_bit_u8_t bit)
Atomic version of *dest &= ~(1 << bit)
static uint8_t atomic_load_u8(const volatile uint8_t *var)
Load an uint8_t atomically.
static atomic_bit_u8_t atomic_bit_u8(volatile uint8_t *dest, uint8_t bit)
Create a reference to a bit in an uint8_t
static void atomic_clear_bit_u16(atomic_bit_u16_t bit)
Atomic version of *dest &= ~(1 << bit)
static void atomic_store_u16(volatile uint16_t *dest, uint16_t val)
Store an uint16_t atomically.
static void atomic_store_u32(volatile uint32_t *dest, uint32_t val)
Store an uint32_t atomically.
static atomic_bit_u16_t atomic_bit_u16(volatile uint16_t *dest, uint8_t bit)
Create a reference to a bit in an uint16_t
static void atomic_set_bit_u32(atomic_bit_u32_t bit)
Atomic version of *dest |= (1 << bit)
static void atomic_clear_bit_u64(atomic_bit_u64_t bit)
Atomic version of *dest &= ~(1 << bit)
static void atomic_set_bit_u16(atomic_bit_u16_t bit)
Atomic version of *dest |= (1 << bit)
Type specifying a bit in an uint16_t
Type specifying a bit in an uint32_t
Type specifying a bit in an uint64_t
Type specifying a bit in an uint8_t