2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * @ingroup adf_os_public
37 * @file adf_os_bitops.h
38 * This file abstracts bit-level operations on a stream of bytes.
41 #ifndef _ADF_OS_BITOPS_H
42 #define _ADF_OS_BITOPS_H
44 #include <adf_os_types.h>
47 * @brief Set a bit atomically
48 * @param[in] nr Bit to change
49 * @param[in] addr Address to start counting from
51 * @note its atomic and cannot be re-ordered.
52 * Note that nr may be almost arbitrarily large; this function is not
53 * restricted to acting on a single-word quantity.
55 static inline void adf_os_set_bit_a(a_uint32_t nr, volatile a_uint32_t *addr)
57 __adf_os_set_bit_a(nr, addr);
62 * @param[in] nr Bit to change
63 * @param[in] addr Address to start counting from
65 * @note its not atomic and can be re-ordered.
66 * Note that nr may be almost arbitrarily large; this function is not
67 * restricted to acting on a single-word quantity.
69 static inline void adf_os_set_bit(a_uint32_t nr, volatile a_uint32_t *addr)
71 __adf_os_set_bit(nr, addr);
75 * @brief Clear a bit atomically
76 * @param[in] nr Bit to change
77 * @param[in] addr Address to start counting from
79 * @note its atomic and cannot be re-ordered.
80 * Note that nr may be almost arbitrarily large; this function is not
81 * restricted to acting on a single-word quantity.
83 static inline void adf_os_clear_bit_a(a_uint32_t nr, volatile a_uint32_t *addr)
85 __adf_os_clear_bit_a(nr, addr);
90 * @param[in] nr Bit to change
91 * @param[in] addr Address to start counting from
93 * @note its not atomic and can be re-ordered.
94 * Note that nr may be almost arbitrarily large; this function is not
95 * restricted to acting on a single-word quantity.
97 static inline void adf_os_clear_bit(a_uint32_t nr, volatile a_uint32_t *addr)
99 __adf_os_clear_bit(nr, addr);
103 * @brief Toggle a bit atomically
104 * @param[in] nr Bit to change
105 * @param[in] addr Address to start counting from
107 * @note its atomic and cannot be re-ordered.
108 * Note that nr may be almost arbitrarily large; this function is not
109 * restricted to acting on a single-word quantity.
111 static inline void adf_os_change_bit_a(a_uint32_t nr, volatile a_uint32_t *addr)
113 __adf_os_change_bit_a(nr, addr);
117 * @brief Toggle a bit
118 * @param[in] nr Bit to change
119 * @param[in] addr Address to start counting from
121 * @note its not atomic and can be re-ordered.
122 * Note that nr may be almost arbitrarily large; this function is not
123 * restricted to acting on a single-word quantity.
125 static inline void adf_os_change_bit(a_uint32_t nr, volatile a_uint32_t *addr)
127 __adf_os_change_bit(nr, addr);
131 * @brief Test and Set a bit atomically
132 * @param[in] nr Bit to set
133 * @param[in] addr Address to start counting from
135 * @note its atomic and cannot be re-ordered.
136 * Note that nr may be almost arbitrarily large; this function is not
137 * restricted to acting on a single-word quantity.
139 static inline void adf_os_test_and_set_bit_a(a_uint32_t nr,
140 volatile a_uint32_t *addr)
142 __adf_os_test_and_set_bit_a(nr, addr);
146 * @brief Test and Set a bit
147 * @param[in] nr Bit to set
148 * @param[in] addr Address to start counting from
150 * @note its not atomic and can be re-ordered.
151 * Note that nr may be almost arbitrarily large; this function is not
152 * restricted to acting on a single-word quantity.
154 static inline void adf_os_test_and_set_bit(a_uint32_t nr,
155 volatile a_uint32_t *addr)
157 __adf_os_test_and_set_bit(nr, addr);
161 * @brief Test and clear a bit atomically
162 * @param[in] nr Bit to set
163 * @param[in] addr Address to start counting from
165 * @note its atomic and cannot be re-ordered.
166 * Note that nr may be almost arbitrarily large; this function is not
167 * restricted to acting on a single-word quantity.
169 static inline void adf_os_test_and_clear_bit_a(a_uint32_t nr,
170 volatile a_uint32_t *addr)
172 __adf_os_test_and_clear_bit_a(nr, addr);
176 * @brief Test and clear a bit
177 * @param[in] nr Bit to set
178 * @param[in] addr Address to start counting from
180 * @note its not atomic and can be re-ordered.
181 * Note that nr may be almost arbitrarily large; this function is not
182 * restricted to acting on a single-word quantity.
184 static inline void adf_os_test_and_clear_bit(a_uint32_t nr,
185 volatile a_uint32_t *addr)
187 __adf_os_test_and_clear_bit(nr, addr);
191 * @brief Test and change a bit atomically
192 * @param[in] nr Bit to set
193 * @param[in] addr Address to start counting from
195 * @note its atomic and cannot be re-ordered.
196 * Note that nr may be almost arbitrarily large; this function is not
197 * restricted to acting on a single-word quantity.
199 static inline void adf_os_test_and_change_bit_a(a_uint32_t nr,
200 volatile a_uint32_t *addr)
202 __adf_os_test_and_change_bit_a(nr, addr);
206 * @brief Test and clear a bit
207 * @param[in] nr Bit to set
208 * @param[in] addr Address to start counting from
210 * @note its not atomic and can be re-ordered.
211 * Note that nr may be almost arbitrarily large; this function is not
212 * restricted to acting on a single-word quantity.
214 static inline void adf_os_test_and_change_bit(a_uint32_t nr,
215 volatile a_uint32_t *addr)
217 __adf_os_test_and_change_bit(nr, addr);
221 * @brief test_bit - Determine whether a bit is set
222 * @param[in] nr bit number to test
223 * @param[in] addr Address to start counting from
225 * @return 1 if set, 0 if not
227 static inline int adf_os_test_bit(a_uint32_t nr, volatile a_uint32_t *addr)
229 __adf_os_test_bit(nr, addr);
233 #endif /**_AOD_BITOPS_H*/