Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
csr_macro.h
Go to the documentation of this file.
1 #ifndef CSR_MACRO_H__
2 #define CSR_MACRO_H__
3 /*****************************************************************************
4 
5  (c) Cambridge Silicon Radio Limited 2010
6  All rights reserved and confidential information of CSR
7 
8  Refer to LICENSE.txt included with this source for details
9  on the license terms.
10 
11 *****************************************************************************/
12 
13 #include <linux/types.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #define FALSE (0)
20 #define TRUE (1)
21 
22 /*------------------------------------------------------------------*/
23 /* Bits - intended to operate on u32 values */
24 /*------------------------------------------------------------------*/
25 #define CSR_MASK_IS_SET(val, mask) (((val) & (mask)) == (mask))
26 #define CSR_MASK_IS_UNSET(val, mask) ((((val) & (mask)) ^ mask) == (mask))
27 #define CSR_MASK_SET(val, mask) ((val) |= (mask))
28 #define CSR_MASK_UNSET(val, mask) ((val) = ((val) ^ (mask)) & (val)) /* Unsets the bits in val that are set in mask */
29 #define CSR_BIT_IS_SET(val, bit) ((u8) ((((val) & (1UL << (bit))) != 0)))
30 #define CSR_BIT_SET(val, bit) ((val) |= (1UL << (bit)))
31 #define CSR_BIT_UNSET(val, bit) ((val) &= ~(1UL << (bit)))
32 #define CSR_BIT_TOGGLE(val, bit) ((val) ^= (1UL << (bit)))
33 
34 /*------------------------------------------------------------------*/
35 /* Endian conversion */
36 /*------------------------------------------------------------------*/
37 #define CSR_GET_UINT16_FROM_LITTLE_ENDIAN(ptr) (((u16) ((u8 *) (ptr))[0]) | ((u16) ((u8 *) (ptr))[1]) << 8)
38 #define CSR_GET_UINT32_FROM_LITTLE_ENDIAN(ptr) (((u32) ((u8 *) (ptr))[0]) | ((u32) ((u8 *) (ptr))[1]) << 8 | \
39  ((u32) ((u8 *) (ptr))[2]) << 16 | ((u32) ((u8 *) (ptr))[3]) << 24)
40 #define CSR_COPY_UINT16_TO_LITTLE_ENDIAN(uint, ptr) ((u8 *) (ptr))[0] = ((u8) ((uint) & 0x00FF)); \
41  ((u8 *) (ptr))[1] = ((u8) ((uint) >> 8))
42 #define CSR_COPY_UINT32_TO_LITTLE_ENDIAN(uint, ptr) ((u8 *) (ptr))[0] = ((u8) ((uint) & 0x000000FF)); \
43  ((u8 *) (ptr))[1] = ((u8) (((uint) >> 8) & 0x000000FF)); \
44  ((u8 *) (ptr))[2] = ((u8) (((uint) >> 16) & 0x000000FF)); \
45  ((u8 *) (ptr))[3] = ((u8) (((uint) >> 24) & 0x000000FF))
46 #define CSR_GET_UINT16_FROM_BIG_ENDIAN(ptr) (((u16) ((u8 *) (ptr))[1]) | ((u16) ((u8 *) (ptr))[0]) << 8)
47 #define CSR_GET_UINT24_FROM_BIG_ENDIAN(ptr) (((u32) ((u8 *) (ptr))[2]) | \
48  ((u32) ((u8 *) (ptr))[1]) << 8 | ((u32) ((u8 *) (ptr))[0]) << 16)
49 #define CSR_GET_UINT32_FROM_BIG_ENDIAN(ptr) (((u32) ((u8 *) (ptr))[3]) | ((u32) ((u8 *) (ptr))[2]) << 8 | \
50  ((u32) ((u8 *) (ptr))[1]) << 16 | ((u32) ((u8 *) (ptr))[0]) << 24)
51 #define CSR_COPY_UINT16_TO_BIG_ENDIAN(uint, ptr) ((u8 *) (ptr))[1] = ((u8) ((uint) & 0x00FF)); \
52  ((u8 *) (ptr))[0] = ((u8) ((uint) >> 8))
53 #define CSR_COPY_UINT24_TO_BIG_ENDIAN(uint, ptr) ((u8 *) (ptr))[2] = ((u8) ((uint) & 0x000000FF)); \
54  ((u8 *) (ptr))[1] = ((u8) (((uint) >> 8) & 0x000000FF)); \
55  ((u8 *) (ptr))[0] = ((u8) (((uint) >> 16) & 0x000000FF))
56 #define CSR_COPY_UINT32_TO_BIG_ENDIAN(uint, ptr) ((u8 *) (ptr))[3] = ((u8) ((uint) & 0x000000FF)); \
57  ((u8 *) (ptr))[2] = ((u8) (((uint) >> 8) & 0x000000FF)); \
58  ((u8 *) (ptr))[1] = ((u8) (((uint) >> 16) & 0x000000FF)); \
59  ((u8 *) (ptr))[0] = ((u8) (((uint) >> 24) & 0x000000FF))
60 
61 /*------------------------------------------------------------------*/
62 /* XAP conversion macros */
63 /*------------------------------------------------------------------*/
64 
65 #define CSR_LSB16(a) ((u8) ((a) & 0x00ff))
66 #define CSR_MSB16(b) ((u8) ((b) >> 8))
67 
68 #define CSR_CONVERT_8_FROM_XAP(output, input) \
69  (output) = ((u8) (input));(input) += 2
70 
71 #define CSR_CONVERT_16_FROM_XAP(output, input) \
72  (output) = (u16) ((((u16) (input)[1]) << 8) | \
73  ((u16) (input)[0]));(input) += 2
74 
75 #define CSR_CONVERT_32_FROM_XAP(output, input) \
76  (output) = (((u32) (input)[1]) << 24) | \
77  (((u32) (input)[0]) << 16) | \
78  (((u32) (input)[3]) << 8) | \
79  ((u32) (input)[2]);input += 4
80 
81 #define CSR_ADD_UINT8_TO_XAP(output, input) \
82  (output)[0] = (input); \
83  (output)[1] = 0;(output) += 2
84 
85 #define CSR_ADD_UINT16_TO_XAP(output, input) \
86  (output)[0] = ((u8) ((input) & 0x00FF)); \
87  (output)[1] = ((u8) ((input) >> 8));(output) += 2
88 
89 #define CSR_ADD_UINT32_TO_XAP(output, input) \
90  (output)[0] = ((u8) (((input) >> 16) & 0x00FF)); \
91  (output)[1] = ((u8) ((input) >> 24)); \
92  (output)[2] = ((u8) ((input) & 0x00FF)); \
93  (output)[3] = ((u8) (((input) >> 8) & 0x00FF));(output) += 4
94 
95 /*------------------------------------------------------------------*/
96 /* Misc */
97 /*------------------------------------------------------------------*/
98 #define CSRMAX(a, b) (((a) > (b)) ? (a) : (b))
99 #define CSRMIN(a, b) (((a) < (b)) ? (a) : (b))
100 
101 /* Use this macro on unused local variables that cannot be removed (such as
102  unused function parameters). This will quell warnings from certain compilers
103  and static code analysis tools like Lint and Valgrind. */
104 #define CSR_UNUSED(x) ((void) (x))
105 
106 #define CSR_TOUPPER(character) (((character) >= 'a') && ((character) <= 'z') ? ((character) - 0x20) : (character))
107 #define CSR_TOLOWER(character) (((character) >= 'A') && ((character) <= 'Z') ? ((character) + 0x20) : (character))
108 #define CSR_ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif