hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
/** @file */
/******************************************************************************
 *
 * Copyright(c) 2019 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.
 *
 ******************************************************************************/
 
#ifndef _MAC_AX_PLTFM_H_
#define _MAC_AX_PLTFM_H_
 
#ifndef __cplusplus /* for win/linux driver */
 
/* Include header file which contain the following definitions, */
/* or modify this file to meet your platform */
/*[Driver] use their own header files*/
#include "../hal_headers_le.h"
 
/*[Driver] provide the define of NULL, u8, u16, u32*/
#ifndef NULL
#define NULL        ((void *)0)
#endif
 
/*[Driver] provide the type mutex*/
/* Mutex type */
#define mac_ax_mutex _os_mutex
 
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr)        (sizeof(arr) / sizeof((arr)[0]))
#endif
 
#define _ASSERT_ BUG_ON
 
/* 1: enable MAC debug messages */
/* 0: disable MAC debug messages */
#define MAC_AX_DBG_MSG_EN    1
 
/* Set debug message level */
#define MAC_AX_MSG_LEVEL_TRACE        3
#define MAC_AX_MSG_LEVEL_WARNING    2
#define MAC_AX_MSG_LEVEL_ERR        1
#define MAC_AX_MSG_LEVEL_ALWAYS        0
#define MAC_AX_MSG_LEVEL        MAC_AX_MSG_LEVEL_TRACE
 
#define SET_CLR_WORD(_w, _v, _f)                                               \
               (((_w) & ~((_f##_MSK) << (_f##_SH))) |         \
               (((_v) & (_f##_MSK)) << (_f##_SH)))
#define SET_WORD(_v, _f)    (((_v) & (_f##_MSK)) << (_f##_SH))
#define GET_FIELD(_w, _f)         (((_w) >> (_f##_SH)) & (_f##_MSK))
 
#define SET_CLR_WOR2(_w, _v, _sh, _msk) (((_w) & ~(_msk << _sh)) |             \
                   (((_v) & _msk) << _sh))
#define SET_WOR2(_v, _sh, _msk)         (((_v) & _msk) << _sh)
#define GET_FIEL2(_w, _sh, _msk)        (((_w) >> _sh) & _msk)
 
#define GET_MSK(_f)         ((_f##_MSK) << (_f##_SH))
 
#else /* for WD1 test program */
 
/* Include header file which contain the following definitions, */
/* or modify this file to meet your platform */
#include <Windows.h> // critical_section
#include <stdint.h>
 
#define BIT(x)    (1 << (x))
 
#ifndef NULL
#define NULL    ((void *)0)
#endif
 
typedef unsigned char    u8;
typedef uint16_t    u16;
typedef uint32_t    u32;
typedef char        s8;
typedef int16_t        s16;
typedef int32_t        s32;
 
#define _os_va_list va_list
 
#include "mac_exp_def.h"
#include "../hal_headers_le.h"
 
typedef u16 __le16;
typedef u32 __le32;
typedef u16 __be16;
typedef u32 __be32;
 
typedef    CRITICAL_SECTION    mac_ax_mutex;
 
#define ARRAY_SIZE(arr)        (sizeof(arr) / sizeof((arr)[0]))
 
/* 1: the platform is Little Endian. */
/* 0: the platform is Big Endian. */
#define MAC_AX_IS_LITTLE_ENDIAN    1
 
/* 1: enable MAC debug messages */
/* 0: disable MAC debug messages */
#define MAC_AX_DBG_MSG_EN    1
 
/* Set debug message level */
#define MAC_AX_MSG_LEVEL_TRACE        3
#define MAC_AX_MSG_LEVEL_WARNING    2
#define MAC_AX_MSG_LEVEL_ERR        1
#define MAC_AX_MSG_LEVEL_ALWAYS        0
#define MAC_AX_MSG_LEVEL        MAC_AX_MSG_LEVEL_TRACE
 
#define SET_CLR_WORD(_w, _v, _f)                                               \
               (((_w) & ~((_f##_MSK) << (_f##_SH))) |         \
               (((_v) & (_f##_MSK)) << (_f##_SH)))
#define SET_WORD(_v, _f)    (((_v) & (_f##_MSK)) << (_f##_SH))
#define GET_FIELD(_w, _f)         (((_w) >> (_f##_SH)) & (_f##_MSK))
 
#define SET_CLR_WOR2(_w, _v, _sh, _msk) (((_w) & ~(_msk << _sh)) |             \
                   (((_v) & _msk) << _sh))
#define SET_WOR2(_v, _sh, _msk)         (((_v) & _msk) << _sh)
#define GET_FIEL2(_w, _sh, _msk)        (((_w) >> _sh) & _msk)
 
#define GET_MSK(_f)         ((_f##_MSK) << (_f##_SH))
 
#define SWAP32(x)                                                              \
   ((u32)((((u32)(x) & (u32)0x000000ff) << 24) |                          \
          (((u32)(x) & (u32)0x0000ff00) << 8) |                           \
          (((u32)(x) & (u32)0x00ff0000) >> 8) |                           \
          (((u32)(x) & (u32)0xff000000) >> 24)))
 
#define SWAP16(x)                                                              \
   ((u16)((((u16)(x) & (u16)0x00ff) << 8) |                               \
          (((u16)(x) & (u16)0xff00) >> 8)))
 
#if MAC_AX_IS_LITTLE_ENDIAN
#define cpu_to_le32(x)              ((u32)(x))
#define le32_to_cpu(x)              ((u32)(x))
#define cpu_to_le16(x)              ((u16)(x))
#define le16_to_cpu(x)              ((u16)(x))
#define cpu_to_be32(x)              SWAP32((x))
#define be32_to_cpu(x)              SWAP32((x))
#define cpu_to_be16(x)              SWAP16((x))
#define be16_to_cpu(x)              SWAP16((x))
#else
#define cpu_to_le32(x)              SWAP32((x))
#define le32_to_cpu(x)              SWAP32((x))
#define cpu_to_le16(x)              SWAP16((x))
#define le16_to_cpu(x)              SWAP16((x))
#define cpu_to_be32(x)              ((u32)(x))
#define be32_to_cpu(x)              ((u32)(x))
#define cpu_to_be16(x)              ((u16)(x))
#define be16_to_cpu(x)              ((u16)(x))
#endif
 
#ifndef __func__
#define __func__ __FUNCTION__
#endif
 
#ifndef fallthrough
   #if __GNUC__ >= 5 || defined(__clang__)
       #ifndef __has_attribute
           #define __has_attribute(x) 0
       #endif
       #if __has_attribute(__fallthrough__)
           #define fallthrough __attribute__((__fallthrough__))
       #endif
   #endif
   #ifndef fallthrough
       #define fallthrough do {} while (0) /* fallthrough */
   #endif
#endif
 
#endif // end of #else /* for WD1 test program */
 
#endif