From 3d474ef0e0d43f2911acb499b157d32539054f15 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Mon, 11 Mar 2013 18:16:02 +0100 Subject: [PATCH] Fix of sync lock emulation for cortex-m0 --- include/core/lpc_core_cm0.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/core/lpc_core_cm0.h b/include/core/lpc_core_cm0.h index 0b4ea41..623f333 100644 --- a/include/core/lpc_core_cm0.h +++ b/include/core/lpc_core_cm0.h @@ -341,17 +341,19 @@ static inline void NVIC_SystemReset(void) /*******************************************************************************/ /* Sync lock */ /*******************************************************************************/ -/* There is no syncro instructions on Cortex-M0 */ +/* There is no syncro instructions on Cortex-M0 + * Returns the old value if the new value has been set (lock acquired) + */ static inline uint32_t sync_lock_test_and_set(volatile uint32_t *addr, uint32_t value) { + uint32_t oldval; lpc_disable_irq(); dsb(); - if (*addr == value) - return 0; + oldval = *addr; *addr = value; dsb(); lpc_enable_irq(); - return value; + return oldval; } /* Remove the lock */ static inline void sync_lock_release(volatile uint32_t *addr) -- 2.43.0