SAMA5D4 Xplained Ultra Board BSP
guowenxue
2019-08-22 b5a0e1f270688ad03f0d20199d194c948b097bd2
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/******************************************************************************
 *
 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 *
 *
 ******************************************************************************/
#ifndef __BASIC_TYPES_H__
#define __BASIC_TYPES_H__
 
 
#define SUCCESS    0
#define FAIL    (-1)
 
#ifndef TRUE
    #define _TRUE    1
#else
    #define _TRUE    TRUE
#endif
 
#ifndef FALSE
    #define _FALSE    0
#else
    #define _FALSE    FALSE
#endif
 
#ifdef PLATFORM_WINDOWS
 
    typedef signed char s8;
    typedef unsigned char u8;
 
    typedef signed short s16;
    typedef unsigned short u16;
 
    typedef signed long s32;
    typedef unsigned long u32;
 
    typedef unsigned int    uint;
    typedef    signed int        sint;
 
 
    typedef signed long long s64;
    typedef unsigned long long u64;
 
    #ifdef NDIS50_MINIPORT
 
        #define NDIS_MAJOR_VERSION       5
        #define NDIS_MINOR_VERSION       0
 
    #endif
 
    #ifdef NDIS51_MINIPORT
 
        #define NDIS_MAJOR_VERSION       5
        #define NDIS_MINOR_VERSION       1
 
    #endif
 
    typedef NDIS_PROC proc_t;
 
    typedef LONG atomic_t;
 
#endif
 
 
#ifdef PLATFORM_LINUX
    #include <linux/version.h>
    #include <linux/types.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/init.h>
    #include <linux/utsname.h>
    #define IN
    #define OUT
    #define VOID void
    #define NDIS_OID uint
    #define NDIS_STATUS uint
 
    typedef    signed int sint;
 
    #ifndef    PVOID
        typedef void *PVOID;
        /* #define PVOID    (void *) */
    #endif
 
    #define UCHAR u8
    #define USHORT u16
    #define UINT u32
    #define ULONG u32
 
    #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
        typedef _Bool bool;
    #endif
 
    typedef void (*proc_t)(void *);
 
    typedef    __kernel_size_t    SIZE_T;
    typedef    __kernel_ssize_t    SSIZE_T;
    #define FIELD_OFFSET(s, field)    ((SSIZE_T)&((s *)(0))->field)
 
#endif
 
 
#ifdef PLATFORM_FREEBSD
 
    typedef signed char s8;
    typedef unsigned char u8;
 
    typedef signed short s16;
    typedef unsigned short u16;
 
    typedef signed int s32;
    typedef unsigned int u32;
 
    typedef unsigned int    uint;
    typedef    signed int        sint;
    typedef long atomic_t;
 
    typedef signed long long s64;
    typedef unsigned long long u64;
    #define IN
    #define OUT
    #define VOID void
    #define NDIS_OID uint
    #define NDIS_STATUS uint
 
    #ifndef    PVOID
        typedef void *PVOID;
        /* #define PVOID    (void *) */
    #endif
    typedef u32 dma_addr_t;
    #define UCHAR u8
    #define USHORT u16
    #define UINT u32
    #define ULONG u32
 
    typedef void (*proc_t)(void *);
 
    typedef unsigned int __kernel_size_t;
    typedef int __kernel_ssize_t;
 
    typedef    __kernel_size_t    SIZE_T;
    typedef    __kernel_ssize_t    SSIZE_T;
    #define FIELD_OFFSET(s, field)    ((SSIZE_T)&((s *)(0))->field)
 
#endif
 
#define MEM_ALIGNMENT_OFFSET    (sizeof (SIZE_T))
#define MEM_ALIGNMENT_PADDING    (sizeof(SIZE_T) - 1)
 
#define SIZE_PTR SIZE_T
#define SSIZE_PTR SSIZE_T
 
/*
* Continuous bits starting from least significant bit
* Example:
* BIT_LEN_MASK_32(0) => 0x00000000
* BIT_LEN_MASK_32(1) => 0x00000001
* BIT_LEN_MASK_32(2) => 0x00000003
* BIT_LEN_MASK_32(32) => 0xFFFFFFFF
*/
#define BIT_LEN_MASK_32(__BitLen) ((u32)(0xFFFFFFFF >> (32 - (__BitLen))))
#define BIT_LEN_MASK_16(__BitLen) ((u16)(0xFFFF >> (16 - (__BitLen))))
#define BIT_LEN_MASK_8(__BitLen) ((u8)(0xFF >> (8 - (__BitLen))))
 
/*
* Continuous bits starting from least significant bit
* Example:
* BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
* BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
*/
#define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ((u32)(BIT_LEN_MASK_32(__BitLen) << (__BitOffset)))
#define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) ((u16)(BIT_LEN_MASK_16(__BitLen) << (__BitOffset)))
#define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) ((u8)(BIT_LEN_MASK_8(__BitLen) << (__BitOffset)))
 
/*
* Convert LE data to host byte order
*/
#define EF1Byte (u8)
#define EF2Byte le16_to_cpu
#define EF4Byte le32_to_cpu
 
/*
* Read LE data from memory to host byte order
*/
#define ReadLE4Byte(_ptr)    le32_to_cpu(*((u32 *)(_ptr)))
#define ReadLE2Byte(_ptr)    le16_to_cpu(*((u16 *)(_ptr)))
#define ReadLE1Byte(_ptr)    (*((u8 *)(_ptr)))
 
/*
* Read BE data from memory to host byte order
*/
#define ReadBEE4Byte(_ptr)    be32_to_cpu(*((u32 *)(_ptr)))
#define ReadBE2Byte(_ptr)    be16_to_cpu(*((u16 *)(_ptr)))
#define ReadBE1Byte(_ptr)    (*((u8 *)(_ptr)))
 
/*
* Write host byte order data to memory in LE order
*/
#define WriteLE4Byte(_ptr, _val)    ((*((u32 *)(_ptr))) = cpu_to_le32(_val))
#define WriteLE2Byte(_ptr, _val)    ((*((u16 *)(_ptr))) = cpu_to_le16(_val))
#define WriteLE1Byte(_ptr, _val)    ((*((u8 *)(_ptr))) = ((u8)(_val)))
 
/*
* Write host byte order data to memory in BE order
*/
#define WriteBE4Byte(_ptr, _val)    ((*((u32 *)(_ptr))) = cpu_to_be32(_val))
#define WriteBE2Byte(_ptr, _val)    ((*((u16 *)(_ptr))) = cpu_to_be16(_val))
#define WriteBE1Byte(_ptr, _val)    ((*((u8 *)(_ptr))) = ((u8)(_val)))
 
/*
* Return 4-byte value in host byte ordering from 4-byte pointer in litten-endian system.
*/
#define LE_P4BYTE_TO_HOST_4BYTE(__pStart) (le32_to_cpu(*((u32 *)(__pStart))))
#define LE_P2BYTE_TO_HOST_2BYTE(__pStart) (le16_to_cpu(*((u16 *)(__pStart))))
#define LE_P1BYTE_TO_HOST_1BYTE(__pStart) ((*((u8 *)(__pStart))))
 
/*
* Return 4-byte value in host byte ordering from 4-byte pointer in big-endian system.
*/
#define BE_P4BYTE_TO_HOST_4BYTE(__pStart) (be32_to_cpu(*((u32 *)(__pStart))))
#define BE_P2BYTE_TO_HOST_2BYTE(__pStart) (be16_to_cpu(*((u16 *)(__pStart))))
#define BE_P1BYTE_TO_HOST_1BYTE(__pStart) ((*((u8 *)(__pStart))))
 
/*
* Translate subfield (continuous bits in little-endian) of 4-byte value in LE byte to
* 4-byte value in host byte ordering.
*/
#define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
    ((LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
 
#define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
    ((LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
 
#define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
    ((LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
 
/*
* Translate subfield (continuous bits in big-endian) of 4-byte value in BE byte to
* 4-byte value in host byte ordering.
*/
#define BE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
    ((BE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_32(__BitLen))
 
#define BE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
    ((BE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_16(__BitLen))
 
#define BE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
    ((BE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset)) & BIT_LEN_MASK_8(__BitLen))
 
/*
* Mask subfield (continuous bits in little-endian) of 4-byte value in LE byte oredering
* and return the result in 4-byte value in host byte ordering.
*/
#define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
    (LE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
 
#define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
    (LE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
 
#define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
    (LE_P1BYTE_TO_HOST_1BYTE(__pStart) & ((u8)(~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen))))
 
/*
* Mask subfield (continuous bits in big-endian) of 4-byte value in BE byte oredering
* and return the result in 4-byte value in host byte ordering.
*/
#define BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
    (BE_P4BYTE_TO_HOST_4BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen)))
 
#define BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
    (BE_P2BYTE_TO_HOST_2BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen)))
 
#define BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
    (BE_P1BYTE_TO_HOST_1BYTE(__pStart) & (~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen)))
 
/*
* Set subfield of little-endian 4-byte value to specified value.
*/
#define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
    do { \
        if (__BitOffset == 0 && __BitLen == 32) \
            WriteLE4Byte(__pStart, __Value); \
        else { \
            WriteLE4Byte(__pStart, \
                LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
                | \
                ((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
            ); \
        } \
    } while (0)
 
#define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
    do { \
        if (__BitOffset == 0 && __BitLen == 16) \
            WriteLE2Byte(__pStart, __Value); \
        else { \
            WriteLE2Byte(__pStart, \
                LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
                | \
                ((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
            ); \
        } \
    } while (0)
 
#define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
    do { \
        if (__BitOffset == 0 && __BitLen == 8) \
            WriteLE1Byte(__pStart, __Value); \
        else { \
            WriteLE1Byte(__pStart, \
                LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
                | \
                ((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
            ); \
        } \
    } while (0)
 
/*
* Set subfield of big-endian 4-byte value to specified value.
*/
#define SET_BITS_TO_BE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
    do { \
        if (__BitOffset == 0 && __BitLen == 32) \
            WriteBE4Byte(__pStart, __Value); \
        else { \
            WriteBE4Byte(__pStart, \
                BE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
                | \
                ((((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset)) \
            ); \
        } \
    } while (0)
 
#define SET_BITS_TO_BE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
    do { \
        if (__BitOffset == 0 && __BitLen == 16) \
            WriteBE2Byte(__pStart, __Value); \
        else { \
            WriteBE2Byte(__pStart, \
                BE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
                | \
                ((((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset)) \
            ); \
        } \
    } while (0)
 
#define SET_BITS_TO_BE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
    do { \
        if (__BitOffset == 0 && __BitLen == 8) \
            WriteBE1Byte(__pStart, __Value); \
        else { \
            WriteBE1Byte(__pStart, \
                BE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
                | \
                ((((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset)) \
            ); \
        } \
    } while (0)
 
/* Get the N-bytes aligment offset from the current length */
#define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
 
typedef unsigned char    BOOLEAN, *PBOOLEAN, boolean;
 
#define TEST_FLAG(__Flag, __testFlag)        (((__Flag) & (__testFlag)) != 0)
#define SET_FLAG(__Flag, __setFlag)            ((__Flag) |= __setFlag)
#define CLEAR_FLAG(__Flag, __clearFlag)        ((__Flag) &= ~(__clearFlag))
#define CLEAR_FLAGS(__Flag)                    ((__Flag) = 0)
#define TEST_FLAGS(__Flag, __testFlags)        (((__Flag) & (__testFlags)) == (__testFlags))
 
#endif /* __BASIC_TYPES_H__ */