USRP Hardware Driver and USRP Manual  Version: 003.008.002-0-ge9d11b35
UHD and USRP Manual
nirio_driver_iface.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_DRIVER_IFACE_H
19 #define INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_DRIVER_IFACE_H
20 
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <string>
25 #include <uhd/config.hpp>
26 #if defined(UHD_PLATFORM_WIN32)
27  #include <Windows.h>
28  #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union
29  #include <WinIoCtl.h>
30  #pragma warning(default:4201)
31 #elif !defined(UHD_PLATFORM_LINUX)
32  #include <IOKit/IOKitLib.h>
33 #endif
34 
35 // CTL_CODE macro for non-win OSes
36 #ifndef UHD_PLATFORM_WIN32
37  #define CTL_CODE(a,controlCode,b,c) (controlCode)
38 #endif
39 
40 namespace nirio_driver_iface {
41 
42 const uint32_t NIRIO_IOCTL_BASE = 0x800;
43 
44 const uint32_t NIRIO_IOCTL_SYNCOP =
45  CTL_CODE(FILE_DEVICE_UNKNOWN,
46  NIRIO_IOCTL_BASE + 4,
47  METHOD_OUT_DIRECT,
48  FILE_READ_DATA | FILE_WRITE_DATA);
53 
54 const uint32_t NIRIO_IOCTL_GET_IFACE_NUM =
55  CTL_CODE(FILE_DEVICE_UNKNOWN,
56  NIRIO_IOCTL_BASE + 6,
57  METHOD_BUFFERED,
58  FILE_READ_DATA);
59 
60 const uint32_t NIRIO_IOCTL_GET_SESSION =
61  CTL_CODE(FILE_DEVICE_UNKNOWN,
62  NIRIO_IOCTL_BASE + 8,
63  METHOD_BUFFERED,
64  FILE_READ_ACCESS);
65 
66 const uint32_t NIRIO_IOCTL_POST_OPEN =
67  CTL_CODE(FILE_DEVICE_UNKNOWN,
68  NIRIO_IOCTL_BASE + 9,
69  METHOD_BUFFERED,
70  FILE_READ_ACCESS);
71 
72 const uint32_t NIRIO_IOCTL_PRE_CLOSE =
73  CTL_CODE(FILE_DEVICE_UNKNOWN,
74  NIRIO_IOCTL_BASE + 10,
75  METHOD_BUFFERED,
76  FILE_READ_ACCESS);
77 
78 
79 //Device handle definition
80 #if defined(UHD_PLATFORM_LINUX)
81  typedef int rio_dev_handle_t;
82 #elif defined(UHD_PLATFORM_WIN32)
83  typedef HANDLE rio_dev_handle_t;
84 #else
85  typedef io_connect_t rio_dev_handle_t;
86 #endif
87 static const rio_dev_handle_t INVALID_RIO_HANDLE = ((rio_dev_handle_t)-1);
88 
89 //Memory mapping container definition
90 #if defined(UHD_PLATFORM_LINUX)
91  struct rio_mmap_t {
92  rio_mmap_t() : addr(NULL), size(0) {}
93  void *addr;
94  size_t size;
95 
96  bool is_null() { return (size == 0 || addr == NULL); }
97  };
98 #elif defined(UHD_PLATFORM_WIN32)
99  enum access_mode_t {
100  ACCESS_MODE_READ,
101  ACCESS_MODE_WRITE
102  };
103 
104  struct rio_mmap_params_t
105  {
106  uint64_t mapped_va_ptr;
107  uint64_t map_ready_event_handle;
108  uint32_t size;
109  uint16_t memoryType;
110  uint8_t access_mode;
111  };
112 
113  struct rio_mmap_threadargs_t
114  {
115  rio_dev_handle_t device_handle;
116  rio_mmap_params_t params;
118  };
119 
120  struct rio_mmap_t
121  {
122  rio_mmap_t() : addr(NULL) {}
123  void *addr;
124  HANDLE map_thread_handle;
125  rio_mmap_threadargs_t map_thread_args;
126 
127  bool is_null() { return addr == NULL; }
128  };
129 #else
130  struct rio_mmap_t {
131  rio_mmap_t() : addr(NULL) {}
132  void *addr;
133 
134  bool is_null() { return addr == NULL; }
135  };
136 #endif
137 
139  const std::string& device_path,
140  rio_dev_handle_t& device_handle);
141 
142  void rio_close(
143  rio_dev_handle_t& device_handle);
144 
145  bool rio_isopen(
146  rio_dev_handle_t device_handle);
147 
149  rio_dev_handle_t device_handle,
150  uint32_t ioctl_code,
151  const void *write_buf,
152  size_t write_buf_len,
153  void *read_buf,
154  size_t read_buf_len);
155 
157  rio_dev_handle_t device_handle,
158  uint16_t memory_type,
159  size_t size,
160  bool writable,
161  rio_mmap_t &map);
162 
164  rio_mmap_t &map);
165 }
166 
167 #endif
rio_mmap_t()
Definition: nirio_driver_iface.h:131
nirio_status rio_mmap(rio_dev_handle_t device_handle, uint16_t memory_type, size_t size, bool writable, rio_mmap_t &map)
const uint32_t NIRIO_IOCTL_GET_IFACE_NUM
Get the interface number for a device.
Definition: nirio_driver_iface.h:54
nirio_status rio_munmap(rio_mmap_t &map)
const uint32_t NIRIO_IOCTL_GET_SESSION
Gets a previously opened session to a device.
Definition: nirio_driver_iface.h:60
bool is_null()
Definition: nirio_driver_iface.h:134
const uint32_t NIRIO_IOCTL_POST_OPEN
Called after opening a session.
Definition: nirio_driver_iface.h:66
io_connect_t rio_dev_handle_t
Definition: nirio_driver_iface.h:85
nirio_status rio_open(const std::string &device_path, rio_dev_handle_t &device_handle)
#define CTL_CODE(a, controlCode, b, c)
Definition: nirio_driver_iface.h:37
Definition: nirio_driver_iface.h:130
bool rio_isopen(rio_dev_handle_t device_handle)
int32_t nirio_status
Definition: status.h:31
const uint32_t NIRIO_IOCTL_SYNCOP
Definition: nirio_driver_iface.h:44
const uint32_t NIRIO_IOCTL_PRE_CLOSE
Called before closing a session.
Definition: nirio_driver_iface.h:72
Definition: nirio_driver_iface.h:40
nirio_status rio_ioctl(rio_dev_handle_t device_handle, uint32_t ioctl_code, const void *write_buf, size_t write_buf_len, void *read_buf, size_t read_buf_len)
const uint32_t NIRIO_IOCTL_BASE
Definition: nirio_driver_iface.h:42
Definition: msg.hpp:50
void rio_close(rio_dev_handle_t &device_handle)
void * addr
Definition: nirio_driver_iface.h:132