GNU Radio Manual and C++ API Reference 3.10.2.0
The Free & Open Software Radio Ecosystem
device_source_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2014 Analog Devices Inc.
4 * Author: Paul Cercueil <paul.cercueil@analog.com>
5 *
6 * SPDX-License-Identifier: GPL-3.0-or-later
7 *
8 */
9
10#ifndef INCLUDED_IIO_DEVICE_SOURCE_IMPL_H
11#define INCLUDED_IIO_DEVICE_SOURCE_IMPL_H
12
14#include <iio.h>
15
16#include <condition_variable>
17#include <mutex>
18#include <string>
19#include <thread>
20#include <vector>
21
22namespace gr {
23namespace iio {
24
25struct ctxInfo {
26 std::string uri;
27 iio_context* ctx;
28 int count;
29};
30
32static std::vector<ctxInfo> contexts;
33
34typedef std::vector<ctxInfo>::iterator ctx_it;
35
37{
38private:
39 void channel_read(const iio_channel* chn, void* dst, size_t len);
40
41 /*std::condition_variable iio_cond, iio_cond2;*/
42 std::mutex iio_mutex;
43 std::thread refill_thd;
44
45 unsigned long items_in_buffer;
46 off_t byte_offset;
47 volatile bool please_refill_buffer;
48 pmt::pmt_t port_id;
49
50 unsigned long timeout;
51
52 pmt::pmt_t d_len_tag_key;
53
54 void refill_thread();
55
56protected:
57 iio_context* ctx;
58 iio_device *dev, *phy;
59 iio_buffer* buf;
60 std::vector<iio_channel*> channel_list;
61 unsigned int buffer_size;
62 unsigned int decimation;
64 volatile bool thread_stopped;
66
67
68public:
69 device_source_impl(iio_context* ctx,
70 bool destroy_ctx,
71 const std::string& device,
72 const std::vector<std::string>& channels,
73 const std::string& device_phy,
74 const iio_param_vec_t& params,
75 unsigned int buffer_size = DEFAULT_BUFFER_SIZE,
76 unsigned int decimation = 0);
77
79
80 static void set_params(iio_device* phy, const iio_param_vec_t& params);
81
82 void set_len_tag_key(const std::string& len_tag_key) override;
83
84 void set_params(const iio_param_vec_t& params);
85 void set_buffer_size(unsigned int buffer_size);
86 void set_timeout_ms(unsigned long timeout);
87
88 // Where all the action really happens
89 int work(int noutput_items,
90 gr_vector_const_void_star& input_items,
91 gr_vector_void_star& output_items);
92
93 bool start();
94 bool stop();
95
96 static void remove_ctx_history(iio_context* ctx, bool destroy_ctx);
97
98 static iio_context* get_context(const std::string& uri);
99 static bool load_fir_filter(std::string& filter, iio_device* phy);
100 static int handle_decimation_interpolation(unsigned long samplerate,
101 const char* channel_name,
102 const char* attr_name,
103 iio_device* dev,
104 bool disable_dec,
105 bool output_chan);
106};
107
108} // namespace iio
109} // namespace gr
110
111#endif /* INCLUDED_IIO_DEVICE_SOURCE_IMPL_H */
Definition: device_source_impl.h:37
void set_timeout_ms(unsigned long timeout)
bool start()
Called to enable drivers, etc for i/o devices.
iio_device * dev
Definition: device_source_impl.h:58
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
just like gr::block::general_work, only this arranges to call consume_each for you
static int handle_decimation_interpolation(unsigned long samplerate, const char *channel_name, const char *attr_name, iio_device *dev, bool disable_dec, bool output_chan)
volatile bool thread_stopped
Definition: device_source_impl.h:64
void set_params(const iio_param_vec_t &params)
void set_buffer_size(unsigned int buffer_size)
Number of samples to be put into each IIO buffered passed to hardware.
iio_device * phy
Definition: device_source_impl.h:58
uint16_t override_tagged_output_channels
Definition: device_source_impl.h:65
void set_len_tag_key(const std::string &len_tag_key) override
Key of the packet length tag. If empty no tag will be emitted.
static bool load_fir_filter(std::string &filter, iio_device *phy)
unsigned int decimation
Definition: device_source_impl.h:62
bool destroy_ctx
Definition: device_source_impl.h:63
device_source_impl(iio_context *ctx, bool destroy_ctx, const std::string &device, const std::vector< std::string > &channels, const std::string &device_phy, const iio_param_vec_t &params, unsigned int buffer_size=DEFAULT_BUFFER_SIZE, unsigned int decimation=0)
bool stop()
Called to disable drivers, etc for i/o devices.
iio_context * ctx
Definition: device_source_impl.h:57
static void remove_ctx_history(iio_context *ctx, bool destroy_ctx)
static void set_params(iio_device *phy, const iio_param_vec_t &params)
unsigned int buffer_size
Definition: device_source_impl.h:61
iio_buffer * buf
Definition: device_source_impl.h:59
static iio_context * get_context(const std::string &uri)
std::vector< iio_channel * > channel_list
Definition: device_source_impl.h:60
Generic source for IIO drivers with buffered output channels.
Definition: device_source.h:37
#define DEFAULT_BUFFER_SIZE
Definition: device_sink.h:20
std::vector< iio_param_t > iio_param_vec_t
Definition: iio_types.h:44
static std::vector< ctxInfo > contexts
Definition: device_source_impl.h:32
std::vector< ctxInfo >::iterator ctx_it
Definition: device_source_impl.h:34
static std::mutex ctx_mutex
Definition: device_source_impl.h:31
boost::mutex mutex
Definition: thread.h:37
boost::thread thread
Definition: thread.h:36
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:84
Definition: device_source_impl.h:25
int count
Definition: device_source_impl.h:28
std::string uri
Definition: device_source_impl.h:26
iio_context * ctx
Definition: device_source_impl.h:27
std::vector< const void * > gr_vector_const_void_star
Definition: types.h:28
std::vector< void * > gr_vector_void_star
Definition: types.h:27