USRP Hardware Driver and USRP Manual  Version: 003.008.002-0-ge9d11b35
UHD and USRP Manual
nirio_fifo.h
Go to the documentation of this file.
1 //
2 // Copyright 2013-2014 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 
19 #ifndef INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_FIFO_H
20 #define INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_FIFO_H
21 
22 #include <stdint.h>
26 #include <boost/noncopyable.hpp>
27 #include <boost/smart_ptr.hpp>
28 #include <string>
29 #include <boost/thread/recursive_mutex.hpp>
30 #include <boost/thread/thread.hpp>
31 
32 namespace uhd { namespace niusrprio {
33 
37  uint32_t width;
38 };
39 
40 template <typename data_t>
41 class nirio_fifo : private boost::noncopyable
42 {
43 public:
44  typedef boost::shared_ptr< nirio_fifo<data_t> > sptr;
45 
46  nirio_fifo(
47  niriok_proxy::sptr riok_proxy,
48  fifo_direction_t direction,
49  const std::string& name,
50  uint32_t fifo_instance);
51  virtual ~nirio_fifo();
52 
53  nirio_status initialize(
54  const size_t requested_depth,
55  size_t& actual_depth,
56  size_t& actual_size);
57 
58  void finalize();
59 
60  inline const std::string& get_name() const { return _name; }
61  inline uint32_t get_channel() const { return _fifo_channel; }
62  inline uint32_t get_direction() const { return _fifo_direction; }
63  inline uint32_t get_scalar_type() const { return _datatype_info.scalar_type; }
64 
65  nirio_status start();
66 
67  nirio_status stop();
68 
69  nirio_status acquire(
70  data_t*& elements,
71  const size_t elements_requested,
72  const uint32_t timeout,
73  size_t& elements_acquired,
74  size_t& elements_remaining);
75 
76  nirio_status release(const size_t elements);
77 
78  nirio_status read(
79  data_t* buf,
80  const uint32_t num_elements,
81  uint32_t timeout,
82  uint32_t& num_read,
83  uint32_t& num_remaining);
84 
85  nirio_status write(
86  const data_t* buf,
87  const uint32_t num_elements,
88  uint32_t timeout,
89  uint32_t& num_remaining);
90 
91 private: //Methods
92  datatype_info_t _get_datatype_info();
93  nirio_status _get_transfer_count(uint64_t& transfer_count);
94  nirio_status _ensure_transfer_completed(uint32_t timeout_ms);
95 
96 private: //Members
97  enum fifo_state_t {
98  UNMAPPED, MAPPED, STARTED
99  };
100 
101  std::string _name;
102  fifo_direction_t _fifo_direction;
103  uint32_t _fifo_channel;
104  datatype_info_t _datatype_info;
105  fifo_state_t _state;
106  size_t _acquired_pending;
108  boost::recursive_mutex _mutex;
109  niriok_proxy::sptr _riok_proxy_ptr;
110 
111  uint64_t _expected_xfer_count;
112  uint32_t _dma_base_addr;
113 
114  static const uint32_t FIFO_LOCK_TIMEOUT_IN_MS = 5000;
115 };
116 
117 #include "nirio_fifo.ipp"
118 
119 }}
120 
121 #endif /* INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_FIFO_H */
boost::shared_ptr< niriok_proxy > sptr
Definition: niriok_proxy.h:168
Definition: nirio_fifo.h:34
const std::string & get_name() const
Definition: nirio_fifo.h:60
uint32_t get_scalar_type() const
Definition: nirio_fifo.h:63
nirio_scalar_type_t
Definition: niriok_proxy.h:81
virtual ~nirio_fifo()
Definition: nirio_fifo.h:51
Definition: convert.hpp:28
uint32_t get_channel() const
Definition: nirio_fifo.h:61
Definition: nirio_driver_iface.h:130
int32_t nirio_status
Definition: status.h:31
uint32_t width
Definition: nirio_fifo.h:37
uint32_t get_direction() const
Definition: nirio_fifo.h:62
datatype_info_t(nirio_scalar_type_t t, uint32_t w)
Definition: nirio_fifo.h:35
fifo_direction_t
Definition: niriok_proxy.h:108
nirio_scalar_type_t scalar_type
Definition: nirio_fifo.h:36
Definition: nirio_fifo.h:41
boost::shared_ptr< nirio_fifo< data_t > > sptr
Definition: nirio_fifo.h:44