commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8405 - in usrp2/branches/developers/eb/u2-newpktfmt:


From: eb
Subject: [Commit-gnuradio] r8405 - in usrp2/branches/developers/eb/u2-newpktfmt: firmware/apps firmware/lib host/apps host/lib
Date: Sun, 11 May 2008 22:01:48 -0600 (MDT)

Author: eb
Date: 2008-05-11 22:01:47 -0600 (Sun, 11 May 2008)
New Revision: 8405

Added:
   usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/tx_only_v2.c
Modified:
   usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/Makefile.am
   usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.c
   usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.h
   usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/rx_only_v2.c
   usrp2/branches/developers/eb/u2-newpktfmt/firmware/lib/db_basic.c
   usrp2/branches/developers/eb/u2-newpktfmt/host/apps/Makefile.am
   usrp2/branches/developers/eb/u2-newpktfmt/host/apps/rx_streaming_samples.cc
   usrp2/branches/developers/eb/u2-newpktfmt/host/apps/tx_samples.cc
   usrp2/branches/developers/eb/u2-newpktfmt/host/lib/usrp2_basic.cc
Log:
tx_only_v2 works with new pkt format

Modified: usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/Makefile.am
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/Makefile.am 
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/Makefile.am 
2008-05-12 04:01:47 UTC (rev 8405)
@@ -41,6 +41,7 @@
        test_serdes \
        timer_test \
        tx_only \
+       tx_only_v2 \
        tx_standalone \
        eth_to_serdes \
        serdes_to_dsp \
@@ -54,6 +55,7 @@
 tx_only_SOURCES = tx_only.c app_common.c
 rx_only_SOURCES = rx_only.c app_common.c
 rx_only_v2_SOURCES = rx_only_v2.c app_common_v2.c
+tx_only_v2_SOURCES = tx_only_v2.c app_common_v2.c
 eth_to_serdes_SOURCES = eth_to_serdes.c app_passthru.c
 serdes_to_dsp_SOURCES = serdes_to_dsp.c app_common.c
 

Modified: 
usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.c
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.c     
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.c     
2008-05-12 04:01:47 UTC (rev 8405)
@@ -96,6 +96,8 @@
       r->hw_rev = 0x0000;      // FIXME
       // r->fpga_md5sum = ;    // FIXME
       // r->sw_md5sum = ;      // FIXME
+
+      // FIXME Add d'board info, including dbid, min/max gain, min/max freq
     }
     send_reply(reply, reply_len);
     break;
@@ -135,7 +137,7 @@
     break;
 
   default:
-    printf("app_common2: unhandled op = %d\n", opcode);
+    printf("app_common_v2: unhandled opcode = %d\n", opcode);
     break;
   }
 }
@@ -196,13 +198,15 @@
   printf("\neth link changed: speed = %d\n", speed);
 }
 
+
 void
-config_tx_cmd(op_config_tx_t *p)
+print_tune_result(char *msg, bool tune_ok,
+                 u2_fxpt_freq_t target_freq, struct tune_result *r)
 {
-  printf("config_tx_cmd: interp = %d\n", p->interp);
-  // print_rmon_regs();
-
-  dsp_tx_regs->freq = p->phase_inc;
-  dsp_tx_regs->scale_iq = p->scale_iq;
-  dsp_tx_regs->interp_rate = p->interp - 1;    // register gets N-1
+  printf("db_tune %s %s\n", msg, tune_ok ? "true" : "false");
+  putstr("  target_freq   "); print_fxpt_freq(target_freq); newline();
+  putstr("  baseband_freq "); print_fxpt_freq(r->baseband_freq); newline();
+  putstr("  dxc_freq      "); print_fxpt_freq(r->dxc_freq); newline();
+  putstr("  residual_freq "); print_fxpt_freq(r->residual_freq); newline();
+  printf("  inverted      %s\n", r->inverted ? "true" : "false");
 }

Modified: 
usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.h
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.h     
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/app_common_v2.h     
2008-05-12 04:01:47 UTC (rev 8405)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 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
@@ -25,6 +25,7 @@
 #include "memory_map.h"
 #include "hal_io.h"
 #include <stddef.h>
+#include <db.h>
 
 #define CPU_TX_BUF     1       // cpu -> eth
 
@@ -43,7 +44,11 @@
 
 void link_changed_callback(int speed);
 
+void
+print_tune_result(char *msg, bool tune_ok,
+                 u2_fxpt_freq_t target_freq, struct tune_result *r);
 
+
 // FIXME move these somewhere else?
 void config_tx_v2_cmd(op_config_tx_v2_t *p);
 void config_rx_v2_cmd(op_config_rx_v2_t *p);

Modified: usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/rx_only_v2.c
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/rx_only_v2.c        
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/rx_only_v2.c        
2008-05-12 04:01:47 UTC (rev 8405)
@@ -31,7 +31,7 @@
 #include "usrp2_eth_packet.h"
 #include "memcpy_wa.h"
 #include "dbsm.h"
-#include "app_common.h"
+#include "app_common_v2.h"
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
@@ -104,20 +104,6 @@
 static volatile bool link_is_up = false;       // eth handler sets this
 
 
-void
-print_tune_result(char *msg, bool tune_ok,
-                 u2_fxpt_freq_t target_freq, struct tune_result *r)
-{
-  printf("db_tune %s %s\n", msg, tune_ok ? "true" : "false");
-  putstr("  target_freq   "); print_fxpt_freq(target_freq); newline();
-  putstr("  baseband_freq "); print_fxpt_freq(r->baseband_freq); newline();
-  putstr("  dxc_freq      "); print_fxpt_freq(r->dxc_freq); newline();
-  putstr("  residual_freq "); print_fxpt_freq(r->residual_freq); newline();
-  printf("  inverted      %s\n", r->inverted ? "true" : "false");
-}
-
-
-
 void 
 config_tx_v2_cmd(op_config_tx_v2_t *p)
 {
@@ -133,7 +119,7 @@
   bool ok = true;
   
   if (p->valid & CFGV_GAIN){
-    rx_dboard->set_gain(rx_dboard, p->gain);
+    ok &= rx_dboard->set_gain(rx_dboard, p->gain);
   }
 
   if (p->valid & CFGV_FREQ){

Copied: usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/tx_only_v2.c 
(from rev 8402, 
usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/tx_only.c)
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/tx_only_v2.c        
                        (rev 0)
+++ usrp2/branches/developers/eb/u2-newpktfmt/firmware/apps/tx_only_v2.c        
2008-05-12 04:01:47 UTC (rev 8405)
@@ -0,0 +1,208 @@
+/*
+ * Copyright 2007,2008 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+#include "pic.h"
+#include "bool.h"
+#include "ethernet.h"
+#include "nonstdio.h"
+#include "usrp2_eth_packet.h"
+#include "dbsm.h"
+#include "app_common_v2.h"
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <db.h>
+#include <db_base.h>
+
+
+/*
+ * This program can respond to queries from the host
+ * and stream rx samples.
+ *
+ * Buffer 1 is used by the cpu to send frames to the host.
+ * Buffers 2 and 3 are used to double-buffer the DSP Rx to eth flow
+ * Buffers 4 and 5 are used to double-buffer the eth to DSP Tx  eth flow
+ */
+//#define CPU_RX_BUF   0       // eth -> cpu
+//#define CPU_TX_BUF   1       // cpu -> eth
+
+#define        DSP_RX_BUF_0    2       // dsp rx -> eth (double buffer)
+#define        DSP_RX_BUF_1    3       // dsp rx -> eth
+#define        DSP_TX_BUF_0    4       // eth -> dsp tx (double buffer)
+#define        DSP_TX_BUF_1    5       // eth -> dsp tx
+
+/*
+ * ================================================================
+ *      configure DSP TX double buffering state machine
+ * ================================================================
+ */
+
+// 4 lines of ethernet hdr + 1 line transport hdr + 2 lines (word0 + timestamp)
+// DSP Tx reads word0 (flags) + timestamp followed by samples
+
+#define DSP_TX_FIRST_LINE ((sizeof(u2_eth_hdr_t) + 
sizeof(u2_transport_hdr_t))/4)
+
+// Receive from ethernet
+buf_cmd_args_t dsp_tx_recv_args = {
+  PORT_ETH,
+  0,
+  BP_LAST_LINE
+};
+
+// send to DSP Tx
+buf_cmd_args_t dsp_tx_send_args = {
+  PORT_DSP,
+  DSP_TX_FIRST_LINE,   // starts just past transport header
+  0                    // filled in from last_line register
+};
+
+dbsm_t dsp_tx_sm;      // the state machine
+
+
+// ----------------------------------------------------------------
+
+
+// The mac address of the host we're sending to.
+u2_mac_addr_t host_mac_addr;
+
+
+void 
+config_tx_v2_cmd(op_config_tx_v2_t *p)
+{
+  struct tune_result   tune_result;
+  memset(&tune_result, 0, sizeof(tune_result));
+
+  bool ok = true;
+  
+  if (p->valid & CFGV_GAIN){
+    ok &= tx_dboard->set_gain(tx_dboard, p->gain);
+  }
+
+  if (p->valid & CFGV_FREQ){
+    u2_fxpt_freq_t f = u2_fxpt_freq_from_hilo(p->freq_hi, p->freq_lo);
+    bool tune_ok = db_tune(tx_dboard, f, &tune_result);
+    ok &= tune_ok;
+    print_tune_result("Tx", tune_ok, f, &tune_result);
+  }
+
+  if (p->valid & CFGV_INTERP_DECIM){
+    dsp_tx_regs->interp_rate = p->interp - 1;  // register gets N-1
+  }
+
+  if (p->valid & CFGV_SCALE_IQ){
+    dsp_tx_regs->scale_iq = p->scale_iq;
+  }
+
+  // FIXME build and send reply
+}
+
+void 
+config_rx_v2_cmd(op_config_rx_v2_t *p)
+{
+  // FIXME nop
+}
+
+
+void
+start_rx_streaming_cmd(const u2_mac_addr_t *host, op_start_rx_streaming_t *p)
+{
+  // FIXME nop
+}
+
+
+void
+stop_rx_cmd(void)
+{
+  // FIXME nop
+}
+
+
+static void
+setup_tx()
+{
+  dsp_tx_regs->clear_state = 1;
+  bp_clear_buf(DSP_TX_BUF_0);
+  bp_clear_buf(DSP_TX_BUF_1);
+
+  int tx_scale = 256;
+  int interp = 32;
+
+  // setup some defaults
+
+  dsp_tx_regs->freq = 0;
+  dsp_tx_regs->scale_iq = (tx_scale << 16) | tx_scale;
+  dsp_tx_regs->interp_rate = interp - 1;               // register gets N-1
+}
+
+
+inline static void
+buffer_irq_handler(unsigned irq)
+{
+  //hal_toggle_leds(0x2);
+
+  uint32_t  status = buffer_pool_status->status;
+
+  dbsm_process_status(&dsp_tx_sm, status);
+
+  if (status & BPS_DONE(CPU_TX_BUF)){
+    bp_clear_buf(CPU_TX_BUF);
+  }
+}
+
+int
+main(void)
+{
+  u2_init();
+
+  putstr("\ntx_only_v2\n");
+
+  ethernet_register_link_changed_callback(link_changed_callback);
+  ethernet_init();
+
+  // initialize double buffering state machine for ethernet -> DSP Tx
+
+  dbsm_init(&dsp_tx_sm, DSP_TX_BUF_0,
+           &dsp_tx_recv_args, &dsp_tx_send_args,
+           eth_pkt_inspector);
+
+  // program tx registers
+  setup_tx();
+
+  // kick off the state machine
+  dbsm_start(&dsp_tx_sm);
+
+  while(1){
+    buffer_irq_handler(0);
+
+    int pending = pic_regs->pending;           // poll for under or overrun
+
+    if (pending & PIC_UNDERRUN_INT){
+      dbsm_handle_tx_underrun(&dsp_tx_sm);
+      pic_regs->pending = PIC_UNDERRUN_INT;    // clear interrupt
+      putchar('U');
+    }
+  }
+}

Modified: usrp2/branches/developers/eb/u2-newpktfmt/firmware/lib/db_basic.c
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/firmware/lib/db_basic.c   
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/firmware/lib/db_basic.c   
2008-05-12 04:01:47 UTC (rev 8405)
@@ -31,6 +31,7 @@
 
 struct db_basic db_basic_tx = {
   .base.dbid = 0x0000,
+  .base.is_tx = true,
   .base.output_enables = 0x0000,
   .base.used_pins = 0x0000,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(-90e9),
@@ -57,6 +58,7 @@
 
 struct db_basic db_basic_rx = {
   .base.dbid = 0x0001,
+  .base.is_tx = false,
   .base.output_enables = 0x0000,
   .base.used_pins = 0x0000,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(-90e9),
@@ -83,6 +85,7 @@
 
 struct db_basic db_lf_tx = {
   .base.dbid = 0x000e,
+  .base.is_tx = true,
   .base.output_enables = 0x0000,
   .base.used_pins = 0x0000,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(-32e6),
@@ -109,6 +112,7 @@
 
 struct db_basic db_lf_rx = {
   .base.dbid = 0x000f,
+  .base.is_tx = false,
   .base.output_enables = 0x0000,
   .base.used_pins = 0x0000,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(0),

Modified: usrp2/branches/developers/eb/u2-newpktfmt/host/apps/Makefile.am
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/host/apps/Makefile.am     
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/host/apps/Makefile.am     
2008-05-12 04:01:47 UTC (rev 8405)
@@ -26,13 +26,14 @@
 bin_PROGRAMS = \
        find_usrps \
        rx_streaming_samples \
+       tx_samples \
        gen_const \
        u2_burn_mac_addr
 
 find_usrps_SOURCES = find_usrps.cc
 # rx_samples_SOURCES = rx_samples.cc
 rx_streaming_samples_SOURCES = rx_streaming_samples.cc
-# tx_samples_SOURCES = tx_samples.cc
+tx_samples_SOURCES = tx_samples.cc
 # tx_samples_at_t = tx_samples_at_t.cc
 gen_const_SOURCES = gen_const.cc
 u2_burn_mac_addr = u2_burn_mac_addr.cc

Modified: 
usrp2/branches/developers/eb/u2-newpktfmt/host/apps/rx_streaming_samples.cc
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/host/apps/rx_streaming_samples.cc 
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/host/apps/rx_streaming_samples.cc 
2008-05-12 04:01:47 UTC (rev 8405)
@@ -183,10 +183,10 @@
   fprintf(stderr, "  -o OUTPUT_FILE       set output filename 
[default=samples.dat]\n");
   fprintf(stderr, "  -f FREQ              set frequency to FREQ 
[default=0]\n");
   fprintf(stderr, "  -d DECIM             set decimation rate to DECIM 
[default=32]\n");
+  fprintf(stderr, "  -g gain              rx gain [default=0dB]\n");
   fprintf(stderr, "  -N NSAMPLES          total number of samples to receive 
[default=infinite]\n");
   fprintf(stderr, "  -F SAMPLES_PER_FRAME number of samples in each frame 
[default=371]\n");
   fprintf(stderr, "  -S SCALE             fpga scaling factor for I & Q 
[default=256]\n");
-  fprintf(stderr, "  -g gain              rx gain [default=0dB]\n");
 }
 
 struct pkt_info {
@@ -200,6 +200,8 @@
       d_seqno(seqno) {}
 };
 
+#define GAIN_NOT_SET (-1000)
+
 int
 main(int argc, char **argv)
 {
@@ -213,7 +215,7 @@
   uint64_t nsamples = ~0;
   int32_t samples_per_frame = 250;
   int32_t scale = 1024;
-  double gain = 0;
+  double gain = GAIN_NOT_SET;
 
   int    ch;
   double tmp;
@@ -343,12 +345,13 @@
   writer->start_undetached();
   
 
-#if 1
   usrp2_tune_result tune_result;
   
-  if (!u2->set_rx_gain(which, gain)){
-    std::cerr << "set_rx_gain failed\n";
-    return 1;
+  if (gain != GAIN_NOT_SET){
+    if (!u2->set_rx_gain(which, gain)){
+      std::cerr << "set_rx_gain failed\n";
+      return 1;
+    }
   }
 
   if (!u2->set_rx_freq(which, freq, &tune_result)){
@@ -371,13 +374,8 @@
     return 1;
   }
   
-#else
-  if (!u2->start_rx(which, freq, decim, 0, samples_per_frame, scale, scale)){
-    std::cerr << "start_rx failed\n";
-    return 1;
-  }
-#endif
 
+
   uint64_t total_samples_recvd = 0;
   int  expected_seqno = 0;
 

Modified: usrp2/branches/developers/eb/u2-newpktfmt/host/apps/tx_samples.cc
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/host/apps/tx_samples.cc   
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/host/apps/tx_samples.cc   
2008-05-12 04:01:47 UTC (rev 8405)
@@ -55,10 +55,13 @@
   fprintf(stderr, "  -r                   repeat.  When EOF of input file is 
reached, seek to beginning\n");
   fprintf(stderr, "  -f FREQ              set frequency to FREQ 
[default=0]\n");
   fprintf(stderr, "  -i INTERP            set interpolation rate to INTERP 
[default=32]\n");
+  fprintf(stderr, "  -g gain              set tx gain\n");
   fprintf(stderr, "  -F SAMPLES_PER_FRAME number of samples in each frame 
[default=371]\n");
   fprintf(stderr, "  -S SCALE             fpga scaling factor for I & Q 
[default=256]\n");
 }
 
+#define GAIN_NOT_SET (-1000)
+
 int
 main(int argc, char **argv)
 {
@@ -68,14 +71,15 @@
   const char *mac_addr_str = 0;
   double freq = 0;
   int32_t interp = 32;
-  int32_t samples_per_frame = 371;
+  int32_t samples_per_frame = U2_MAX_SAMPLES;
   int32_t scale = 256;
+  double gain = GAIN_NOT_SET;
   
   int    ch;
   double tmp;
   u2_mac_addr_t mac_addr;
 
-  while ((ch = getopt(argc, argv, "he:m:I:rf:i:F:S")) != EOF){
+  while ((ch = getopt(argc, argv, "he:m:I:rf:i:F:S:g:")) != EOF){
     switch (ch){
 
     case 'e':
@@ -148,9 +152,10 @@
     }
   }
 
-  if (samples_per_frame < 9 || samples_per_frame > 506){
+  if (samples_per_frame < 9 || samples_per_frame > U2_MAX_SAMPLES){
     std::cerr << prettify_progname(argv[0])
-             << ": samples_per_frame is out of range.  Must be in [9, 506].\n";
+             << ": samples_per_frame is out of range.  "
+             << "Must be in [9, " << U2_MAX_SAMPLES << "].\n";
     usage(argv[0]);
     return 1;
   }
@@ -176,13 +181,31 @@
   u2_mac_addr_t which = r[0].addr;     // pick the first one
 
 
-  if (1){
-    if (!u2->config_tx(which, freq, interp, scale, scale)){
-      std::cerr << "tx_samples: config_tx failed\n";
+  usrp2_tune_result tune_result;
+  
+  if (gain != GAIN_NOT_SET){
+    if (!u2->set_tx_gain(which, gain)){
+      std::cerr << "set_tx_gain failed\n";
       return 1;
     }
   }
 
+  if (!u2->set_tx_freq(which, freq, &tune_result)){
+    std::cerr << "set_tx_freq failed\n";
+    return 1;
+  }
+
+  if (!u2->set_tx_interp(which, interp)){
+    std::cerr << "set_tx_interp failed\n";
+    return 1;
+  }
+
+  if (!u2->set_tx_scale_iq(which, scale, scale)){
+    std::cerr << "set_tx_scale_iq failed\n";
+    return 1;
+  }
+
+
   u2_eth_samples_t     pkt;
   u2p_set_word0(&pkt.hdrs.fixed, U2P_TX_IMMEDIATE | U2P_TX_START_OF_BURST, 0);
   u2p_set_timestamp(&pkt.hdrs.fixed, T_NOW);

Modified: usrp2/branches/developers/eb/u2-newpktfmt/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/eb/u2-newpktfmt/host/lib/usrp2_basic.cc   
2008-05-12 02:18:44 UTC (rev 8404)
+++ usrp2/branches/developers/eb/u2-newpktfmt/host/lib/usrp2_basic.cc   
2008-05-12 04:01:47 UTC (rev 8405)
@@ -338,6 +338,9 @@
 bool
 usrp2_basic::start_rx_streaming(const u2_mac_addr_t &which, unsigned int 
items_per_frame)
 {
+  if (items_per_frame == 0)    // provide our default
+    items_per_frame = 250;
+
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
 
@@ -364,134 +367,179 @@
   return true;
 }
 
+bool
+usrp2_basic::stop_rx(const u2_mac_addr_t &which)
+{
+  uint8_t      pktbuf[MAX_PKTLEN];
+  memset(pktbuf, 0, sizeof(pktbuf));
 
+  struct command {
+    u2_eth_packet_t    h;
+    op_id_t            op_stop_rx;
+  };
+    
+  command      *c = (command *) pktbuf;
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
-#if 0
-static int32_t 
-compute_freq_control_word_fpga(double master_freq, double target_freq,
-                              double *actual_freq)
-{
-  int  v = (int) rint (target_freq / master_freq * pow (2.0, 32.0));
-  *actual_freq = v * master_freq / pow (2.0, 32.0);
-  return v;
+  c->op_stop_rx.opcode = OP_STOP_RX;
+  c->op_stop_rx.len = sizeof(op_stop_rx_t);
+  int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+  if (d_ethernet->write_packet(c, len) != len)
+    return false;
+
+  return true;
 }
-#endif
 
-#if 0
+/*
+ * ------------------------------------------------------------------------
+ *                       Tx configuration
+ * ------------------------------------------------------------------------
+ */
+
 bool
-usrp2_basic::start_rx(const u2_mac_addr_t &which,
-                     double freq,
-                     unsigned int decim,
-                     unsigned int total_samples,       // 0 or [9, 2**21 - 1]
-                     unsigned int samples_per_frame,   // [9, 371] or [9, 505] 
if MTU==2034
-                     int scale_i,                      // 16.0 fixed point 
format
-                     int scale_q,                      // 16.0 fixed point 
format
-                     bool rx_now,
-                     uint32_t rx_time
-                     )
+usrp2_basic::set_tx_gain(const u2_mac_addr_t &which, double gain)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
 
   struct command {
     u2_eth_packet_t    h;
-    op_start_rx_t      op;
+    op_config_tx_v2_t  op;
+    op_eop_t           eop;
   };
-    
-  if ((total_samples < 9 && total_samples != 0) || total_samples >= (1L << 
21)){
-    std::cerr << "usrp2_basic::start_rx: total_samples is out of range\n";
-    return false;
-  }
 
-  if (samples_per_frame < 9 || samples_per_frame > U2_MAX_SAMPLES){
-    std::cerr << "usrp2_basic::start_rx: samples_per_frame is out of range\n";
+  command *c = (command *) pktbuf;
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
+
+  c->op.opcode = OP_CONFIG_TX_V2;
+  c->op.len = sizeof(op_config_tx_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) MIN_PKTLEN, sizeof(command));
+  if (d_ethernet->write_packet(c, len) != len)
     return false;
-  }
 
-  command      *c = (command *) pktbuf;
+  // FIXME wait for corresponding reply, etc.
+
+  return true;
+}
+
+bool
+usrp2_basic::set_tx_freq(const u2_mac_addr_t &which, double freq,
+                        usrp2_tune_result *result)
+{
+  uint8_t      pktbuf[MAX_PKTLEN];
+  memset(pktbuf, 0, sizeof(pktbuf));
+
+  struct command {
+    u2_eth_packet_t    h;
+    op_config_tx_v2_t  op;
+    op_eop_t           eop;
+  };
+
+  command *c = (command *) pktbuf;
   init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
-  c->op.opcode = OP_START_RX;
-  c->op.len = sizeof(op_start_rx_t);
+  c->op.opcode = OP_CONFIG_TX_V2;
+  c->op.len = sizeof(op_config_tx_v2_t);
+  c->op.rid = d_next_rid++;
 
-  double actual_freq;
-  c->op.rx_now = rx_now ? 1 : 0;
-  c->op.phase_inc = htonl(compute_freq_control_word_fpga(adc_rate(), freq, 
&actual_freq));
-  c->op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff));
-  c->op.decim = htonl(decim);
-  c->op.samples_per_frame = htonl(samples_per_frame);
-  c->op.total_samples = htonl(total_samples);
-  c->op.rx_time = htonl(rx_time);
+  c->op.valid = htons(CFGV_FREQ);
+  u2_fxpt_freq_t  fxpt = u2_double_to_fxpt_freq(freq);
+  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) MIN_PKTLEN, sizeof(command));
   if (d_ethernet->write_packet(c, len) != len)
     return false;
 
+  // FIXME wait for corresponding reply, etc.
+
+  if (result)
+    memset(result, 0, sizeof(*result));
+
   return true;
 }
-#endif
 
 bool
-usrp2_basic::stop_rx(const u2_mac_addr_t &which)
+usrp2_basic::set_tx_interp(const u2_mac_addr_t &which, int 
interpolation_factor)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
 
   struct command {
     u2_eth_packet_t    h;
-    op_id_t            op_stop_rx;
+    op_config_tx_v2_t  op;
+    op_eop_t           eop;
   };
-    
-  command      *c = (command *) pktbuf;
+
+  command *c = (command *) pktbuf;
   init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
-  c->op_stop_rx.opcode = OP_STOP_RX;
-  c->op_stop_rx.len = sizeof(op_stop_rx_t);
+  c->op.opcode = OP_CONFIG_TX_V2;
+  c->op.len = sizeof(op_config_tx_v2_t);
+  c->op.rid = d_next_rid++;
+
+  c->op.valid = htons(CFGV_INTERP_DECIM);
+  c->op.interp = htonl(interpolation_factor);
+
+  c->eop.opcode = OP_EOP;
+  c->eop.len = sizeof(op_eop_t);
+
   int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
   if (d_ethernet->write_packet(c, len) != len)
     return false;
 
+  // FIXME wait for corresponding reply, etc.
+
   return true;
 }
 
-#if 0
 bool
-usrp2_basic::config_tx(const u2_mac_addr_t &which,
-                      double freq,
-                      unsigned int interp,
-                      int scale_i,                     // 16.0 fixed point 
format
-                      int scale_q                      // 16.0 fixed point 
format
-                      )
+usrp2_basic::set_tx_scale_iq(const u2_mac_addr_t &which, int scale_i, int 
scale_q)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
 
   struct command {
     u2_eth_packet_t    h;
-    op_config_tx_t     op;
+    op_config_tx_v2_t  op;
+    op_eop_t           eop;
   };
-    
-  command      *c = (command *) pktbuf;
+
+  command *c = (command *) pktbuf;
   init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
-  c->op.opcode = OP_CONFIG_TX;
-  c->op.len = sizeof(op_config_tx_t);
+  c->op.opcode = OP_CONFIG_TX_V2;
+  c->op.len = sizeof(op_config_tx_v2_t);
+  c->op.rid = d_next_rid++;
 
-  double actual_freq;
-  c->op.phase_inc = htonl(compute_freq_control_word_fpga(adc_rate(), freq, 
&actual_freq));
+  c->op.valid = htons(CFGV_SCALE_IQ);
   c->op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff));
-  c->op.interp = htonl(interp);
 
+  c->eop.opcode = OP_EOP;
+  c->eop.len = sizeof(op_eop_t);
+
   int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
   if (d_ethernet->write_packet(c, len) != len)
     return false;
 
+  // FIXME wait for corresponding reply, etc.
+
   return true;
 }
-#endif
 
 
+
 // ------------------------------------------------------------------------
 
 void





reply via email to

[Prev in Thread] Current Thread [Next in Thread]