aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-07-08 11:58:51 -0700
committerJosh Blum <josh@joshknows.com>2011-07-08 11:58:51 -0700
commit54229a06d1e4c05158ef9517fd61e61204363ed6 (patch)
tree9102001f3a60d3af433d5b257ed213cd3faa9fdf /host
parentaa6b340f436acf4c0cad80416f69312ecfe3f29f (diff)
downloaduhd-54229a06d1e4c05158ef9517fd61e61204363ed6.tar.gz
uhd-54229a06d1e4c05158ef9517fd61e61204363ed6.tar.bz2
uhd-54229a06d1e4c05158ef9517fd61e61204363ed6.zip
usrp: added software scale factor adjustment
Diffstat (limited to 'host')
-rw-r--r--host/lib/transport/super_recv_packet_handler.hpp9
-rw-r--r--host/lib/transport/super_send_packet_handler.hpp9
-rw-r--r--host/lib/usrp/b100/io_impl.cpp2
-rw-r--r--host/lib/usrp/cores/rx_dsp_core_200.cpp14
-rw-r--r--host/lib/usrp/cores/rx_dsp_core_200.hpp2
-rw-r--r--host/lib/usrp/e100/io_impl.cpp2
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp2
7 files changed, 38 insertions, 2 deletions
diff --git a/host/lib/transport/super_recv_packet_handler.hpp b/host/lib/transport/super_recv_packet_handler.hpp
index d79e0b2c0..15bd78242 100644
--- a/host/lib/transport/super_recv_packet_handler.hpp
+++ b/host/lib/transport/super_recv_packet_handler.hpp
@@ -74,6 +74,7 @@ public:
{
this->resize(size);
set_alignment_failure_threshold(1000);
+ this->set_scale_factor(1/32767.);
}
//! Resize the number of transport channels
@@ -153,6 +154,11 @@ public:
return boost::mutex::scoped_lock(_mutex);
}
+ //! Set the scale factor used in float conversion
+ void set_scale_factor(const double scale_factor){
+ _scale_factor = scale_factor;
+ }
+
/*******************************************************************
* Receive:
* The entry point for the fast-path receive calls.
@@ -238,6 +244,7 @@ private:
std::vector<void *> _io_buffs; //used in conversion
size_t _bytes_per_item; //used in conversion
std::vector<uhd::convert::function_type> _converters; //used in conversion
+ double _scale_factor;
//! information stored for a received buffer
struct per_buffer_info_type{
@@ -558,7 +565,7 @@ private:
}
//copy-convert the samples from the recv buffer
- _converters[io_type.tid](buff_info.copy_buff, _io_buffs, nsamps_to_copy_per_io_buff, 1/32767.);
+ _converters[io_type.tid](buff_info.copy_buff, _io_buffs, nsamps_to_copy_per_io_buff, _scale_factor);
//update the rx copy buffer to reflect the bytes copied
buff_info.copy_buff += bytes_to_copy;
diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp
index 05557250f..d5d9e6fe3 100644
--- a/host/lib/transport/super_send_packet_handler.hpp
+++ b/host/lib/transport/super_send_packet_handler.hpp
@@ -58,6 +58,7 @@ public:
_next_packet_seq(0)
{
this->resize(size);
+ this->set_scale_factor(32767.);
}
//! Resize the number of transport channels
@@ -132,6 +133,11 @@ public:
return boost::mutex::scoped_lock(_mutex);
}
+ //! Set the scale factor used in float conversion
+ void set_scale_factor(const double scale_factor){
+ _scale_factor = scale_factor;
+ }
+
/*******************************************************************
* Send:
* The entry point for the fast-path send calls.
@@ -238,6 +244,7 @@ private:
size_t _max_samples_per_packet;
std::vector<const void *> _zero_buffs;
size_t _next_packet_seq;
+ double _scale_factor;
/*******************************************************************
* Send a single packet:
@@ -270,7 +277,7 @@ private:
otw_mem += if_packet_info.num_header_words32;
//copy-convert the samples into the send buffer
- _converters[io_type.tid](_io_buffs, otw_mem, nsamps_per_buff, 32767.);
+ _converters[io_type.tid](_io_buffs, otw_mem, nsamps_per_buff, _scale_factor);
//commit the samples to the zero-copy interface
size_t num_bytes_total = (_header_offset_words32+if_packet_info.num_packet_words32)*sizeof(boost::uint32_t);
diff --git a/host/lib/usrp/b100/io_impl.cpp b/host/lib/usrp/b100/io_impl.cpp
index d4515bbb5..d841188c0 100644
--- a/host/lib/usrp/b100/io_impl.cpp
+++ b/host/lib/usrp/b100/io_impl.cpp
@@ -129,6 +129,8 @@ void b100_impl::update_tick_rate(const double rate){
void b100_impl::update_rx_samp_rate(const double rate){
boost::mutex::scoped_lock recv_lock = _io_impl->recv_handler.get_scoped_lock();
_io_impl->recv_handler.set_samp_rate(rate);
+ const double adj = _rx_dsps.front()->get_scaling_adjustment();
+ _io_impl->recv_handler.set_scale_factor(adj/32767.);
}
void b100_impl::update_tx_samp_rate(const double rate){
diff --git a/host/lib/usrp/cores/rx_dsp_core_200.cpp b/host/lib/usrp/cores/rx_dsp_core_200.cpp
index e059ddfca..82bc7c1bf 100644
--- a/host/lib/usrp/cores/rx_dsp_core_200.cpp
+++ b/host/lib/usrp/cores/rx_dsp_core_200.cpp
@@ -43,6 +43,10 @@
#define REG_RX_CTRL_NSAMPS_PP _ctrl_base + 28
#define REG_RX_CTRL_NCHANNELS _ctrl_base + 32
+template <class T> T ceil_log2(T num){
+ return std::ceil(std::log(num)/std::log(T(2)));
+}
+
using namespace uhd;
class rx_dsp_core_200_impl : public rx_dsp_core_200{
@@ -146,9 +150,18 @@ public:
_iface->poke32(REG_DSP_RX_DECIM, (hb1 << 9) | (hb0 << 8) | (decim & 0xff));
+ // Calculate CIC decimation (i.e., without halfband decimators)
+ // Calculate closest multiplier constant to reverse gain absent scale multipliers
+ const double rate_pow = std::pow(double(decim & 0xff), 4);
+ _scaling_adjustment = std::pow(2, ceil_log2(rate_pow))/(1.65*rate_pow);
+
return _tick_rate/decim_rate;
}
+ double get_scaling_adjustment(void){
+ return _scaling_adjustment;
+ }
+
double set_freq(const double freq_){
//correct for outside of rate (wrap around)
double freq = std::fmod(freq_, _tick_rate);
@@ -181,6 +194,7 @@ private:
const size_t _dsp_base, _ctrl_base;
double _tick_rate, _link_rate;
bool _continuous_streaming;
+ double _scaling_adjustment;
};
rx_dsp_core_200::sptr rx_dsp_core_200::make(wb_iface::sptr iface, const size_t dsp_base, const size_t ctrl_base, const boost::uint32_t sid, const bool lingering_packet){
diff --git a/host/lib/usrp/cores/rx_dsp_core_200.hpp b/host/lib/usrp/cores/rx_dsp_core_200.hpp
index abe7bf817..391cc8441 100644
--- a/host/lib/usrp/cores/rx_dsp_core_200.hpp
+++ b/host/lib/usrp/cores/rx_dsp_core_200.hpp
@@ -48,6 +48,8 @@ public:
virtual double set_host_rate(const double rate) = 0;
+ virtual double get_scaling_adjustment(void) = 0;
+
virtual uhd::meta_range_t get_freq_range(void) = 0;
virtual double set_freq(const double freq) = 0;
diff --git a/host/lib/usrp/e100/io_impl.cpp b/host/lib/usrp/e100/io_impl.cpp
index 9f7dc9921..412febd83 100644
--- a/host/lib/usrp/e100/io_impl.cpp
+++ b/host/lib/usrp/e100/io_impl.cpp
@@ -217,6 +217,8 @@ void e100_impl::update_tick_rate(const double rate){
void e100_impl::update_rx_samp_rate(const double rate){
boost::mutex::scoped_lock recv_lock = _io_impl->recv_handler.get_scoped_lock();
_io_impl->recv_handler.set_samp_rate(rate);
+ const double adj = _rx_dsps.front()->get_scaling_adjustment();
+ _io_impl->recv_handler.set_scale_factor(adj/32767.);
}
void e100_impl::update_tx_samp_rate(const double rate){
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index eda2267bc..4c55012ce 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -299,6 +299,8 @@ void usrp2_impl::update_tick_rate(const double rate){
void usrp2_impl::update_rx_samp_rate(const double rate){
boost::mutex::scoped_lock recv_lock = _io_impl->recv_handler.get_scoped_lock();
_io_impl->recv_handler.set_samp_rate(rate);
+ const double adj = _mbc[_mbc.keys().front()].rx_dsps.front()->get_scaling_adjustment();
+ _io_impl->recv_handler.set_scale_factor(adj/32767.);
}
void usrp2_impl::update_tx_samp_rate(const double rate){