Blame view

RIOT/cpu/cortexm_common/atomic_arch.c 1.07 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  /*
   * Copyright (C) 2014-2015 Freie Universität Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser General
   * Public License v2.1. See the file LICENSE in the top level directory for more
   * details.
   */
  
  /**
   * @ingroup     cpu_cortexm_common
   * @{
   *
   * @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 Nohlgård <joakim.nohlgard@eistec.se>
   *
   * @}
   */
  
  #include <stdint.h>
  #include "atomic.h"
  #include "irq.h"
  #include "cpu.h"
  
  #if ARCH_HAS_ATOMIC_COMPARE_AND_SWAP
  int atomic_cas(atomic_int_t *var, int old, int now)
  {
      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);
  }
  #endif