Staging: csr: update to version 5.1.0 of the driver
[pandora-kernel.git] / drivers / staging / csr / csr_util.h
1 #ifndef CSR_UTIL_H__
2 #define CSR_UTIL_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 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #include "csr_types.h"
18 #include "csr_macro.h"
19
20 /*------------------------------------------------------------------*/
21 /* Bits - intended to operate on CsrUint32 values */
22 /*------------------------------------------------------------------*/
23 CsrUint8 CsrBitCountSparse(CsrUint32 n);
24 CsrUint8 CsrBitCountDense(CsrUint32 n);
25
26 /*------------------------------------------------------------------*/
27 /* Base conversion */
28 /*------------------------------------------------------------------*/
29 CsrBool CsrHexStrToUint8(const CsrCharString *string, CsrUint8 *returnValue);
30 CsrBool CsrHexStrToUint16(const CsrCharString *string, CsrUint16 *returnValue);
31 CsrBool CsrHexStrToUint32(const CsrCharString *string, CsrUint32 *returnValue);
32 CsrUint32 CsrPow(CsrUint32 base, CsrUint32 exponent);
33 void CsrIntToBase10(CsrInt32 number, CsrCharString *str);
34 void CsrUInt16ToHex(CsrUint16 number, CsrCharString *str);
35 void CsrUInt32ToHex(CsrUint32 number, CsrCharString *str);
36
37 /*------------------------------------------------------------------*/
38 /* Standard C Library functions */
39 /*------------------------------------------------------------------*/
40 #ifdef CSR_USE_STDC_LIB
41 #define CsrMemCpy memcpy
42 #define CsrMemMove memmove
43 #define CsrStrCpy strcpy
44 #define CsrStrNCpy strncpy
45 #define CsrStrCat strcat
46 #define CsrStrNCat strncat
47 #define CsrMemCmp(s1, s2, n) ((CsrInt32) memcmp((s1), (s2), (n)))
48 #define CsrStrCmp(s1, s2) ((CsrInt32) strcmp((s1), (s2)))
49 #define CsrStrNCmp(s1, s2, n) ((CsrInt32) strncmp((s1), (s2), (n)))
50 /*#define CsrMemChr memchr*/
51 #define CsrStrChr strchr
52 /*#define CsrStrCSpn strcspn*/
53 /*#define CsrStrPBrk strpbrk*/
54 /*#define CsrStrRChr strrchr*/
55 /*#define CsrStrSpn strspn*/
56 #define CsrStrStr strstr
57 /*#define CsrStrTok strtok*/
58 #define CsrMemSet memset
59 #define CsrStrLen strlen
60 /*#define CsrVsnprintf(s, n, format, arg) ((CsrInt32) vsnprintf((s), (n), (format), (arg)))*/
61 #else /* !CSR_USE_STDC_LIB */
62 void *CsrMemCpy(void *dest, const void *src, CsrSize count);
63 void *CsrMemMove(void *dest, const void *src, CsrSize count);
64 CsrCharString *CsrStrCpy(CsrCharString *dest, const CsrCharString *src);
65 CsrCharString *CsrStrNCpy(CsrCharString *dest, const CsrCharString *src, CsrSize count);
66 CsrCharString *CsrStrCat(CsrCharString *dest, const CsrCharString *src);
67 CsrCharString *CsrStrNCat(CsrCharString *dest, const CsrCharString *src, CsrSize count);
68 CsrInt32 CsrMemCmp(const void *buf1, const void *buf2, CsrSize count);
69 CsrInt32 CsrStrCmp(const CsrCharString *string1, const CsrCharString *string2);
70 CsrInt32 CsrStrNCmp(const CsrCharString *string1, const CsrCharString *string2, CsrSize count);
71 CsrCharString *CsrStrChr(const CsrCharString *string, CsrCharString c);
72 CsrCharString *CsrStrStr(const CsrCharString *string1, const CsrCharString *string2);
73 void *CsrMemSet(void *dest, CsrUint8 c, CsrSize count);
74 CsrSize CsrStrLen(const CsrCharString *string);
75 #endif /* !CSR_USE_STDC_LIB */
76 CsrInt32 CsrVsnprintf(CsrCharString *string, CsrSize count, const CsrCharString *format, va_list args);
77
78 /*------------------------------------------------------------------*/
79 /* Non-standard utility functions */
80 /*------------------------------------------------------------------*/
81 void *CsrMemDup(const void *buf1, CsrSize count);
82 int CsrStrNICmp(const CsrCharString *string1, const CsrCharString *string2, CsrSize count);
83 CsrCharString *CsrStrDup(const CsrCharString *string);
84 CsrUint32 CsrStrToInt(const CsrCharString *string);
85 CsrCharString *CsrStrNCpyZero(CsrCharString *dest, const CsrCharString *src, CsrSize count);
86
87 /*------------------------------------------------------------------*/
88 /* Filename */
89 /*------------------------------------------------------------------*/
90 const CsrCharString *CsrGetBaseName(const CsrCharString *file);
91
92 /*------------------------------------------------------------------*/
93 /* Misc */
94 /*------------------------------------------------------------------*/
95 CsrBool CsrIsSpace(CsrUint8 c);
96 #define CsrOffsetOf(st, m)  ((CsrSize) & ((st *) 0)->m)
97
98 #ifdef __cplusplus
99 }
100 #endif
101
102 #endif