EVE 1.0
atomic.h
Go to the documentation of this file.
1 #ifndef EVE_ATOMIC_H_INCLUDED
2 #define EVE_ATOMIC_H_INCLUDED
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2014-2015, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33  /**
34  * \file
35  * \brief Header file for the EVE atomic primitives set.
36  *
37  * \author DT, Jetro AS
38  */ /******************************************************************/
39 
40 /**
41  * \addtogroup atomic
42  * @{
43  * EVE atomic primitives set
44  */
45 
46 /**********************************************************************/
47 /**
48  * Atomically sets the value of a variable to value and returns the old value: 32 bit version.
49  *
50  * \param p The atomic variable.
51  * \param value The value to set.
52  * \return The old value of the atomic variable.
53  */
54 uint32_t atomic_xchg32(volatile uint32_t *p, uint32_t value);
55 
56 /**********************************************************************/
57 /**
58  * Atomically sets thevalue of a variable to value and returns the old value: 16 bit version.
59  *
60  * \param p The atomic variable.
61  * \param value The value to set.
62  * \return The old value of the atomic variable.
63  */
64 uint16_t atomic_xchg16(volatile uint16_t *p, uint16_t value);
65 
66 /**********************************************************************/
67 /**
68  * Atomically sets thevalue of a variable to value and returns the old value: 8 bit version.
69  *
70  * \param p The atomic variable.
71  * \param value The value to set.
72  * \return The old value of the atomic variable.
73  */
74 uint8_t atomic_xchg8(volatile uint8_t *p, uint8_t value);
75 
76 /**********************************************************************/
77 /**
78  * Atomically sets thevalue of a variable to value and returns the old value: bool version.
79  *
80  * \param p The atomic variable.
81  * \param value The value to set.
82  * \return The old value of the atomic variable.
83  */
84 bool atomic_xchg_bool(volatile bool *p, bool value);
85 
86 /**********************************************************************/
87 /**
88  * Atomically adds delta to the current value of a variable: 32 bit version.
89  *
90  * \param p The atomic variable.
91  * \param delta The delta to add.
92  * \return The new value of the atomic variable.
93  */
94 uint32_t atomic_add32(volatile uint32_t *p, int32_t delta);
95 
96 /**********************************************************************/
97 /**
98  * Atomically adds delta to the current value of a variable: 16 bit version.
99  *
100  * \param p The atomic variable.
101  * \param delta The delta to add.
102  * \return The new value of the atomic variable.
103  */
104 uint16_t atomic_add16(volatile uint16_t *p, int16_t delta);
105 
106 /**********************************************************************/
107 /**
108  * Atomically adds delta to the current value of a variable: 8 bit version.
109  *
110  * \param p The atomic variable.
111  * \param delta The delta to add.
112  * \return The new value of the atomic variable.
113  */
114 uint8_t atomic_add8(volatile uint8_t *p, int8_t delta);
115 
116 /**********************************************************************/
117 /**
118  * Atomically ORs value with the current value of a variable: 32 bit version.
119  *
120  * \param p The atomic variable.
121  * \param value The value to binary OR with the variable.
122  * \return The updated value of the atomic variable.
123  */
124 uint32_t atomic_or32(volatile uint32_t *p, uint32_t value);
125 
126 /**********************************************************************/
127 /**
128  * Atomically ORs value with the current value of a variable: 16 bit version.
129  *
130  * \param p The atomic variable.
131  * \param value The value to binary OR with the variable.
132  * \return The updated value of the atomic variable.
133  */
134 uint16_t atomic_or16(volatile uint16_t *p, uint16_t value);
135 
136 /**********************************************************************/
137 /**
138  * Atomically ORs value with the current value of a variable: 8 bit version.
139  *
140  * \param p The atomic variable.
141  * \param value The value to binary OR with the variable.
142  * \return The updated value of the atomic variable.
143  */
144 uint8_t atomic_or8(volatile uint8_t *p, uint8_t value);
145 
146 /**********************************************************************/
147 /**
148  * Atomically ANDs value with the current value of a variable: 32 bit version.
149  *
150  * \param p The atomic variable.
151  * \param value The value to binary AND with the variable.
152  * \return The updated value of the atomic variable.
153  */
154 uint32_t atomic_and32(volatile uint32_t *p, uint32_t value);
155 
156 /**********************************************************************/
157 /**
158  * Atomically ANDs value with the current value of a variable: 16 bit version.
159  *
160  * \param p The atomic variable.
161  * \param value The value to binary AND with the variable.
162  * \return The updated value of the atomic variable.
163  */
164 uint16_t atomic_and16(volatile uint16_t *p, uint16_t value);
165 
166 /**********************************************************************/
167 /**
168  * Atomically ANDs value with the current value of a variable: 8 bit version.
169  *
170  * \param p The atomic variable.
171  * \param value The value to binary AND with the variable.
172  * \return The updated value of the atomic variable.
173  */
174 uint8_t atomic_and8(volatile uint8_t *p, uint8_t value);
175 
176 /**********************************************************************/
177 /**
178  * Atomically XORs value with the current value of a variable: 32 bit version.
179  *
180  * \param p The atomic variable.
181  * \param value The value to binary XOR with the variable.
182  * \return The updated value of the atomic variable.
183  */
184 uint32_t atomic_xor32(volatile uint32_t *p, uint32_t value);
185 
186 /**********************************************************************/
187 /**
188  * Atomically XORs value with the current value of a variable: 16 bit version.
189  *
190  * \param p The atomic variable.
191  * \param value The value to binary XOR with the variable.
192  * \return The updated value of the atomic variable.
193  */
194 uint16_t atomic_xor16(volatile uint16_t *p, uint16_t value);
195 
196 /**********************************************************************/
197 /**
198  * Atomically XORs value with the current value of a variable: 8 bit version.
199  *
200  * \param p The atomic variable.
201  * \param value The value to binary XOR with the variable.
202  * \return The updated value of the atomic variable.
203  */
204 uint8_t atomic_xor8(volatile uint8_t *p, uint8_t value);
205 
206 /** @} */ /* atomic */
207 
208 #endif /* EVE_ATOMIC_H_INCLUDED */
uint32_t atomic_and32(volatile uint32_t *p, uint32_t value)
uint8_t atomic_xor8(volatile uint8_t *p, uint8_t value)
uint32_t atomic_xor32(volatile uint32_t *p, uint32_t value)
uint16_t atomic_add16(volatile uint16_t *p, int16_t delta)
uint16_t atomic_or16(volatile uint16_t *p, uint16_t value)
bool atomic_xchg_bool(volatile bool *p, bool value)
uint8_t atomic_or8(volatile uint8_t *p, uint8_t value)
uint32_t atomic_add32(volatile uint32_t *p, int32_t delta)
uint32_t atomic_or32(volatile uint32_t *p, uint32_t value)
uint8_t atomic_xchg8(volatile uint8_t *p, uint8_t value)
uint16_t atomic_xor16(volatile uint16_t *p, uint16_t value)
uint16_t atomic_and16(volatile uint16_t *p, uint16_t value)
uint16_t atomic_xchg16(volatile uint16_t *p, uint16_t value)
uint8_t atomic_and8(volatile uint8_t *p, uint8_t value)
uint8_t atomic_add8(volatile uint8_t *p, int8_t delta)
uint32_t atomic_xchg32(volatile uint32_t *p, uint32_t value)