From 34baaf3f93e69bbc80382d3bc00cd67da0a3e4d2 Mon Sep 17 00:00:00 2001 From: Dimitri Stolnikov Date: Sun, 29 Apr 2012 19:53:17 +0200 Subject: [PATCH] rtl: add xtal arguments for rtl and tuner chips --- grc/gen_osmosdr_blocks.py | 2 +- lib/rtl/rtl_source_c.cc | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/grc/gen_osmosdr_blocks.py b/grc/gen_osmosdr_blocks.py index 7150350..d095bc0 100644 --- a/grc/gen_osmosdr_blocks.py +++ b/grc/gen_osmosdr_blocks.py @@ -107,7 +107,7 @@ of devices. If left blank, the first device found will be used. Examples: fcd=0 fcd=1 fcd=2 ... - rtl=0 rtl=1 rtl=2 ... + rtl=0 rtl=1 rtl=2,rtl_xtal=28.80001e6,tuner_xtal=26e6 ... uhd=0|name,mcr=52e6,nchan=2,subdev='\\\\'B:0 A:0'\\\\' ... osmosdr=0|name,mcr=64e6,nchan=5,port=/dev/ttyUSB0 ... diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc index 532d86a..4a63824 100644 --- a/lib/rtl/rtl_source_c.cc +++ b/lib/rtl/rtl_source_c.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -77,13 +78,19 @@ rtl_source_c::rtl_source_c (const std::string &args) gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))) { int ret; - unsigned int dev_index = 0; + unsigned int dev_index = 0, rtl_freq = 0, tuner_freq = 0; dict_t dict = params_to_dict(args); if (dict.count("rtl")) dev_index = boost::lexical_cast< unsigned int >( dict["rtl"] ); + if (dict.count("rtl_xtal")) + rtl_freq = (unsigned int)boost::lexical_cast< double >( dict["rtl_xtal"] ); + + if (dict.count("tuner_xtal")) + tuner_freq = (unsigned int)boost::lexical_cast< double >( dict["tuner_xtal"] ); + _buf_num = 32; _buf = (unsigned short **) malloc(_buf_num * sizeof(unsigned short *)); @@ -116,6 +123,18 @@ rtl_source_c::rtl_source_c (const std::string &args) if (ret < 0) throw std::runtime_error("Failed to open rtlsdr device."); + if (rtl_freq > 0 || tuner_freq > 0) { + if (rtl_freq) + std::cerr << "Setting rtl clock to " << rtl_freq << " Hz." << std::endl; + if (tuner_freq) + std::cerr << "Setting tuner clock to " << tuner_freq << " Hz." << std::endl; + + ret = rtlsdr_set_xtal_freq( _dev, rtl_freq, tuner_freq ); + if (ret < 0) + throw std::runtime_error( + str(boost::format("Failed to set xtal frequencies. Error %d.") % ret )); + } + ret = rtlsdr_set_sample_rate( _dev, 1024000 ); if (ret < 0) throw std::runtime_error("Failed to set default samplerate.");