Merge branch 'maint'
[debian/gnuradio] / usrp2 / firmware / lib / db_rfx.c
index b127f2c335d6991e98ef282a700eb167e2a2f8e4..d07d3c1fb4c0a3cf7f9e3146c478cb83f23877ec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -19,7 +19,6 @@
 #include <memory_map.h>
 #include <db_base.h>
 #include <hal_io.h>
-#include <ad9510.h>
 #include <stdio.h>
 #include <mdelay.h>
 #include <lsdac.h>
@@ -73,7 +72,6 @@ struct db_rfx_common {
   unsigned char CP2;
   int freq_mult;
   int spi_mask;  
-  u2_fxpt_freq_t freq_offset;
 };
 
 struct db_rfx_dummy {
@@ -122,6 +120,16 @@ struct db_rfx_1800_tx {
   struct db_rfx_common common;
 };
 
+struct db_rfx_2200_rx {
+  struct db_base       base;
+  struct db_rfx_common common;
+};
+
+struct db_rfx_2200_tx {
+  struct db_base       base;
+  struct db_rfx_common common;
+};
+
 struct db_rfx_2400_rx {
   struct db_base       base;
   struct db_rfx_common common;
@@ -149,7 +157,7 @@ struct db_rfx_400_rx db_rfx_400_rx = {
   .base.is_quadrature = true,
   .base.i_and_q_swapped = true,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
   .base.init = rfx_init_rx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_rx,
@@ -159,12 +167,12 @@ struct db_rfx_400_rx db_rfx_400_rx = {
   .base.atr_rxval = POWER_UP|MIX_EN,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 0,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_RX_DB,
-  .common.freq_mult = 2,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(0)
+  .common.freq_mult = 2
 };
 
 
@@ -179,9 +187,9 @@ struct db_rfx_400_tx db_rfx_400_tx = {
   //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   .base.is_quadrature = true,
-  .base.i_and_q_swapped = true,
+  .base.i_and_q_swapped = false,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
   .base.init = rfx_init_tx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_tx,
@@ -191,12 +199,12 @@ struct db_rfx_400_tx db_rfx_400_tx = {
   .base.atr_rxval = POWER_UP|ANT_SW,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 1,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_TX_DB,
-  .common.freq_mult = 2,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6)
+  .common.freq_mult = 2
 };
 
 struct db_rfx_900_rx db_rfx_900_rx = {
@@ -204,15 +212,15 @@ struct db_rfx_900_rx db_rfx_900_rx = {
   .base.is_tx = false,
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
-  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(800e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1000e6),
+  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(750e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1050e6),
   .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
   .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
   .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
   .base.is_quadrature = true,
   .base.i_and_q_swapped = true,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
   .base.init = rfx_init_rx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_rx,
@@ -222,12 +230,12 @@ struct db_rfx_900_rx db_rfx_900_rx = {
   .base.atr_rxval = MIX_EN,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 1,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_RX_DB,
-  .common.freq_mult = 2,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(0)
+  .common.freq_mult = 2
 };
 
 
@@ -236,15 +244,15 @@ struct db_rfx_900_tx db_rfx_900_tx = {
   .base.is_tx = true,
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
-  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(800e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1000e6),
+  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(750e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1050e6),
   //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   .base.is_quadrature = true,
-  .base.i_and_q_swapped = true,
+  .base.i_and_q_swapped = false,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
   .base.init = rfx_init_tx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_tx,
@@ -254,12 +262,12 @@ struct db_rfx_900_tx db_rfx_900_tx = {
   .base.atr_rxval = ANT_SW,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 1,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_TX_DB,
-  .common.freq_mult = 2,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6)
+  .common.freq_mult = 2
 };
 
 struct db_rfx_1200_rx db_rfx_1200_rx = {
@@ -268,14 +276,14 @@ struct db_rfx_1200_rx db_rfx_1200_rx = {
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1150e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1350e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1450e6),
   .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
   .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
   .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
   .base.is_quadrature = true,
   .base.i_and_q_swapped = true,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
   .base.init = rfx_init_rx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_rx,
@@ -285,12 +293,12 @@ struct db_rfx_1200_rx db_rfx_1200_rx = {
   .base.atr_rxval = MIX_EN,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 1,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_RX_DB,
-  .common.freq_mult = 2,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(0)
+  .common.freq_mult = 2
 };
 
 
@@ -300,14 +308,14 @@ struct db_rfx_1200_tx db_rfx_1200_tx = {
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1150e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1350e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(1450e6),
   //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   .base.is_quadrature = true,
-  .base.i_and_q_swapped = true,
+  .base.i_and_q_swapped = false,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
   .base.init = rfx_init_tx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_tx,
@@ -317,12 +325,12 @@ struct db_rfx_1200_tx db_rfx_1200_tx = {
   .base.atr_rxval = ANT_SW,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 1,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_TX_DB,
-  .common.freq_mult = 2,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6)
+  .common.freq_mult = 2
 };
 
 struct db_rfx_1800_rx db_rfx_1800_rx = {
@@ -330,15 +338,15 @@ struct db_rfx_1800_rx db_rfx_1800_rx = {
   .base.is_tx = false,
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
-  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1600e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2000e6),
+  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1500e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2100e6),
   .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
   .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
   .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
   .base.is_quadrature = true,
   .base.i_and_q_swapped = true,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
   .base.init = rfx_init_rx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_rx,
@@ -348,12 +356,12 @@ struct db_rfx_1800_rx db_rfx_1800_rx = {
   .base.atr_rxval = MIX_EN,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 0,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_RX_DB,
-  .common.freq_mult = 1,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(0)
+  .common.freq_mult = 1
 };
 
 
@@ -362,15 +370,79 @@ struct db_rfx_1800_tx db_rfx_1800_tx = {
   .base.is_tx = true,
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
-  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1600e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2000e6),
+  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(1500e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2100e6),
   //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   .base.is_quadrature = true,
+  .base.i_and_q_swapped = false,
+  .base.spectrum_inverted = false,
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
+  .base.init = rfx_init_tx,
+  .base.set_freq = rfx_set_freq,
+  .base.set_gain = rfx_set_gain_tx,
+  .base.set_tx_enable = rfx_set_tx_enable,
+  .base.atr_mask = 0x00E0,
+  .base.atr_txval = MIX_EN, 
+  .base.atr_rxval = ANT_SW,
+  // .base.atr_tx_delay =
+  // .base.atr_rx_delay =
+  .base.set_antenna = 0,
+  .common.DIV2 = 0,
+  .common.CP1 = 7,
+  .common.CP2 = 7,
+  .common.spi_mask = SPI_SS_TX_DB,
+  .common.freq_mult = 1  
+};
+
+
+struct db_rfx_2200_rx db_rfx_2200_rx = {
+  .base.dbid = 0x002c,
+  .base.is_tx = false,
+  .base.output_enables = 0x00E0,
+  .base.used_pins = 0x00FF,
+  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(2000e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2400e6),
+  .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
+  .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
+  .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
+  .base.is_quadrature = true,
   .base.i_and_q_swapped = true,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
+  .base.init = rfx_init_rx,
+  .base.set_freq = rfx_set_freq,
+  .base.set_gain = rfx_set_gain_rx,
+  .base.set_tx_enable = 0,
+  .base.atr_mask = 0x00E0,
+  .base.atr_txval = 0,
+  .base.atr_rxval = MIX_EN,
+  // .base.atr_tx_delay =
+  // .base.atr_rx_delay =
+  .base.set_antenna = 0,
+  .common.DIV2 = 0,
+  .common.CP1 = 7,
+  .common.CP2 = 7,
+  .common.spi_mask = SPI_SS_RX_DB,
+  .common.freq_mult = 1
+};
+
+
+struct db_rfx_2200_tx db_rfx_2200_tx = {
+  .base.dbid = 0x002d,
+  .base.is_tx = true,
+  .base.output_enables = 0x00E0,
+  .base.used_pins = 0x00FF,
+  .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(2000e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2400e6),
+  //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+  //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+  //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
+  .base.is_quadrature = true,
+  .base.i_and_q_swapped = false,
+  .base.spectrum_inverted = false,
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
   .base.init = rfx_init_tx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_tx,
@@ -380,12 +452,12 @@ struct db_rfx_1800_tx db_rfx_1800_tx = {
   .base.atr_rxval = ANT_SW,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 0,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_TX_DB,
-  .common.freq_mult = 1,  
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6)
+  .common.freq_mult = 1
 };
 
 
@@ -395,14 +467,14 @@ struct db_rfx_2400_rx db_rfx_2400_rx = {
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(2300e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2700e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2900e6),
   .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
   .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(70),
   .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.034),
   .base.is_quadrature = true,
   .base.i_and_q_swapped = true,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
   .base.init = rfx_init_rx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_rx,
@@ -412,12 +484,12 @@ struct db_rfx_2400_rx db_rfx_2400_rx = {
   .base.atr_rxval = MIX_EN,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 0,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_RX_DB,
-  .common.freq_mult = 1,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(0)
+  .common.freq_mult = 1
 };
 
 
@@ -427,14 +499,14 @@ struct db_rfx_2400_tx db_rfx_2400_tx = {
   .base.output_enables = 0x00E0,
   .base.used_pins = 0x00FF,
   .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(2300e6),
-  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2700e6),
+  .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2900e6),
   //.base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   //.base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(xxx),
   .base.is_quadrature = true,
-  .base.i_and_q_swapped = true,
+  .base.i_and_q_swapped = false,
   .base.spectrum_inverted = false,
-  //.base.lo_offset = U2_DOUBLE_TO_FXPT_FREQ(4e6),
+  .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6),
   .base.init = rfx_init_tx,
   .base.set_freq = rfx_set_freq,
   .base.set_gain = rfx_set_gain_tx,
@@ -444,12 +516,12 @@ struct db_rfx_2400_tx db_rfx_2400_tx = {
   .base.atr_rxval = ANT_SW,
   // .base.atr_tx_delay =
   // .base.atr_rx_delay =
+  .base.set_antenna = 0,
   .common.DIV2 = 0,
   .common.CP1 = 7,
   .common.CP2 = 7,
   .common.spi_mask = SPI_SS_TX_DB,
-  .common.freq_mult = 1,
-  .common.freq_offset = U2_DOUBLE_TO_FXPT_FREQ(12.5e6)
+  .common.freq_mult = 1
 };
 
 
@@ -488,7 +560,7 @@ rfx_set_freq(struct db_base *dbb, u2_fxpt_freq_t freq, u2_fxpt_freq_t *dc)
 
   *dc = 0;
   struct db_rfx_dummy *db = (struct db_rfx_dummy *) dbb;
-  u2_fxpt_freq_t desired_n = ((1LL<<20)*db->common.freq_mult*(freq+db->common.freq_offset))/phdet_freq;
+  u2_fxpt_freq_t desired_n = (U2_DOUBLE_TO_FXPT_FREQ(1.0)*db->common.freq_mult*freq)/phdet_freq;
   int N_DIV = u2_fxpt_freq_round_to_int(desired_n);
   int B = N_DIV/PRESCALER;
   int A = N_DIV - PRESCALER*B;