USRP Hardware Driver and USRP Manual  Version: 4.8.0.0
UHD and USRP Manual
serial.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010-2013 Ettus Research LLC
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #pragma once
9 
10 #include <uhd/config.hpp>
11 #include <cstddef>
12 #include <cstdint>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 namespace uhd {
18 
22 typedef std::vector<uint8_t> byte_vector_t;
23 
37 {
38 public:
39  typedef std::shared_ptr<i2c_iface> sptr;
40 
41  virtual ~i2c_iface(void);
42 
44  i2c_iface::sptr eeprom16(void);
45 
51  virtual void write_i2c(uint16_t addr, const byte_vector_t& buf) = 0;
52 
59  virtual byte_vector_t read_i2c(uint16_t addr, size_t num_bytes) = 0;
60 
67  virtual void write_eeprom(uint16_t addr, uint16_t offset, const byte_vector_t& buf);
68 
76  virtual byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes);
77 };
78 
84 {
89  enum edge_t { EDGE_RISE = 'r', EDGE_FALL = 'f' };
90 
93 
96 
99 
101  size_t divider;
102 
107  spi_config_t(edge_t edge = EDGE_RISE);
108 
114  spi_config_t(edge_t edge, size_t divider);
115 };
116 
123 {
124 public:
125  typedef std::shared_ptr<spi_iface> sptr;
126 
127  virtual ~spi_iface(void);
128 
138  virtual uint32_t transact_spi(int which_slave,
139  const spi_config_t& config,
140  uint32_t data,
141  size_t num_bits,
142  bool readback) = 0;
143 
152  virtual uint32_t read_spi(
153  int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
154 
162  virtual void write_spi(
163  int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
164 };
165 
170 {
171 public:
172  typedef std::shared_ptr<uart_iface> sptr;
173 
174  virtual ~uart_iface(void);
175 
180  virtual void write_uart(const std::string& buf) = 0;
181 
187  virtual std::string read_uart(double timeout) = 0;
188 };
189 
190 } // namespace uhd
config.hpp
uhd::spi_config_t::edge_t
edge_t
Definition: serial.hpp:89
UHD_API
#define UHD_API
Definition: config.h:87
uhd::i2c_iface::sptr
std::shared_ptr< i2c_iface > sptr
Definition: serial.hpp:39
uhd::uart_iface::sptr
std::shared_ptr< uart_iface > sptr
Definition: serial.hpp:172
uhd::byte_vector_t
std::vector< uint8_t > byte_vector_t
Byte vector used for I2C data passing and EEPROM parsing.
Definition: byte_vector.hpp:21
uhd
Definition: build_info.hpp:12
uhd::uart_iface
Definition: serial.hpp:169
uhd::spi_config_t::mosi_edge
edge_t mosi_edge
on what edge is the mosi data valid?
Definition: serial.hpp:92
uhd::spi_config_t::miso_edge
edge_t miso_edge
on what edge is the miso data valid?
Definition: serial.hpp:95
uhd::spi_config_t::divider
size_t divider
Optionally set the SPI clock divider for this transaction.
Definition: serial.hpp:101
uhd::i2c_iface
Definition: serial.hpp:36
uhd::spi_config_t
Definition: serial.hpp:83
uhd::spi_iface
Definition: serial.hpp:122
uhd::spi_iface::sptr
std::shared_ptr< spi_iface > sptr
Definition: serial.hpp:125
uhd::spi_config_t::use_custom_divider
bool use_custom_divider
Set the clock speed for this transaction.
Definition: serial.hpp:98