commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8365 - in usrp2/trunk/firmware: apps lib


From: eb
Subject: [Commit-gnuradio] r8365 - in usrp2/trunk/firmware: apps lib
Date: Sat, 10 May 2008 17:35:02 -0600 (MDT)

Author: eb
Date: 2008-05-10 17:35:01 -0600 (Sat, 10 May 2008)
New Revision: 8365

Added:
   usrp2/trunk/firmware/apps/can_i_sub.c
   usrp2/trunk/firmware/lib/db.h
   usrp2/trunk/firmware/lib/print_fxpt.c
Modified:
   usrp2/trunk/firmware/apps/Makefile.am
   usrp2/trunk/firmware/apps/tx_only.c
   usrp2/trunk/firmware/lib/Makefile.am
   usrp2/trunk/firmware/lib/db_base.h
   usrp2/trunk/firmware/lib/db_init.c
   usrp2/trunk/firmware/lib/nonstdio.h
   usrp2/trunk/firmware/lib/u2_init.c
Log:
work-in-progress

Modified: usrp2/trunk/firmware/apps/Makefile.am
===================================================================
--- usrp2/trunk/firmware/apps/Makefile.am       2008-05-10 22:09:36 UTC (rev 
8364)
+++ usrp2/trunk/firmware/apps/Makefile.am       2008-05-10 23:35:01 UTC (rev 
8365)
@@ -23,6 +23,7 @@
        blink_leds \
        blink_leds2 \
        buf_ram_test \
+       can_i_sub \
        gen_eth_packets \
        hello \
        ibs_rx_test \

Added: usrp2/trunk/firmware/apps/can_i_sub.c
===================================================================
--- usrp2/trunk/firmware/apps/can_i_sub.c                               (rev 0)
+++ usrp2/trunk/firmware/apps/can_i_sub.c       2008-05-10 23:35:01 UTC (rev 
8365)
@@ -0,0 +1,24 @@
+#include <u2_init.h>
+#include <nonstdio.h>
+
+//typedef long long int64_t;
+
+
+int64_t sub(int64_t a, int64_t b);
+void print(int64_t d);
+
+int main(void)
+{
+  u2_init();
+
+  int64_t d = sub(462550990848000LL, 462028800000000LL);
+  print_uint64(d);
+  return 0;
+}
+
+int64_t sub(int64_t a, int64_t b)
+{
+  return a - b;
+}
+
+


Property changes on: usrp2/trunk/firmware/apps/can_i_sub.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: usrp2/trunk/firmware/apps/tx_only.c
===================================================================
--- usrp2/trunk/firmware/apps/tx_only.c 2008-05-10 22:09:36 UTC (rev 8364)
+++ usrp2/trunk/firmware/apps/tx_only.c 2008-05-10 23:35:01 UTC (rev 8365)
@@ -34,6 +34,7 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
+#include <db.h>
 #include <db_base.h>
 
 
@@ -148,10 +149,23 @@
   ethernet_register_link_changed_callback(link_changed_callback);
   ethernet_init();
 
-  u2_fxpt_freq_t actual = 0;
+#if 0
   bool ok = tx_dboard->set_freq(tx_dboard, U2_DOUBLE_TO_FXPT_FREQ(440e6), 
&actual);
   printf ("tune = %d, actual = %d\n", ok, u2_fxpt_freq_round_to_int(actual));
+#endif
 
+#if 1
+  struct tune_result  r;
+  u2_fxpt_freq_t target_freq = U2_DOUBLE_TO_FXPT_FREQ(441.123e6);
+  bool ok = db_tune(tx_dboard, target_freq, &r);
+  printf("db_tune %s\n", 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");
+#endif
+
   // initialize double buffering state machine for ethernet -> DSP Tx
 
   dbsm_init(&dsp_tx_sm, DSP_TX_BUF_0,

Modified: usrp2/trunk/firmware/lib/Makefile.am
===================================================================
--- usrp2/trunk/firmware/lib/Makefile.am        2008-05-10 22:09:36 UTC (rev 
8364)
+++ usrp2/trunk/firmware/lib/Makefile.am        2008-05-10 23:35:01 UTC (rev 
8365)
@@ -43,6 +43,7 @@
        pic.c \
        print_mac_addr.c \
        print_rmon_regs.c \
+       print_fxpt.c \
        printf.c \
        spi.c \
        u2_init.c       

Added: usrp2/trunk/firmware/lib/db.h
===================================================================
--- usrp2/trunk/firmware/lib/db.h                               (rev 0)
+++ usrp2/trunk/firmware/lib/db.h       2008-05-10 23:35:01 UTC (rev 8365)
@@ -0,0 +1,88 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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/>.
+ */
+
+/*
+ * Interface to daughterboard code
+ */
+
+#ifndef INCLUDED_DB_H
+#define INCLUDED_DB_H
+
+#include <usrp2_types.h>
+
+
+struct db_base;
+
+/* pointers to daughterboard structures */
+extern struct db_base *tx_dboard;
+extern struct db_base *rx_dboard;
+
+
+//! Intermediate tuning information
+
+struct tune_result
+{
+  //! The RF frequency that corresponds to DC in the IF from the daughterboard
+  u2_fxpt_freq_t       baseband_freq;
+
+  //! The DDC/DUC frequency used to down/up convert to/from the target 
frequency
+  u2_fxpt_freq_t       dxc_freq;
+
+  //! Any differerence btwn target and actual (typically < 0.01 Hz)
+  u2_fxpt_freq_t       residual_freq;
+
+  //! Is the complex baseband spectrum inverted
+  bool                 inverted;
+};
+
+
+/*!
+ * \brief One-time init at powerup
+ *
+ *  Sets rx_dboard, tx_dboard and initializes daughterboards.
+ */
+void 
+db_init(void);
+
+/*!
+ * \brief Two stage tuning.  Given target_freq, tune LO and DDC/DUC
+ *
+ * \param[in] db is the daughterboard instance
+ * \param[in] target_freq is the freq to translate the complex baseband 
to/from.
+ * \param[out] result provides details of the resulting configuration.
+ * 
+ */
+bool
+db_tune(struct db_base *db, u2_fxpt_freq_t target_freq, struct tune_result 
*result);
+
+
+/*
+ * Set only the DDC frequency
+ */
+bool
+db_set_ddc_freq(u2_fxpt_freq_t dxc_freq, u2_fxpt_freq_t *actual_dxc_freq);
+
+/*
+ * Set only the DUC frequency
+ */
+bool
+db_set_duc_freq(u2_fxpt_freq_t dxc_freq, u2_fxpt_freq_t *actual_dxc_freq);
+
+
+
+#endif /* INCLUDED_DB_H */


Property changes on: usrp2/trunk/firmware/lib/db.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: usrp2/trunk/firmware/lib/db_base.h
===================================================================
--- usrp2/trunk/firmware/lib/db_base.h  2008-05-10 22:09:36 UTC (rev 8364)
+++ usrp2/trunk/firmware/lib/db_base.h  2008-05-10 23:35:01 UTC (rev 8365)
@@ -64,8 +64,4 @@
 };
 
 
-/* pointers to daughterboard structures */
-extern struct db_base *tx_dboard;
-extern struct db_base *rx_dboard;
-
 #endif /* INCLUDED_DB_BASE_H */

Modified: usrp2/trunk/firmware/lib/db_init.c
===================================================================
--- usrp2/trunk/firmware/lib/db_init.c  2008-05-10 22:09:36 UTC (rev 8364)
+++ usrp2/trunk/firmware/lib/db_init.c  2008-05-10 23:35:01 UTC (rev 8365)
@@ -22,8 +22,10 @@
 #include <usrp2_i2c_addr.h>
 #include <string.h>
 #include <stdio.h>
+#include <db.h>
 #include <db_base.h>
 #include <hal_io.h>
+#include <nonstdio.h>
 
 
 struct db_base *tx_dboard;     // the tx daughterboard that's installed
@@ -83,13 +85,15 @@
   //printf("\nread_raw_dboard_eeprom: %d\n", s);
 
   switch (s){
+  case UDBE_OK:
+    return (buf[DB_EEPROM_ID_MSB] << 8) | buf[DB_EEPROM_ID_LSB];
+
+  case UDBE_NO_EEPROM:
   default:
-  case UDBE_NO_EEPROM:
     return -1;
+
   case UDBE_INVALID_EEPROM:
     return -2;
-  case UDBE_OK:
-    return (buf[DB_EEPROM_ID_MSB] << 8) | buf[DB_EEPROM_ID_LSB];
   }
 }
 
@@ -182,3 +186,141 @@
   set_gpio_mode(GPIO_RX_BANK, rx_dboard);
   rx_dboard->init(rx_dboard);
 }
+
+/*!
+ *  Calculate the frequency to use for setting the digital down converter.
+ *
+ *  \param[in] target_freq   desired RF frequency (Hz)
+ *  \param[in] baseband_freq the RF frequency that corresponds to DC in the IF.
+ * 
+ *  \param[out] dxc_freq is the value for the ddc
+ *  \param[out] inverted is true if we're operating in an inverted Nyquist 
zone.
+*/
+void
+calc_dxc_freq(u2_fxpt_freq_t target_freq, u2_fxpt_freq_t baseband_freq,
+             u2_fxpt_freq_t *dxc_freq, bool *inverted)
+{
+  u2_fxpt_freq_t fs = U2_DOUBLE_TO_FXPT_FREQ(100e6);   // converter sample rate
+  u2_fxpt_freq_t delta = target_freq - baseband_freq;
+
+  printf("calc_dxc_freq\n");
+  printf("  fs       = "); print_fxpt_freq(fs); newline();
+  printf("  target   = "); print_fxpt_freq(target_freq); newline();
+  printf("  baseband = "); print_fxpt_freq(baseband_freq); newline();
+  printf("  delta    = "); print_fxpt_freq(delta); newline();
+  
+  printf("--- printed as uint64_t ---\n");
+  printf("  fs       = "); print_uint64(fs); newline();
+  printf("  target   = "); print_uint64(target_freq); newline();
+  printf("  baseband = "); print_uint64(baseband_freq); newline();
+  printf("  delta    = "); print_uint64(delta); newline();
+
+
+  if (delta >= 0){
+    while (delta > fs)
+      delta -= fs;
+    if (delta <= fs/2){                // non-inverted region
+      *dxc_freq = -delta;
+      *inverted = false;
+    }
+    else {                     // inverted region
+      *dxc_freq = delta - fs;
+      *inverted = true;
+    }
+  }
+  else {
+    while (delta < -fs){
+      delta += fs;
+      if (delta >= -fs/2){     // non-inverted region
+       *dxc_freq = -delta;
+       *inverted = false;
+      }
+      else {                   // inverted region
+       *dxc_freq = delta + fs;
+       *inverted = true;
+      }
+    }
+  }
+}
+
+
+bool
+db_tune(struct db_base *db, u2_fxpt_freq_t target_freq, struct tune_result 
*result)
+{
+  memset(result, 0, sizeof(*result));
+  bool inverted = false;
+  u2_fxpt_freq_t dxc_freq;
+  u2_fxpt_freq_t actual_dxc_freq;
+
+  // Ask the d'board to tune as closely as it can to target_freq
+  bool ok = db->set_freq(db, target_freq, &result->baseband_freq);
+
+  // Calculate the DDC setting that will downconvert the baseband from the
+  // daughterboard to our target frequency.
+  calc_dxc_freq(target_freq, result->baseband_freq, &dxc_freq, &inverted);
+
+  // If the spectrum is inverted, and the daughterboard doesn't do
+  // quadrature downconversion, we can fix the inversion by flipping the
+  // sign of the dxc_freq...  (This only happens using the basic_rx board)
+  
+  if (db->spectrum_inverted)
+    inverted = !inverted;
+
+  if (inverted && !db->is_quadrature){
+    dxc_freq = -dxc_freq;
+    inverted = !inverted;
+  }
+
+  if (db->is_tx){
+    dxc_freq = -dxc_freq;      // down conversion versus up conversion
+    ok &= db_set_duc_freq(dxc_freq, &actual_dxc_freq);
+  }
+  else {
+    ok &= db_set_ddc_freq(dxc_freq, &actual_dxc_freq);
+  }
+
+  result->dxc_freq = dxc_freq;
+  result->residual_freq = dxc_freq - actual_dxc_freq;
+  result->inverted = inverted;
+  return ok;
+}
+
+static int32_t
+compute_freq_control_word(u2_fxpt_freq_t target_freq, u2_fxpt_freq_t 
*actual_freq)
+{
+  // If we were using floating point, we'd calculate
+  //   master = 100e6;
+  //   v = (int) rint(target_freq / master_freq) * pow(2.0, 32.0);
+
+  printf("compute_freq_control_word\n");
+  printf("  target_freq = "); print_fxpt_freq(target_freq); newline();
+
+  int32_t master_freq = 100000000;     // 100M
+
+  int32_t v = ((target_freq << 12)) / master_freq;
+  printf("  fcw = %d\n", v);
+
+  *actual_freq = (v * (int64_t) master_freq) >> 12;
+
+  printf("  actual = "); print_fxpt_freq(*actual_freq); newline();
+
+  return v;
+}
+
+
+bool
+db_set_ddc_freq(u2_fxpt_freq_t dxc_freq, u2_fxpt_freq_t *actual_dxc_freq)
+{
+  int32_t v = compute_freq_control_word(dxc_freq, actual_dxc_freq);
+  dsp_rx_regs->freq = v;
+  return true;
+}
+
+bool
+db_set_duc_freq(u2_fxpt_freq_t dxc_freq, u2_fxpt_freq_t *actual_dxc_freq)
+{
+  int32_t v = compute_freq_control_word(dxc_freq, actual_dxc_freq);
+  dsp_tx_regs->freq = v;
+  return true;
+}
+

Modified: usrp2/trunk/firmware/lib/nonstdio.h
===================================================================
--- usrp2/trunk/firmware/lib/nonstdio.h 2008-05-10 22:09:36 UTC (rev 8364)
+++ usrp2/trunk/firmware/lib/nonstdio.h 2008-05-10 23:35:01 UTC (rev 8365)
@@ -20,6 +20,7 @@
 #define INCLUDED_NONSTDIO_H
 
 #include <stdio.h>
+#include <usrp2_types.h>
 
 void putstr(const char *s);            // cf puts, no added newline
 void puthex4(unsigned long x);         // output 1 hex digit
@@ -35,5 +36,8 @@
 void newline();                                // putchar('\n')
 
 void print_mac_addr(const unsigned char addr[6]);
+void print_fxpt_freq(u2_fxpt_freq_t v);
+void print_fxpt_gain(u2_fxpt_gain_t v);
+void print_uint64(uint64_t v);
 
 #endif /* INCLUDED_NONSTDIO_H */

Added: usrp2/trunk/firmware/lib/print_fxpt.c
===================================================================
--- usrp2/trunk/firmware/lib/print_fxpt.c                               (rev 0)
+++ usrp2/trunk/firmware/lib/print_fxpt.c       2008-05-10 23:35:01 UTC (rev 
8365)
@@ -0,0 +1,83 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 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/>.
+ */
+#include <nonstdio.h>
+
+/*
+ * print uint64_t
+ */
+void
+print_uint64(uint64_t u)
+{
+  const char *_hex = "0123456789ABCDEF";
+  if (u >= 10)
+    print_uint64(u/10);
+  putchar(_hex[u%10]);
+}
+
+static void
+print_thousandths(int thousandths)
+{
+  putchar('.');
+  if (thousandths < 100)
+    putchar('0');
+  if (thousandths < 10)
+    putchar('0');
+  printf("%d", thousandths);
+}
+
+
+void 
+print_fxpt_freq(u2_fxpt_freq_t v)
+{
+  if (v < 0){
+    v = -v;
+    putchar('-');
+  }
+
+  int64_t int_part = v >> 20;
+  int32_t frac_part = v & ((1 << 20) - 1);
+  
+#if 0  
+  // would work, if we had it
+  printf("%lld.%03d", int_part, (frac_part * 1000) >> 20);
+#else
+  print_uint64(int_part);
+  print_thousandths((frac_part * 1000) >> 20);
+#endif
+}
+
+void
+print_fxpt_gain(u2_fxpt_gain_t v)
+{
+  if (v < 0){
+    v = -v;
+    putchar('-');
+  }
+
+  int32_t int_part = v >> 7;
+  int32_t frac_part = v & ((1 << 7) - 1);
+
+#if 0  
+  // would work, if we had it
+  printf("%d.%03d", int_part, (frac_part * 1000) >> 7);
+#else
+  printf("%d", int_part);
+  print_thousandths((frac_part * 1000) >> 7);
+#endif
+}
+


Property changes on: usrp2/trunk/firmware/lib/print_fxpt.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: usrp2/trunk/firmware/lib/u2_init.c
===================================================================
--- usrp2/trunk/firmware/lib/u2_init.c  2008-05-10 22:09:36 UTC (rev 8364)
+++ usrp2/trunk/firmware/lib/u2_init.c  2008-05-10 23:35:01 UTC (rev 8365)
@@ -29,11 +29,10 @@
 #include "mdelay.h"
 #include "ad9777.h"
 #include "ad9510.h"
+#include "db.h"
 
 //#include "nonstdio.h"
 
-void db_init(void);
-
 /*
  * We ought to arrange for this to be called before main, but for now,
  * we require that the user's main call u2_init as the first thing...





reply via email to

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