diff options
author | Dawid Niedzwiecki <dn@semihalf.com> | 2020-09-24 12:09:18 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-08 06:02:22 +0000 |
commit | a54cd39627e62e60af73e2d3ef51504f43d1fb0e (patch) | |
tree | 0e1aa8903f8d2e5f6f59770aaa9b4984f7c5bf52 /core | |
parent | 853e6337629e3ef27e430075b7f3276f3832fa03 (diff) | |
download | chrome-ec-a54cd39627e62e60af73e2d3ef51504f43d1fb0e.tar.gz |
core/cortex-m: add Zephyr compatible atomic functions
Add atomic functions with prototypes equal to the ones in Zephyr.
It is done as a part of porting to Zephyr, the next step is to use in
the code atomic_* instead of deprecated_atomic_*.
Some atomic functions in Zephyr return a value e.g. atomic_add - it
returns the value of the variable before the add operation.
The current state of ATOMIC_OP macro is not designed to return such value
so instead of reworking it or writing new custom asm code just use
builtin functions.
BUG=b:169151160
BRANCH=none
TEST=buildall
Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
Change-Id: Iccd7a4d674601271f11f88834c8b2db08c537534
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2428945
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/cortex-m/atomic.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/cortex-m/atomic.h b/core/cortex-m/atomic.h index 736d5887b4..1f432e8d1e 100644 --- a/core/cortex-m/atomic.h +++ b/core/cortex-m/atomic.h @@ -10,6 +10,9 @@ #include "common.h" +typedef int atomic_t; +typedef atomic_t atomic_val_t; + /** * Implements atomic arithmetic operations on 32-bit integers. * @@ -42,23 +45,43 @@ static inline void deprecated_atomic_clear_bits(uint32_t volatile *addr, ATOMIC_OP(bic, addr, bits); } +static inline void atomic_clear_bits(atomic_t *addr, atomic_val_t bits) +{ + __atomic_fetch_and(addr, ~bits, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_or(uint32_t volatile *addr, uint32_t bits) { ATOMIC_OP(orr, addr, bits); } +static inline atomic_val_t atomic_or(atomic_t *addr, atomic_val_t bits) +{ + return __atomic_fetch_or(addr, bits, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_add(uint32_t volatile *addr, uint32_t value) { ATOMIC_OP(add, addr, value); } +static inline atomic_val_t atomic_add(atomic_t *addr, atomic_val_t value) +{ + return __atomic_fetch_add(addr, value, __ATOMIC_SEQ_CST); +} + static inline void deprecated_atomic_sub(uint32_t volatile *addr, uint32_t value) { ATOMIC_OP(sub, addr, value); } +static inline atomic_val_t atomic_sub(atomic_t *addr, atomic_val_t value) +{ + return __atomic_fetch_sub(addr, value, __ATOMIC_SEQ_CST); +} + static inline uint32_t deprecated_atomic_read_clear(uint32_t volatile *addr) { uint32_t ret, tmp; @@ -73,4 +96,10 @@ static inline uint32_t deprecated_atomic_read_clear(uint32_t volatile *addr) return ret; } + +static inline atomic_val_t atomic_read_clear(atomic_t *addr) +{ + return __atomic_exchange_n(addr, 0, __ATOMIC_SEQ_CST); +} + #endif /* __CROS_EC_ATOMIC_H */ |