00001
00013 #ifndef _CO_ENDIAN_H_
00014 #define _CO_ENDIAN_H_
00015
00037
00038
00039
00040
00041 #include "co_int.h"
00042 #include "rwnx_config.h"
00043 #include "compiler.h"
00044 #include "arch.h"
00045
00046
00055 __INLINE uint32_t co_bswap32(uint32_t val32)
00056 {
00057
00058 return (val32<<24) | ((val32<<8)&0xFF0000) | ((val32>>8)&0xFF00) | ((val32>>24)&0xFF);
00059 }
00060
00069 __INLINE uint16_t co_bswap16(uint16_t val16)
00070 {
00071 return ((val16<<8)&0xFF00) | ((val16>>8)&0xFF);
00072 }
00074
00075
00103 __INLINE uint32_t co_htonl(uint32_t hostlong)
00104 {
00105 #if !CPU_LE
00106 return hostlong;
00107 #else
00108 return co_bswap32(hostlong);
00109 #endif
00110 }
00111
00120 __INLINE uint16_t co_htons(uint16_t hostshort)
00121 {
00122 #if !CPU_LE
00123 return hostshort;
00124 #else
00125 return co_bswap16(hostshort);
00126 #endif
00127 }
00128
00137 __INLINE uint32_t co_ntohl(uint32_t netlong)
00138 {
00139 return co_htonl(netlong);
00140 }
00141
00150 __INLINE uint16_t co_ntohs(uint16_t netshort)
00151 {
00152 return co_htons(netshort);
00153 }
00155
00180 __INLINE uint32_t co_htowl(uint32_t hostlong)
00181 {
00182 #if CPU_LE
00183 return hostlong;
00184 #else
00185 return co_bswap32(hostlong);
00186 #endif
00187 }
00188
00197 __INLINE uint16_t co_htows(uint16_t hostshort)
00198 {
00199 #if CPU_LE
00200 return hostshort;
00201 #else
00202 return co_bswap16(hostshort);
00203 #endif
00204 }
00205
00206
00215 __INLINE uint32_t co_wtohl(uint32_t wlanlong)
00216 {
00217 return co_htowl(wlanlong);
00218 }
00219
00220
00229 __INLINE uint16_t co_wtohs(uint16_t wlanshort)
00230 {
00231 return co_htows(wlanshort);
00232 }
00234
00235 #endif // _CO_ENDIAN_H_