aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bladerf
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bladerf')
-rw-r--r--lib/bladerf/CMakeLists.txt26
-rw-r--r--lib/bladerf/bladerf_common.cc24
-rw-r--r--lib/bladerf/bladerf_common.h11
-rw-r--r--lib/bladerf/bladerf_compat.h2
-rw-r--r--lib/bladerf/bladerf_sink_c.cc25
-rw-r--r--lib/bladerf/bladerf_source_c.cc14
6 files changed, 52 insertions, 50 deletions
diff --git a/lib/bladerf/CMakeLists.txt b/lib/bladerf/CMakeLists.txt
index ea9cf49..c253a22 100644
--- a/lib/bladerf/CMakeLists.txt
+++ b/lib/bladerf/CMakeLists.txt
@@ -1,19 +1,19 @@
# Copyright 2013 Free Software Foundation, Inc.
#
-# This file is part of gr-osmosdr
+# This file is part of GNU Radio
#
-# gr-osmosdr is free software; you can redistribute it and/or modify
+# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
-# gr-osmosdr is distributed in the hope that it will be useful,
+# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with gr-osmosdr; see the file COPYING. If not, write to
+# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
@@ -21,20 +21,20 @@
# This file included, use CMake directory variables
########################################################################
-target_include_directories(gnuradio-osmosdr PRIVATE
+include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${LIBBLADERF_INCLUDE_DIRS}
- ${Volk_INCLUDE_DIRS}
+ ${VOLK_INCLUDE_DIRS}
)
-APPEND_LIB_LIST(
- ${LIBBLADERF_LIBRARIES}
- ${Volk_LIBRARIES}
-)
-
-list(APPEND gr_osmosdr_srcs
+set(bladerf_srcs
${CMAKE_CURRENT_SOURCE_DIR}/bladerf_source_c.cc
${CMAKE_CURRENT_SOURCE_DIR}/bladerf_sink_c.cc
${CMAKE_CURRENT_SOURCE_DIR}/bladerf_common.cc
)
-set(gr_osmosdr_srcs ${gr_osmosdr_srcs} PARENT_SCOPE)
+
+########################################################################
+# Append gnuradio-osmosdr library sources
+########################################################################
+list(APPEND gr_osmosdr_srcs ${bladerf_srcs})
+list(APPEND gr_osmosdr_libs ${LIBBLADERF_LIBRARIES} ${VOLK_LIBRARIES})
diff --git a/lib/bladerf/bladerf_common.cc b/lib/bladerf/bladerf_common.cc
index 67bf736..93b039d 100644
--- a/lib/bladerf/bladerf_common.cc
+++ b/lib/bladerf/bladerf_common.cc
@@ -35,8 +35,10 @@
#include <string>
#include <boost/assign.hpp>
+#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/weak_ptr.hpp>
#include "bladerf_common.h"
@@ -48,8 +50,8 @@ static size_t const STREAM_TIMEOUT_MS = 3000;
using namespace boost::assign;
-std::mutex bladerf_common::_devs_mutex;
-std::list<std::weak_ptr<struct bladerf>> bladerf_common::_devs;
+boost::mutex bladerf_common::_devs_mutex;
+std::list<boost::weak_ptr<struct bladerf> > bladerf_common::_devs;
/* name for system-wide gain (which is not its own libbladeRF gain stage) */
static const char *SYSTEM_GAIN_NAME = "system";
@@ -133,7 +135,7 @@ size_t num_streams(bladerf_channel_layout layout)
* Public methods
******************************************************************************/
bladerf_common::bladerf_common() :
- _dev(NULL),
+ _dev(boost::shared_ptr<struct bladerf>()),
_pfx("[bladeRF common] "),
_failures(0),
_num_buffers(NUM_BUFFERS),
@@ -497,7 +499,7 @@ int bladerf_common::channel2rfport(bladerf_channel ch)
bladerf_channel bladerf_common::chan2channel(bladerf_direction direction,
size_t chan)
{
- for (bladerf_channel_map::value_type &i : _chanmap) {
+ BOOST_FOREACH(bladerf_channel_map::value_type &i, _chanmap) {
bladerf_channel ch = i.first;
if (
(i.second == (int)chan) && (
@@ -641,7 +643,7 @@ osmosdr::freq_range_t bladerf_common::filter_bandwidths(bladerf_channel ch)
0.75, 0.875, 1.25, 1.375, 1.5, 1.92, 2.5,
2.75, 3, 3.5, 4.375, 5, 6, 7, 10, 14;
- for (double half_bw : half_bandwidths)
+ BOOST_FOREACH( double half_bw, half_bandwidths )
bandwidths += osmosdr::range_t( half_bw * 2e6 );
#else
@@ -1077,7 +1079,7 @@ bladerf_sptr bladerf_common::open(std::string const &device_name)
struct bladerf *raw_dev = NULL;
struct bladerf_devinfo devinfo;
- std::lock_guard<std::mutex> lock(_devs_mutex);
+ boost::unique_lock<boost::mutex> lock(_devs_mutex);
/* Initialize the information used to identify the desired device
* to all wildcard (i.e., "any device") values */
@@ -1107,15 +1109,15 @@ bladerf_sptr bladerf_common::open(std::string const &device_name)
/* Add the device handle to our cache */
bladerf_sptr dev = bladerf_sptr(raw_dev, bladerf_common::close);
- _devs.push_back(static_cast<std::weak_ptr<struct bladerf>>(dev));
+ _devs.push_back(static_cast<boost::weak_ptr<struct bladerf> >(dev));
return dev;
}
void bladerf_common::close(void *dev)
{
- std::lock_guard<std::mutex> lock(_devs_mutex);
- std::list<std::weak_ptr<struct bladerf>>::iterator it(_devs.begin());
+ boost::unique_lock<boost::mutex> lock(_devs_mutex);
+ std::list<boost::weak_ptr<struct bladerf> >::iterator it(_devs.begin());
/* Prune expired entries from device cache */
while (it != _devs.end()) {
@@ -1135,7 +1137,7 @@ bladerf_sptr bladerf_common::get_cached_device(struct bladerf_devinfo devinfo)
int status;
struct bladerf_devinfo other_devinfo;
- for (std::weak_ptr<struct bladerf> dev : _devs) {
+ BOOST_FOREACH(boost::weak_ptr<struct bladerf> dev, _devs) {
status = bladerf_get_devinfo(bladerf_sptr(dev).get(), &other_devinfo);
if (status < 0) {
BLADERF_THROW_STATUS(status, "Failed to get devinfo for cached device");
@@ -1198,7 +1200,7 @@ void bladerf_common::print_device_info()
bool bladerf_common::is_antenna_valid(bladerf_direction dir,
const std::string &antenna)
{
- for (std::string ant : get_antennas(dir)) {
+ BOOST_FOREACH(std::string ant, get_antennas(dir)) {
if (antenna == ant) {
return true;
}
diff --git a/lib/bladerf/bladerf_common.h b/lib/bladerf/bladerf_common.h
index 741b1e7..51dedc9 100644
--- a/lib/bladerf/bladerf_common.h
+++ b/lib/bladerf/bladerf_common.h
@@ -23,11 +23,12 @@
#include <list>
#include <map>
-#include <memory>
-#include <mutex>
#include <string>
#include <vector>
+#include <boost/thread/mutex.hpp>
+#include <boost/weak_ptr.hpp>
+
#include <libbladeRF.h>
#include "osmosdr/ranges.h"
@@ -42,7 +43,7 @@ typedef ptrdiff_t ssize_t;
#define BLADERF_DEBUG_ENABLE
-typedef std::shared_ptr<struct bladerf> bladerf_sptr;
+typedef boost::shared_ptr<struct bladerf> bladerf_sptr;
/* Identification of the bladeRF hardware in use */
typedef enum {
@@ -286,8 +287,8 @@ private:
/*****************************************************************************
* Private members
****************************************************************************/
- static std::mutex _devs_mutex; /**< mutex for access to _devs */
- static std::list<std::weak_ptr<struct bladerf>> _devs; /**< dev cache */
+ static boost::mutex _devs_mutex; /**< mutex for access to _devs */
+ static std::list<boost::weak_ptr<struct bladerf> > _devs; /**< dev cache */
};
#endif
diff --git a/lib/bladerf/bladerf_compat.h b/lib/bladerf/bladerf_compat.h
index 2ad24be..45e6a16 100644
--- a/lib/bladerf/bladerf_compat.h
+++ b/lib/bladerf/bladerf_compat.h
@@ -66,7 +66,7 @@
}
/* Changed enums/defines */
- #define BLADERF_GAIN_DEFAULT BLADERF_GAIN_AUTOMATIC
+ #define BLADERF_GAIN_DEFAULT BLADERF_GAIN_MANUAL
#define BLADERF_GAIN_MGC BLADERF_GAIN_MANUAL
#define BLADERF_RX_MUX_BASEBAND BLADERF_RX_MUX_BASEBAND_LMS
diff --git a/lib/bladerf/bladerf_sink_c.cc b/lib/bladerf/bladerf_sink_c.cc
index 6ee3acd..d3d607b 100644
--- a/lib/bladerf/bladerf_sink_c.cc
+++ b/lib/bladerf/bladerf_sink_c.cc
@@ -96,7 +96,7 @@ bladerf_sink_c::bladerf_sink_c(const std::string &args) :
}
/* Initialize channel <-> antenna map */
- for (std::string ant : get_antennas()) {
+ BOOST_FOREACH(std::string ant, get_antennas()) {
_chanmap[str2channel(ant)] = -1;
}
@@ -174,11 +174,9 @@ bool bladerf_sink_c::start()
for (size_t ch = 0; ch < get_max_channels(); ++ch) {
bladerf_channel brfch = BLADERF_CHANNEL_TX(ch);
- if (get_channel_enable(brfch)) {
- status = bladerf_enable_module(_dev.get(), brfch, true);
- if (status != 0) {
- BLADERF_THROW_STATUS(status, "bladerf_enable_module failed");
- }
+ status = bladerf_enable_module(_dev.get(), brfch, get_channel_enable(brfch));
+ if (status != 0) {
+ BLADERF_THROW_STATUS(status, "bladerf_enable_module failed");
}
}
@@ -210,11 +208,9 @@ bool bladerf_sink_c::stop()
for (size_t ch = 0; ch < get_max_channels(); ++ch) {
bladerf_channel brfch = BLADERF_CHANNEL_TX(ch);
- if (get_channel_enable(brfch)) {
- status = bladerf_enable_module(_dev.get(), brfch, false);
- if (status != 0) {
- BLADERF_THROW_STATUS(status, "bladerf_enable_module failed");
- }
+ status = bladerf_enable_module(_dev.get(), brfch, get_channel_enable(brfch));
+ if (status != 0) {
+ BLADERF_THROW_STATUS(status, "bladerf_enable_module failed");
}
}
@@ -241,6 +237,11 @@ int bladerf_sink_c::work(int noutput_items,
return 0;
}
+ noutput_items &= ~(3ULL);
+ if (!noutput_items) {
+ return 0;
+ }
+
// copy the samples from input_items
gr_complex const **in = reinterpret_cast<gr_complex const **>(&input_items[0]);
@@ -329,7 +330,7 @@ int bladerf_sink_c::transmit_with_tags(int16_t const *samples,
}
}
- for (gr::tag_t tag : tags) {
+ BOOST_FOREACH(gr::tag_t tag, tags) {
// Upon seeing an SOB tag, update our offset. We'll TX the start of the
// burst when we see an EOB or at the end of this function - whichever
// occurs first.
diff --git a/lib/bladerf/bladerf_source_c.cc b/lib/bladerf/bladerf_source_c.cc
index 83db677..e37bd67 100644
--- a/lib/bladerf/bladerf_source_c.cc
+++ b/lib/bladerf/bladerf_source_c.cc
@@ -144,7 +144,7 @@ bladerf_source_c::bladerf_source_c(const std::string &args) :
}
/* Initialize channel <-> antenna map */
- for (std::string ant : get_antennas()) {
+ BOOST_FOREACH(std::string ant, get_antennas()) {
_chanmap[str2channel(ant)] = -1;
}
@@ -180,7 +180,7 @@ bladerf_source_c::bladerf_source_c(const std::string &args) :
bool bladerf_source_c::is_antenna_valid(const std::string &antenna)
{
- for (std::string ant : get_antennas()) {
+ BOOST_FOREACH(std::string ant, get_antennas()) {
if (antenna == ant) {
return true;
}
@@ -230,11 +230,9 @@ bool bladerf_source_c::start()
for (size_t ch = 0; ch < get_max_channels(); ++ch) {
bladerf_channel brfch = BLADERF_CHANNEL_RX(ch);
- if (get_channel_enable(brfch)) {
- status = bladerf_enable_module(_dev.get(), brfch, true);
- if (status != 0) {
- BLADERF_THROW_STATUS(status, "bladerf_enable_module failed");
- }
+ status = bladerf_enable_module(_dev.get(), brfch, get_channel_enable(brfch));
+ if (status != 0) {
+ BLADERF_THROW_STATUS(status, "bladerf_enable_module failed");
}
}
@@ -344,7 +342,7 @@ int bladerf_source_c::work(int noutput_items,
memcpy(out[0], _32fcbuf, sizeof(gr_complex) * noutput_items);
}
- return noutput_items;
+ return noutput_items/(get_num_channels());
}
osmosdr::meta_range_t bladerf_source_c::get_sample_rates()