summaryrefslogtreecommitdiff
path: root/drivers/staging/csr/csr_util.h
blob: a124c73a5d6e66403fbe3a5669ec52d64f5b0341 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef CSR_UTIL_H__
#define CSR_UTIL_H__
/*****************************************************************************

            (c) Cambridge Silicon Radio Limited 2010
            All rights reserved and confidential information of CSR

            Refer to LICENSE.txt included with this source for details
            on the license terms.

*****************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

#include <linux/kernel.h>
#include <linux/types.h>
#include "csr_macro.h"

/*------------------------------------------------------------------*/
/* Bits - intended to operate on u32 values */
/*------------------------------------------------------------------*/
u8 CsrBitCountSparse(u32 n);
u8 CsrBitCountDense(u32 n);

/*------------------------------------------------------------------*/
/* Base conversion */
/*------------------------------------------------------------------*/
u8 CsrHexStrToUint8(const char *string, u8 *returnValue);
u8 CsrHexStrToUint16(const char *string, u16 *returnValue);
u8 CsrHexStrToUint32(const char *string, u32 *returnValue);
u32 CsrPow(u32 base, u32 exponent);
void CsrIntToBase10(s32 number, char *str);
void CsrUInt16ToHex(u16 number, char *str);
void CsrUInt32ToHex(u32 number, char *str);

/*------------------------------------------------------------------*/
/* Standard C Library functions */
/*------------------------------------------------------------------*/
#ifdef CSR_USE_STDC_LIB
#define CsrMemCpy memcpy
#define CsrMemMove memmove
#define CsrStrCpy strcpy
#define CsrStrNCpy strncpy
#define CsrStrCat strcat
#define CsrStrNCat strncat
#define CsrMemCmp(s1, s2, n) ((s32) memcmp((s1), (s2), (n)))
#define CsrStrCmp(s1, s2) ((s32) strcmp((s1), (s2)))
#define CsrStrNCmp(s1, s2, n) ((s32) strncmp((s1), (s2), (n)))
#define CsrStrChr strchr
#define CsrStrStr strstr
#define CsrMemSet memset
#define CsrStrLen strlen
#else /* !CSR_USE_STDC_LIB */
void *CsrMemCpy(void *dest, const void *src, size_t count);
void *CsrMemMove(void *dest, const void *src, size_t count);
char *CsrStrCpy(char *dest, const char *src);
char *CsrStrNCpy(char *dest, const char *src, size_t count);
char *CsrStrCat(char *dest, const char *src);
char *CsrStrNCat(char *dest, const char *src, size_t count);
s32 CsrMemCmp(const void *buf1, const void *buf2, size_t count);
s32 CsrStrCmp(const char *string1, const char *string2);
s32 CsrStrNCmp(const char *string1, const char *string2, size_t count);
char *CsrStrChr(const char *string, char c);
char *CsrStrStr(const char *string1, const char *string2);
void *CsrMemSet(void *dest, u8 c, size_t count);
size_t CsrStrLen(const char *string);
#endif /* !CSR_USE_STDC_LIB */
s32 CsrVsnprintf(char *string, size_t count, const char *format, va_list args);

/*------------------------------------------------------------------*/
/* Non-standard utility functions */
/*------------------------------------------------------------------*/
void *CsrMemDup(const void *buf1, size_t count);
int CsrStrNICmp(const char *string1, const char *string2, size_t count);
char *CsrStrDup(const char *string);
u32 CsrStrToInt(const char *string);
char *CsrStrNCpyZero(char *dest, const char *src, size_t count);

/*------------------------------------------------------------------*/
/* Filename */
/*------------------------------------------------------------------*/
const char *CsrGetBaseName(const char *file);

/*------------------------------------------------------------------*/
/* Misc */
/*------------------------------------------------------------------*/
u8 CsrIsSpace(u8 c);
#define CsrOffsetOf(st, m)  ((size_t) & ((st *) 0)->m)

#ifdef __cplusplus
}
#endif

#endif