GNU Radio's IIO Package
eightbit_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_EIGHTBIT_SOURCE_IMPL_H
23 #define INCLUDED_IIO_EIGHTBIT_SOURCE_IMPL_H
24 
25 #include <string>
26 #include <vector>
27 
28 #include <iio.h>
29 #include <boost/thread.hpp>
30 #include <iio/eightbit_source.h>
31 
32 namespace gr {
33  namespace iio {
34 
35  struct ctxInfo{std::string uri; struct iio_context * ctx; int count;};
36  static std::vector<ctxInfo> contexts;
37  static boost::mutex ctx_mutex;
38 
39  typedef std::vector<ctxInfo>::iterator ctx_it;
40 
42  {
43  private:
44  void channel_read(const struct iio_channel *chn,
45  void *dst, size_t len);
46 
47  boost::mutex iio_mutex;
48  boost::condition_variable iio_cond, iio_cond2;
49  unsigned long items_in_buffer;
50  off_t byte_offset;
51  volatile bool please_refill_buffer, thread_stopped;
52  pmt::pmt_t port_id;
53 
54  boost::thread refill_thd;
55 
56  unsigned long timeout;
57 
58  void refill_thread();
59 
60  protected:
61  struct iio_context *ctx;
62  struct iio_device *dev, *phy;
63  struct iio_buffer *buf;
64  std::vector <struct iio_channel *> channel_list;
65  unsigned int buffer_size;
66  unsigned int decimation;
68 
69  public:
70  eightbit_source_impl(struct iio_context *ctx, bool destroy_ctx,
71  const std::string &device,
72  const std::vector<std::string> &channels,
73  const std::string &device_phy,
74  const std::vector<std::string> &params,
75  unsigned int buffer_size = DEFAULT_BUFFER_SIZE,
76  unsigned int decimation = 0);
78 
79  static void set_params(struct iio_device *phy,
80  const std::vector<std::string> &params);
81 
82  void set_params(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 void remove_ctx_history(struct iio_context *ctx, bool destroy_ctx);
95 
96  static struct iio_context * get_context(const std::string &uri);
97  static bool load_fir_filter(std::string &filter, struct iio_device *phy);
98  };
99 
100  } // namespace iio
101 } // namespace gr
102 
103 #endif /* INCLUDED_IIO_EIGHTBIT_SOURCE_IMPL_H */
struct iio_context * ctx
Definition: eightbit_source_impl.h:61
bool destroy_ctx
Definition: eightbit_source_impl.h:67
void set_timeout_ms(unsigned long timeout)
#define DEFAULT_BUFFER_SIZE
Definition: device_sink.h:29
std::vector< struct iio_channel * > channel_list
Definition: eightbit_source_impl.h:64
static std::vector< ctxInfo > contexts
Definition: device_source_impl.h:36
struct iio_device * phy
Definition: eightbit_source_impl.h:62
static boost::mutex ctx_mutex
Definition: device_source_impl.h:37
int count
Definition: device_source_impl.h:35
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
std::string uri
Definition: device_source_impl.h:35
struct iio_context * ctx
Definition: device_source_impl.h:35
Definition: attr_sink.h:29
std::vector< ctxInfo >::iterator ctx_it
Definition: device_source_impl.h:39
Definition: eightbit_source_impl.h:41
static bool load_fir_filter(std::string &filter, struct iio_device *phy)
<+description of block+>
Definition: eightbit_source.h:43
unsigned int decimation
Definition: eightbit_source_impl.h:66
static void set_params(struct iio_device *phy, const std::vector< std::string > &params)
eightbit_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)
struct iio_device * dev
Definition: eightbit_source_impl.h:62
void set_buffer_size(unsigned int buffer_size)
static void remove_ctx_history(struct iio_context *ctx, bool destroy_ctx)
static struct iio_context * get_context(const std::string &uri)
struct iio_buffer * buf
Definition: eightbit_source_impl.h:63
unsigned int buffer_size
Definition: eightbit_source_impl.h:65