[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9061 - in usrp2/branches/developers/eb/wip/host-ng: a
From: |
eb |
Subject: |
[Commit-gnuradio] r9061 - in usrp2/branches/developers/eb/wip/host-ng: apps include/usrp2 lib |
Date: |
Wed, 30 Jul 2008 15:56:31 -0600 (MDT) |
Author: eb
Date: 2008-07-30 15:56:27 -0600 (Wed, 30 Jul 2008)
New Revision: 9061
Modified:
usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h
usrp2/branches/developers/eb/wip/host-ng/lib/control.h
usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc
usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc
usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h
Log:
Fixed all zero reception by setting tx and rx scaling in usrp2::impl
constructor.
Added tx config messages that parallel rx config messages.
Modified: usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
2008-07-30 19:43:48 UTC (rev 9060)
+++ usrp2/branches/developers/eb/wip/host-ng/apps/test2_usrp2.cc
2008-07-30 21:56:27 UTC (rev 9061)
@@ -56,7 +56,7 @@
operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata
*metadata)
{
// printf("W0: %08x TS: %08x\n", metadata->word0, metadata->timestamp);
- printf("I0: %08x\n", items[0]);
+ // printf("I0: %08x\n", items[0]);
d_nsamples += nitems;
d_nframes++;
Modified: usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h
2008-07-30 19:43:48 UTC (rev 9060)
+++ usrp2/branches/developers/eb/wip/host-ng/include/usrp2/usrp2.h
2008-07-30 21:56:27 UTC (rev 9061)
@@ -79,7 +79,9 @@
~usrp2();
/*
+ * ----------------------------------------------------------------
* Rx configuration and control
+ * ----------------------------------------------------------------
*/
/*!
@@ -143,6 +145,47 @@
*/
unsigned int rx_missing();
+ /*
+ * ----------------------------------------------------------------
+ * Tx configuration and control
+ * ----------------------------------------------------------------
+ */
+
+ /*!
+ * Set receiver gain
+ */
+ bool set_tx_gain(double gain);
+
+ /*!
+ * Set transmitter center frequency
+ */
+ bool set_tx_center_freq(double frequency, tune_result *result);
+
+ /*!
+ * Set transmitter sample rate interpolation
+ */
+ bool set_tx_interp(int interpolation_factor);
+
+ /*!
+ * Set transmit IQ magnitude scaling
+ */
+ bool set_tx_scale_iq(int scale_i, int scale_q);
+
+ /*!
+ * Set transmit sample format
+ *
+ * domain: complex or real
+ * type: floating, fixed point, or raw
+ * depth: bits per sample
+ *
+ * Sets format over the wire for samples to USRP2.
+ */
+ // bool set_tx_format(...);
+
+ // bool tx_samples(...)
+
+
+
class impl; // implementation details
private:
Modified: usrp2/branches/developers/eb/wip/host-ng/lib/control.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/control.h 2008-07-30
19:43:48 UTC (rev 9060)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/control.h 2008-07-30
21:56:27 UTC (rev 9061)
@@ -46,6 +46,14 @@
op_generic_t eop;
};
+ struct op_config_tx_v2_cmd
+ {
+ u2_eth_packet_t h;
+ op_config_tx_v2_t op;
+ op_generic_t eop;
+ };
+
+
/*!
* Control mechanism to allow API calls to block waiting for reply packets
*/
Modified: usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc 2008-07-30
19:43:48 UTC (rev 9060)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/usrp2.cc 2008-07-30
21:56:27 UTC (rev 9061)
@@ -45,6 +45,8 @@
// NOP
}
+ // Receive
+
bool
usrp2::set_rx_gain(double gain)
{
@@ -99,4 +101,33 @@
return d_impl->rx_missing();
}
+ // Transmit
+
+ bool
+ usrp2::set_tx_gain(double gain)
+ {
+ return d_impl->set_tx_gain(gain);
+ }
+
+ bool
+ usrp2::set_tx_center_freq(double frequency, tune_result *result)
+ {
+ return d_impl->set_tx_center_freq(frequency, result);
+ }
+
+ bool
+ usrp2::set_tx_interp(int interpolation_factor)
+ {
+ return d_impl->set_tx_interp(interpolation_factor);
+ }
+
+ bool
+ usrp2::set_tx_scale_iq(int scale_i, int scale_q)
+ {
+ return d_impl->set_tx_scale_iq(scale_i, scale_q);
+ }
+
+
+
+
} // namespace usrp2
Modified: usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc 2008-07-30
19:43:48 UTC (rev 9060)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.cc 2008-07-30
21:56:27 UTC (rev 9061)
@@ -43,6 +43,9 @@
#define DEBUG_LOG(x)
#endif
+static const int DEFAULT_RX_SCALE = 1024;
+static const int DEFAULT_TX_SCALE = 3000;
+
namespace usrp2 {
static const double DEF_CMD_TIMEOUT = 0.1;
@@ -140,6 +143,9 @@
d_bg_thread = new usrp2_thread(this);
d_bg_thread->start();
+
+ set_rx_scale_iq(DEFAULT_RX_SCALE, DEFAULT_RX_SCALE); // set workable
default
+ set_tx_scale_iq(DEFAULT_TX_SCALE, DEFAULT_TX_SCALE); // set workable
default
}
usrp2::impl::~impl()
@@ -223,6 +229,189 @@
cmd->eop.len = sizeof(cmd->eop);
}
+ void
+ usrp2::impl::init_config_tx_v2_cmd(op_config_tx_v2_cmd *cmd)
+ {
+ memset(cmd, 0, sizeof(*cmd));
+ init_etf_hdrs(&cmd->h, d_addr, 0, CONTROL_CHAN, -1);
+ cmd->op.opcode = OP_CONFIG_TX_V2;
+ cmd->op.len = sizeof(cmd->op);
+ cmd->op.rid = d_next_rid++;
+ cmd->eop.opcode = OP_EOP;
+ cmd->eop.len = sizeof(cmd->eop);
+ }
+
+ bool
+ usrp2::impl::transmit_cmd(void *cmd, size_t len, pending_reply *p, double
secs)
+ {
+ if (p)
+ d_pending_replies[p->rid()] = p;
+
+ // Transmit command
+ if (d_eth_buf->tx_frame(cmd, len) != eth_buffer::EB_OK) {
+ d_pending_replies[p->rid()] = 0;
+ return false;
+ }
+
+ int res = 1;
+ if (p)
+ res = p->wait(secs);
+
+ d_pending_replies[p->rid()] = 0;
+ return res == 1;
+ }
+
+ // ----------------------------------------------------------------
+ // Background loop: received packet demuxing
+ // ----------------------------------------------------------------
+
+ void
+ usrp2::impl::stop_bg()
+ {
+ d_bg_running = false;
+ d_bg_pending_cond.signal();
+
+ void *dummy_status;
+ d_bg_thread->join(&dummy_status);
+ }
+
+ void
+ usrp2::impl::bg_loop()
+ {
+ d_bg_running = true;
+ while(d_bg_running) {
+ DEBUG_LOG(":");
+ // Receive available frames from ethernet buffer. Handler will
+ // process control frames, enqueue data packets in channel
+ // rings, and signal blocked API threads
+ int res = d_eth_buf->rx_frames(this, 100); // FIXME magic timeout
+ if (res == eth_buffer::EB_ERROR)
+ break;
+
+ // Wait for user API thread(s) to process all enqueued packets.
+ // The channel ring thread that decrements d_num_enqueued to zero
+ // will signal this thread to continue.
+ {
+ omni_mutex_lock l(d_enqueued_mutex);
+ while(d_num_enqueued > 0 && d_bg_running)
+ d_bg_pending_cond.wait();
+ }
+ }
+ d_bg_running = false;
+ }
+
+ //
+ // passed to eth_buffer::rx_frames
+ //
+ data_handler::result
+ usrp2::impl::operator()(const void *base, size_t len)
+ {
+ u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
+
+ // FIXME unaligned load!
+ int chan = u2p_chan(&pkt->hdrs.fixed);
+
+ if (chan == CONTROL_CHAN) { // control packets
+ DEBUG_LOG("c");
+ return handle_control_packet(base, len);
+ }
+ else { // data packets
+ return handle_data_packet(base, len);
+ }
+
+ // not reached
+ }
+
+ data_handler::result
+ usrp2::impl::handle_control_packet(const void *base, size_t len)
+ {
+ // point to beginning of payload (subpackets)
+ unsigned char *p = (unsigned char *)base + sizeof(u2_eth_packet_t);
+
+ // FIXME (p % 4) == 2. Not good. Must watch for unaligned loads.
+
+ // FIXME iterate over payload, handling more than a single subpacket.
+
+ //int opcode = p[0];
+ unsigned int oplen = p[1];
+ unsigned int rid = p[2];
+
+ pending_reply *rp = d_pending_replies[rid];
+ if (rp) {
+ unsigned int buflen = rp->len();
+ if (oplen != buflen) {
+ std::cerr << "usrp2: mismatched command reply length ("
+ << oplen << " != " << buflen << ")"
+ << std::endl;
+ }
+
+ // Copy reply into caller's buffer
+ memcpy(rp->buffer(), p, std::min(oplen, buflen));
+ rp->signal();
+ d_pending_replies[rid] = 0;
+ return data_handler::RELEASE;
+ }
+
+ // TODO: handle unsolicited, USRP2 initiated, or late replies
+ DEBUG_LOG("l");
+ return data_handler::RELEASE;
+ }
+
+ data_handler::result
+ usrp2::impl::handle_data_packet(const void *base, size_t len)
+ {
+ u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
+ d_num_rx_frames++;
+ d_num_rx_bytes += len;
+
+ /* --- FIXME start of fake transport layer handler --- */
+
+ if (d_rx_seqno != -1) {
+ int expected_seqno = (d_rx_seqno + 1) & 0xFF;
+ int seqno = pkt->hdrs.thdr.seqno;
+
+ if (seqno != expected_seqno) {
+ ::write(2, "uS", 2); // missing sequence number
+ int missing = seqno - expected_seqno;
+ if (missing < 0)
+ missing += 256;
+
+ d_num_rx_overruns++;
+ d_num_rx_missing += missing;
+ }
+ }
+
+ d_rx_seqno = pkt->hdrs.thdr.seqno;
+
+ /* --- end of fake transport layer handler --- */
+
+ // FIXME unaligned load!
+ unsigned int chan = u2p_chan(&pkt->hdrs.fixed);
+
+ if (!d_channel_rings[chan]) {
+ DEBUG_LOG("!");
+ return data_handler::RELEASE; // discard packet, no channel handler
+ }
+
+ // Strip off ethernet header and transport header and enqueue the rest
+
+ size_t offset = offsetof(u2_eth_samples_t, hdrs.fixed);
+ if (d_channel_rings[chan]->enqueue(&pkt->hdrs.fixed, len-offset)) {
+ inc_enqueued();
+ DEBUG_LOG("+");
+ return data_handler::KEEP; // channel ring runner will mark frame
done
+ }
+ else {
+ DEBUG_LOG("!");
+ return data_handler::RELEASE; // discard, no room in channel ring
+ }
+ return data_handler::RELEASE;
+ }
+
+ // ----------------------------------------------------------------
+ // Receive
+ // ----------------------------------------------------------------
+
bool
usrp2::impl::set_rx_gain(double gain)
{
@@ -407,156 +596,7 @@
return success;
}
- bool
- usrp2::impl::transmit_cmd(void *cmd, size_t len, pending_reply *p, double
secs)
- {
- if (p)
- d_pending_replies[p->rid()] = p;
-
- // Transmit command
- if (d_eth_buf->tx_frame(cmd, len) != eth_buffer::EB_OK) {
- d_pending_replies[p->rid()] = 0;
- return false;
- }
- int res = 1;
- if (p)
- res = p->wait(secs);
-
- d_pending_replies[p->rid()] = 0;
- return res == 1;
- }
-
- void
- usrp2::impl::bg_loop()
- {
- d_bg_running = true;
- while(d_bg_running) {
- DEBUG_LOG(":");
- // Receive available frames from ethernet buffer. Handler will
- // process control frames, enqueue data packets in channel
- // rings, and signal blocked API threads
- int res = d_eth_buf->rx_frames(this, 100); // FIXME magic timeout
- if (res == eth_buffer::EB_ERROR)
- break;
-
- // Wait for user API thread(s) to process all enqueued packets.
- // The channel ring thread that decrements d_num_enqueued to zero
- // will signal this thread to continue.
- {
- omni_mutex_lock l(d_enqueued_mutex);
- while(d_num_enqueued > 0 && d_bg_running)
- d_bg_pending_cond.wait();
- }
- }
- d_bg_running = false;
- }
-
- data_handler::result
- usrp2::impl::operator()(const void *base, size_t len)
- {
- u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
-
- // FIXME unaligned load!
- int chan = u2p_chan(&pkt->hdrs.fixed);
-
- if (chan == CONTROL_CHAN) { // control packets
- DEBUG_LOG("c");
- return handle_control_packet(base, len);
- }
- else { // data packets
- return handle_data_packet(base, len);
- }
-
- // not reached
- }
-
- data_handler::result
- usrp2::impl::handle_control_packet(const void *base, size_t len)
- {
- // point to beginning of payload (subpackets)
- unsigned char *p = (unsigned char *)base + sizeof(u2_eth_packet_t);
-
- // FIXME (p % 4) == 2. Not good. Must watch for unaligned loads.
-
- // FIXME iterate over payload, handling more than a single subpacket.
-
- //int opcode = p[0];
- unsigned int oplen = p[1];
- unsigned int rid = p[2];
-
- pending_reply *rp = d_pending_replies[rid];
- if (rp) {
- unsigned int buflen = rp->len();
- if (oplen != buflen) {
- std::cerr << "usrp2: mismatched command reply length ("
- << oplen << " != " << buflen << ")"
- << std::endl;
- }
-
- // Copy reply into caller's buffer
- memcpy(rp->buffer(), p, std::min(oplen, buflen));
- rp->signal();
- d_pending_replies[rid] = 0;
- return data_handler::RELEASE;
- }
-
- // TODO: handle unsolicited, USRP2 initiated, or late replies
- DEBUG_LOG("l");
- return data_handler::RELEASE;
- }
-
- data_handler::result
- usrp2::impl::handle_data_packet(const void *base, size_t len)
- {
- u2_eth_samples_t *pkt = (u2_eth_samples_t *)base;
- d_num_rx_frames++;
- d_num_rx_bytes += len;
-
- /* --- FIXME start of fake transport layer handler --- */
-
- if (d_rx_seqno != -1) {
- int expected_seqno = (d_rx_seqno + 1) & 0xFF;
- int seqno = pkt->hdrs.thdr.seqno;
-
- if (seqno != expected_seqno) {
- ::write(2, "uS", 2); // missing sequence number
- int missing = seqno - expected_seqno;
- if (missing < 0)
- missing += 256;
-
- d_num_rx_overruns++;
- d_num_rx_missing += missing;
- }
- }
-
- d_rx_seqno = pkt->hdrs.thdr.seqno;
-
- /* --- end of fake transport layer handler --- */
-
- // FIXME unaligned load!
- unsigned int chan = u2p_chan(&pkt->hdrs.fixed);
-
- if (!d_channel_rings[chan]) {
- DEBUG_LOG("!");
- return data_handler::RELEASE; // discard packet, no channel handler
- }
-
- // Strip off ethernet header and transport header and enqueue the rest
-
- size_t offset = offsetof(u2_eth_samples_t, hdrs.fixed);
- if (d_channel_rings[chan]->enqueue(&pkt->hdrs.fixed, len-offset)) {
- inc_enqueued();
- DEBUG_LOG("+");
- return data_handler::KEEP; // channel ring runner will mark frame
done
- }
- else {
- DEBUG_LOG("!");
- return data_handler::RELEASE; // discard, no room in channel ring
- }
- return data_handler::RELEASE;
- }
-
bool
usrp2::impl::rx_samples(unsigned int channel, rx_sample_handler *handler)
{
@@ -605,14 +645,101 @@
return true;
}
- void
- usrp2::impl::stop_bg()
+ // ----------------------------------------------------------------
+ // Transmit
+ // ----------------------------------------------------------------
+
+ bool
+ usrp2::impl::set_tx_gain(double gain)
{
- d_bg_running = false;
- d_bg_pending_cond.signal();
+ op_config_tx_v2_cmd cmd;
+ op_config_tx_reply_v2_t reply;
+
+ init_config_tx_v2_cmd(&cmd);
+ cmd.op.valid = htons(CFGV_GAIN);
+ cmd.op.gain = htons(u2_double_to_fxpt_gain(gain));
- void *dummy_status;
- d_bg_thread->join(&dummy_status);
+ 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;
+ op_config_tx_reply_v2_t reply;
+
+ init_config_tx_v2_cmd(&cmd);
+ cmd.op.valid = htons(CFGV_FREQ);
+ 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));
+
+ 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);
+ if (result && success) {
+ result->baseband_freq =
+ u2_fxpt_freq_to_double(
+ u2_fxpt_freq_from_hilo(ntohl(reply.baseband_freq_hi),
+ ntohl(reply.baseband_freq_lo)));
+
+ result->dxc_freq =
+ u2_fxpt_freq_to_double(
+ u2_fxpt_freq_from_hilo(ntohl(reply.duc_freq_hi),
+ ntohl(reply.duc_freq_lo)));
+
+ result->residual_freq =
+ u2_fxpt_freq_to_double(
+ u2_fxpt_freq_from_hilo(ntohl(reply.residual_freq_hi),
+ ntohl(reply.residual_freq_lo)));
+
+ result->spectrum_inverted = (bool)(ntohx(reply.inverted) == 1);
+ }
+
+ return success;
+ }
+
+ bool
+ usrp2::impl::set_tx_interp(int interpolation_factor)
+ {
+ op_config_tx_v2_cmd cmd;
+ op_config_tx_reply_v2_t reply;
+
+ init_config_tx_v2_cmd(&cmd);
+ cmd.op.valid = htons(CFGV_INTERP_DECIM);
+ cmd.op.interp = htonl(interpolation_factor);
+
+ 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_scale_iq(int scale_i, int scale_q)
+ {
+ op_config_tx_v2_cmd cmd;
+ op_config_tx_reply_v2_t reply;
+
+ init_config_tx_v2_cmd(&cmd);
+ cmd.op.valid = htons(CFGV_SCALE_IQ);
+ cmd.op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff));
+
+ 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
Modified: usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h
===================================================================
--- usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h 2008-07-30
19:43:48 UTC (rev 9060)
+++ usrp2/branches/developers/eb/wip/host-ng/lib/usrp2_impl.h 2008-07-30
21:56:27 UTC (rev 9061)
@@ -82,6 +82,7 @@
int word0_flags, int chan, uint32_t timestamp);
void stop_bg();
void init_config_rx_v2_cmd(op_config_rx_v2_cmd *cmd);
+ void init_config_tx_v2_cmd(op_config_tx_v2_cmd *cmd);
bool transmit_cmd(void *cmd, size_t len, pending_reply *p, double
secs=0.0);
virtual data_handler::result operator()(const void *base, size_t len);
data_handler::result handle_control_packet(const void *base, size_t len);
@@ -92,6 +93,7 @@
~impl();
void bg_loop();
+
bool set_rx_gain(double gain);
bool set_rx_center_freq(double frequency, tune_result *result);
bool set_rx_decim(int decimation_factor);
@@ -101,6 +103,12 @@
bool stop_rx_streaming(unsigned int channel);
unsigned int rx_overruns() const { return d_num_rx_overruns; }
unsigned int rx_missing() const { return d_num_rx_missing; }
+
+ bool set_tx_gain(double gain);
+ bool set_tx_center_freq(double frequency, tune_result *result);
+ bool set_tx_interp(int interpolation_factor);
+ bool set_tx_scale_iq(int scale_i, int scale_q);
+
};
} // namespace usrp2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9061 - in usrp2/branches/developers/eb/wip/host-ng: apps include/usrp2 lib,
eb <=