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 b196ee12c0
commit 93ad959d8d
4 changed files with 26 additions and 21 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

@ -72,6 +72,7 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args)
gr::io_signature::make (MIN_IN, MAX_IN, sizeof (gr_complex)),
gr::io_signature::make (MIN_OUT, MAX_OUT, sizeof (gr_complex)))
{
int ret;
unsigned int device_number = 0;
std::string device_name;
@ -105,7 +106,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
@ -119,7 +120,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
@ -156,7 +157,10 @@ 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();
ret = bladerf_enable_module(this->dev, TX, true);
if ( ret != 0 )
std::cerr << "bladerf_enable_module has returned with " << ret << std::endl;
this->thread = gr::thread::thread(write_task_dispatch, this);
}
@ -165,9 +169,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

@ -72,6 +72,7 @@ bladerf_source_c::bladerf_source_c (const std::string &args)
gr::io_signature::make (MIN_IN, MAX_IN, sizeof (gr_complex)),
gr::io_signature::make (MIN_OUT, MAX_OUT, sizeof (gr_complex)))
{
int ret;
unsigned int device_number = 0;
std::string device_name;
@ -105,7 +106,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
@ -119,7 +120,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
@ -159,7 +160,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 = gr::thread::thread(read_task_dispatch, this);
}
@ -168,9 +172,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 );
}