Statistics
| Branch: | Tag: | Revision:

root / usrp / host / lib / legacy / usrp_bytesex.h @ 0bf2128a

History | View | Annotate | Download (2.2 kB)

1
/* -*- c++ -*- */
2
/*
3
 * Copyright 2004 Free Software Foundation, Inc.
4
 * 
5
 * This file is part of GNU Radio
6
 * 
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 2, or (at your option)
10
 * any later version.
11
 * 
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.
16
 * 
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.
21
 */
22
#ifndef INCLUDED_USRP_BYTESEX_H
23
#define INCLUDED_USRP_BYTESEX_H
24
25
/*!
26
 * \brief routines for convertering between host and usrp byte order
27
 *
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.
31
 */
32
33
#ifdef HAVE_BYTESWAP_H
34
#include <byteswap.h>
35
#else
36
static inline unsigned short int
37
bswap_16 (unsigned short int x)
38
{
39
  return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
40
}
41
42
static inline unsigned int
43
bswap32 (unsigned int x)
44
{
45
  return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) \
46
        | (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24));
47
}
48
#endif
49
50
51
#ifdef WORDS_BIGENDIAN
52
53
static inline unsigned int
54
host_to_usrp_u32 (unsigned int x)
55
{
56
  return bswap_32(x);
57
}
58
59
static inline unsigned int
60
usrp_to_host_u32 (unsigned int x)
61
{
62
  return bswap_32(x);
63
}
64
65
static inline short int
66
host_to_usrp_short (short int x)
67
{
68
  return bswap_16 (x);
69
}
70
71
static inline short int
72
usrp_to_host_short (short int x)
73
{
74
  return bswap_16 (x);
75
}
76
77
#else
78
79
static inline unsigned int
80
host_to_usrp_u32 (unsigned int x)
81
{
82
  return x;
83
}
84
85
static inline unsigned int
86
usrp_to_host_u32 (unsigned int x)
87
{
88
  return x;
89
}
90
91
static inline short int
92
host_to_usrp_short (short int x)
93
{
94
  return x;
95
}
96
97
static inline short int
98
usrp_to_host_short (unsigned short int x)
99
{
100
  return x;
101
}
102
103
#endif
104
105
#endif /* INCLUDED_USRP_BYTESEX_H */