AnsweredAssumed Answered

How to realize atomic&spin_lock operation in s32R MCU's

Question asked by bin zhang on Apr 15, 2019
Latest reply on Apr 15, 2019 by Lukas Zadrapa

I user S32R274, it's a muti core MCUs and has hardware lock between cpus.


but , i think a mechanism  like spin_lock/spin_lock_irqsave  and atomic is needed in 

muti-core MCU. 

so I test like 


static __inline__ int atomic_add_return(int a, atomic_t *v)
int t;

__asm__ __volatile__(
"1: lwarx %0,0,%2 # atomic_add_return\n\
add %0,%1,%0\n"
" stwcx. %0,0,%2 \n\
se_bne 1b"
: "=&r" (t)
: "r" (a), "r" (&v->counter)
: "cc", "memory");

return t;


but it seems not a atomic operation in a concurrent scenario。


So,do anyone know how to do it and pls tell me .


thanks a lot