Imported Upstream version 3.2.2
[debian/gnuradio] / gr-usrp2 / src / usrp2_base.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008,2009 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef INCLUDED_USRP2_BASE_H
24 #define INCLUDED_USRP2_BASE_H
25
26 #include <gr_sync_block.h>
27 #include <usrp2/usrp2.h>
28 #include <stdexcept>
29
30 // BIG ASS FIXME: get from lower layer MTU calculation
31 #define USRP2_MIN_RX_SAMPLES 371
32
33 /*!
34  * Base class for all USRP2 blocks
35  */
36 class usrp2_base : public gr_sync_block
37 {
38 protected:
39   usrp2_base(const char *name,
40              gr_io_signature_sptr input_signature,
41              gr_io_signature_sptr output_signature,
42              const std::string &ifc,
43              const std::string &mac)
44     throw (std::runtime_error);
45
46   usrp2::usrp2::sptr d_u2;
47
48 public:
49   ~usrp2_base();
50
51   /*!
52    * \brief Get USRP2 hardware MAC address
53    */
54   std::string mac_addr() const;
55   
56   /*!
57    * \brief Get interface name used to communicat with USRP2
58    */
59   std::string interface_name() const;
60
61   /*!
62    * \brief Get USRP2 master clock rate
63    */
64   bool fpga_master_clock_freq(long *freq) const;
65
66   /*!
67    * \brief MIMO configuration
68    */
69   bool config_mimo(int flags);
70   
71   /*!
72    * \brief Set master time to 0 at next PPS rising edge
73    */
74   bool sync_to_pps();
75
76   /*!
77    * Reset master time to 0 at every PPS edge
78    */
79   bool sync_every_pps(bool enable);
80
81   /*!
82    * \brief Read memory from Wishbone bus as words
83    */
84   std::vector<uint32_t> peek32(uint32_t addr, uint32_t words);
85
86   /*!
87    * \brief Write memory to Wishbone bus as words
88    */
89   bool poke32(uint32_t addr, const std::vector<uint32_t> &data);
90
91   /*!
92    * \brief Called by scheduler when starting flowgraph
93    */
94   virtual bool start();
95   
96   /*!
97    * \brief Called by scheduler when stopping flowgraph
98    */
99   virtual bool stop();
100
101   /*!
102    * \brief Derived class must override this
103    */
104   virtual int work(int noutput_items,
105                    gr_vector_const_void_star &input_items,
106                    gr_vector_void_star &output_items) = 0;
107 };
108
109 #endif /* INCLUDED_USRP2_BASE_H */