UHD  003.005.003-781-g91040b6f
include/uhd/types/serial.hpp
Go to the documentation of this file.
00001 //
00002 // Copyright 2010-2013 Ettus Research LLC
00003 //
00004 // This program is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef INCLUDED_UHD_TYPES_SERIAL_HPP
00019 #define INCLUDED_UHD_TYPES_SERIAL_HPP
00020 
00021 #include <uhd/config.hpp>
00022 #include <boost/shared_ptr.hpp>
00023 #include <boost/cstdint.hpp>
00024 #include <vector>
00025 
00026 namespace uhd{
00027 
00031     typedef std::vector<boost::uint8_t> byte_vector_t;
00032 
00045     class UHD_API i2c_iface{
00046     public:
00047         typedef boost::shared_ptr<i2c_iface> sptr;
00048 
00049         virtual ~i2c_iface(void);
00050 
00052         i2c_iface::sptr eeprom16(void);
00053 
00059         virtual void write_i2c(
00060             boost::uint16_t addr,
00061             const byte_vector_t &buf
00062         ) = 0;
00063 
00070         virtual byte_vector_t read_i2c(
00071             boost::uint16_t addr,
00072             size_t num_bytes
00073         ) = 0;
00074 
00081         virtual void write_eeprom(
00082             boost::uint16_t addr,
00083             boost::uint16_t offset,
00084             const byte_vector_t &buf
00085         );
00086 
00094         virtual byte_vector_t read_eeprom(
00095             boost::uint16_t addr,
00096             boost::uint16_t offset,
00097             size_t num_bytes
00098         );
00099     };
00100 
00105     struct UHD_API spi_config_t{
00110         enum edge_t{
00111             EDGE_RISE = 'r',
00112             EDGE_FALL = 'f'
00113         };
00114 
00116         edge_t mosi_edge;
00117 
00119         edge_t miso_edge;
00120 
00125         spi_config_t(edge_t edge = EDGE_RISE);
00126     };
00127     
00132     class UHD_API spi_iface{
00133     public:
00134         typedef boost::shared_ptr<spi_iface> sptr;
00135 
00136         virtual ~spi_iface(void);
00137 
00147         virtual boost::uint32_t transact_spi(
00148             int which_slave,
00149             const spi_config_t &config,
00150             boost::uint32_t data,
00151             size_t num_bits,
00152             bool readback
00153         ) = 0;
00154         
00163         virtual boost::uint32_t read_spi(
00164             int which_slave,
00165             const spi_config_t &config,
00166             boost::uint32_t data,
00167             size_t num_bits
00168         );
00169         
00177         virtual void write_spi(
00178             int which_slave,
00179             const spi_config_t &config,
00180             boost::uint32_t data,
00181             size_t num_bits
00182         );
00183     };
00184 
00188     class UHD_API uart_iface{
00189     public:
00190         typedef boost::shared_ptr<uart_iface> sptr;
00191 
00192         virtual ~uart_iface(void);
00193 
00198         virtual void write_uart(const std::string &buf) = 0;
00199 
00206         virtual std::string read_uart(double timeout) = 0;
00207     };
00208 
00209 } //namespace uhd
00210 
00211 #endif /* INCLUDED_UHD_TYPES_SERIAL_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines