forked from sdr/gr-osmosdr
bladerf: Moved no longer "common" items out of bladerf_common
The gr_complex FIFO is no longer used on the TX side, so it doesn't really make sense to have it in bladerf_common. The associated items have been moved into bladerf_source, and some renaming has been done in bladerf_sink to tidy up. Pending further performance tests of the bladerf_source, the _fifo member (boost::circular_buffer) may need to be replaced.
This commit is contained in:
parent
46a241624a
commit
03c42ef320
|
@ -40,49 +40,13 @@
|
||||||
|
|
||||||
#include "bladerf_common.h"
|
#include "bladerf_common.h"
|
||||||
|
|
||||||
#define BLADERF_FIFO_SIZE_ENV "BLADERF_SAMPLE_FIFO_SIZE"
|
|
||||||
|
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
||||||
boost::mutex bladerf_common::_devs_mutex;
|
boost::mutex bladerf_common::_devs_mutex;
|
||||||
std::list<boost::weak_ptr<struct bladerf> > bladerf_common::_devs;
|
std::list<boost::weak_ptr<struct bladerf> > bladerf_common::_devs;
|
||||||
|
|
||||||
bladerf_common::bladerf_common() :
|
bladerf_common::bladerf_common() : _is_running(false) {}
|
||||||
_is_running(false)
|
bladerf_common::~bladerf_common() {}
|
||||||
{
|
|
||||||
const char *env_fifo_size;
|
|
||||||
size_t fifo_size;
|
|
||||||
|
|
||||||
env_fifo_size = getenv(BLADERF_FIFO_SIZE_ENV);
|
|
||||||
fifo_size = BLADERF_SAMPLE_FIFO_SIZE;
|
|
||||||
|
|
||||||
if (env_fifo_size != NULL) {
|
|
||||||
try {
|
|
||||||
fifo_size = boost::lexical_cast<size_t>(env_fifo_size);
|
|
||||||
} catch (const boost::bad_lexical_cast &e) {
|
|
||||||
std::cerr << "Warning: \"" << BLADERF_FIFO_SIZE_ENV
|
|
||||||
<< "\" is invalid" << "... defaulting to "
|
|
||||||
<< fifo_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fifo_size < BLADERF_SAMPLE_FIFO_MIN_SIZE) {
|
|
||||||
fifo_size = BLADERF_SAMPLE_FIFO_MIN_SIZE;
|
|
||||||
std::cerr << "Warning: \"" << BLADERF_FIFO_SIZE_ENV
|
|
||||||
<< "\" is too small" << "... defaulting to "
|
|
||||||
<< BLADERF_SAMPLE_FIFO_MIN_SIZE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_fifo = new boost::circular_buffer<gr_complex>(fifo_size);
|
|
||||||
if (!_fifo)
|
|
||||||
throw std::runtime_error( std::string(__FUNCTION__) +
|
|
||||||
" has failed to allocate a sample FIFO!" );
|
|
||||||
}
|
|
||||||
|
|
||||||
bladerf_common::~bladerf_common()
|
|
||||||
{
|
|
||||||
delete _fifo;
|
|
||||||
}
|
|
||||||
|
|
||||||
bladerf_sptr bladerf_common:: get_cached_device(struct bladerf_devinfo devinfo)
|
bladerf_sptr bladerf_common:: get_cached_device(struct bladerf_devinfo devinfo)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,16 +39,6 @@
|
||||||
/* We currently read/write 1024 samples (pairs of 16-bit signed ints) */
|
/* We currently read/write 1024 samples (pairs of 16-bit signed ints) */
|
||||||
#define BLADERF_SAMPLE_BLOCK_SIZE (1024)
|
#define BLADERF_SAMPLE_BLOCK_SIZE (1024)
|
||||||
|
|
||||||
/*
|
|
||||||
* Default size of sample FIFO, in entries.
|
|
||||||
* This can be overridden by the environment variable BLADERF_SAMPLE_FIFO_SIZE.
|
|
||||||
*/
|
|
||||||
#ifndef BLADERF_SAMPLE_FIFO_SIZE
|
|
||||||
# define BLADERF_SAMPLE_FIFO_SIZE (2 * 1024 * 1024)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BLADERF_SAMPLE_FIFO_MIN_SIZE (3 * BLADERF_SAMPLE_BLOCK_SIZE)
|
|
||||||
|
|
||||||
typedef boost::shared_ptr<struct bladerf> bladerf_sptr;
|
typedef boost::shared_ptr<struct bladerf> bladerf_sptr;
|
||||||
|
|
||||||
class bladerf_common
|
class bladerf_common
|
||||||
|
@ -78,12 +68,9 @@ protected:
|
||||||
|
|
||||||
gr::thread::thread _thread;
|
gr::thread::thread _thread;
|
||||||
|
|
||||||
boost::circular_buffer<gr_complex> *_fifo;
|
|
||||||
boost::mutex _fifo_lock;
|
|
||||||
boost::condition_variable _samp_avail;
|
|
||||||
|
|
||||||
osmosdr::gain_range_t _vga1_range;
|
osmosdr::gain_range_t _vga1_range;
|
||||||
osmosdr::gain_range_t _vga2_range;
|
osmosdr::gain_range_t _vga2_range;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _is_running;
|
bool _is_running;
|
||||||
boost::shared_mutex _state_lock;
|
boost::shared_mutex _state_lock;
|
||||||
|
|
|
@ -239,7 +239,7 @@ bladerf_sink_c::~bladerf_sink_c ()
|
||||||
|
|
||||||
/* Ensure work() or callbacks return from wait() calls */
|
/* Ensure work() or callbacks return from wait() calls */
|
||||||
_buf_status_lock.lock();
|
_buf_status_lock.lock();
|
||||||
_samp_avail.notify_all();
|
_buffer_filled.notify_all();
|
||||||
_buffer_emptied.notify_all();
|
_buffer_emptied.notify_all();
|
||||||
_buf_status_lock.unlock();
|
_buf_status_lock.unlock();
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ void *bladerf_sink_c::get_next_buffer( void *samples, size_t num_samples)
|
||||||
|
|
||||||
/* Wait for our next buffer to become filled */
|
/* Wait for our next buffer to become filled */
|
||||||
while ((running = is_running()) && !_filled[_next_to_tx]) {
|
while ((running = is_running()) && !_filled[_next_to_tx]) {
|
||||||
_samp_avail.wait(lock);
|
_buffer_filled.wait(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (running) {
|
if (running) {
|
||||||
|
@ -363,7 +363,7 @@ int bladerf_sink_c::work( int noutput_items,
|
||||||
_samples_left = _samples_per_buffer;
|
_samples_left = _samples_per_buffer;
|
||||||
|
|
||||||
/* Signal that we have filled a buffer */
|
/* Signal that we have filled a buffer */
|
||||||
_samp_avail.notify_one();
|
_buffer_filled.notify_one();
|
||||||
|
|
||||||
/* Wait here if the next buffer isn't full. The callback will
|
/* Wait here if the next buffer isn't full. The callback will
|
||||||
* signal us when it has freed up a buffer */
|
* signal us when it has freed up a buffer */
|
||||||
|
|
|
@ -126,16 +126,16 @@ private: /* members */
|
||||||
bool *_filled;
|
bool *_filled;
|
||||||
|
|
||||||
/* Acquire while updating _filled, and signalling/waiting on
|
/* Acquire while updating _filled, and signalling/waiting on
|
||||||
* _buffer_emptied and _samples_avail */
|
* _buffer_emptied and _buffer_filled */
|
||||||
boost::mutex _buf_status_lock;
|
boost::mutex _buf_status_lock;
|
||||||
|
|
||||||
/* wait() may block waiting for the TX callbacks to make a buffer availble.
|
/* work() may block waiting for the stream callback to empty (consume) a
|
||||||
* The callback uses this to signal when it has emptied out a buffer. */
|
* buffer. The callback uses this to signal when it has emptied a buffer. */
|
||||||
boost::condition_variable _buffer_emptied;
|
boost::condition_variable _buffer_emptied;
|
||||||
|
|
||||||
/* The parent's _samples_avail is used to denote that work() has
|
/* The stream callback may block waiting for work() to fill (produce) a
|
||||||
* filled a buffer, unblocking a TX callback that's waiting for samples */
|
* buffer. work() uses this to signal that it has filled a buffer. */
|
||||||
|
boost::condition_variable _buffer_filled;
|
||||||
|
|
||||||
/* These values are only to be updated and accessed from within work() */
|
/* These values are only to be updated and accessed from within work() */
|
||||||
int16_t *_next_value; /* I/Q value insertion point in current buffer */
|
int16_t *_next_value; /* I/Q value insertion point in current buffer */
|
||||||
|
|
|
@ -39,6 +39,14 @@
|
||||||
#include "arg_helpers.h"
|
#include "arg_helpers.h"
|
||||||
#include "bladerf_source_c.h"
|
#include "bladerf_source_c.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Default size of sample FIFO, in entries.
|
||||||
|
*/
|
||||||
|
#define BLADERF_SAMPLE_FIFO_SIZE (2 * 1024 * 1024)
|
||||||
|
|
||||||
|
#define BLADERF_SAMPLE_FIFO_MIN_SIZE (3 * BLADERF_SAMPLE_BLOCK_SIZE)
|
||||||
|
|
||||||
|
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -74,6 +82,7 @@ bladerf_source_c::bladerf_source_c (const std::string &args)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned int device_number = 0;
|
unsigned int device_number = 0;
|
||||||
|
size_t fifo_size;
|
||||||
std::string device_name;
|
std::string device_name;
|
||||||
|
|
||||||
dict_t dict = params_to_dict(args);
|
dict_t dict = params_to_dict(args);
|
||||||
|
@ -101,6 +110,29 @@ bladerf_source_c::bladerf_source_c (const std::string &args)
|
||||||
"failed to open bladeRF device " + device_name );
|
"failed to open bladeRF device " + device_name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Size of FIFO gr_complex samples, in # samples. */
|
||||||
|
fifo_size = BLADERF_SAMPLE_FIFO_SIZE;
|
||||||
|
if (dict.count("fifo")) {
|
||||||
|
try {
|
||||||
|
fifo_size = boost::lexical_cast<size_t>(dict["fifo"]);
|
||||||
|
} catch (const boost::bad_lexical_cast &e) {
|
||||||
|
std::cerr << "Warning: \"fifo\" value is invalid. Defaulting to "
|
||||||
|
<< fifo_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fifo_size < BLADERF_SAMPLE_FIFO_MIN_SIZE) {
|
||||||
|
fifo_size = BLADERF_SAMPLE_FIFO_MIN_SIZE;
|
||||||
|
std::cerr << "Warning: \"fifo\" value is too small. Defaulting to "
|
||||||
|
<< BLADERF_SAMPLE_FIFO_MIN_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_fifo = new boost::circular_buffer<gr_complex>(fifo_size);
|
||||||
|
if (!_fifo) {
|
||||||
|
throw std::runtime_error( std::string(__FUNCTION__) +
|
||||||
|
" has failed to allocate a sample FIFO!" );
|
||||||
|
}
|
||||||
|
|
||||||
if (dict.count("fw"))
|
if (dict.count("fw"))
|
||||||
{
|
{
|
||||||
std::string fw = dict["fw"];
|
std::string fw = dict["fw"];
|
||||||
|
@ -211,6 +243,8 @@ bladerf_source_c::~bladerf_source_c ()
|
||||||
|
|
||||||
/* Release stream resources */
|
/* Release stream resources */
|
||||||
bladerf_deinit_stream(_stream);
|
bladerf_deinit_stream(_stream);
|
||||||
|
|
||||||
|
delete _fifo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *bladerf_source_c::stream_callback( struct bladerf *dev,
|
void *bladerf_source_c::stream_callback( struct bladerf *dev,
|
||||||
|
|
|
@ -120,6 +120,17 @@ private: /* functions */
|
||||||
|
|
||||||
private: /* members */
|
private: /* members */
|
||||||
osmosdr::gain_range_t _lna_range;
|
osmosdr::gain_range_t _lna_range;
|
||||||
|
|
||||||
|
/* The stream callback converts SC16Q12 samples from the bladeRF to gr_complex
|
||||||
|
* values, and adds them to this FIFO. work() fetches the gr_complex values
|
||||||
|
* from this queue */
|
||||||
|
boost::circular_buffer<gr_complex> *_fifo;
|
||||||
|
boost::mutex _fifo_lock;
|
||||||
|
|
||||||
|
/* work() will block if the stream callback hasn't produced samples. The
|
||||||
|
* callback uses this to notify work of the availability of samples */
|
||||||
|
boost::condition_variable _samp_avail;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* INCLUDED_BLADERF_SOURCE_C_H */
|
#endif /* INCLUDED_BLADERF_SOURCE_C_H */
|
||||||
|
|
Loading…
Reference in New Issue