diff options
author | gnychis | 2009-01-16 18:51:42 +0000 |
---|---|---|
committer | gnychis | 2009-01-16 18:51:42 +0000 |
commit | c3f5183d1383a2fb029bf2a77555499ebf0530ff (patch) | |
tree | beb90d92d091e3fbbfb62d3d0f9e66a3762bc5ee /usrp | |
parent | 4b5cfa809a01a494c4f5e6b052414ed9b3d066cb (diff) | |
download | gnuradio-c3f5183d1383a2fb029bf2a77555499ebf0530ff.tar.gz gnuradio-c3f5183d1383a2fb029bf2a77555499ebf0530ff.tar.bz2 gnuradio-c3f5183d1383a2fb029bf2a77555499ebf0530ff.zip |
merging 10218 to 10241 for full daughterboard support with in-band project
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10244 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'usrp')
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_2tx.cc | 6 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_rx.cc | 5 | ||||
-rw-r--r-- | usrp/host/apps-inband/test_usrp_inband_tx.cc | 7 | ||||
-rw-r--r-- | usrp/host/lib/inband/usrp_usb_interface.cc | 152 | ||||
-rw-r--r-- | usrp/host/lib/inband/usrp_usb_interface.h | 8 |
5 files changed, 150 insertions, 28 deletions
diff --git a/usrp/host/apps-inband/test_usrp_inband_2tx.cc b/usrp/host/apps-inband/test_usrp_inband_2tx.cc index caa780339..11a1a491c 100644 --- a/usrp/host/apps-inband/test_usrp_inband_2tx.cc +++ b/usrp/host/apps-inband/test_usrp_inband_2tx.cc @@ -127,9 +127,9 @@ test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string &instance_name pmt_intern("interp-tx"), pmt_from_long(128)); - pmt_dict_set(usrp_dict, - pmt_intern("rf-freq"), - pmt_from_long(10e6)); +// pmt_dict_set(usrp_dict, +// pmt_intern("rf-freq"), +// pmt_from_long(10e6)); define_component("server", "usrp_server", usrp_dict); diff --git a/usrp/host/apps-inband/test_usrp_inband_rx.cc b/usrp/host/apps-inband/test_usrp_inband_rx.cc index dcb87a7c9..4f21e4afc 100644 --- a/usrp/host/apps-inband/test_usrp_inband_rx.cc +++ b/usrp/host/apps-inband/test_usrp_inband_rx.cc @@ -112,6 +112,11 @@ test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string &instance_name pmt_intern("decim-rx"), pmt_from_long(64)); +// If unspecified, chooses center frequency from range +// pmt_dict_set(usrp_dict, +// pmt_intern("rf-freq"), +// pmt_from_long(10e6)); + define_component("server", "usrp_server", usrp_dict); connect("self", "rx0", "server", "rx0"); diff --git a/usrp/host/apps-inband/test_usrp_inband_tx.cc b/usrp/host/apps-inband/test_usrp_inband_tx.cc index 7ce38c2e4..9f294e770 100644 --- a/usrp/host/apps-inband/test_usrp_inband_tx.cc +++ b/usrp/host/apps-inband/test_usrp_inband_tx.cc @@ -124,9 +124,10 @@ test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string &instance_name pmt_intern("interp-tx"), pmt_from_long(64)); - pmt_dict_set(usrp_dict, - pmt_intern("rf-freq"), - pmt_from_long(10e6)); +// If unspecified, chooses center frequency from range +// pmt_dict_set(usrp_dict, +// pmt_intern("rf-freq"), +// pmt_from_long(10e6)); define_component("server", "usrp_server", usrp_dict); diff --git a/usrp/host/lib/inband/usrp_usb_interface.cc b/usrp/host/lib/inband/usrp_usb_interface.cc index d82b589b4..cd77974c7 100644 --- a/usrp/host/lib/inband/usrp_usb_interface.cc +++ b/usrp/host/lib/inband/usrp_usb_interface.cc @@ -36,6 +36,7 @@ #include "usrp_tx.h" #include "usrp_standard.h" #include <stdio.h> +#include <usrp_dbid.h> typedef usrp_inband_usb_packet transport_pkt; @@ -59,7 +60,7 @@ usrp_usb_interface::usrp_usb_interface(mb_runtime *rt, const std::string &instan d_rx_reading(false), d_interp_tx(128), d_decim_rx(128), - d_rf_freq(10e6), + d_rf_freq(-1), d_rbf("inband_tx_rx.rbf") { // Dictionary for arguments to all of the components @@ -299,17 +300,51 @@ usrp_usb_interface::handle_cmd_open(pmt_t data) return; } - if(!d_utx->set_tx_freq (0,d_rf_freq) || !d_utx->set_tx_freq(1,d_rf_freq)) { // try setting center freq to 0 - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Failed to set center frequency on TX\n"; - reply_data = pmt_list2(invocation_handle, PMT_F); - d_cs->send(s_response_usrp_open, reply_data); - return; + // Perform TX daughterboard tuning + double target_freq; + unsigned int mux; + int tgain, rgain; + float input_rate; + bool ok; + usrp_tune_result r; + + // Cast to usrp_basic and then detect daughterboards + d_ub_tx = d_utx; + usrp_subdev_spec tspec = pick_tx_subdevice(); + db_base_sptr tsubdev = d_ub_tx->selected_subdev(tspec); + + // Set the TX mux value + mux = d_utx->determine_tx_mux_value(tspec); + d_utx->set_mux(mux); + + // Set the TX gain and determine rate + tgain = tsubdev->gain_max(); + tsubdev->set_gain(tgain); + input_rate = d_ub_tx->converter_rate() / d_utx->interp_rate(); + + // Perform the actual tuning, if no frequency specified then pick + if(d_rf_freq==-1) + target_freq = tsubdev->freq_min()+((tsubdev->freq_max()-tsubdev->freq_min())/2.0); + else + target_freq = d_rf_freq; + ok = d_utx->tune(tsubdev->which(), tsubdev, target_freq, &r); + tsubdev->set_enable(true); + + if(verbose) { + printf("TX Subdevice name is %s\n", tsubdev->name().c_str()); + printf("TX Subdevice freq range: (%g, %g)\n", + tsubdev->freq_min(), tsubdev->freq_max()); + printf("mux: %#08x\n", mux); + printf("target_freq: %f\n", target_freq); + printf("ok: %s\n", ok ? "true" : "false"); + printf("r.baseband_freq: %f\n", r.baseband_freq); + printf("r.dxc_freq: %f\n", r.dxc_freq); + printf("r.residual_freq: %f\n", r.residual_freq); + printf("r.inverted: %d\n", r.inverted); } - if(!d_utx->set_mux(0xBA98)) { - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Failed to set TX mux\n"; + if(!ok) { + std::cerr << "[USRP_USB_INTERFACE] Failed to set center frequency on TX\n"; reply_data = pmt_list2(invocation_handle, PMT_F); d_cs->send(s_response_usrp_open, reply_data); return; @@ -337,20 +372,39 @@ usrp_usb_interface::handle_cmd_open(pmt_t data) d_cs->send(s_response_usrp_open, reply_data); return; } + + // Cast to usrp_basic and then detect daughterboards + d_ub_rx = d_urx; + usrp_subdev_spec rspec = pick_rx_subdevice(); + db_base_sptr rsubdev = d_ub_rx->selected_subdev(rspec); + + // Set the RX mux value + mux = d_urx->determine_rx_mux_value(rspec); + d_urx->set_mux(mux); + + // Set the TX gain and determine rate + rgain = rsubdev->gain_max(); + rsubdev->set_gain(rgain); + input_rate = d_ub_rx->converter_rate() / d_urx->decim_rate(); - if(!d_urx->set_rx_freq (0, -d_rf_freq) || !d_urx->set_rx_freq(1, -d_rf_freq)) { - if (verbose) - std::cout << "[usrp_server] Failed to set center frequency on RX\n"; - reply_data = pmt_list2(invocation_handle, PMT_F); - d_cs->send(s_response_usrp_open, reply_data); - return; + ok = d_urx->tune(rsubdev->which(), rsubdev, target_freq, &r); + rsubdev->set_enable(true); + + if(verbose) { + printf("RX Subdevice name is %s\n", rsubdev->name().c_str()); + printf("RX Subdevice freq range: (%g, %g)\n", + rsubdev->freq_min(), rsubdev->freq_max()); + printf("mux: %#08x\n", mux); + printf("target_freq: %f\n", target_freq); + printf("ok: %s\n", ok ? "true" : "false"); + printf("r.baseband_freq: %f\n", r.baseband_freq); + printf("r.dxc_freq: %f\n", r.dxc_freq); + printf("r.residual_freq: %f\n", r.residual_freq); + printf("r.inverted: %d\n", r.inverted); } - // Two channels ... this really needs to end up being set correctly by - // querying for what dboards are connected - if(!d_urx->set_mux(0x32103210)) { - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Failed to set RX mux\n"; + if(!ok) { + std::cerr << "[USRP_USB_INTERFACE] Failed to set center frequency on RX\n"; reply_data = pmt_list2(invocation_handle, PMT_F); d_cs->send(s_response_usrp_open, reply_data); return; @@ -486,5 +540,61 @@ usrp_usb_interface::handle_cmd_close(pmt_t data) shutdown_all(PMT_T); } +usrp_subdev_spec +usrp_usb_interface::pick_rx_subdevice() +{ + int dbids[] = { + USRP_DBID_FLEX_400_RX, + USRP_DBID_FLEX_900_RX, + USRP_DBID_FLEX_1200_RX, + USRP_DBID_FLEX_2400_RX, + USRP_DBID_TV_RX, + USRP_DBID_TV_RX_REV_2, + USRP_DBID_DBS_RX, + USRP_DBID_DBS_RX_REV_2_1, + USRP_DBID_BASIC_RX + }; + + std::vector<int> candidates(dbids, dbids+(sizeof(dbids)/sizeof(int))); + return pick_subdev(d_ub_rx, candidates); +} + +usrp_subdev_spec +usrp_usb_interface::pick_tx_subdevice() +{ + int dbids[] = { + USRP_DBID_FLEX_400_TX, + USRP_DBID_FLEX_900_TX, + USRP_DBID_FLEX_1200_TX, + USRP_DBID_FLEX_2400_TX, + USRP_DBID_BASIC_TX + }; + + std::vector<int> candidates(dbids, dbids+(sizeof(dbids)/sizeof(int))); + return pick_subdev(d_ub_tx, candidates); +} + +usrp_subdev_spec +usrp_usb_interface::pick_subdev(boost::shared_ptr<usrp_basic> d_usrp_basic, std::vector<int> candidates) +{ + int dbid0 = d_usrp_basic->selected_subdev(usrp_subdev_spec(0, 0))->dbid(); + int dbid1 = d_usrp_basic->selected_subdev(usrp_subdev_spec(1, 0))->dbid(); + + for (int i = 0; i < candidates.size(); i++) { + int dbid = candidates[i]; + if (dbid0 == dbid) + return usrp_subdev_spec(0, 0); + if (dbid1 == dbid) + return usrp_subdev_spec(1, 0); + } + + if (dbid0 >= 0) + return usrp_subdev_spec(0, 0); + if (dbid1 >= 0) + return usrp_subdev_spec(1, 0); + + throw std::runtime_error("No suitable daughterboard found!"); +} + REGISTER_MBLOCK_CLASS(usrp_usb_interface); diff --git a/usrp/host/lib/inband/usrp_usb_interface.h b/usrp/host/lib/inband/usrp_usb_interface.h index c10741516..4d7750a7d 100644 --- a/usrp/host/lib/inband/usrp_usb_interface.h +++ b/usrp/host/lib/inband/usrp_usb_interface.h @@ -34,6 +34,9 @@ class usrp_usb_interface : public mb_mblock usrp_standard_tx_sptr d_utx; usrp_standard_rx_sptr d_urx; + + boost::shared_ptr<usrp_basic> d_ub_tx; + boost::shared_ptr<usrp_basic> d_ub_rx; mb_port_sptr d_cs; mb_port_sptr d_rx_cs; @@ -49,7 +52,7 @@ class usrp_usb_interface : public mb_mblock long d_interp_tx; long d_decim_rx; - long d_rf_freq; + double d_rf_freq; std::string d_rbf; @@ -58,6 +61,9 @@ class usrp_usb_interface : public mb_mblock ~usrp_usb_interface(); void initial_transition(); void handle_message(mb_message_sptr msg); + usrp_subdev_spec pick_rx_subdevice(); + usrp_subdev_spec pick_tx_subdevice(); + usrp_subdev_spec pick_subdev(boost::shared_ptr<usrp_basic> d_usrp_basic, std::vector<int> candidates); private: void handle_cmd_open(pmt_t data); |