3 * Copyright 2008 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_USRP2_TYPES_H
19 #define INCLUDED_USRP2_TYPES_H
21 #include <usrp2_cdefs.h>
27 * \brief Fixed point representation of a frequency in Hertz (VITA-49 compatible)
29 * 64-bit two's complement, with the radix point 20 bits up from the bottom.
30 * Q44.20 format (20 bits to the right of the radix point)
32 * Values range from +/- 8.79 terahertz with a resolution of 0.95 microhertz.
34 typedef int64_t u2_fxpt_freq_t;
36 #define U2_FPF_RP 20 // location of radix point in u2_fxpt_freq_t
38 // macro so we can init structs at compile time
39 #define U2_DOUBLE_TO_FXPT_FREQ(f) (int64_t)((f) * (1LL << U2_FPF_RP))
41 static inline u2_fxpt_freq_t
42 u2_double_to_fxpt_freq(double f)
44 return U2_DOUBLE_TO_FXPT_FREQ(f);
48 u2_fxpt_freq_round_to_int(u2_fxpt_freq_t fx)
50 return (int)((fx+(1<<(U2_FPF_RP-1)))>>U2_FPF_RP);
54 u2_fxpt_freq_to_double(u2_fxpt_freq_t fx)
56 return ((double) fx) * 1.0/(1 << U2_FPF_RP);
59 static inline uint32_t
60 u2_fxpt_freq_hi(u2_fxpt_freq_t f)
62 return ((f >> 32) & 0xffffffff);
65 static inline uint32_t
66 u2_fxpt_freq_lo(u2_fxpt_freq_t f)
68 return (f & 0xffffffff);
71 static inline u2_fxpt_freq_t
72 u2_fxpt_freq_from_hilo(uint32_t hi, uint32_t lo)
74 return (((u2_fxpt_freq_t) hi) << 32) | lo;
78 * \brief Fixed point representation of a gain in dB (VITA-49 compatible)
80 * 16-bit two's complement, with the radix point 7 bits up from the bottom.
81 * Q9.7 format (7 bits to the right of the radix point)
83 typedef int16_t u2_fxpt_gain_t;
85 #define U2_FPG_RP 7 // location of radix point in u2_fxpt_gain_t
87 // macro so we can init structs at compile time
88 #define U2_DOUBLE_TO_FXPT_GAIN(g) (int16_t)((g) * (1 << U2_FPG_RP))
90 static inline u2_fxpt_gain_t
91 u2_double_to_fxpt_gain(double g)
93 return U2_DOUBLE_TO_FXPT_GAIN(g);
97 u2_fxpt_gain_to_double(u2_fxpt_gain_t fx)
99 return ((double) fx) * 1.0/(1 << U2_FPG_RP);
103 u2_fxpt_gain_round_to_int(u2_fxpt_gain_t fx)
105 return (int)((fx+(1<<(U2_FPG_RP-1)))>>U2_FPG_RP);
112 #endif /* INCLUDED_USRP2_TYPES_H */