diff options
-rw-r--r-- | firmware/fx2/common/spi.c | 95 | ||||
-rw-r--r-- | firmware/fx2/common/spi.h | 7 | ||||
-rw-r--r-- | firmware/fx2/common/usrp_commands.h | 7 | ||||
-rw-r--r-- | firmware/fx2/usrp1/usrp_main.c | 10 | ||||
-rw-r--r-- | host/CMakeLists.txt | 6 | ||||
-rw-r--r-- | host/docs/build.rst | 4 | ||||
-rw-r--r-- | host/docs/index.rst | 4 | ||||
-rw-r--r-- | host/include/uhd/config.hpp | 2 | ||||
-rw-r--r-- | host/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/codec_ctrl.cpp | 73 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/usrp1_iface.cpp | 46 |
11 files changed, 69 insertions, 187 deletions
diff --git a/firmware/fx2/common/spi.c b/firmware/fx2/common/spi.c index 0c4f63d5a..04a1d8477 100644 --- a/firmware/fx2/common/spi.c +++ b/firmware/fx2/common/spi.c @@ -97,18 +97,13 @@ count_bits8 (unsigned char v) static void write_byte_msb (unsigned char v); -unsigned char -transact_byte_msb (unsigned char v); - static void write_bytes_msb (const xdata unsigned char *buf, unsigned char len); static void read_bytes_msb (xdata unsigned char *buf, unsigned char len); -static void -transact_bytes_msb (xdata unsigned char *buf, unsigned char len); - + // returns non-zero if successful, else 0 unsigned char spi_read (unsigned char header_hi, unsigned char header_lo, @@ -219,93 +214,7 @@ spi_write (unsigned char header_hi, unsigned char header_lo, return 1; // success } -unsigned char -spi_transact (unsigned char data0, unsigned char data1, - unsigned char data2, unsigned char data3, - unsigned char enables, xdata unsigned char *buf, - unsigned char len) -{ - if (count_bits8 (enables) > 1) - return 0; // error, too many enables set - - if (len > 4) - return 0; - - setup_enables (enables); - - buf[0] = data0; - buf[1] = data1; - buf[2] = data2; - buf[3] = data3; - - if (len != 0) - transact_bytes_msb(buf, len); - - disable_all (); - return 1; // success -} - -static unsigned char -transact_byte_msb (unsigned char v) -{ - v = (v << 1) | (v >> 7); // rotate left (MSB into bottom bit) - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; // read into bottom bit - bitS_CLK = 0; - - v = (v << 1) | (v >> 7); - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; - bitS_CLK = 0; - - v = (v << 1) | (v >> 7); - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; - bitS_CLK = 0; - - v = (v << 1) | (v >> 7); - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; - bitS_CLK = 0; - - v = (v << 1) | (v >> 7); - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; - bitS_CLK = 0; - - v = (v << 1) | (v >> 7); - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; - bitS_CLK = 0; - - v = (v << 1) | (v >> 7); - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; - bitS_CLK = 0; - - v = (v << 1) | (v >> 7); - bitS_OUT = v & 0x1; - bitS_CLK = 1; - v |= bitS_IN; - bitS_CLK = 0; - - return v; -} - -static void -transact_bytes_msb (xdata unsigned char *buf, unsigned char len) -{ - while (len-- != 0){ - *buf++ = transact_byte_msb (*buf); - } -} +// ---------------------------------------------------------------- static void write_byte_msb (unsigned char v) diff --git a/firmware/fx2/common/spi.h b/firmware/fx2/common/spi.h index 5342b82b8..12bc5e544 100644 --- a/firmware/fx2/common/spi.h +++ b/firmware/fx2/common/spi.h @@ -39,12 +39,5 @@ spi_write (unsigned char header_hi, unsigned char header_lo, unsigned char enables, unsigned char format, const xdata unsigned char *buf, unsigned char len); -// returns non-zero if successful, else 0 -unsigned char -spi_transact (unsigned char data0, unsigned char data1, - unsigned char data2, unsigned char data3, - unsigned char enables, xdata unsigned char *buf, - unsigned char len); - #endif /* INCLUDED_SPI_H */ diff --git a/firmware/fx2/common/usrp_commands.h b/firmware/fx2/common/usrp_commands.h index 02778c7e3..20c28e264 100644 --- a/firmware/fx2/common/usrp_commands.h +++ b/firmware/fx2/common/usrp_commands.h @@ -54,13 +54,6 @@ // wIndexL: format // len: how much to read -#define VRQ_SPI_TRANSACT 0x83 // wValueH: OUT byte 0 - // wValueL: OUT byte 1 - // wIndexH: OUT byte 2 - // wIndexL: OUT byte 3 - // wLengthH: enables - // wLengthL: transaction length - // OUT commands #define VRQ_SET_LED 0x01 // wValueL off/on {0,1}; wIndexL: which {0,1} diff --git a/firmware/fx2/usrp1/usrp_main.c b/firmware/fx2/usrp1/usrp_main.c index 3eb8c001f..802516c0b 100644 --- a/firmware/fx2/usrp1/usrp_main.c +++ b/firmware/fx2/usrp1/usrp_main.c @@ -118,7 +118,7 @@ app_vendor_cmd (void) EP0BCH = 0; EP0BCL = wLengthL; break; - + case VRQ_SPI_READ: if (!spi_read (wValueH, wValueL, wIndexH, wIndexL, EP0BUF, wLengthL)) return 0; @@ -127,14 +127,6 @@ app_vendor_cmd (void) EP0BCL = wLengthL; break; - case VRQ_SPI_TRANSACT: - if (!spi_transact (wValueH, wValueL, wIndexH, wIndexL, wLengthH, EP0BUF, wLengthL)) - return 0; - - EP0BCH = 0; - EP0BCL = wLengthL; - break; - default: return 0; } diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 97b084572..290ffdc7d 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -72,8 +72,10 @@ IF(CMAKE_COMPILER_IS_GNUCXX) ADD_DEFINITIONS(-Wextra) #ADD_DEFINITIONS(-pedantic) #ADD_DEFINITIONS(-ansi) - #only export symbols that are declared to be part of the uhd api: - UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN) + IF(NOT WIN32) + #only export symbols that are declared to be part of the uhd api (non dll platforms) + UHD_ADD_OPTIONAL_CXX_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN) + ENDIF(NOT WIN32) ENDIF(CMAKE_COMPILER_IS_GNUCXX) IF(MSVC) diff --git a/host/docs/build.rst b/host/docs/build.rst index b81e25de1..c645817ab 100644 --- a/host/docs/build.rst +++ b/host/docs/build.rst @@ -197,9 +197,7 @@ Open the Visual Studio Command Prompt Shorcut: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Setup the PATH environment variable ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -* Add the boost library path to %PATH% (usually c:\\program files\\boost\\<version>\\lib) -* Add the uhd library path to %PATH% (usually c:\\program files\\uhd\\lib) -* Add the libusb library to %PATH% (if using usb support) +* Add the uhd bin path to %PATH% (usually c:\\program files\\uhd\\bin) **Note:** The interface for editing environment variable paths in Windows is very poor. diff --git a/host/docs/index.rst b/host/docs/index.rst index 734300164..467d5f385 100644 --- a/host/docs/index.rst +++ b/host/docs/index.rst @@ -4,9 +4,7 @@ UHD - Universal Hardware Driver The UHD is the universal hardware driver for Ettus Research products. The goal of the UHD is to provide a host driver and api for current and future Ettus Research products. -Users will be able to use the UHD driver standalone/without gnuradio. -Also, a dual license option will be available for those who build against the UHD -but cannot release their software products under the GPL. +Users will be able to use the UHD driver standalone or with 3rd party applications. ------------------------------------------------------------------------ Contents diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index 1a04680e9..fdb168950 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -49,7 +49,7 @@ typedef ptrdiff_t ssize_t; #endif //BOOST_MSVC //define cross platform attribute macros -#if defined(BOOST_MSVC) || defined(BOOST_HAS_DECLSPEC) +#if defined(BOOST_HAS_DECLSPEC) #define UHD_EXPORT __declspec(dllexport) #define UHD_IMPORT __declspec(dllimport) #define UHD_INLINE __forceinline diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 54f4893e3..f8886566a 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -121,5 +121,5 @@ ENDIF(DEFINED LIBUHD_OUTPUT_NAME) INSTALL(TARGETS uhd LIBRARY DESTINATION ${LIBRARY_DIR} COMPONENT libraries # .so file ARCHIVE DESTINATION ${LIBRARY_DIR} COMPONENT libraries # .lib file - RUNTIME DESTINATION ${LIBRARY_DIR} COMPONENT libraries # .dll file + RUNTIME DESTINATION ${RUNTIME_DIR} COMPONENT libraries # .dll file ) diff --git a/host/lib/usrp/usrp1/codec_ctrl.cpp b/host/lib/usrp/usrp1/codec_ctrl.cpp index 1b4411002..9df29da0e 100644 --- a/host/lib/usrp/usrp1/codec_ctrl.cpp +++ b/host/lib/usrp/usrp1/codec_ctrl.cpp @@ -71,7 +71,6 @@ private: usrp1_clock_ctrl::sptr _clock_ctrl; int _spi_slave; ad9862_regs_t _ad9862_regs; - aux_adc_t _last_aux_adc_a, _last_aux_adc_b; void send_reg(boost::uint8_t addr); void recv_reg(boost::uint8_t addr); @@ -134,6 +133,10 @@ usrp1_codec_ctrl_impl::usrp1_codec_ctrl_impl(usrp1_iface::sptr iface, this->send_reg(addr); } + //always start conversions for aux ADC + _ad9862_regs.start_a = 1; + _ad9862_regs.start_b = 1; + //aux adc clock _ad9862_regs.clk_4 = ad9862_regs_t::CLK_4_1_4; this->send_reg(34); @@ -206,55 +209,37 @@ static double aux_adc_to_volts(boost::uint8_t high, boost::uint8_t low) return double(((boost::uint16_t(high) << 2) | low)*3.3)/0x3ff; } -double usrp1_codec_ctrl_impl::read_aux_adc(aux_adc_t which) -{ - //check to see if the switch needs to be set - bool write_switch = false; - switch(which) { - +double usrp1_codec_ctrl_impl::read_aux_adc(aux_adc_t which){ + switch(which){ case AUX_ADC_A1: + _ad9862_regs.select_a = ad9862_regs_t::SELECT_A_AUX_ADC1; + this->send_reg(34); //start conversion and select mux + this->recv_reg(28); //read the value (2 bytes, 2 reads) + this->recv_reg(29); + return aux_adc_to_volts(_ad9862_regs.aux_adc_a1_9_2, _ad9862_regs.aux_adc_a1_1_0); + case AUX_ADC_A2: - if (which != _last_aux_adc_a) { - _ad9862_regs.select_a = (which == AUX_ADC_A1)? - ad9862_regs_t::SELECT_A_AUX_ADC1: ad9862_regs_t::SELECT_A_AUX_ADC2; - _last_aux_adc_a = which; - write_switch = true; - } - break; + _ad9862_regs.select_a = ad9862_regs_t::SELECT_A_AUX_ADC2; + this->send_reg(34); //start conversion and select mux + this->recv_reg(26); //read the value (2 bytes, 2 reads) + this->recv_reg(27); + return aux_adc_to_volts(_ad9862_regs.aux_adc_a2_9_2, _ad9862_regs.aux_adc_a2_1_0); case AUX_ADC_B1: - case AUX_ADC_B2: - if (which != _last_aux_adc_b) { - _ad9862_regs.select_b = (which == AUX_ADC_B1)? - ad9862_regs_t::SELECT_B_AUX_ADC1: ad9862_regs_t::SELECT_B_AUX_ADC2; - _last_aux_adc_b = which; - write_switch = true; - } - break; + _ad9862_regs.select_b = ad9862_regs_t::SELECT_B_AUX_ADC1; + this->send_reg(34); //start conversion and select mux + this->recv_reg(32); //read the value (2 bytes, 2 reads) + this->recv_reg(33); + return aux_adc_to_volts(_ad9862_regs.aux_adc_b1_9_2, _ad9862_regs.aux_adc_b1_1_0); + case AUX_ADC_B2: + _ad9862_regs.select_b = ad9862_regs_t::SELECT_B_AUX_ADC2; + this->send_reg(34); //start conversion and select mux + this->recv_reg(30); //read the value (2 bytes, 2 reads) + this->recv_reg(31); + return aux_adc_to_volts(_ad9862_regs.aux_adc_b2_9_2, _ad9862_regs.aux_adc_b2_1_0); } - - //write the switch if it changed - if(write_switch) this->send_reg(34); - - //map aux adcs to register values to read - static const uhd::dict<aux_adc_t, boost::uint8_t> aux_dac_to_addr = boost::assign::map_list_of - (AUX_ADC_A2, 26) (AUX_ADC_A1, 28) - (AUX_ADC_B2, 30) (AUX_ADC_B1, 32) - ; - - //read the value - this->recv_reg(aux_dac_to_addr[which]+0); - this->recv_reg(aux_dac_to_addr[which]+1); - - //return the value scaled to volts - switch(which) { - case AUX_ADC_A1: return aux_adc_to_volts(_ad9862_regs.aux_adc_a1_9_2, _ad9862_regs.aux_adc_a1_1_0); - case AUX_ADC_A2: return aux_adc_to_volts(_ad9862_regs.aux_adc_a2_9_2, _ad9862_regs.aux_adc_a2_1_0); - case AUX_ADC_B1: return aux_adc_to_volts(_ad9862_regs.aux_adc_b1_9_2, _ad9862_regs.aux_adc_b1_1_0); - case AUX_ADC_B2: return aux_adc_to_volts(_ad9862_regs.aux_adc_b2_9_2, _ad9862_regs.aux_adc_b2_1_0); - } - UHD_ASSERT_THROW(false); + UHD_THROW_INVALID_CODE_PATH(); } /*********************************************************************** diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index ea7c1cea5..8f10df751 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -175,24 +175,31 @@ public: UHD_ASSERT_THROW((num_bits <= 32) && !(num_bits % 8)); size_t num_bytes = num_bits / 8; - // Byteswap on num_bytes - unsigned char buff[4] = { 0 }; - for (size_t i = 1; i <= num_bytes; i++) - buff[num_bytes - i] = (bits >> ((i - 1) * 8)) & 0xff; - if (readback) { - boost::uint8_t w_len_h = which_slave & 0xff; - boost::uint8_t w_len_l = num_bytes & 0xff; - - int ret = _ctrl_transport->usrp_control_read( - VRQ_SPI_TRANSACT, - (buff[0] << 8) | (buff[1] << 0), - (buff[2] << 8) | (buff[3] << 0), - buff, - (w_len_h << 8) | (w_len_l << 0)); - - if (ret < 0) throw uhd::io_error("USRP1: failed SPI readback transaction"); - + unsigned char buff[4] = { + (bits >> 0) & 0xff, (bits >> 8) & 0xff, + (bits >> 16) & 0xff, (bits >> 24) & 0xff + }; + //conditions where there are two header bytes + if (num_bytes >= 3 and buff[num_bytes-1] != 0 and buff[num_bytes-2] != 0 and buff[num_bytes-3] == 0){ + if (int(num_bytes-2) != _ctrl_transport->usrp_control_read( + VRQ_SPI_READ, (buff[num_bytes-1] << 8) | (buff[num_bytes-2] << 0), + (which_slave << 8) | SPI_FMT_MSB | SPI_FMT_HDR_2, + buff, num_bytes-2 + )) throw uhd::io_error("USRP1: failed SPI readback transaction"); + } + + //conditions where there is one header byte + else if (num_bytes >= 2 and buff[num_bytes-1] != 0 and buff[num_bytes-2] == 0){ + if (int(num_bytes-1) != _ctrl_transport->usrp_control_read( + VRQ_SPI_READ, buff[num_bytes-1], + (which_slave << 8) | SPI_FMT_MSB | SPI_FMT_HDR_1, + buff, num_bytes-1 + )) throw uhd::io_error("USRP1: failed SPI readback transaction"); + } + else{ + throw uhd::io_error("USRP1: invalid input data for SPI readback"); + } boost::uint32_t val = (((boost::uint32_t)buff[0]) << 0) | (((boost::uint32_t)buff[1]) << 8) | (((boost::uint32_t)buff[2]) << 16) | @@ -200,6 +207,11 @@ public: return val; } else { + // Byteswap on num_bytes + unsigned char buff[4] = { 0 }; + for (size_t i = 1; i <= num_bytes; i++) + buff[num_bytes - i] = (bits >> ((i - 1) * 8)) & 0xff; + boost::uint8_t w_index_h = which_slave & 0xff; boost::uint8_t w_index_l = (SPI_FMT_MSB | SPI_FMT_HDR_0) & 0xff; |