aboutsummaryrefslogtreecommitdiffstats
path: root/gr-iio/lib/device_source_impl.h
diff options
context:
space:
mode:
authorAdam Horden <adam.horden@horden.engineering>2021-02-22 22:22:40 +0000
committermormj <34754695+mormj@users.noreply.github.com>2021-06-04 06:21:34 -0400
commit6d3965f79d671afbb0b688620f3b4b218e02a352 (patch)
tree83a38f0c1795616509f4f7896da4f82e0ebce3e5 /gr-iio/lib/device_source_impl.h
parentgr-blocks: Add missing pybind11 binding for Phase Shift block. (diff)
downloadgnuradio-6d3965f79d671afbb0b688620f3b4b218e02a352.tar.xz
gnuradio-6d3965f79d671afbb0b688620f3b4b218e02a352.zip
feature: gr-iio
Co-authored-by: Edward Kigwana <ekigwana@scires.com> Co-authored-by: Travis Collins <travis.collins@analog.com> Signed-off-by: Adam Horden <adam.horden@horden.engineering>
Diffstat (limited to 'gr-iio/lib/device_source_impl.h')
-rw-r--r--gr-iio/lib/device_source_impl.h102
1 files changed, 102 insertions, 0 deletions
diff --git a/gr-iio/lib/device_source_impl.h b/gr-iio/lib/device_source_impl.h
new file mode 100644
index 000000000..07f331f23
--- /dev/null
+++ b/gr-iio/lib/device_source_impl.h
@@ -0,0 +1,102 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2014 Analog Devices Inc.
+ * Author: Paul Cercueil <paul.cercueil@analog.com>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#ifndef INCLUDED_IIO_DEVICE_SOURCE_IMPL_H
+#define INCLUDED_IIO_DEVICE_SOURCE_IMPL_H
+
+#include <string>
+#include <vector>
+
+#include <gnuradio/iio/device_source.h>
+#include <iio.h>
+#include <boost/thread.hpp>
+
+namespace gr {
+namespace iio {
+
+struct ctxInfo {
+ std::string uri;
+ struct iio_context* ctx;
+ int count;
+};
+static std::vector<ctxInfo> contexts;
+static boost::mutex ctx_mutex;
+
+typedef std::vector<ctxInfo>::iterator ctx_it;
+
+class device_source_impl : public device_source
+{
+private:
+ void channel_read(const struct iio_channel* chn, void* dst, size_t len);
+
+ boost::mutex iio_mutex;
+ boost::condition_variable iio_cond, iio_cond2;
+ unsigned long items_in_buffer;
+ off_t byte_offset;
+ volatile bool please_refill_buffer;
+ pmt::pmt_t port_id;
+
+ boost::thread refill_thd;
+
+ unsigned long timeout;
+
+ void refill_thread();
+
+protected:
+ struct iio_context* ctx;
+ struct iio_device *dev, *phy;
+ struct iio_buffer* buf;
+ std::vector<struct iio_channel*> channel_list;
+ unsigned int buffer_size;
+ unsigned int decimation;
+ bool destroy_ctx;
+ volatile bool thread_stopped;
+
+
+public:
+ device_source_impl(struct iio_context* ctx,
+ bool destroy_ctx,
+ const std::string& device,
+ const std::vector<std::string>& channels,
+ const std::string& device_phy,
+ const std::vector<std::string>& params,
+ unsigned int buffer_size = DEFAULT_BUFFER_SIZE,
+ unsigned int decimation = 0);
+ ~device_source_impl();
+
+ static void set_params(struct iio_device* phy,
+ const std::vector<std::string>& params);
+
+ void set_params(const std::vector<std::string>& params);
+ void set_buffer_size(unsigned int buffer_size);
+ void set_timeout_ms(unsigned long timeout);
+
+ // Where all the action really happens
+ int work(int noutput_items,
+ gr_vector_const_void_star& input_items,
+ gr_vector_void_star& output_items);
+
+ bool start();
+ bool stop();
+
+ static void remove_ctx_history(struct iio_context* ctx, bool destroy_ctx);
+
+ static struct iio_context* get_context(const std::string& uri);
+ static bool load_fir_filter(std::string& filter, struct iio_device* phy);
+ int handle_decimation_interpolation(unsigned long samplerate,
+ const char* channel_name,
+ const char* attr_name,
+ struct iio_device* dev,
+ bool disable_dec);
+};
+
+} // namespace iio
+} // namespace gr
+
+#endif /* INCLUDED_IIO_DEVICE_SOURCE_IMPL_H */