Modify licenses
[scp/ocu/5gnr.git] / Include / vos_byteorder.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 ICT/CAS.
4 *
5 *   Licensed under the O-RAN Software License, Version 1.0 (the "Software License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       https://www.o-ran.org/software
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 *
17 *******************************************************************************/
18
19
20
21
22 #ifndef _VOS_BYTEORDER_H_
23 #define _VOS_BYTEORDER_H_
24
25 #ifdef __cplusplus
26 extern "C"{
27 #endif /* __cplusplus */
28
29 /*
30  * 下面两个宏为RPU软件定义另外字节顺序,也是
31  * 两个互斥的宏。各个产品应该根据所采用CPU的类别恰当地设置
32  *  default endian is little??
33  *  #include <arpa/inet.h> for ntohl, ntohs, htons, htonl
34  */
35 #include <arpa/inet.h>
36
37 #define VOS_LITTLE_ENDIAN       (1)
38 #define VOS_BIG_ENDIAN          (0)
39 #include <arpa/inet.h>
40
41
42 #if VOS_LITTLE_ENDIAN
43
44 #ifndef VOS_NTOHL /* 4字节 */
45 #if 0
46 #define VOS_NTOHL(x) ((((x) & 0xFF000000)>>24) |  (((x) & 0x00FF0000)>>8) | \
47                        (((x) & 0x0000FF00)<<8 ) |  (((x) & 0x000000FF)<<24))
48 #endif
49 #define VOS_NTOHL(x) ntohl(x)
50 #endif
51
52 #ifndef VOS_NTOHS
53 #define VOS_NTOHS(x) ntohs(x)
54 #endif
55
56 #ifndef VOS_HTONL /* 4字节 */
57 #define VOS_HTONL(x) htonl(x)
58 #endif
59
60 #ifndef VOS_HTONS
61 #define VOS_HTONS(x) htons(x)
62 #endif
63
64 #elif VOS_BIG_ENDIAN
65
66 #ifndef VOS_NTOHL
67 #define VOS_NTOHL(x) (x)
68 #endif
69
70 #ifndef VOS_NTOHS
71 #define VOS_NTOHS(x) (x)
72 #endif
73
74 #ifndef VOS_HTONL
75 #define VOS_HTONL(x) (x)
76 #endif
77
78 #ifndef VOS_HTONS
79 #define VOS_HTONS(x) (x)
80 #endif
81 #else
82 "BYTEORDER not defined"
83 #endif /* VOS_LITTLE_ENDIAN */
84
85
86 #ifndef HAVE_MAKEWORD
87 #define HAVE_MAKEWORD
88 #define MAKEWORD(a, b)      ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
89 #endif
90
91 #ifndef HAVE_MAKELONG
92 #define HAVE_MAKELONG
93 #define MAKELONG(a, b)      ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
94 #endif
95
96 #ifndef HAVE_LOWORD
97 #define HAVE_LOWORD
98 #define LOWORD(l)           ((WORD)(l))
99 #endif
100
101 #ifndef HAVE_HIWORD
102 #define HAVE_HIWORD
103 #define HIWORD(l)           ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
104 #endif
105
106 #ifndef HAVE_LOBYTE
107 #define HAVE_LOBYTE
108 #define LOBYTE(w)           ((BYTE)(w))
109 #endif
110
111 #ifndef HAVE_HIBYTE
112 #define HAVE_HIBYTE
113 #define HIBYTE(w)           ((BYTE)(((WORD)(w) >> 8) & 0xFF))
114 #endif
115
116 #ifdef __cplusplus
117 }
118 #endif /* __cplusplus */
119
120 #endif /* _VOS_BYTEORDER_H_ */