oro_arm/oro_arch.h
Go to the documentation of this file.
1 /***************************************************************************
2  * File copied from
3  * https://github.com/psoetens/orocos-rtt/blob/arm-port/src/os/oro_atomic.h
4 
5  ***************************************************************************
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public *
8  * License as published by the Free Software Foundation; *
9  * version 2 of the License. *
10  * *
11  * As a special exception, you may use this file as part of a free *
12  * software library without restriction. Specifically, if other files *
13  * instantiate templates or use macros or inline functions from this *
14  * file, or you compile this file and link it with other files to *
15  * produce an executable, this file does not by itself cause the *
16  * resulting executable to be covered by the GNU General Public *
17  * License. This exception does not however invalidate any other *
18  * reasons why the executable file might be covered by the GNU General *
19  * Public License. *
20  * *
21  * This library is distributed in the hope that it will be useful, *
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
24  * Lesser General Public License for more details. *
25  * *
26  * You should have received a copy of the GNU General Public *
27  * License along with this library; if not, write to the Free Software *
28  * Foundation, Inc., 59 Temple Place, *
29  * Suite 330, Boston, MA 02111-1307 USA *
30  * *
31  ***************************************************************************/
32 
33 #ifndef __ARCH_arm_ORO_ATOMIC__
34 #define __ARCH_arm_ORO_ATOMIC__
35 
36 #define oro_localirq_save_hw_notrace(x) \
37  ({ \
38  unsigned long temp; \
39  (void) (&temp == &x); \
40  __asm__ __volatile__( \
41  "mrs %0, cpsr @ oro_localirq_save_hw\n" \
42 " orr %1, %0, #128\n" \
43 " msr cpsr_c, %1" \
44  : "=r" (x), "=r" (temp) \
45  : \
46  : "memory", "cc"); \
47  })
48 #define oro_localirq_save_hw(flags) oro_localirq_save_hw_notrace(flags)
49 
50 #define oro_localirq_restore_hw_notrace(x) \
51  __asm__ __volatile__( \
52  "msr cpsr_c, %0 @ oro_localirq_restore_hw\n" \
53  : \
54  : "r" (x) \
55  : "memory", "cc")
56 #define oro_localirq_restore_hw(flags) oro_localirq_restore_hw_notrace(flags)
57 
58 typedef struct { volatile int counter; } oro_atomic_t;
59 
60 #define ORO_ATOMIC_INIT(i) { (i) }
61 
62 #define oro_atomic_read(v) ((v)->counter)
63 
64 #define oro_atomic_set(v,i) (((v)->counter) = (i))
65 
66 static inline int oro_atomic_add_return(int i, oro_atomic_t *v)
67 {
68  unsigned long flags;
69  int val;
70 
71  oro_localirq_save_hw(flags);
72  val = v->counter;
73  v->counter = val += i;
75 
76  return val;
77 }
78 
79 static inline int oro_atomic_sub_return(int i, oro_atomic_t *v)
80 {
81  unsigned long flags;
82  int val;
83 
84  oro_localirq_save_hw(flags);
85  val = v->counter;
86  v->counter = val -= i;
88 
89  return val;
90 }
91 
92 static inline int oro_atomic_cmpxchg(oro_atomic_t *v, int old, int a)
93 {
94  int ret;
95  unsigned long flags;
96 
97  oro_localirq_save_hw(flags);
98  ret = v->counter;
99  v->counter = a;
101 
102  return ret;
103 }
104 
105 static inline void oro_atomic_clear_mask(unsigned long mask, unsigned long *addr)
106 {
107  unsigned long flags;
108 
109  oro_localirq_save_hw(flags);
110  *addr &= ~mask;
112 }
113 
114 #define oro_atomic_xchg(v, new) (xchg(&((v)->counter), new))
115 
116 static inline int oro_atomic_add_unless(oro_atomic_t *v, int a, int u)
117 {
118  int c, old;
119 
120  c = oro_atomic_read(v);
121  while (c != u && (old = oro_atomic_cmpxchg((v), c, c + a)) != c)
122  c = old;
123  return c != u;
124 }
125 #define oro_atomic_inc_not_zero(v) oro_atomic_add_unless((v), 1, 0)
126 
127 #define oro_atomic_add(i, v) (void) oro_atomic_add_return(i, v)
128 #define oro_atomic_inc(v) (void) oro_atomic_add_return(1, v)
129 #define oro_atomic_sub(i, v) (void) oro_atomic_sub_return(i, v)
130 #define oro_atomic_dec(v) (void) oro_atomic_sub_return(1, v)
131 
132 #define oro_atomic_inc_and_test(v) (oro_atomic_add_return(1, v) == 0)
133 #define oro_atomic_dec_and_test(v) (oro_atomic_sub_return(1, v) == 0)
134 #define oro_atomic_inc_return(v) (oro_atomic_add_return(1, v))
135 #define oro_atomic_dec_return(v) (oro_atomic_sub_return(1, v))
136 #define oro_atomic_sub_and_test(i, v) (oro_atomic_sub_return(i, v) == 0)
137 
138 #define oro_atomic_add_negative(i,v) (oro_atomic_add_return(i, v) < 0)
139 
140 /* oro_atomic operations are already serializing on ARM */
141 #define smp_mb__before_oro_atomic_dec() barrier()
142 #define smp_mb__after_oro_atomic_dec() barrier()
143 #define smp_mb__before_oro_atomic_inc() barrier()
144 #define smp_mb__after_oro_atomic_inc() barrier()
145 
146 #endif // __ARCH_arm_ORO_atomic__
#define oro_localirq_save_hw(flags)
#define oro_localirq_restore_hw(flags)
static void oro_atomic_clear_mask(unsigned long mask, unsigned long *addr)
static int oro_atomic_sub_return(int i, oro_atomic_t *v)
volatile int counter
volatile long oro_atomic_t
static int oro_atomic_add_unless(oro_atomic_t *v, int a, int u)
static int oro_atomic_add_return(int i, oro_atomic_t *v)
static int oro_atomic_cmpxchg(oro_atomic_t *v, int old, int a)
#define oro_atomic_read(v)


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:24