aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp1/usrp1_iface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/usrp/usrp1/usrp1_iface.cpp')
-rw-r--r--host/lib/usrp/usrp1/usrp1_iface.cpp54
1 files changed, 41 insertions, 13 deletions
diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp
index 8f10df751..0942e2613 100644
--- a/host/lib/usrp/usrp1/usrp1_iface.cpp
+++ b/host/lib/usrp/usrp1/usrp1_iface.cpp
@@ -17,19 +17,17 @@
#include "usrp1_iface.hpp"
#include "usrp_commands.h"
+#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/byteswap.hpp>
#include <boost/format.hpp>
#include <stdexcept>
-#include <iostream>
#include <iomanip>
using namespace uhd;
using namespace uhd::usrp;
using namespace uhd::transport;
-static const bool iface_debug = false;
-
class usrp1_iface_impl : public usrp1_iface{
public:
/*******************************************************************
@@ -53,12 +51,11 @@ public:
{
boost::uint32_t swapped = uhd::htonx(value);
- if (iface_debug) {
- std::cout.fill('0');
- std::cout << "poke32(";
- std::cout << std::dec << std::setw(2) << addr << ", 0x";
- std::cout << std::hex << std::setw(8) << value << ")" << std::endl;
- }
+ UHD_LOGV(always)
+ << "poke32("
+ << std::dec << std::setw(2) << addr << ", 0x"
+ << std::hex << std::setw(8) << value << ")" << std::endl
+ ;
boost::uint8_t w_index_h = SPI_ENABLE_FPGA & 0xff;
boost::uint8_t w_index_l = (SPI_FMT_MSB | SPI_FMT_HDR_1) & 0xff;
@@ -75,6 +72,11 @@ public:
boost::uint32_t peek32(boost::uint32_t addr)
{
+ UHD_LOGV(always)
+ << "peek32("
+ << std::dec << std::setw(2) << addr << ")" << std::endl
+ ;
+
boost::uint32_t value_out;
boost::uint8_t w_index_h = SPI_ENABLE_FPGA & 0xff;
@@ -119,6 +121,10 @@ public:
void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes)
{
+ UHD_LOGV(always) << "write_i2c:" << std::endl
+ << " addr 0x" << std::hex << int(addr) << std::endl
+ << " len " << bytes.size() << std::endl
+ ;
UHD_ASSERT_THROW(bytes.size() < max_i2c_data_bytes);
unsigned char buff[max_i2c_data_bytes];
@@ -129,12 +135,16 @@ public:
bytes.size());
// TODO throw and catch i2c failures during eeprom read
- if (iface_debug && (ret < 0))
- std::cerr << "USRP: failed i2c write: " << ret << std::endl;
+ if (ret < 0)
+ UHD_LOGV(often) << "USRP: failed i2c write: " << ret << std::endl;
}
byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes)
{
+ UHD_LOGV(always) << "read_i2c:" << std::endl
+ << " addr 0x" << std::hex << int(addr) << std::endl
+ << " len " << num_bytes << std::endl
+ ;
UHD_ASSERT_THROW(num_bytes < max_i2c_data_bytes);
unsigned char buff[max_i2c_data_bytes];
@@ -143,8 +153,8 @@ public:
num_bytes);
// TODO throw and catch i2c failures during eeprom read
- if (iface_debug && ((ret < 0) || (unsigned)ret < (num_bytes))) {
- std::cerr << "USRP: failed i2c read: " << ret << std::endl;
+ if (ret < 0 or (unsigned)ret < num_bytes) {
+ UHD_LOGV(often) << "USRP: failed i2c read: " << ret << std::endl;
return byte_vector_t(num_bytes, 0xff);
}
@@ -155,6 +165,17 @@ public:
return out_bytes;
}
+ //! overload read_eeprom to handle multi-byte reads
+ byte_vector_t read_eeprom(
+ boost::uint8_t addr,
+ boost::uint8_t offset,
+ size_t num_bytes
+ ){
+ //do a zero byte write to start read cycle
+ this->write_i2c(addr, byte_vector_t(1, offset));
+ return this->read_i2c(addr, num_bytes); //read all bytes
+ }
+
/*******************************************************************
* SPI
*
@@ -172,6 +193,13 @@ public:
size_t num_bits,
bool readback)
{
+ UHD_LOGV(always)
+ << "transact_spi: " << std::endl
+ << " slave: " << which_slave << std::endl
+ << " bits: " << bits << std::endl
+ << " num_bits: " << num_bits << std::endl
+ << " readback: " << readback << std::endl
+ ;
UHD_ASSERT_THROW((num_bits <= 32) && !(num_bits % 8));
size_t num_bytes = num_bits / 8;