GNU Radio 3.3.0 C++ API
usrp2_types.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2008 Free Software Foundation, Inc.
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 #ifndef INCLUDED_USRP2_TYPES_H
00019 #define INCLUDED_USRP2_TYPES_H
00020 
00021 #include <usrp2_cdefs.h>
00022 #include <stdint.h>
00023 
00024 __U2_BEGIN_DECLS
00025 
00026 /*!
00027  * \brief Fixed point representation of a frequency in Hertz (VITA-49 compatible)
00028  *
00029  * 64-bit two's complement, with the radix point 20 bits up from the bottom. 
00030  * Q44.20 format (20 bits to the right of the radix point)
00031  *
00032  * Values range from +/- 8.79 terahertz with a resolution of 0.95 microhertz.
00033  */
00034 typedef int64_t u2_fxpt_freq_t;
00035 
00036 #define U2_FPF_RP       20      // location of radix point in u2_fxpt_freq_t
00037 
00038 // macro so we can init structs at compile time
00039 #define U2_DOUBLE_TO_FXPT_FREQ(f) (int64_t)((f) * (1LL << U2_FPF_RP))
00040 
00041 static inline u2_fxpt_freq_t
00042 u2_double_to_fxpt_freq(double f)
00043 {
00044   return U2_DOUBLE_TO_FXPT_FREQ(f);
00045 }
00046 
00047 static inline int
00048 u2_fxpt_freq_round_to_int(u2_fxpt_freq_t fx)
00049 {
00050   return (int)((fx+(1<<(U2_FPF_RP-1)))>>U2_FPF_RP);
00051 }
00052 
00053 static inline unsigned int
00054 u2_fxpt_freq_round_to_uint(u2_fxpt_freq_t fx)
00055 {
00056   return (unsigned int)((fx+(1<<(U2_FPF_RP-1)))>>U2_FPF_RP);
00057 }
00058 
00059 static inline double
00060 u2_fxpt_freq_to_double(u2_fxpt_freq_t fx)
00061 {
00062   return ((double) fx) * 1.0/(1 << U2_FPF_RP);
00063 }
00064 
00065 static inline uint32_t
00066 u2_fxpt_freq_hi(u2_fxpt_freq_t f)
00067 {
00068   return ((f >> 32) & 0xffffffff);
00069 }
00070 
00071 static inline uint32_t
00072 u2_fxpt_freq_lo(u2_fxpt_freq_t f)
00073 {
00074   return (f & 0xffffffff);
00075 }
00076 
00077 static inline u2_fxpt_freq_t
00078 u2_fxpt_freq_from_hilo(uint32_t hi, uint32_t lo)
00079 {
00080   return (((u2_fxpt_freq_t) hi) << 32) | lo;
00081 }
00082 
00083 /*!
00084  * \brief Fixed point representation of a gain in dB (VITA-49 compatible)
00085  *
00086  * 16-bit two's complement, with the radix point 7 bits up from the bottom. 
00087  * Q9.7 format (7 bits to the right of the radix point)
00088  */
00089 typedef int16_t u2_fxpt_gain_t;
00090 
00091 #define U2_FPG_RP       7       // location of radix point in u2_fxpt_gain_t
00092 
00093 // macro so we can init structs at compile time
00094 #define U2_DOUBLE_TO_FXPT_GAIN(g) (int16_t)((g) * (1 << U2_FPG_RP))
00095 
00096 static inline u2_fxpt_gain_t
00097 u2_double_to_fxpt_gain(double g)
00098 {
00099   return U2_DOUBLE_TO_FXPT_GAIN(g);
00100 }
00101 
00102 static inline float
00103 u2_fxpt_gain_to_double(u2_fxpt_gain_t fx)
00104 {
00105   return ((double) fx) * 1.0/(1 << U2_FPG_RP);
00106 }
00107 
00108 static inline int
00109 u2_fxpt_gain_round_to_int(u2_fxpt_gain_t fx)
00110 { 
00111   return (int)((fx+(1<<(U2_FPG_RP-1)))>>U2_FPG_RP);
00112 }
00113 
00114 
00115 __U2_END_DECLS
00116 
00117 
00118 #endif /* INCLUDED_USRP2_TYPES_H */