bladerf: migrate to new api to enable/disable TX/RX modules

TX support has been verified with osmocom_siggen and fpga image from git
f6c6a3abcb22d2794946e5adbc556805a73788a3
This commit is contained in:
Dimitri Stolnikov 2013-07-26 21:46:47 +02:00
parent 65e34f6863
commit 41bb9a0ef9
4 changed files with 27 additions and 22 deletions

View File

@ -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 */

View File

@ -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();

View File

@ -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 );
}

View File

@ -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 );
}