3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
22 #ifndef INCLUDED_USRP_BYTESEX_H
23 #define INCLUDED_USRP_BYTESEX_H
26 * \brief routines for convertering between host and usrp byte order
28 * Prior to including this file, the user must include "config.h"
29 * which will or won't define WORDS_BIGENDIAN based on the
30 * result of the AC_C_BIGENDIAN autoconf test.
33 #ifdef HAVE_BYTESWAP_H
37 #warning Using non-portable code (likely wrong other than ILP32).
39 static inline unsigned short int
40 bswap_16 (unsigned short int x)
42 return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
45 static inline unsigned int
46 bswap_32 (unsigned int x)
48 return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \
49 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24));
54 #ifdef WORDS_BIGENDIAN
56 static inline unsigned int
57 host_to_usrp_u32 (unsigned int x)
62 static inline unsigned int
63 usrp_to_host_u32 (unsigned int x)
68 static inline short int
69 host_to_usrp_short (short int x)
74 static inline short int
75 usrp_to_host_short (short int x)
82 static inline unsigned int
83 host_to_usrp_u32 (unsigned int x)
88 static inline unsigned int
89 usrp_to_host_u32 (unsigned int x)
94 static inline short int
95 host_to_usrp_short (short int x)
100 static inline short int
101 usrp_to_host_short (unsigned short int x)
108 #endif /* INCLUDED_USRP_BYTESEX_H */