0e5aa5cf0e3b8b72d595ea182ec9e34ac9d26177
[scp/ocu/5gnr.git] / Include / vos_byteorder.h
1 /******************************************************************************
2 ###############################################################################
3 #   Copyright (c) [2017-2020] [ICT/CAS]                                        #
4 #   Licensed under the ORAN Software License v1.0 (License)             #
5 ###############################################################################
6 ******************************************************************************/
7
8
9
10 #ifndef _VOS_BYTEORDER_H_
11 #define _VOS_BYTEORDER_H_
12
13 #ifdef __cplusplus
14 extern "C"{
15 #endif /* __cplusplus */
16
17 /*
18  * 下面两个宏为RPU软件定义另外字节顺序,也是
19  * 两个互斥的宏。各个产品应该根据所采用CPU的类别恰当地设置
20  *  default endian is little??
21  *  #include <arpa/inet.h> for ntohl, ntohs, htons, htonl
22  */
23 #include <arpa/inet.h>
24
25 #define VOS_LITTLE_ENDIAN       (1)
26 #define VOS_BIG_ENDIAN          (0)
27 #include <arpa/inet.h>
28
29
30 #if VOS_LITTLE_ENDIAN
31
32 #ifndef VOS_NTOHL /* 4字节 */
33 #if 0
34 #define VOS_NTOHL(x) ((((x) & 0xFF000000)>>24) |  (((x) & 0x00FF0000)>>8) | \
35                        (((x) & 0x0000FF00)<<8 ) |  (((x) & 0x000000FF)<<24))                      
36 #endif
37 #define VOS_NTOHL(x) ntohl(x)
38 #endif
39
40 #ifndef VOS_NTOHS
41 #define VOS_NTOHS(x) ntohs(x)
42 #endif
43
44 #ifndef VOS_HTONL /* 4字节 */
45 #define VOS_HTONL(x) htonl(x)
46 #endif
47
48 #ifndef VOS_HTONS
49 #define VOS_HTONS(x) htons(x)
50 #endif
51
52 #elif VOS_BIG_ENDIAN
53
54 #ifndef VOS_NTOHL
55 #define VOS_NTOHL(x) (x)
56 #endif
57
58 #ifndef VOS_NTOHS
59 #define VOS_NTOHS(x) (x)
60 #endif
61
62 #ifndef VOS_HTONL
63 #define VOS_HTONL(x) (x)
64 #endif
65
66 #ifndef VOS_HTONS
67 #define VOS_HTONS(x) (x)
68 #endif
69 #else
70 "BYTEORDER not defined"
71 #endif /* VOS_LITTLE_ENDIAN */
72
73
74 #ifndef HAVE_MAKEWORD
75 #define HAVE_MAKEWORD
76 #define MAKEWORD(a, b)      ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
77 #endif
78
79 #ifndef HAVE_MAKELONG
80 #define HAVE_MAKELONG
81 #define MAKELONG(a, b)      ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
82 #endif
83
84 #ifndef HAVE_LOWORD
85 #define HAVE_LOWORD
86 #define LOWORD(l)           ((WORD)(l))
87 #endif
88
89 #ifndef HAVE_HIWORD
90 #define HAVE_HIWORD
91 #define HIWORD(l)           ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
92 #endif
93
94 #ifndef HAVE_LOBYTE
95 #define HAVE_LOBYTE
96 #define LOBYTE(w)           ((BYTE)(w))
97 #endif
98
99 #ifndef HAVE_HIBYTE
100 #define HAVE_HIBYTE
101 #define HIBYTE(w)           ((BYTE)(((WORD)(w) >> 8) & 0xFF))
102 #endif
103
104 #ifdef __cplusplus
105 }
106 #endif /* __cplusplus */
107
108 #endif /* _VOS_BYTEORDER_H_ */