[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8543 - in usrp2/trunk/host-ng: apps include/usrp2 lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8543 - in usrp2/trunk/host-ng: apps include/usrp2 lib |
Date: |
Mon, 2 Jun 2008 09:54:49 -0600 (MDT) |
Author: jcorgan
Date: 2008-06-02 09:54:47 -0600 (Mon, 02 Jun 2008)
New Revision: 8543
Modified:
usrp2/trunk/host-ng/apps/test_usrp2.cc
usrp2/trunk/host-ng/include/usrp2/usrp2.h
usrp2/trunk/host-ng/lib/find.cc
usrp2/trunk/host-ng/lib/usrp2.cc
Log:
wip, ported rx config and control to ng
Modified: usrp2/trunk/host-ng/apps/test_usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-06-02 07:53:14 UTC (rev
8542)
+++ usrp2/trunk/host-ng/apps/test_usrp2.cc 2008-06-02 15:54:47 UTC (rev
8543)
@@ -31,10 +31,11 @@
if (rt != RT_OK)
std::cerr << "Failed to enable realtime scheduling" << std::endl;
- // usrp2::usrp2::sptr u2 = usrp2::usrp2::make("eth0", "00:50:c2:85:31:67");
- // usrp2::usrp2::sptr u2 = usrp2::usrp2::make("eth0", "BO:GU:SA:DD:RE:SS");
usrp2::usrp2::sptr u2 = usrp2::usrp2::make("eth0");
+ u2->set_rx_gain(1.0);
+ u2->set_rx_freq(0.0, NULL);
+ u2->set_rx_decim(10);
u2->start_rx_streaming();
struct timespec ts;
Modified: usrp2/trunk/host-ng/include/usrp2/usrp2.h
===================================================================
--- usrp2/trunk/host-ng/include/usrp2/usrp2.h 2008-06-02 07:53:14 UTC (rev
8542)
+++ usrp2/trunk/host-ng/include/usrp2/usrp2.h 2008-06-02 15:54:47 UTC (rev
8543)
@@ -41,6 +41,29 @@
props_vector_t find(const std::string &ifc, const std::string &addr="");
+/*!
+ * Structure to hold results of tuning
+ */
+class usrp2_tune_result
+{
+public:
+ // RF frequency that corresponds to DC in the IF
+ double baseband_freq;
+
+ // frequency programmed into the DDC/DUC
+ double dxc_freq;
+
+ // residual frequency (typically < 0.01 Hz)
+ double residual_freq;
+
+ // is the spectrum inverted?
+ bool spectrum_inverted;
+
+ usrp2_tune_result()
+ : baseband_freq(0), dxc_freq(0), residual_freq(0),
spectrum_inverted(false) {}
+ ~usrp2_tune_result();
+};
+
class usrp2 : boost::noncopyable
{
public:
@@ -63,7 +86,31 @@
*/
~usrp2();
+ /*
+ * Rx configuration and control
+ */
+
/*!
+ * Set receiver gain
+ */
+ bool set_rx_gain(double gain);
+
+ /*!
+ * Set receiver center frequency
+ */
+ bool set_rx_freq(double frequency, usrp2_tune_result *result);
+
+ /*!
+ * Set receiver sample rate decimation
+ */
+ bool set_rx_decim(int decimation_factor);
+
+ /*!
+ * Set receiver IQ magnitude scaling
+ */
+ bool set_rx_scale_iq(int scale_i, int scale_q);
+
+ /*!
* Set received sample format
*
* domain: complex or real
Modified: usrp2/trunk/host-ng/lib/find.cc
===================================================================
--- usrp2/trunk/host-ng/lib/find.cc 2008-06-02 07:53:14 UTC (rev 8542)
+++ usrp2/trunk/host-ng/lib/find.cc 2008-06-02 15:54:47 UTC (rev 8543)
@@ -27,7 +27,7 @@
#include "pktfilter.h"
#include <iostream>
-#define FIND_DEBUG 1
+#define FIND_DEBUG 0
namespace usrp2 {
Modified: usrp2/trunk/host-ng/lib/usrp2.cc
===================================================================
--- usrp2/trunk/host-ng/lib/usrp2.cc 2008-06-02 07:53:14 UTC (rev 8542)
+++ usrp2/trunk/host-ng/lib/usrp2.cc 2008-06-02 15:54:47 UTC (rev 8543)
@@ -22,6 +22,7 @@
#include <usrp2/usrp2.h>
#include <usrp2_eth_packet.h>
+#include <usrp2_types.h>
#include "ethernet.h"
#include "pktfilter.h"
#include "usrp2_thread.h"
@@ -32,7 +33,7 @@
#include <netinet/in.h>
#include <errno.h>
-#define USRP2_DEBUG 1
+#define USRP2_DEBUG 0
#if USRP2_DEBUG
#define DEBUG_LOG(x) ::write(2, x, 1)
@@ -53,10 +54,13 @@
std::string d_addr;
usrp2_thread *d_thread;
bool d_tx_active;
+ int d_rx_decim;
int d_rx_seqno;
int d_tx_seqno;
+ int d_next_rid;
unsigned int d_num_rx_frames;
unsigned int d_num_rx_lost;
+ unsigned int d_num_rx_bytes;
public:
impl(const std::string &ifc, const std::string &addr);
@@ -66,13 +70,15 @@
void init_et_hdrs(u2_eth_packet_t *p, const std::string &dst);
void init_etf_hdrs(u2_eth_packet_t *p, const std::string &dst,
int word0_flags, int chan, uint32_t timestamp);
-
- bool start_rx_streaming(unsigned int items_per_frame);
- bool stop_rx_streaming();
-
void loop_body();
void rx_frames();
void tx_frames();
+ bool set_rx_gain(double gain);
+ bool set_rx_freq(double frequency, usrp2_tune_result *result);
+ bool set_rx_decim(int decimation_factor);
+ bool set_rx_scale_iq(int scale_i, int scale_q);
+ bool start_rx_streaming(unsigned int items_per_frame);
+ bool stop_rx_streaming();
};
// ----------------------------------------------------------------------
@@ -99,7 +105,31 @@
// ----------------------------------------------------------------------
+bool
+usrp2::set_rx_gain(double gain)
+{
+ return d_impl->set_rx_gain(gain);
+}
+
bool
+usrp2::set_rx_freq(double frequency, usrp2_tune_result *result)
+{
+ return d_impl->set_rx_freq(frequency, result);
+}
+
+bool
+usrp2::set_rx_decim(int decimation_factor)
+{
+ return d_impl->set_rx_decim(decimation_factor);
+}
+
+bool
+usrp2::set_rx_scale_iq(int scale_i, int scale_q)
+{
+ return d_impl->set_rx_scale_iq(scale_i, scale_q);
+}
+
+bool
usrp2::start_rx_streaming(unsigned int items_per_frame)
{
return d_impl->start_rx_streaming(items_per_frame);
@@ -114,8 +144,9 @@
// ----------------------------------------------------------------------
usrp2::impl::impl(const std::string &ifc, const std::string &addr)
- : d_ethernet(new ethernet()), d_pf(0), d_thread(0),
- d_rx_seqno(-1), d_tx_seqno(0), d_num_rx_frames(0), d_num_rx_lost(0)
+ : d_ethernet(new ethernet()), d_pf(0), d_thread(0), d_rx_decim(0),
+ d_rx_seqno(-1), d_tx_seqno(0), d_next_rid(0),
+ d_num_rx_frames(0), d_num_rx_lost(0), d_num_rx_bytes(0)
{
props_vector_t u2s = find(ifc, addr);
if (u2s.size() != 1)
@@ -147,9 +178,10 @@
if (USRP2_DEBUG) {
std::cerr << "usrp2 destructor: received " << d_num_rx_frames
- << " frames, with " << d_num_rx_lost << " gaps ("
+ << " frames, with " << d_num_rx_lost << " lost ("
<< (int)(100.0*d_num_rx_lost/d_num_rx_frames)
- << "%)" << std::endl;
+ << "%), totaling " << d_num_rx_bytes
+ << " bytes" << std::endl;
}
}
@@ -204,7 +236,158 @@
}
}
+bool
+usrp2::impl::set_rx_gain(double gain)
+{
+ if (USRP2_DEBUG)
+ std::cerr << "usrp2: setting receive gain to " << gain << std::endl;
+
+ uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ memset(pktbuf, 0, sizeof(pktbuf));
+
+ struct command {
+ u2_eth_packet_t h;
+ op_config_rx_v2_t op;
+ op_eop_t eop;
+ };
+
+ command *c = (command *) pktbuf;
+ init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+
+ c->op.opcode = OP_CONFIG_RX_V2;
+ c->op.len = sizeof(op_config_rx_v2_t);
+ c->op.rid = d_next_rid++;
+
+ c->op.valid = htons(CFGV_GAIN);
+ c->op.gain = htons(u2_double_to_fxpt_gain(gain));
+
+ c->eop.opcode = OP_EOP;
+ c->eop.len = sizeof(op_eop_t);
+
+ int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
+ if (d_ethernet->write_packet(c, len) != len)
+ return false;
+
+ // FIXME wait for corresponding reply, etc.
+
+ return true;
+}
+
bool
+usrp2::impl::set_rx_freq(double frequency, usrp2_tune_result *result)
+{
+ if (USRP2_DEBUG)
+ std::cerr << "usrp2: setting frequency to " << frequency << std::endl;
+
+ uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ memset(pktbuf, 0, sizeof(pktbuf));
+
+ struct command {
+ u2_eth_packet_t h;
+ op_config_rx_v2_t op;
+ op_eop_t eop;
+ };
+
+ command *c = (command *) pktbuf;
+ init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+
+ c->op.opcode = OP_CONFIG_RX_V2;
+ c->op.len = sizeof(op_config_rx_v2_t);
+ c->op.rid = d_next_rid++;
+
+ c->op.valid = htons(CFGV_FREQ);
+ u2_fxpt_freq_t fxpt = u2_double_to_fxpt_freq(frequency);
+ c->op.freq_hi = htonl(u2_fxpt_freq_hi(fxpt));
+ c->op.freq_lo = htonl(u2_fxpt_freq_lo(fxpt));
+
+ c->eop.opcode = OP_EOP;
+ c->eop.len = sizeof(op_eop_t);
+
+ int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
+ if (d_ethernet->write_packet(c, len) == len) {
+ // FIXME: wait for corresponding reply, set tune result members
+ }
+
+ return true;
+}
+
+bool
+usrp2::impl::set_rx_decim(int decimation_factor)
+{
+ if (USRP2_DEBUG)
+ std::cerr << "usrp2: setting receive decimation rate to "
+ << decimation_factor << std::endl;
+ uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ memset(pktbuf, 0, sizeof(pktbuf));
+
+ struct command {
+ u2_eth_packet_t h;
+ op_config_rx_v2_t op;
+ op_eop_t eop;
+ };
+
+ command *c = (command *) pktbuf;
+ init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+
+ c->op.opcode = OP_CONFIG_RX_V2;
+ c->op.len = sizeof(op_config_rx_v2_t);
+ c->op.rid = d_next_rid++;
+
+ c->op.valid = htons(CFGV_INTERP_DECIM);
+ c->op.decim = htonl(decimation_factor);
+
+ c->eop.opcode = OP_EOP;
+ c->eop.len = sizeof(op_eop_t);
+
+ int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
+ if (d_ethernet->write_packet(c, len) != len)
+ return false;
+
+ // FIXME wait for corresponding reply, etc.
+
+ d_rx_decim = decimation_factor;
+ return true;
+}
+
+bool
+usrp2::impl::set_rx_scale_iq(int scale_i, int scale_q)
+{
+ if (USRP2_DEBUG)
+ std::cerr << "usrp2: setting RX IQ scaling to "
+ << scale_i << ", " << scale_q << std::endl;
+
+ uint8_t pktbuf[ethernet::MAX_PKTLEN];
+ memset(pktbuf, 0, sizeof(pktbuf));
+
+ struct command {
+ u2_eth_packet_t h;
+ op_config_rx_v2_t op;
+ op_eop_t eop;
+ };
+
+ command *c = (command *) pktbuf;
+ init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+
+ c->op.opcode = OP_CONFIG_RX_V2;
+ c->op.len = sizeof(op_config_rx_v2_t);
+ c->op.rid = d_next_rid++;
+
+ c->op.valid = htons(CFGV_SCALE_IQ);
+ c->op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff));
+
+ c->eop.opcode = OP_EOP;
+ c->eop.len = sizeof(op_eop_t);
+
+ int len = std::max((size_t) ethernet::MIN_PKTLEN, sizeof(command));
+ if (d_ethernet->write_packet(c, len) != len)
+ return false;
+
+ // FIXME wait for corresponding reply, etc.
+
+ return true;
+}
+
+bool
usrp2::impl::start_rx_streaming(unsigned int items_per_frame)
{
// Assume for now rx format is complex floats
@@ -288,8 +471,6 @@
void
usrp2::impl::rx_frames()
{
- //uint8_t pktbuf[ethernet::MAX_PKTLEN];
- //memset(pktbuf, 0, sizeof(pktbuf));
u2_eth_samples_t pkt;
int len;
@@ -312,16 +493,14 @@
}
d_num_rx_frames += 1;
+ d_num_rx_bytes += len;
+
if (d_rx_seqno != -1) {
int expected_seqno = (d_rx_seqno + 1) & 0xFF;
int seqno = pkt.hdrs.thdr.seqno;
if (seqno != expected_seqno) {
- std::cerr << "\nL expected=" << expected_seqno
- << " actual=" << seqno
- << std::endl;
-
- //DEBUG_LOG("L"); // missed packet
+ ::write(2, "uS", 2); // missing sequence number
int missing = expected_seqno - seqno;
if (missing < 0)
missing += 256;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8543 - in usrp2/trunk/host-ng: apps include/usrp2 lib,
jcorgan <=