diff --git a/lib/bladerf/bladerf_common.cc b/lib/bladerf/bladerf_common.cc index d12dd33..a474e10 100644 --- a/lib/bladerf/bladerf_common.cc +++ b/lib/bladerf/bladerf_common.cc @@ -87,19 +87,6 @@ bladerf_common::~bladerf_common() delete this->sample_fifo; } -void bladerf_common::setup_device() -{ - gpio_write( this->dev, 0x57 ); /* enable LMS RX & TX, select lower band */ - lms_spi_write( this->dev, 0x5a, 0xa0 ); /* polarity of the IQSel signal */ - /* values are taken from LMS6002D FAQ 5.27 */ - lms_spi_write( this->dev, 0x05, 0x3e ); /* enable the tx and rx modules */ - lms_spi_write( this->dev, 0x47, 0x40 ); /* Improving Tx spurious emission performance */ - lms_spi_write( this->dev, 0x59, 0x29 ); /* Improving ADC's performance */ - lms_spi_write( this->dev, 0x64, 0x36 ); /* Common Mode Voltage For ADC's */ - lms_spi_write( this->dev, 0x79, 0x37 ); /* Higher LNA Gain */ - return; -} - osmosdr::freq_range_t bladerf_common::freq_range() { /* assuming the same for RX & TX */ diff --git a/lib/bladerf/bladerf_common.h b/lib/bladerf/bladerf_common.h index 2db4c62..f6f1ccf 100644 --- a/lib/bladerf/bladerf_common.h +++ b/lib/bladerf/bladerf_common.h @@ -55,8 +55,6 @@ public: ~bladerf_common(); protected: - void setup_device(); - osmosdr::freq_range_t freq_range(); osmosdr::meta_range_t sample_rates(); osmosdr::freq_range_t filter_bandwidths(); diff --git a/lib/bladerf/bladerf_sink_c.cc b/lib/bladerf/bladerf_sink_c.cc index ca44e74..b3faf6c 100644 --- a/lib/bladerf/bladerf_sink_c.cc +++ b/lib/bladerf/bladerf_sink_c.cc @@ -73,6 +73,7 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)), gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))) { + int ret; unsigned int device_number = 0; std::string device_name; @@ -106,7 +107,7 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) std::string fpga = dict["fpga"]; std::cerr << "Loading FPGA bitstream " << fpga << "..." << std::endl; - int ret = bladerf_load_fpga( this->dev, fpga.c_str() ); + ret = bladerf_load_fpga( this->dev, fpga.c_str() ); if ( ret != 0 ) std::cerr << "bladerf_load_fpga has returned with " << ret << std::endl; else @@ -120,7 +121,7 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) std::cerr << "Flashing firmware image " << fw << "..., " << "DO NOT INTERRUPT!" << std::endl; - int ret = bladerf_flash_firmware( this->dev, fw.c_str() ); + ret = bladerf_flash_firmware( this->dev, fw.c_str() ); if ( ret != 0 ) std::cerr << "bladerf_flash_firmware has failed with " << ret << std::endl; else @@ -157,8 +158,11 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) /* Set the range of VGA2, VGA2GAIN[4:0] */ this->vga2_range = osmosdr::gain_range_t( 0, 25, 1 ); - this->setup_device(); - this->thread = gruel::thread(write_task_dispatch, this); + ret = bladerf_enable_module(this->dev, TX, true); + if ( ret != 0 ) + std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; + + this->thread = gruel::thread(write_task_dispatch, this); } /* @@ -166,9 +170,15 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) */ bladerf_sink_c::~bladerf_sink_c () { + int ret; + this->set_running(false); this->thread.join(); + ret = bladerf_enable_module(this->dev, TX, false); + if ( ret != 0 ) + std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; + /* Close the device */ bladerf_close( this->dev ); } diff --git a/lib/bladerf/bladerf_source_c.cc b/lib/bladerf/bladerf_source_c.cc index 70d2b9e..b73b2a5 100644 --- a/lib/bladerf/bladerf_source_c.cc +++ b/lib/bladerf/bladerf_source_c.cc @@ -73,6 +73,7 @@ bladerf_source_c::bladerf_source_c (const std::string &args) gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)), gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))) { + int ret; unsigned int device_number = 0; std::string device_name; @@ -106,7 +107,7 @@ bladerf_source_c::bladerf_source_c (const std::string &args) std::string fpga = dict["fpga"]; std::cerr << "Loading FPGA bitstream " << fpga << "..." << std::endl; - int ret = bladerf_load_fpga( this->dev, fpga.c_str() ); + ret = bladerf_load_fpga( this->dev, fpga.c_str() ); if ( ret != 0 ) std::cerr << "bladerf_load_fpga has returned with " << ret << std::endl; else @@ -120,7 +121,7 @@ bladerf_source_c::bladerf_source_c (const std::string &args) std::cerr << "Flashing firmware image " << fw << "..., " << "DO NOT INTERRUPT!" << std::endl; - int ret = bladerf_flash_firmware( this->dev, fw.c_str() ); + ret = bladerf_flash_firmware( this->dev, fw.c_str() ); if ( ret != 0 ) std::cerr << "bladerf_flash_firmware has failed with " << ret << std::endl; else @@ -160,7 +161,10 @@ bladerf_source_c::bladerf_source_c (const std::string &args) /* Set the range of VGA2 VGA2GAIN[4:0], not recommended to be used above 30dB */ this->vga2_range = osmosdr::gain_range_t( 0, 60, 3 ); - this->setup_device(); + ret = bladerf_enable_module(this->dev, RX, true); + if ( ret != 0 ) + std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; + this->thread = gruel::thread(read_task_dispatch, this); } @@ -169,9 +173,15 @@ bladerf_source_c::bladerf_source_c (const std::string &args) */ bladerf_source_c::~bladerf_source_c () { + int ret; + this->set_running(false); this->thread.join(); + ret = bladerf_enable_module(this->dev, RX, false); + if ( ret != 0 ) + std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; + /* Close the device */ bladerf_close( this->dev ); }