USRP Hardware Driver and USRP Manual  Version: 003.008.002-0-ge9d11b35
UHD and USRP Manual
niusrprio_session.h
Go to the documentation of this file.
1 //
2 // Copyright 2013 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_NIUSRPRIO_SESSION_H
20 #define INCLUDED_UHD_TRANSPORT_NIRIO_NIUSRPRIO_SESSION_H
21 
22 #include <stdint.h>
27 #include <boost/noncopyable.hpp>
28 #include <boost/smart_ptr.hpp>
29 #include <boost/thread/recursive_mutex.hpp>
30 #include <string>
31 
32 namespace uhd { namespace niusrprio {
33 
34 class UHD_API niusrprio_session : private boost::noncopyable
35 {
36 public:
37  typedef boost::shared_ptr<niusrprio_session> sptr;
40 
41  static nirio_status enumerate(
42  const std::string& rpc_port_name,
43  device_info_vtr& device_info_vtr);
44 
46  const std::string& resource_name,
47  const std::string& port_name);
48  virtual ~niusrprio_session();
49 
50  nirio_status open(
51  nifpga_lvbitx::sptr lvbitx,
52  bool force_download = false);
53 
54  void close(bool skip_reset = false);
55 
56  nirio_status reset();
57 
58  template<typename data_t>
60  const char* fifo_name,
61  boost::shared_ptr< nirio_fifo<data_t> >& fifo)
62  {
63  if (!_session_open) return NiRio_Status_ResourceNotInitialized;
64  return _resource_manager.create_tx_fifo(fifo_name, fifo);
65  }
66 
67  template<typename data_t>
69  uint32_t fifo_instance,
70  boost::shared_ptr< nirio_fifo<data_t> >& fifo)
71  {
72  if ((size_t)fifo_instance >= _lvbitx->get_output_fifo_count()) return NiRio_Status_InvalidParameter;
73  return create_tx_fifo(_lvbitx->get_output_fifo_names()[fifo_instance], fifo);
74  }
75 
76  template<typename data_t>
78  const char* fifo_name,
79  boost::shared_ptr< nirio_fifo<data_t> >& fifo)
80  {
81  if (!_session_open) return NiRio_Status_ResourceNotInitialized;
82  return _resource_manager.create_rx_fifo(fifo_name, fifo);
83  }
84 
85  template<typename data_t>
87  uint32_t fifo_instance,
88  boost::shared_ptr< nirio_fifo<data_t> >& fifo)
89  {
90  if ((size_t)fifo_instance >= _lvbitx->get_input_fifo_count()) return NiRio_Status_InvalidParameter;
91  return create_rx_fifo(_lvbitx->get_input_fifo_names()[fifo_instance], fifo);
92  }
93 
95  return _riok_proxy;
96  }
97 
98  nirio_status download_bitstream_to_flash(const std::string& bitstream_path);
99 
100  //Static
101  static niriok_proxy::sptr create_kernel_proxy(
102  const std::string& resource_name,
103  const std::string& rpc_port_name);
104 
105 private:
106  nirio_status _verify_signature();
107  std::string _read_bitstream_checksum();
108  nirio_status _write_bitstream_checksum(const std::string& checksum);
109  nirio_status _ensure_fpga_ready();
110 
111  std::string _resource_name;
112  nifpga_lvbitx::sptr _lvbitx;
113  std::string _interface_path;
114  bool _session_open;
115  niriok_proxy::sptr _riok_proxy;
116  nirio_resource_manager _resource_manager;
118  boost::recursive_mutex _session_mutex;
119 
120  static const uint32_t FPGA_READY_TIMEOUT_IN_MS = 1000;
121  static const uint32_t SESSION_LOCK_TIMEOUT_IN_MS = 3000;
122  static const uint32_t SESSION_LOCK_RETRY_INT_IN_MS = 500;
123 };
124 
125 }}
126 
127 #endif /* INCLUDED_UHD_TRANSPORT_NIRIO_NIUSRPRIO_SESSION_H */
Definition: nirio_resource_manager.h:58
Definition: usrprio_rpc_common.hpp:39
boost::shared_ptr< niriok_proxy > sptr
Definition: niriok_proxy.h:168
boost::shared_ptr< nifpga_lvbitx > sptr
Definition: nifpga_lvbitx.h:29
uhd::usrprio_rpc::usrprio_device_info_vtr device_info_vtr
Definition: niusrprio_session.h:39
#define UHD_API
Definition: config.hpp:79
Definition: convert.hpp:28
#define UHD_INLINE
Definition: config.hpp:69
uhd::usrprio_rpc::usrprio_device_info device_info
Definition: niusrprio_session.h:38
int32_t nirio_status
Definition: status.h:31
nirio_status create_tx_fifo(const char *fifo_name, boost::shared_ptr< nirio_fifo< data_t > > &fifo)
Definition: niusrprio_session.h:59
boost::shared_ptr< niusrprio_session > sptr
Definition: niusrprio_session.h:37
nirio_status create_rx_fifo(const char *fifo_name, boost::shared_ptr< nirio_fifo< data_t > > &fifo)
Definition: niusrprio_session.h:77
std::vector< usrprio_device_info > usrprio_device_info_vtr
Definition: usrprio_rpc_common.hpp:56
UHD_INLINE niriok_proxy::sptr get_kernel_proxy()
Definition: niusrprio_session.h:94
Definition: niusrprio_session.h:34
nirio_status create_rx_fifo(uint32_t fifo_instance, boost::shared_ptr< nirio_fifo< data_t > > &fifo)
Definition: niusrprio_session.h:86
Definition: usrprio_rpc_client.hpp:28
Definition: nirio_fifo.h:41
nirio_status create_tx_fifo(uint32_t fifo_instance, boost::shared_ptr< nirio_fifo< data_t > > &fifo)
Definition: niusrprio_session.h:68