usrp_bytesex.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_USRP_BYTESEX_H
00023 #define INCLUDED_USRP_BYTESEX_H
00024
00033 #ifdef HAVE_BYTESWAP_H
00034 #include <byteswap.h>
00035 #else
00036
00037 #warning Using non-portable code (likely wrong other than ILP32).
00038
00039 static inline unsigned short int
00040 bswap_16 (unsigned short int x)
00041 {
00042 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
00043 }
00044
00045 static inline unsigned int
00046 bswap_32 (unsigned int x)
00047 {
00048 return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \
00049 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24));
00050 }
00051 #endif
00052
00053
00054 #ifdef WORDS_BIGENDIAN
00055
00056 static inline unsigned int
00057 host_to_usrp_u32 (unsigned int x)
00058 {
00059 return bswap_32(x);
00060 }
00061
00062 static inline unsigned int
00063 usrp_to_host_u32 (unsigned int x)
00064 {
00065 return bswap_32(x);
00066 }
00067
00068 static inline short int
00069 host_to_usrp_short (short int x)
00070 {
00071 return bswap_16 (x);
00072 }
00073
00074 static inline short int
00075 usrp_to_host_short (short int x)
00076 {
00077 return bswap_16 (x);
00078 }
00079
00080 #else
00081
00082 static inline unsigned int
00083 host_to_usrp_u32 (unsigned int x)
00084 {
00085 return x;
00086 }
00087
00088 static inline unsigned int
00089 usrp_to_host_u32 (unsigned int x)
00090 {
00091 return x;
00092 }
00093
00094 static inline short int
00095 host_to_usrp_short (short int x)
00096 {
00097 return x;
00098 }
00099
00100 static inline short int
00101 usrp_to_host_short (unsigned short int x)
00102 {
00103 return x;
00104 }
00105
00106 #endif
00107
00108 #endif