diff options
| -rw-r--r-- | host/examples/rx_timed_samples.cpp | 9 | ||||
| -rw-r--r-- | host/lib/usrp/usrp_e100/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | host/lib/usrp/usrp_e100/fpga_downloader.cpp (renamed from host/lib/usrp/usrp_e100/fpga-downloader.cc) | 40 | ||||
| -rw-r--r-- | host/usrp_e_utils/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | host/usrp_e_utils/clkgen_config.hpp (renamed from host/usrp_e_utils/clkgen-config.cpp) | 49 | ||||
| -rw-r--r-- | host/usrp_e_utils/fpga-downloader.cpp | 267 | ||||
| -rw-r--r-- | host/usrp_e_utils/usrp-e-utility.cpp | 72 | 
7 files changed, 126 insertions, 321 deletions
| diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index 9ebe36c5a..630b4a7a9 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -32,7 +32,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      std::string args;      double seconds_in_future;      size_t total_num_samps; -    double rate, freq; +    double rate, freq, clock;      //setup the program options      po::options_description desc("Allowed options"); @@ -41,6 +41,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){          ("args", po::value<std::string>(&args)->default_value(""), "single uhd device address args")          ("secs", po::value<double>(&seconds_in_future)->default_value(3), "number of seconds in the future to receive")          ("nsamps", po::value<size_t>(&total_num_samps)->default_value(1000), "total number of samples to receive") +        ("clock", po::value<double>(&clock), "master clock frequency in Hz")          ("rate", po::value<double>(&rate)->default_value(100e6/16), "rate of incoming samples")          ("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz")          ("dilv", "specify to disable inner-loop verbose") @@ -63,6 +64,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){      uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args);      std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl; +    //optionally set the clock rate (do before setting anything else) +    if (vm.count("clock")){ +        std::cout << boost::format("Setting master clock rate: %f MHz...") % (clock/1e6) << std::endl; +        usrp->set_master_clock_rate(clock); +    } +      //set the rx sample rate      std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl;      usrp->set_rx_rate(rate); diff --git a/host/lib/usrp/usrp_e100/CMakeLists.txt b/host/lib/usrp/usrp_e100/CMakeLists.txt index c32dd87f8..acbac177e 100644 --- a/host/lib/usrp/usrp_e100/CMakeLists.txt +++ b/host/lib/usrp/usrp_e100/CMakeLists.txt @@ -1,5 +1,5 @@  # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC  #  # This program is free software: you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ IF(ENABLE_USRP_E100)          ${CMAKE_CURRENT_SOURCE_DIR}/dboard_impl.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/dboard_iface.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/dsp_impl.cpp -        ${CMAKE_CURRENT_SOURCE_DIR}/fpga-downloader.cc +        ${CMAKE_CURRENT_SOURCE_DIR}/fpga_downloader.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/io_impl.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/mboard_impl.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/usrp_e100_impl.cpp diff --git a/host/lib/usrp/usrp_e100/fpga-downloader.cc b/host/lib/usrp/usrp_e100/fpga_downloader.cpp index 4a3d3b9af..926e6fcaf 100644 --- a/host/lib/usrp/usrp_e100/fpga-downloader.cc +++ b/host/lib/usrp/usrp_e100/fpga_downloader.cpp @@ -43,6 +43,8 @@   *  */ +namespace usrp_e_fpga_downloader_utility{ +  const unsigned int PROG_B = 175;  const unsigned int DONE   = 173;  const unsigned int INIT_B = 114; @@ -209,11 +211,10 @@ static void send_file_to_fpga(const std::string &file_name, gpio &error, gpio &d  {  	std::ifstream bitstream; -	std::cout << "File name - " << file_name.c_str() << std::endl; -  	bitstream.open(file_name.c_str(), std::ios::binary); -	if (!bitstream.is_open()) -		std::cout << "File " << file_name << " not opened succesfully." << std::endl; +	if (!bitstream.is_open()) throw std::runtime_error( +		"Coult not open the file: " + file_name +	);  	spidev spi("/dev/spidev1.0");  	char buf[BUF_SIZE]; @@ -232,35 +233,20 @@ static void send_file_to_fpga(const std::string &file_name, gpio &error, gpio &d  	} while (bitstream.gcount() == BUF_SIZE);  } -/* -int main(int argc, char *argv[]) -{ - -	gpio gpio_prog_b(PROG_B, OUT); -	gpio gpio_init_b(INIT_B, IN); -	gpio gpio_done  (DONE,   IN); - -	if (argc == 2) -		bit_file = argv[1]; - -	std::cout << "FPGA config file: " << bit_file << std::endl; - -	prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b); - -	std::cout << "Done = " << gpio_done.get_value() << std::endl; - -	send_file_to_fpga(bit_file, gpio_init_b, gpio_done); -} -*/ +}//namespace usrp_e_fpga_downloader_utility  void usrp_e100_load_fpga(const std::string &bin_file){ +	using namespace usrp_e_fpga_downloader_utility; +  	gpio gpio_prog_b(PROG_B, OUT);  	gpio gpio_init_b(INIT_B, IN);  	gpio gpio_done  (DONE,   IN);  	std::cout << "Loading FPGA image: " << bin_file << "... " << std::flush; -	UHD_ASSERT_THROW(std::system("/sbin/rmmod usrp_e") == 0); +	if(std::system("/sbin/rmmod usrp_e") != 0){ +		std::cerr << "USRP-E100 FPGA downloader: could not unload usrp_e module" << std::endl; +	}  	prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b); @@ -268,7 +254,9 @@ void usrp_e100_load_fpga(const std::string &bin_file){  	send_file_to_fpga(bin_file, gpio_init_b, gpio_done); -	UHD_ASSERT_THROW(std::system("/sbin/modprobe usrp_e") == 0); +	if(std::system("/sbin/modprobe usrp_e") != 0){ +		std::cerr << "USRP-E100 FPGA downloader: could not load usrp_e module" << std::endl; +	}  } diff --git a/host/usrp_e_utils/CMakeLists.txt b/host/usrp_e_utils/CMakeLists.txt index 96842a684..5123af592 100644 --- a/host/usrp_e_utils/CMakeLists.txt +++ b/host/usrp_e_utils/CMakeLists.txt @@ -26,13 +26,13 @@ LIBUHD_REGISTER_COMPONENT("USRP-E Utils" ENABLE_USRP_E_UTILS OFF "LINUX_TARGET"  IF(ENABLE_USRP_E_UTILS)      ENABLE_LANGUAGE(C) +    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})      INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/usrp/usrp_e100)      INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/usrp/usrp_e100/include)      INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/lib/ic_reg_maps)      SET(usrp_e_utils_sources -        fpga-downloader.cpp -        clkgen-config.cpp +        usrp-e-utility.cpp          usrp-e-loopback.c          usrp-e-wb-test.cpp          usrp-e-debug-pins.c @@ -44,7 +44,7 @@ IF(ENABLE_USRP_E_UTILS)      FOREACH(util_source ${usrp_e_utils_sources})          GET_FILENAME_COMPONENT(util_name ${util_source} NAME_WE)          ADD_EXECUTABLE(${util_name} ${util_source}) -        TARGET_LINK_LIBRARIES(${util_name} -lpthread) +        TARGET_LINK_LIBRARIES(${util_name} ${Boost_LIBRARIES})          INSTALL(TARGETS ${util_name} RUNTIME DESTINATION ${PKG_DATA_DIR}/usrp_e_utils)      ENDFOREACH(util_source) diff --git a/host/usrp_e_utils/clkgen-config.cpp b/host/usrp_e_utils/clkgen_config.hpp index 8d29efff1..0c9dc8de2 100644 --- a/host/usrp_e_utils/clkgen-config.cpp +++ b/host/usrp_e_utils/clkgen_config.hpp @@ -1,24 +1,22 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc. - * - * This file is part of UHD - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING.  If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. -*/ +// +// Copyright 2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.  If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef USRP_E_UTILS_CLKGEN_CONFIG_HPP +#define USRP_E_UTILS_CLKGEN_CONFIG_HPP  #include <iostream>  #include <sstream> @@ -34,6 +32,7 @@  #include <linux/spi/spidev.h> +namespace usrp_e_clkgen_config_utility{  const unsigned int CLKGEN_SELECT = 145; @@ -73,6 +72,7 @@ class spidev {  };  gpio::gpio(unsigned int _gpio_num, gpio_direction pin_direction, bool close_action) +:close_action(close_action)  {  	std::fstream export_file; @@ -296,10 +296,15 @@ static void send_config_to_clkgen(gpio &chip_select)  } -int main(int argc, char *argv[]) +}//namespace usrp_e_clkgen_config_utility + +//int main(int argc, char *argv[]) +static void clock_genconfig_main(void)  { +	using namespace usrp_e_clkgen_config_utility;  	gpio clkgen_select(CLKGEN_SELECT, OUT, true);  	send_config_to_clkgen(clkgen_select);  } +#endif /*USRP_E_UTILS_CLKGEN_CONFIG_HPP*/ diff --git a/host/usrp_e_utils/fpga-downloader.cpp b/host/usrp_e_utils/fpga-downloader.cpp deleted file mode 100644 index 80ee71600..000000000 --- a/host/usrp_e_utils/fpga-downloader.cpp +++ /dev/null @@ -1,267 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING.  If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. -*/ - -#include <iostream> -#include <sstream> -#include <fstream> -#include <string> -#include <cstdlib> - -#include <fcntl.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> - -#include <linux/spi/spidev.h> - -/* - * Configuration connections - * - * CCK    - MCSPI1_CLK - * DIN    - MCSPI1_MOSI - * PROG_B - GPIO_175     - output (change mux) - * DONE   - GPIO_173     - input  (change mux) - * INIT_B - GPIO_114     - input  (change mux) - * -*/ - -const unsigned int PROG_B = 175; -const unsigned int DONE   = 173; -const unsigned int INIT_B = 114; - -static std::string bit_file = "safe_u1e.bin"; - -const int BUF_SIZE = 4096; - -enum gpio_direction {IN, OUT}; - -class gpio { -	public: - -	gpio(unsigned int gpio_num, gpio_direction pin_direction); - -	bool get_value(); -	void set_value(bool state); - -	private: - -	std::stringstream base_path; -	std::fstream value_file;	 -}; - -class spidev { -	public: - -	spidev(std::string dev_name); -	~spidev(); - -	void send(char *wbuf, char *rbuf, unsigned int nbytes); - -	private: - -	int fd; - -}; - -gpio::gpio(unsigned int gpio_num, gpio_direction pin_direction) -{ -	std::fstream export_file; - -	export_file.open("/sys/class/gpio/export", std::ios::out); -	if (!export_file.is_open())  ///\todo Poor error handling -		std::cout << "Failed to open gpio export file." << std::endl; - -	export_file << gpio_num << std::endl; - -	base_path << "/sys/class/gpio/gpio" << gpio_num << std::flush; - -	std::fstream direction_file; -	std::string direction_file_name; - -	direction_file_name = base_path.str() + "/direction"; - -	direction_file.open(direction_file_name.c_str());  -	if (!direction_file.is_open()) -		std::cout << "Failed to open direction file." << std::endl; -	if (pin_direction == OUT) -		direction_file << "out" << std::endl; -	else -		direction_file << "in" << std::endl; - -	std::string value_file_name; - -	value_file_name = base_path.str() + "/value"; - -	value_file.open(value_file_name.c_str(), std::ios_base::in | std::ios_base::out); -	if (!value_file.is_open()) -		std::cout << "Failed to open value file." << std::endl; -} - -bool gpio::get_value() -{ - -	std::string val; - -	std::getline(value_file, val); -	value_file.seekg(0); - -	if (val == "0") -		return false; -	else if (val == "1") -		return true; -	else -		std::cout << "Data read from value file|" << val << "|" << std::endl; - -	return false; -} - -void gpio::set_value(bool state) -{ - -	if (state) -		value_file << "1" << std::endl; -	else -		value_file << "0" << std::endl; -} - -static void prepare_fpga_for_configuration(gpio &prog, gpio &init) -{ - -	prog.set_value(true); -	prog.set_value(false); -	prog.set_value(true); - -#if 0 -	bool ready_to_program(false); -	unsigned int count(0); -	do { -		ready_to_program = init.get_value(); -		count++; - -		sleep(1); -	} while (count < 10 && !ready_to_program); - -	if (count == 10) { -		std::cout << "FPGA not ready for programming." << std::endl; -		exit(-1); -	} -#endif -} - -spidev::spidev(std::string fname) -{ -	int ret; -	int mode = 0; -	int speed = 12000000; -	int bits = 8; - -	fd = open(fname.c_str(), O_RDWR); - -	ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); -	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); -	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); -} -	 - -spidev::~spidev() -{ -	close(fd); -} - -void spidev::send(char *buf, char *rbuf, unsigned int nbytes) -{ -	int ret; - -	struct spi_ioc_transfer tr; -	tr.tx_buf = (unsigned long) buf; -	tr.rx_buf = (unsigned long) rbuf; -	tr.len = nbytes; -	tr.delay_usecs = 0; -	tr.speed_hz = 48000000; -	tr.bits_per_word = 8; - -	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);	 - -} - -static void send_file_to_fpga(std::string &file_name, gpio &error, gpio &done) -{ -	std::ifstream bitstream; - -	std::cout << "File name - " << file_name.c_str() << std::endl; - -	bitstream.open(file_name.c_str(), std::ios::binary); -	if (!bitstream.is_open()) -		std::cout << "File " << file_name << " not opened succesfully." << std::endl; - -	spidev spi("/dev/spidev1.0"); -	char buf[BUF_SIZE]; -	char rbuf[BUF_SIZE]; - -	do { -		bitstream.read(buf, BUF_SIZE); -		spi.send(buf, rbuf, bitstream.gcount()); - -		if (error.get_value()) -			std::cout << "INIT_B went high, error occured." << std::endl; - -		if (!done.get_value()) -			std::cout << "Configuration complete." << std::endl; - -	} while (bitstream.gcount() == BUF_SIZE); -} - -int main(int argc, char *argv[]) -{ - -	gpio gpio_prog_b(PROG_B, OUT); -	gpio gpio_init_b(INIT_B, IN); -	gpio gpio_done  (DONE,   IN); - -	if (argc == 2) -		bit_file = argv[1]; - -	bool module_found(false); -	std::ifstream mod_file("/proc/modules"); -	while (!mod_file.eof()) { -		std::string line; -		getline(mod_file, line); -		if (line.find("usrp_e") != std::string::npos) -			module_found = true; -	} -	mod_file.close(); - -	if (module_found) { -		std::cout << "USRP Embedded kernel module loaded, not loading FPGA." << std::endl; -		return -1; -	} - -	std::cout << "FPGA config file: " << bit_file << std::endl; - -	prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b); - -	std::cout << "Done = " << gpio_done.get_value() << std::endl; - -	send_file_to_fpga(bit_file, gpio_init_b, gpio_done); -} - diff --git a/host/usrp_e_utils/usrp-e-utility.cpp b/host/usrp_e_utils/usrp-e-utility.cpp new file mode 100644 index 000000000..139aabc30 --- /dev/null +++ b/host/usrp_e_utils/usrp-e-utility.cpp @@ -0,0 +1,72 @@ +// +// Copyright 2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.  If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/utils/safe_main.hpp> +#include <boost/program_options.hpp> +#include <boost/format.hpp> +#include <iostream> + +#include "fpga_downloader.cpp" +#include "clkgen_config.hpp" + +namespace po = boost::program_options; + +static const std::string default_passthrough_path = "/usr/share/uhd/images/usrp_e1xx_passthrough.bin"; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + +    //variables to be set by po +    std::string fpga_path; + +    //setup the program options +    po::options_description desc("Allowed options"); +    desc.add_options() +        ("help", "help message") +        ("fpga", po::value<std::string>(&fpga_path)->default_value(""), "loads the specified FPGA file") +        ("reclk",                                                       "runs the clock recovery") +    ; +    po::variables_map vm; +    po::store(po::parse_command_line(argc, argv, desc), vm); +    po::notify(vm); + +    //print the help message +    if (vm.count("help")){ +        std::cout << boost::format("UHD USRP-E Utility %s") % desc << std::endl; +        return ~0; +    } + +    bool loaded_fpga_image = false; +    if (vm.count("fpga")){ +        std::cout << "USRP-E Utility loading the FPGA..." << std::endl << std::endl; +        usrp_e100_load_fpga(fpga_path); +        loaded_fpga_image = true; +        sleep(1); +    } + +    if (vm.count("reclk")){ +        std::cout << "USRP-E Utility running the clock recovery..." << std::endl << std::endl; +        //if an image was not loaded or specified, we load pass-through +        if (fpga_path.empty()) fpga_path = default_passthrough_path; +        if (not loaded_fpga_image) usrp_e100_load_fpga(fpga_path); +        clock_genconfig_main(); +        std::system("rm /tmp/usrp*hash"); //clear hash so driver must reload +    } + +    std::cout << "Done!" << std::endl; + +    return 0; +} | 
