Statistics
| Branch: | Tag: | Revision:

root / host / utils / fx2_init_eeprom.cpp @ 82c4e283

History | View | Annotate | Download (3.34 KB)

1 b96088b6 Nick Foster
//
2
// Copyright 2010 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17
18
#include <uhd/utils/safe_main.hpp>
19
#include <uhd/device.hpp>
20 1ade1f94 Josh Blum
#include <uhd/property_tree.hpp>
21 b96088b6 Nick Foster
#include <boost/program_options.hpp>
22
#include <boost/format.hpp>
23
#include <iostream>
24 59eae14d Josh Blum
#include <cstdlib>
25 b96088b6 Nick Foster
26 5e01b9eb Nick Foster
const std::string FX2_VENDOR_ID("0x04b4");
27
const std::string FX2_PRODUCT_ID("0x8613");
28
29 b96088b6 Nick Foster
namespace po = boost::program_options;
30
31
int UHD_SAFE_MAIN(int argc, char *argv[]){
32 d2a38f7f Nick Foster
    std::string type;
33 b96088b6 Nick Foster
    po::options_description desc("Allowed options");
34
    desc.add_options()
35
        ("help", "help message")
36 7b066a45 Nick Foster
        ("image", po::value<std::string>(), "BIN image file")
37 5e01b9eb Nick Foster
        ("vid", po::value<std::string>(), "VID of device to program")
38
        ("pid", po::value<std::string>(), "PID of device to program")
39
        ("type", po::value<std::string>(), "device type (usrp1 or b100)")
40 b96088b6 Nick Foster
    ;
41
42
    po::variables_map vm;
43
    po::store(po::parse_command_line(argc, argv, desc), vm);
44
    po::notify(vm); 
45
46
    //print the help message
47
    if (vm.count("help")){
48
        std::cout << boost::format("USRP EEPROM initialization %s") % desc << std::endl;
49
        return ~0;
50
    }
51
52 59eae14d Josh Blum
    //cant find a uninitialized usrp with this mystery module in the way...
53
    if (std::system("/sbin/rmmod usbtest") != 0){
54
        std::cerr << "Did not rmmod usbtest, this may be ok..." << std::endl;
55
    }
56
57 b96088b6 Nick Foster
    //load the options into the address
58
    uhd::device_addr_t device_addr;
59 d2a38f7f Nick Foster
    device_addr["type"] = type;
60 5e01b9eb Nick Foster
    if(vm.count("vid") or vm.count("pid") or vm.count("type")) {
61
        if(not (vm.count("vid") and vm.count("pid") and vm.count("type"))) {
62
            std::cerr << "ERROR: Must specify vid, pid, and type if specifying any of the three args" << std::endl;
63
        } else {
64
            device_addr["vid"] = vm["vid"].as<std::string>();
65
            device_addr["pid"] = vm["pid"].as<std::string>();
66
            device_addr["type"] = vm["type"].as<std::string>();
67
        }
68
    } else {
69
        device_addr["vid"] = FX2_VENDOR_ID;
70
        device_addr["pid"] = FX2_PRODUCT_ID;
71
    }
72 b96088b6 Nick Foster
73
    //find and create a control transport to do the writing.
74
75
    uhd::device_addrs_t found_addrs = uhd::device::find(device_addr);
76
77
    if (found_addrs.size() == 0){
78 5e01b9eb Nick Foster
        std::cerr << "No USRP devices found" << std::endl;
79 b96088b6 Nick Foster
        return ~0;
80
    }
81
82
    for (size_t i = 0; i < found_addrs.size(); i++){
83
        std::cout << "Writing EEPROM data..." << std::endl;
84
        //uhd::device_addrs_t devs = uhd::device::find(found_addrs[i]);
85
        uhd::device::sptr dev = uhd::device::make(found_addrs[i]);
86 9851de07 Josh Blum
        uhd::property_tree::sptr tree = dev->get_tree();
87 1ade1f94 Josh Blum
        tree->access<std::string>("/mboards/0/load_eeprom").set(vm["image"].as<std::string>());
88 b96088b6 Nick Foster
    }
89
90
91
    std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl;
92
    return 0;
93
}