summaryrefslogtreecommitdiff
path: root/usrp2/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'usrp2/host/lib')
-rw-r--r--usrp2/host/lib/control.h8
-rw-r--r--usrp2/host/lib/usrp2.cc14
-rw-r--r--usrp2/host/lib/usrp2_impl.cc88
-rw-r--r--usrp2/host/lib/usrp2_impl.h5
4 files changed, 110 insertions, 5 deletions
diff --git a/usrp2/host/lib/control.h b/usrp2/host/lib/control.h
index 2c042f0cf..33f73fa94 100644
--- a/usrp2/host/lib/control.h
+++ b/usrp2/host/lib/control.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008,2009 Free Software Foundation, Inc.
*
* 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
@@ -93,6 +93,12 @@ namespace usrp2 {
// eop must be dynamically written here
};
+ struct op_freq_cmd {
+ u2_eth_packet_t h;
+ op_freq_t op;
+ op_generic_t eop;
+ };
+
/*!
* Control mechanism to allow API calls to block waiting for reply packets
*/
diff --git a/usrp2/host/lib/usrp2.cc b/usrp2/host/lib/usrp2.cc
index 90a31b220..6a54c6da6 100644
--- a/usrp2/host/lib/usrp2.cc
+++ b/usrp2/host/lib/usrp2.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008,2009 Free Software Foundation, Inc.
*
* 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
@@ -187,6 +187,12 @@ namespace usrp2 {
}
bool
+ usrp2::set_rx_lo_offset(double frequency)
+ {
+ return d_impl->set_rx_lo_offset(frequency);
+ }
+
+ bool
usrp2::set_rx_center_freq(double frequency, tune_result *result)
{
return d_impl->set_rx_center_freq(frequency, result);
@@ -279,6 +285,12 @@ namespace usrp2 {
}
bool
+ usrp2::set_tx_lo_offset(double frequency)
+ {
+ return d_impl->set_tx_lo_offset(frequency);
+ }
+
+ bool
usrp2::set_tx_center_freq(double frequency, tune_result *result)
{
return d_impl->set_tx_center_freq(frequency, result);
diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc
index 2aa430138..4b4de024f 100644
--- a/usrp2/host/lib/usrp2_impl.cc
+++ b/usrp2/host/lib/usrp2_impl.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008,2009 Free Software Foundation, Inc.
*
* 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
@@ -73,6 +73,10 @@ namespace usrp2 {
case OP_SYNC_TO_PPS: return "OP_SYNC_TO_PPS";
case OP_PEEK: return "OP_PEEK";
case OP_PEEK_REPLY: return "OP_PEEK_REPLY";
+ case OP_SET_TX_LO_OFFSET: return "OP_SET_TX_LO_OFFSET";
+ case OP_SET_TX_LO_OFFSET_REPLY: return "OP_SET_TX_LO_OFFSET_REPLY";
+ case OP_SET_RX_LO_OFFSET: return "OP_SET_RX_LO_OFFSET";
+ case OP_SET_RX_LO_OFFSET_REPLY: return "OP_SET_RX_LO_OFFSET_REPLY";
default:
char buf[64];
@@ -169,6 +173,10 @@ namespace usrp2 {
fprintf(stderr, " gain_db_per_step = %g\n", rx_gain_db_per_step());
}
+ // Ensure any custom values in hardware are cleared
+ if (!reset_db())
+ std::cerr << "usrp2::ctor reset_db failed\n";
+
// default gains to mid point
if (!set_tx_gain((tx_gain_min() + tx_gain_max()) / 2))
std::cerr << "usrp2::ctor set_tx_gain failed\n";
@@ -472,6 +480,33 @@ namespace usrp2 {
}
bool
+ usrp2::impl::set_rx_lo_offset(double frequency)
+ {
+ op_freq_cmd cmd;
+ op_generic_t reply;
+
+ memset(&cmd, 0, sizeof(cmd));
+ init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+ cmd.op.opcode = OP_SET_RX_LO_OFFSET;
+ cmd.op.len = sizeof(cmd.op);
+ cmd.op.rid = d_next_rid++;
+
+ u2_fxpt_freq_t fxpt = u2_double_to_fxpt_freq(frequency);
+ cmd.op.freq_hi = htonl(u2_fxpt_freq_hi(fxpt));
+ cmd.op.freq_lo = htonl(u2_fxpt_freq_lo(fxpt));
+
+ cmd.eop.opcode = OP_EOP;
+ cmd.eop.len = sizeof(cmd.eop);
+
+ pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+ if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
+ return false;
+
+ bool success = (ntohx(reply.ok) == 1);
+ return success;
+ }
+
+ bool
usrp2::impl::set_rx_center_freq(double frequency, tune_result *result)
{
op_config_rx_v2_cmd cmd;
@@ -711,6 +746,33 @@ namespace usrp2 {
}
bool
+ usrp2::impl::set_tx_lo_offset(double frequency)
+ {
+ op_freq_cmd cmd;
+ op_generic_t reply;
+
+ memset(&cmd, 0, sizeof(cmd));
+ init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+ cmd.op.opcode = OP_SET_TX_LO_OFFSET;
+ cmd.op.len = sizeof(cmd.op);
+ cmd.op.rid = d_next_rid++;
+
+ u2_fxpt_freq_t fxpt = u2_double_to_fxpt_freq(frequency);
+ cmd.op.freq_hi = htonl(u2_fxpt_freq_hi(fxpt));
+ cmd.op.freq_lo = htonl(u2_fxpt_freq_lo(fxpt));
+
+ cmd.eop.opcode = OP_EOP;
+ cmd.eop.len = sizeof(cmd.eop);
+
+ pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+ if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
+ return false;
+
+ bool success = (ntohx(reply.ok) == 1);
+ return success;
+ }
+
+ bool
usrp2::impl::set_tx_center_freq(double frequency, tune_result *result)
{
op_config_tx_v2_cmd cmd;
@@ -1152,7 +1214,7 @@ namespace usrp2 {
// Copy data from vector into packet space
uint32_t *dest = (uint32_t *)((uint8_t *)cmd+plen);
- for (unsigned int i = 0; i < words; i++) {
+ for (int i = 0; i < words; i++) {
//fprintf(stderr, "%03i@%p\n", i, dest);
*dest++ = htonl(data[i]);
}
@@ -1174,4 +1236,26 @@ namespace usrp2 {
return ok;
}
+ bool
+ usrp2::impl::reset_db()
+ {
+ op_generic_cmd cmd;
+ op_generic_t reply;
+
+ memset(&cmd, 0, sizeof(cmd));
+ init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
+ cmd.op.opcode = OP_RESET_DB;
+ cmd.op.len = sizeof(cmd.op);
+ cmd.op.rid = d_next_rid++;
+ cmd.eop.opcode = OP_EOP;
+ cmd.eop.len = sizeof(cmd.eop);
+
+ pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+ if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
+ return false;
+
+ bool success = (ntohx(reply.ok) == 1);
+ return success;
+ }
+
} // namespace usrp2
diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h
index b332d65d2..dfd054c03 100644
--- a/usrp2/host/lib/usrp2_impl.h
+++ b/usrp2/host/lib/usrp2_impl.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2008 Free Software Foundation, Inc.
+ * Copyright 2008,2009 Free Software Foundation, Inc.
*
* 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
@@ -108,6 +108,7 @@ namespace usrp2 {
data_handler::result handle_control_packet(const void *base, size_t len);
data_handler::result handle_data_packet(const void *base, size_t len);
bool dboard_info();
+ bool reset_db();
public:
impl(const std::string &ifc, props *p);
@@ -123,6 +124,7 @@ namespace usrp2 {
double rx_gain_min() { return d_rx_db_info.gain_min; }
double rx_gain_max() { return d_rx_db_info.gain_max; }
double rx_gain_db_per_step() { return d_rx_db_info.gain_step_size; }
+ bool set_rx_lo_offset(double frequency);
bool set_rx_center_freq(double frequency, tune_result *result);
double rx_freq_min() { return d_rx_db_info.freq_min; }
double rx_freq_max() { return d_rx_db_info.freq_max; }
@@ -141,6 +143,7 @@ namespace usrp2 {
double tx_gain_min() { return d_tx_db_info.gain_min; }
double tx_gain_max() { return d_tx_db_info.gain_max; }
double tx_gain_db_per_step() { return d_tx_db_info.gain_step_size; }
+ bool set_tx_lo_offset(double frequency);
bool set_tx_center_freq(double frequency, tune_result *result);
double tx_freq_min() { return d_tx_db_info.freq_min; }
double tx_freq_max() { return d_tx_db_info.freq_max; }