USRP Hardware Driver and USRP Manual  Version: 003.008.001-0-g2474ac32
UHD and USRP Manual
niriok_proxy.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 #ifndef INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_INTERFACE_H
19 #define INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_INTERFACE_H
20 
21 #include <stdint.h>
22 #include <boost/smart_ptr.hpp>
23 #include <boost/noncopyable.hpp>
24 #include <boost/thread/shared_mutex.hpp>
25 #include <boost/thread/locks.hpp>
28 
29 #define NI_VENDOR_NUM 0x1093
30 
31 #define VERSION_BUILD_SHIFT 0
32 #define VERSION_PHASE_SHIFT 14
33 #define VERSION_MAINT_SHIFT 16
34 #define VERSION_UPGRD_SHIFT 20
35 #define VERSION_MAJOR_SHIFT 24
36 #define VERSION_BUILD_MASK 0x00003FFF
37 #define VERSION_PHASE_MASK 0x0000C000
38 #define VERSION_MAINT_MASK 0x000F0000
39 #define VERSION_UPGRD_MASK 0x00F00000
40 #define VERSION_MAJOR_MASK 0xFF000000
41 
42 #define GET_FIFO_MEMORY_TYPE(fifo_inst) (static_cast<uint16_t>(0x0100 | static_cast<uint16_t>(fifo_inst)))
43 
44 #define READER_LOCK \
45  boost::shared_lock<boost::shared_mutex> reader_lock(_synchronization);
46 
47 #define WRITER_LOCK \
48  boost::upgrade_lock<boost::shared_mutex> write_upgrade_lock(_synchronization);\
49  boost::upgrade_to_unique_lock<boost::shared_mutex> write_unique_lock(write_upgrade_lock);
50 
51 
52 namespace uhd { namespace niusrprio
53 {
55 
57  INVALID = 0,
59  FPGA = 2,
61  };
62 
63  typedef uint64_t nirio_u64_t;
64  typedef uint32_t nirio_u32_t;
65  typedef uint16_t nirio_u16_t;
66  typedef uint8_t nirio_u8_t;
67  typedef int32_t nirio_i32_t;
68 
69  typedef enum {
70  RIO_PRODUCT_NUMBER = 2UL, // 200
71  RIO_CURRENT_VERSION = 14UL, // 220
73  RIO_ADDRESS_SPACE = 25UL, // 230
74  RIO_IS_FPGA_PROGRAMMED = 48UL, // 300
75  RIO_FPGA_DEFAULT_SIGNATURE_OFFSET = 53UL, // 300 Default Offsets for FPGA
76  // registers. Supplied by
77  // the board driver on device
78  // start.
80 
81  typedef enum {
91 
92  static inline nirio_scalar_type_t map_int_to_scalar_type(uint32_t scalar_type_as_int)
93  {
94  switch (scalar_type_as_int)
95  {
96  case 1: return RIO_SCALAR_TYPE_IB;
97  case 2: return RIO_SCALAR_TYPE_IW;
98  case 3: return RIO_SCALAR_TYPE_IL;
99  case 4: return RIO_SCALAR_TYPE_IQ;
100  case 5: return RIO_SCALAR_TYPE_UB;
101  case 6: return RIO_SCALAR_TYPE_UW;
102  case 7: return RIO_SCALAR_TYPE_UL;
103  case 8: return RIO_SCALAR_TYPE_UQ;
104  default: UHD_ASSERT_THROW(false); return RIO_SCALAR_TYPE_UL;
105  }
106  }
107 
111  };
112 
115  uint32_t arg_channel,
116  const char* arg_name,
117  fifo_direction_t arg_direction,
118  uint32_t arg_base_addr,
119  uint32_t arg_depth,
120  nirio_scalar_type_t arg_scalar_type,
121  uint32_t arg_bitWidth,
122  int32_t arg_integerWordLength,
123  uint32_t arg_version) :
124  channel(arg_channel),
125  name(arg_name),
126  direction(arg_direction),
127  base_addr(arg_base_addr),
128  depth(arg_depth),
129  scalar_type(arg_scalar_type),
130  bitWidth(arg_bitWidth),
131  integerWordLength(arg_integerWordLength),
132  version(arg_version)
133  {}
134 
135  uint32_t channel;
136  std::string name;
138  uint32_t base_addr;
139  uint32_t depth;
140  nirio_scalar_type_t scalar_type;
141  uint32_t bitWidth;
143  uint32_t version;
144  };
145 
146  class UHD_API niriok_proxy : public boost::noncopyable {
147  public:
150  void* const _outBuf,
151  const uint32_t _outSize,
152  const int32_t _statusCode)
153  {
154  outBuf._64BitField = 0;
155  outBuf.pointer = _outBuf;
156  outSize = _outSize;
157  statusCode = _statusCode;
158  };
159 
160  union {
161  void* pointer;
162  uint64_t _64BitField;
163  } outBuf;
164 
165  uint32_t outSize;
166  int32_t statusCode;
167  };
168  typedef boost::shared_ptr<niriok_proxy> sptr;
169 
170  static sptr make_and_open(const std::string& interface_path);
171 
172  niriok_proxy();
173  virtual ~niriok_proxy();
174 
175  //File operations
176  virtual nirio_status open(const std::string& interface_path) = 0;
177  virtual void close(void) = 0;
178 
179  virtual nirio_status reset() = 0;
180 
181  uint32_t get_interface_num() { return _interface_num; }
182 
183  virtual nirio_status get_cached_session(
184  uint32_t& session) = 0;
185 
186  virtual nirio_status get_version(
187  nirio_version_t type,
188  uint32_t& major,
189  uint32_t& upgrade,
190  uint32_t& maintenance,
191  char& phase,
192  uint32_t& build) = 0;
193 
194  virtual nirio_status get_attribute(
195  const nirio_device_attribute32_t attribute,
196  uint32_t& attrValue) = 0;
197 
198  virtual nirio_status set_attribute(
199  const nirio_device_attribute32_t attribute,
200  const uint32_t value) = 0;
201 
202  virtual nirio_status peek(uint32_t offset, uint32_t& value) = 0;
203 
204  virtual nirio_status peek(uint32_t offset, uint64_t& value) = 0;
205 
206  virtual nirio_status poke(uint32_t offset, const uint32_t& value) = 0;
207 
208  virtual nirio_status poke(uint32_t offset, const uint64_t& value) = 0;
209 
210  virtual nirio_status map_fifo_memory(
211  uint32_t fifo_instance,
212  size_t size,
214 
215  virtual nirio_status unmap_fifo_memory(
217 
218  virtual nirio_status stop_all_fifos() = 0;
219 
221  return _rio_quirks;
222  }
223 
224  virtual nirio_status add_fifo_resource(const nirio_fifo_info_t& fifo_info) = 0;
225 
226  virtual nirio_status set_device_config() = 0;
227 
228  virtual nirio_status start_fifo(
229  uint32_t channel) = 0;
230 
231  virtual nirio_status stop_fifo(
232  uint32_t channel) = 0;
233 
234  virtual nirio_status configure_fifo(
235  uint32_t channel,
236  uint32_t requested_depth,
237  uint8_t requires_actuals,
238  uint32_t& actual_depth,
239  uint32_t& actual_size) = 0;
240 
241  virtual nirio_status wait_on_fifo(
242  uint32_t channel,
243  uint32_t elements_requested,
244  uint32_t scalar_type,
245  uint32_t bit_width,
246  uint32_t timeout,
247  uint8_t output,
248  void*& data_pointer,
249  uint32_t& elements_acquired,
250  uint32_t& elements_remaining) = 0;
251 
252  virtual nirio_status grant_fifo(
253  uint32_t channel,
254  uint32_t elements_to_grant) = 0;
255 
256  virtual nirio_status read_fifo(
257  uint32_t channel,
258  uint32_t elements_to_read,
259  void* buffer,
260  uint32_t buffer_datatype_width,
261  uint32_t scalar_type,
262  uint32_t bit_width,
263  uint32_t timeout,
264  uint32_t& number_read,
265  uint32_t& number_remaining) = 0;
266 
267  virtual nirio_status write_fifo(
268  uint32_t channel,
269  uint32_t elements_to_write,
270  void* buffer,
271  uint32_t buffer_datatype_width,
272  uint32_t scalar_type,
273  uint32_t bit_width,
274  uint32_t timeout,
275  uint32_t& number_remaining) = 0;
276 
277  protected: //Members
279  uint32_t _interface_num;
281 
282  static boost::shared_mutex _synchronization;
283 
284  // protected close function that doesn't acquire synchronization lock
285  virtual void _close() = 0;
286  };
287 
288  class niriok_scoped_addr_space : public boost::noncopyable {
289  public:
291  driver_proxy(proxy)
292  {
293  cache_status = driver_proxy->get_attribute(RIO_ADDRESS_SPACE, cached_addr_space);
294  nirio_status_chain(driver_proxy->set_attribute(RIO_ADDRESS_SPACE, addr_space), status);
295  }
296 
298  if (nirio_status_not_fatal(cache_status))
299  driver_proxy->set_attribute(RIO_ADDRESS_SPACE, cached_addr_space);
300  }
301 
302  private:
303  niriok_proxy::sptr driver_proxy;
304  uint32_t cached_addr_space;
305  nirio_status cache_status;
306  };
307 }}
308 
309 #endif /* INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_INTERFACE_H */
void * pointer
Definition: niriok_proxy.h:161
Definition: niriok_proxy.h:88
Definition: niriok_proxy.h:109
Definition: niriok_proxy.h:58
Definition: niriok_proxy.h:74
int32_t nirio_i32_t
Definition: niriok_proxy.h:67
Definition: niriok_proxy.h:84
nirio_version_t
Definition: niriok_proxy.h:54
boost::shared_ptr< niriok_proxy > sptr
Definition: niriok_proxy.h:168
nirio_ioctl_packet_t(void *const _outBuf, const uint32_t _outSize, const int32_t _statusCode)
Definition: niriok_proxy.h:149
Definition: niriok_proxy.h:288
uint64_t nirio_u64_t
Definition: niriok_proxy.h:63
Definition: niriok_proxy.h:54
nirio_quirks _rio_quirks
Definition: niriok_proxy.h:280
Definition: nirio_quirks.h:33
io_connect_t rio_dev_handle_t
Definition: nirio_driver_iface.h:85
Definition: niriok_proxy.h:87
nirio_addr_space_t
Definition: niriok_proxy.h:56
Definition: niriok_proxy.h:70
niriok_scoped_addr_space(niriok_proxy::sptr proxy, nirio_addr_space_t addr_space, nirio_status &status)
Definition: niriok_proxy.h:290
#define UHD_ASSERT_THROW(code)
Definition: exception.hpp:160
uint32_t nirio_u32_t
Definition: niriok_proxy.h:64
std::string name
Definition: niriok_proxy.h:136
Definition: niriok_proxy.h:113
uint32_t outSize
Definition: niriok_proxy.h:165
#define UHD_API
Definition: config.hpp:79
uint32_t get_interface_num()
Definition: niriok_proxy.h:181
nirio_scalar_type_t
Definition: niriok_proxy.h:81
Definition: convert.hpp:28
~niriok_scoped_addr_space()
Definition: niriok_proxy.h:297
Definition: niriok_proxy.h:85
uint32_t _interface_num
Definition: niriok_proxy.h:279
uint32_t version
Definition: niriok_proxy.h:143
Definition: niriok_proxy.h:71
Definition: nirio_driver_iface.h:130
uint64_t _64BitField
Definition: niriok_proxy.h:162
int32_t nirio_status
Definition: status.h:30
static boost::shared_mutex _synchronization
Definition: niriok_proxy.h:282
#define nirio_status_not_fatal(status)
Definition: status.h:49
Definition: niriok_proxy.h:82
Definition: niriok_proxy.h:59
#define nirio_status_chain(func, status)
Definition: status.h:51
Definition: niriok_proxy.h:54
uint32_t channel
Definition: niriok_proxy.h:135
Definition: niriok_proxy.h:146
uint32_t bitWidth
Definition: niriok_proxy.h:141
Definition: niriok_proxy.h:73
fifo_direction_t
Definition: niriok_proxy.h:108
int32_t integerWordLength
Definition: niriok_proxy.h:142
uint32_t depth
Definition: niriok_proxy.h:139
nirio_driver_iface::rio_dev_handle_t _device_handle
Definition: niriok_proxy.h:278
nirio_fifo_info_t(uint32_t arg_channel, const char *arg_name, fifo_direction_t arg_direction, uint32_t arg_base_addr, uint32_t arg_depth, nirio_scalar_type_t arg_scalar_type, uint32_t arg_bitWidth, int32_t arg_integerWordLength, uint32_t arg_version)
Definition: niriok_proxy.h:114
fifo_direction_t direction
Definition: niriok_proxy.h:137
uint8_t nirio_u8_t
Definition: niriok_proxy.h:66
Definition: niriok_proxy.h:86
uint16_t nirio_u16_t
Definition: niriok_proxy.h:65
Definition: niriok_proxy.h:60
Definition: msg.hpp:50
Definition: niriok_proxy.h:57
uint32_t base_addr
Definition: niriok_proxy.h:138
Definition: niriok_proxy.h:83
nirio_quirks & get_rio_quirks()
Definition: niriok_proxy.h:220
Definition: niriok_proxy.h:110
int32_t statusCode
Definition: niriok_proxy.h:166
nirio_scalar_type_t scalar_type
Definition: niriok_proxy.h:140
Definition: niriok_proxy.h:89
nirio_device_attribute32_t
Definition: niriok_proxy.h:69