From: Nathael Pajani Date: Mon, 11 Mar 2013 17:16:02 +0000 (+0100) Subject: Fix of sync lock emulation for cortex-m0 X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=3d474ef0e0d43f2911acb499b157d32539054f15;p=soft%2Flpc122x%2Fcore Fix of sync lock emulation for cortex-m0 --- 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)