USRP Hardware Driver and USRP Manual Version: 4.2.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 <stdint.h>
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace uhd {
17
21typedef std::vector<uint8_t> byte_vector_t;
22
36{
37public:
38 typedef std::shared_ptr<i2c_iface> sptr;
39
40 virtual ~i2c_iface(void);
41
44
50 virtual void write_i2c(uint16_t addr, const byte_vector_t& buf) = 0;
51
58 virtual byte_vector_t read_i2c(uint16_t addr, size_t num_bytes) = 0;
59
66 virtual void write_eeprom(uint16_t addr, uint16_t offset, const byte_vector_t& buf);
67
75 virtual byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes);
76};
77
83{
88 enum edge_t { EDGE_RISE = 'r', EDGE_FALL = 'f' };
89
92
95
98
100 size_t divider;
101
106 spi_config_t(edge_t edge = EDGE_RISE);
107
113 spi_config_t(edge_t edge, size_t divider);
114};
115
122{
123public:
124 typedef std::shared_ptr<spi_iface> sptr;
125
126 virtual ~spi_iface(void);
127
137 virtual uint32_t transact_spi(int which_slave,
138 const spi_config_t& config,
139 uint32_t data,
140 size_t num_bits,
141 bool readback) = 0;
142
151 virtual uint32_t read_spi(
152 int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
153
161 virtual void write_spi(
162 int which_slave, const spi_config_t& config, uint32_t data, size_t num_bits);
163};
164
169{
170public:
171 typedef std::shared_ptr<uart_iface> sptr;
172
173 virtual ~uart_iface(void);
174
179 virtual void write_uart(const std::string& buf) = 0;
180
186 virtual std::string read_uart(double timeout) = 0;
187};
188
189} // namespace uhd
Definition: serial.hpp:36
virtual byte_vector_t read_i2c(uint16_t addr, size_t num_bytes)=0
virtual byte_vector_t read_eeprom(uint16_t addr, uint16_t offset, size_t num_bytes)
virtual ~i2c_iface(void)
virtual void write_i2c(uint16_t addr, const byte_vector_t &buf)=0
i2c_iface::sptr eeprom16(void)
Create an i2c_iface than can talk to 16 bit addressable EEPROMS.
std::shared_ptr< i2c_iface > sptr
Definition: serial.hpp:38
virtual void write_eeprom(uint16_t addr, uint16_t offset, const byte_vector_t &buf)
Definition: serial.hpp:122
std::shared_ptr< spi_iface > sptr
Definition: serial.hpp:124
virtual ~spi_iface(void)
virtual uint32_t transact_spi(int which_slave, const spi_config_t &config, uint32_t data, size_t num_bits, bool readback)=0
virtual uint32_t read_spi(int which_slave, const spi_config_t &config, uint32_t data, size_t num_bits)
virtual void write_spi(int which_slave, const spi_config_t &config, uint32_t data, size_t num_bits)
Definition: serial.hpp:169
virtual void write_uart(const std::string &buf)=0
virtual ~uart_iface(void)
virtual std::string read_uart(double timeout)=0
std::shared_ptr< uart_iface > sptr
Definition: serial.hpp:171
#define UHD_API
Definition: config.h:87
Definition: build_info.hpp:12
std::vector< uint8_t > byte_vector_t
Byte vector used for I2C data passing and EEPROM parsing.
Definition: byte_vector.hpp:19
Definition: serial.hpp:83
edge_t miso_edge
on what edge is the miso data valid?
Definition: serial.hpp:94
spi_config_t(edge_t edge=EDGE_RISE)
edge_t
Definition: serial.hpp:88
bool use_custom_divider
Set the clock speed for this transaction.
Definition: serial.hpp:97
edge_t mosi_edge
on what edge is the mosi data valid?
Definition: serial.hpp:91
spi_config_t(edge_t edge, size_t divider)
size_t divider
Optionally set the SPI clock divider for this transaction.
Definition: serial.hpp:100