mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
cortex-m3: Add atomic_cas implementation
This commit is contained in:
parent
46b9358e84
commit
b7db351400
@ -10,23 +10,37 @@
|
||||
* @ingroup cpu_cortexm3_common
|
||||
* @{
|
||||
*
|
||||
* @file atomic_arch.c
|
||||
* @file
|
||||
* @brief Implementation of the kernels atomic interface
|
||||
*
|
||||
* @author Stefan Pfeiffer <stefan.pfeiffer@fu-berlin.de>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @author Joakim Gebart <joakim.gebart@eistec.se>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "arch/atomic_arch.h"
|
||||
#include <stdint.h>
|
||||
#include "atomic.h"
|
||||
#include "irq.h"
|
||||
#include "cpu.h"
|
||||
|
||||
unsigned int atomic_arch_set_return(unsigned int *to_set, unsigned int value)
|
||||
int atomic_cas(atomic_int_t *var, int old, int now)
|
||||
{
|
||||
disableIRQ();
|
||||
unsigned int old = *to_set;
|
||||
*to_set = value;
|
||||
enableIRQ();
|
||||
return old;
|
||||
int tmp;
|
||||
int status;
|
||||
|
||||
/* Load exclusive */
|
||||
tmp = __LDREXW((volatile uint32_t *)(&ATOMIC_VALUE(*var)));
|
||||
|
||||
if (tmp != old) {
|
||||
/* Clear memory exclusivity */
|
||||
__CLREX();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Try to write the new value */
|
||||
status = __STREXW(now, (volatile uint32_t *)(&ATOMIC_VALUE(*var)));
|
||||
|
||||
return (status == 0);
|
||||
}
|
||||
|
@ -23,13 +23,13 @@
|
||||
* @author Joakim Gebart <joakim.gebart@eistec.se>
|
||||
*/
|
||||
|
||||
#ifndef __CORTEXM_COMMON_H
|
||||
#define __CORTEXM_COMMON_H
|
||||
#ifndef CORTEXM_COMMON_H_
|
||||
#define CORTEXM_COMMON_H_
|
||||
|
||||
/**
|
||||
* @brief Cortex-M3 has architecture specific atomic operations in atomic_arch.c.
|
||||
*/
|
||||
#define ARCH_HAS_ATOMIC_INT 1
|
||||
#define ARCH_HAS_ATOMIC_COMPARE_AND_SWAP 1
|
||||
|
||||
#include "cpu-conf.h"
|
||||
|
||||
@ -55,5 +55,5 @@ void cpu_init(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORTEXM_COMMON_H */
|
||||
#endif /* CORTEXM_COMMON_H_ */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user