GNU Radio's IIO Package
flexi_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  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this software; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef INCLUDED_IIO_FLEXI_SOURCE_IMPL_H
23 #define INCLUDED_IIO_FLEXI_SOURCE_IMPL_H
24 
25 #include <string>
26 #include <vector>
27 #include <map>
28 
29 #include <iio.h>
30 #include <boost/thread.hpp>
31 #include <iio/flexi_source.h>
32 
33 namespace gr {
34  namespace iio {
35 
36  static std::map<std::string,struct iio_context *> contexts;
37 
39  {
40  private:
41  void channel_read(const struct iio_channel *chn,
42  void *dst, size_t len);
43 
44  boost::mutex iio_mutex;
45  boost::condition_variable iio_cond, iio_cond2;
46  unsigned long items_in_buffer;
47  off_t byte_offset;
48  unsigned long sample_counter;
49  volatile bool please_refill_buffer, thread_stopped;
50  pmt::pmt_t port_id;
51 
52  boost::thread refill_thd;
53 
54  unsigned long timeout;
55 
56  void refill_thread();
57 
58  protected:
59  struct iio_context *ctx;
60  struct iio_device *dev, *phy;
61  struct iio_buffer *buf;
62  std::vector <struct iio_channel *> channel_list;
63  unsigned int buffer_size;
64  unsigned int decimation;
66 
67  public:
68  flexi_source_impl(struct iio_context *ctx, bool destroy_ctx,
69  const std::string &device,
70  const std::vector<std::string> &channels,
71  const std::string &device_phy,
72  const std::vector<std::string> &devparams,
73  const std::vector<std::string> &phyparams,
74  unsigned int buffer_size = DEFAULT_BUFFER_SIZE,
75  unsigned int decimation = 0);
77 
78  static void set_params(struct iio_device *phy,
79  const std::vector<std::string> &params);
80 
81  void set_devparams(const std::vector<std::string> &params);
82  void set_phyparams(const std::vector<std::string> &params);
83  void set_buffer_size(unsigned int buffer_size);
84  void set_timeout_ms(unsigned long timeout);
85 
86  // Where all the action really happens
87  int work(int noutput_items,
88  gr_vector_const_void_star &input_items,
89  gr_vector_void_star &output_items);
90 
91  bool start();
92  bool stop();
93 
94  static struct iio_context * get_context(const std::string &uri);
95  };
96 
97  } // namespace iio
98 } // namespace gr
99 
100 #endif /* INCLUDED_IIO_FLEXI_SOURCE_IMPL_H */
void set_phyparams(const std::vector< std::string > &params)
flexi_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 > &devparams, const std::vector< std::string > &phyparams, unsigned int buffer_size=DEFAULT_BUFFER_SIZE, unsigned int decimation=0)
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
Definition: flexi_source_impl.h:38
#define DEFAULT_BUFFER_SIZE
Definition: device_sink.h:29
static std::vector< ctxInfo > contexts
Definition: device_source_impl.h:36
unsigned int decimation
Definition: flexi_source_impl.h:64
unsigned int buffer_size
Definition: flexi_source_impl.h:63
struct iio_context * ctx
Definition: flexi_source_impl.h:59
void set_timeout_ms(unsigned long timeout)
Definition: attr_sink.h:29
void set_buffer_size(unsigned int buffer_size)
struct iio_buffer * buf
Definition: flexi_source_impl.h:61
<+description of block+>
Definition: flexi_source.h:43
struct iio_device * dev
Definition: flexi_source_impl.h:60
static struct iio_context * get_context(const std::string &uri)
bool destroy_ctx
Definition: flexi_source_impl.h:65
struct iio_device * phy
Definition: flexi_source_impl.h:60
void set_devparams(const std::vector< std::string > &params)
std::vector< struct iio_channel * > channel_list
Definition: flexi_source_impl.h:62
static void set_params(struct iio_device *phy, const std::vector< std::string > &params)