From b66a74ff1f629af714e26040b410d472c08be522 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 7 Apr 2010 00:46:42 -0700 Subject: Reworked the spi part of the dboard interface. It turns out to be more complicated. The integer type is better for holding the bits. The edges can be different, so the spi config hold 2 edge setting for mosi and miso. --- firmware/microblaze/apps/txrx.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'firmware') diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 69a04d771..561f3148f 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -253,29 +253,18 @@ void handle_udp_ctrl_packet( * SPI ******************************************************************/ case USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO:{ - uint8_t num_bytes = ctrl_data_in->data.spi_args.bytes; - - //load the data from the array of bytes - uint32_t data = 0x0; - for (size_t i = 0; i < num_bytes; i++){ - data = (data << 8) | ctrl_data_in->data.spi_args.data[i]; - } - //transact uint32_t result = spi_transact( (ctrl_data_in->data.spi_args.readback == 0)? SPI_TXONLY : SPI_TXRX, - ctrl_data_in->data.spi_args.dev, - data, num_bytes*8, //length in bits - (ctrl_data_in->data.spi_args.edge == USRP2_CLK_EDGE_RISE)? SPIF_PUSH_RISE : SPIF_PUSH_FALL | - (ctrl_data_in->data.spi_args.edge == USRP2_CLK_EDGE_RISE)? SPIF_LATCH_RISE : SPIF_LATCH_FALL + ctrl_data_in->data.spi_args.dev, //which device + ctrl_data_in->data.spi_args.data, //32 bit data + ctrl_data_in->data.spi_args.num_bits, //length in bits + (ctrl_data_in->data.spi_args.mosi_edge == USRP2_CLK_EDGE_RISE)? SPIF_PUSH_FALL : SPIF_PUSH_RISE | + (ctrl_data_in->data.spi_args.miso_edge == USRP2_CLK_EDGE_RISE)? SPIF_LATCH_RISE : SPIF_LATCH_FALL ); - //load the result into the array of bytes - for (size_t i = 0; i < num_bytes; i++){ - uint8_t byte_shift = num_bytes - i - 1; - ctrl_data_out.data.spi_args.data[i] = (result >> (byte_shift*8)) & 0xff; - } - ctrl_data_out.data.spi_args.bytes = num_bytes; + //load output + ctrl_data_out.data.spi_args.data = result; ctrl_data_out.id = USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE; } break; -- cgit v1.2.3 From 841400bb4e72375b439f04f0bd855e64b9f83f00 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 13 Apr 2010 16:08:14 -0700 Subject: Moved ad9777 control 100% on to the host --- firmware/microblaze/lib/Makefile.am | 3 -- firmware/microblaze/lib/ad9777.c | 47 ---------------------- firmware/microblaze/lib/ad9777.h | 31 -------------- firmware/microblaze/lib/ad9777_regs.h | 71 --------------------------------- firmware/microblaze/lib/u2_init.c | 16 -------- host/lib/ic_reg_maps/gen_ad9777_regs.py | 8 ++-- host/lib/usrp/usrp2/mboard_impl.cpp | 25 ++++++++++++ 7 files changed, 29 insertions(+), 172 deletions(-) delete mode 100644 firmware/microblaze/lib/ad9777.c delete mode 100644 firmware/microblaze/lib/ad9777.h delete mode 100644 firmware/microblaze/lib/ad9777_regs.h (limited to 'firmware') diff --git a/firmware/microblaze/lib/Makefile.am b/firmware/microblaze/lib/Makefile.am index 4ca05739c..3d02cfe8b 100644 --- a/firmware/microblaze/lib/Makefile.am +++ b/firmware/microblaze/lib/Makefile.am @@ -25,7 +25,6 @@ noinst_LIBRARIES = \ libu2fw_a_SOURCES = \ abort.c \ ad9510.c \ - ad9777.c \ bsm12.c \ buffer_pool.c \ clocks.c \ @@ -60,8 +59,6 @@ libu2fw_a_SOURCES = \ noinst_HEADERS = \ ad9510.h \ - ad9777.h \ - ad9777_regs.h \ bsm12.h \ buffer_pool.h \ clocks.h \ diff --git a/firmware/microblaze/lib/ad9777.c b/firmware/microblaze/lib/ad9777.c deleted file mode 100644 index 734ccd7e5..000000000 --- a/firmware/microblaze/lib/ad9777.c +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 . - */ - -#include "ad9777.h" -#include "memory_map.h" -#include "spi.h" - -#define IB_RD 0x80 -#define IB_WR 0x00 -#define IB_XFER_1 0x00 -#define IB_XFER_2 0x20 -#define IB_XFER_3 0x40 -#define IB_XFER_4 0x60 -#define IB_ADDR_MASK 0x1f - -void -ad9777_write_reg(int regno, uint8_t value) -{ - uint8_t instr = IB_WR | IB_XFER_1 | (regno & IB_ADDR_MASK); - spi_transact(SPI_TXONLY, SPI_SS_AD9777, - (instr << 8) | (value & 0xff), 16, SPIF_PUSH_FALL); -} - -int -ad9777_read_reg(int regno) -{ - uint8_t instr = IB_RD | IB_XFER_1 | (regno & IB_ADDR_MASK); - uint32_t r = spi_transact(SPI_TXRX, SPI_SS_AD9777, - (instr << 8) | 0, 16, - SPIF_PUSH_FALL | SPIF_LATCH_RISE); - return r & 0xff; -} diff --git a/firmware/microblaze/lib/ad9777.h b/firmware/microblaze/lib/ad9777.h deleted file mode 100644 index d4d104910..000000000 --- a/firmware/microblaze/lib/ad9777.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- c++ -*- */ -/* - * 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 . - */ -#ifndef INCLUDED_AD9777_H -#define INCLUDED_AD9777_H - -#include -#include "ad9777_regs.h" - -/* - * Analog Devices AD9777 16-bit, 160 MS/s, Dual Interpolating TxDAC - */ - -void ad9777_write_reg(int regno, uint8_t value); -int ad9777_read_reg(int regno); - -#endif /* INCLUDED_AD9777_H */ diff --git a/firmware/microblaze/lib/ad9777_regs.h b/firmware/microblaze/lib/ad9777_regs.h deleted file mode 100644 index de2936c15..000000000 --- a/firmware/microblaze/lib/ad9777_regs.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 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 . - */ -#ifndef INCLUDED_AD9777_REGS_H -#define INCLUDED_AD9777_REGS_H - -#define R0_SW_RESET (1 << 5) -#define R0_SLEEP (1 << 4) -#define R0_POWER_DN (1 << 3) -#define R0_1R (1 << 2) -#define R0_2R (0 << 2) -#define R0_PLL_LOCKED (1 << 1) - -#define R1_INTERP_1X 0x00 -#define R1_INTERP_2X 0x40 -#define R1_INTERP_4X 0x80 -#define R1_INTERP_8X 0xC0 -#define R1_MOD_NONE 0x00 -#define R1_MOD_FS_2 0x10 // Fs/2 -#define R1_MOD_FS_4 0x20 // Fs/4 -#define R1_MOD_FS_8 0x30 // Fs/8 -#define R1_ZERO_STUFF (1 << 3) // N.B., doubles output rate -#define R1_REAL_MIX (1 << 2) -#define R1_CMPLX_MIX (0 << 2) -#define R1_POS_EXP (1 << 1) // exp(+jwt) -#define R1_NEG_EXP (0 << 1) // exp(-jwt) -#define R1_DATACLK_OUT (1 << 0) - -#define R2_2S_COMP (0 << 7) -#define R2_2PORT_MODE (0 << 6) -#define R2_1PORT_MODE (1 << 6) - -#define R3_PLL_DIV_1 0x00 -#define R3_PLL_DIV_2 0x01 -#define R3_PLL_DIV_4 0x02 -#define R3_PLL_DIV_8 0x03 - -#define R4_PLL_ON (1 << 7) -#define R4_CP_MANUAL (1 << 6) -#define R4_CP_AUTO (0 << 6) -#define R4_CP_50uA (0x00 | R4_CP_MANUAL) -#define R4_CP_100uA (0x01 | R4_CP_MANUAL) -#define R4_CP_200uA (0x02 | R4_CP_MANUAL) -#define R4_CP_400uA (0x03 | R4_CP_MANUAL) -#define R4_CP_800uA (0x07 | R4_CP_MANUAL) - -#define R5_I_FINE_GAIN(g) (g) // 8-bits -#define R6_I_COARSE_GAIN(g) ((g) & 0xf) // low 4-bits - -#define R9_Q_FINE_GAIN(g) (g) // 8-bits -#define R10_Q_COARSE_GAIN(g) ((g) & 0xf) // low 4-bits - - -// FIXME more registers for offset and gain control... - - -#endif /* INCLUDED_AD9777_REGS_H */ diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index 2e2e6a0fb..c56468c08 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -26,7 +26,6 @@ #include "hal_uart.h" #include "i2c.h" #include "mdelay.h" -#include "ad9777.h" #include "clocks.h" #include "db.h" #include "usrp2_i2c_addr.h" @@ -75,21 +74,6 @@ u2_init(void) // Enable ADCs output_regs->adc_ctrl = ADC_CTRL_ON; - - // Set up AD9777 DAC - ad9777_write_reg(0, R0_1R); - ad9777_write_reg(1, R1_INTERP_4X | R1_REAL_MIX); - ad9777_write_reg(2, 0); - ad9777_write_reg(3, R3_PLL_DIV_1); - ad9777_write_reg(4, R4_PLL_ON | R4_CP_AUTO); - ad9777_write_reg(5, R5_I_FINE_GAIN(0)); - ad9777_write_reg(6, R6_I_COARSE_GAIN(0xf)); - ad9777_write_reg(7, 0); // I dac offset - ad9777_write_reg(8, 0); - ad9777_write_reg(9, R9_Q_FINE_GAIN(0)); - ad9777_write_reg(10, R10_Q_COARSE_GAIN(0xf)); - ad9777_write_reg(11, 0); // Q dac offset - ad9777_write_reg(12, 0); // Initial values for tx and rx mux registers dsp_tx_regs->tx_mux = 0x10; diff --git a/host/lib/ic_reg_maps/gen_ad9777_regs.py b/host/lib/ic_reg_maps/gen_ad9777_regs.py index 5bfd404c2..135d5c724 100644 --- a/host/lib/ic_reg_maps/gen_ad9777_regs.py +++ b/host/lib/ic_reg_maps/gen_ad9777_regs.py @@ -49,7 +49,7 @@ pll_lock_indicator 0[1] 0 filter_interp_rate 1[6:7] 0 1x, 2x, 4x, 8x modulation_mode 1[4:5] 0 none, fs_2, fs_4, fs_8 zero_stuff_mode 1[3] 0 -real_mix_mode 1[2] 0 +mix_mode 1[2] 1 complex, real modulation_form 1[1] 0 e_minus_jwt, e_plus_jwt data_clk_pll_lock_sel 1[0] 0 pll_lock, data_clk ######################################################################## @@ -70,7 +70,7 @@ pll_divide_ratio 3[0:1] 0 div1, div2, div4, div8 ######################################################################## ## address 4 ######################################################################## -pll_off 4[7] 0 off, on +pll_state 4[7] 0 off, on auto_cp_control 4[6] 0 dis, enb pll_cp_control 4[0:2] 0 50ua=0, 100ua=1, 200ua=2, 400ua=3, 800ua=7 ######################################################################## @@ -81,8 +81,8 @@ qdac_fine_gain_adjust 9[0:7] 0 ######################################################################## ## address 6 and A ######################################################################## -idac_fine_coarse_adjust 6[0:3] 0 -qdac_fine_coarse_adjust A[0:3] 0 +idac_coarse_gain_adjust 6[0:3] 0 +qdac_coarse_gain_adjust A[0:3] 0 ######################################################################## ## address 7, 8 and B, C ######################################################################## diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 4361e45cd..ea268651a 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -17,6 +17,7 @@ #include "usrp2_impl.hpp" #include "usrp2_regs.hpp" +#include "ad9777_regs.hpp" #include #include #include @@ -35,6 +36,30 @@ void usrp2_impl::mboard_init(void){ ); _clock_control = clock_control::make_ad9510(this); + + //setup the ad9777 dac + ad9777_regs_t ad9777_regs; + ad9777_regs.x_1r_2r_mode = ad9777_regs_t::X_1R_2R_MODE_1R; + ad9777_regs.filter_interp_rate = ad9777_regs_t::FILTER_INTERP_RATE_4X; + ad9777_regs.mix_mode = ad9777_regs_t::MIX_MODE_REAL; + ad9777_regs.pll_divide_ratio = ad9777_regs_t::PLL_DIVIDE_RATIO_DIV1; + ad9777_regs.pll_state = ad9777_regs_t::PLL_STATE_OFF; + ad9777_regs.auto_cp_control = ad9777_regs_t::AUTO_CP_CONTROL_ENB; + //I dac values + ad9777_regs.idac_fine_gain_adjust = 0; + ad9777_regs.idac_coarse_gain_adjust = 0xf; + ad9777_regs.idac_offset_adjust_lsb = 0; + ad9777_regs.idac_offset_adjust_msb = 0; + //Q dac values + ad9777_regs.qdac_fine_gain_adjust = 0; + ad9777_regs.qdac_coarse_gain_adjust = 0xf; + ad9777_regs.qdac_offset_adjust_lsb = 0; + ad9777_regs.qdac_offset_adjust_msb = 0; + //write all regs + for(boost::uint8_t addr = 0; addr <= 0xC; addr++){ + boost::uint16_t data = ad9777_regs.get_write_reg(addr); + this->transact_spi(SPI_SS_AD9777, spi_config_t::EDGE_RISE, data, 16, false /*no rb*/); + } } clock_control::sptr usrp2_impl::get_clock_control(void){ -- cgit v1.2.3 From c10e58cf253feb47e16d01ff5d47924d8de71365 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 13 Apr 2010 16:19:33 -0700 Subject: removed unused firmware code --- firmware/microblaze/lib/db.h | 78 ---------- firmware/microblaze/lib/db_init.c | 291 -------------------------------------- firmware/microblaze/lib/u2_init.c | 1 - 3 files changed, 370 deletions(-) (limited to 'firmware') diff --git a/firmware/microblaze/lib/db.h b/firmware/microblaze/lib/db.h index 5153822c6..358cb222b 100644 --- a/firmware/microblaze/lib/db.h +++ b/firmware/microblaze/lib/db.h @@ -28,82 +28,4 @@ int read_dboard_eeprom(int i2c_addr); -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 Set daughterboard LO offset frequency. - * - * \param[in] db is the daughterboard instance - * \param[in] offset is the amount to add to tuning requests - * \param[out] success or failure - */ -bool -db_set_lo_offset(struct db_base *db, u2_fxpt_freq_t offset); - -/*! - * \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); - - -/*! - * \brief Set gain - */ -bool -db_set_gain(struct db_base *db, u2_fxpt_gain_t gain); - - -void -set_atr_regs(int bank, int atr_rxval, int atr_txval); - #endif /* INCLUDED_DB_H */ diff --git a/firmware/microblaze/lib/db_init.c b/firmware/microblaze/lib/db_init.c index 4a0b49ada..23805d9cd 100644 --- a/firmware/microblaze/lib/db_init.c +++ b/firmware/microblaze/lib/db_init.c @@ -75,294 +75,3 @@ read_dboard_eeprom(int i2c_addr) return -2; } } - - -static struct db_base * -lookup_dbid(int dbid) -{ - return 0; -} - -static struct db_base * -lookup_dboard(int i2c_addr, struct db_base *default_db, char *msg) -{ - struct db_base *db; - int dbid = read_dboard_eeprom(i2c_addr); - - // FIXME removing this printf has the system hang if there are two d'boards - // installed. (I think the problem is in i2c_read/write or the way - // I kludge the zero-byte write to set the read address in eeprom_read.) - printf("%s dbid: 0x%x\n", msg, dbid); - - if (dbid < 0){ // there was some kind of problem. Treat as Basic Tx - return default_db; - } - else if ((db = lookup_dbid(dbid)) == 0){ - printf("No daugherboard code for dbid = 0x%x\n", dbid); - return default_db; - } - return db; -} - -void -set_atr_regs(int bank, int atr_rxval, int atr_txval) -{ - uint32_t val[4]; - int shift; - int mask; - int i; - - val[ATR_IDLE] = atr_rxval; - val[ATR_RX] = atr_rxval; - val[ATR_TX] = atr_txval; - val[ATR_FULL] = atr_txval; - - if (bank == GPIO_TX_BANK){ - mask = 0xffff0000; - shift = 16; - } - else { - mask = 0x0000ffff; - shift = 0; - } - - for (i = 0; i < 4; i++){ - int t = (atr_regs->v[i] & ~mask) | ((val[i] << shift) & mask); - //printf("atr_regs[%d] = 0x%x\n", i, t); - atr_regs->v[i] = t; - } -} - -static void -set_gpio_mode(int bank, struct db_base *db) -{ - int i; - - hal_gpio_set_ddr(bank, /*db->output_enables*/0, 0xffff); - //set_atr_regs(bank, db); - - for (i = 0; i < 16; i++){ - if (/*db->used_pins*/0 & (1 << i)){ - // set to either GPIO_SEL_SW or GPIO_SEL_ATR - hal_gpio_set_sel(bank, i, (/*db->atr_mask*/0 & (1 << i)) ? 'a' : 's'); - } - } -} - -static int __attribute__((unused)) -determine_tx_mux_value(struct db_base *db) -{ - if (/*db->i_and_q_swapped*/0) - return 0x01; - else - return 0x10; -} - -static int -determine_rx_mux_value(struct db_base *db) -{ -#define ADC0 0x0 -#define ADC1 0x1 -#define ZERO 0x2 - - static int truth_table[8] = { - /* swap_iq, uses */ - /* 0, 0x0 */ (ZERO << 2) | ZERO, // N/A - /* 0, 0x1 */ (ZERO << 2) | ADC0, - /* 0, 0x2 */ (ZERO << 2) | ADC1, - /* 0, 0x3 */ (ADC1 << 2) | ADC0, - /* 1, 0x0 */ (ZERO << 2) | ZERO, // N/A - /* 1, 0x1 */ (ZERO << 2) | ADC0, - /* 1, 0x2 */ (ZERO << 2) | ADC1, - /* 1, 0x3 */ (ADC0 << 2) | ADC1, - }; - - int subdev0_uses; - int subdev1_uses; - int uses; - - if (/*db->is_quadrature*/0) - subdev0_uses = 0x3; // uses A/D 0 and 1 - else - subdev0_uses = 0x1; // uses A/D 0 only - - // FIXME second subdev on Basic Rx, LF RX - // if subdev2 exists - // subdev1_uses = 0x2; - subdev1_uses = 0; - - uses = subdev0_uses; - - int swap_iq = /*db->i_and_q_swapped*/0 & 0x1; - int index = (swap_iq << 2) | uses; - - return truth_table[index]; -} - - -void -db_init(void) -{ - /*int m; - - tx_dboard = lookup_dboard(I2C_ADDR_TX_A, &db_basic_tx, "Tx"); - //printf("db_init: tx dbid = 0x%x\n", tx_dboard->dbid); - set_gpio_mode(GPIO_TX_BANK, tx_dboard); - tx_dboard->init(tx_dboard); - m = determine_tx_mux_value(tx_dboard); - dsp_tx_regs->tx_mux = m; - //printf("tx_mux = 0x%x\n", m); - tx_dboard->current_lo_offset = tx_dboard->default_lo_offset; - - rx_dboard = lookup_dboard(I2C_ADDR_RX_A, &db_basic_rx, "Rx"); - //printf("db_init: rx dbid = 0x%x\n", rx_dboard->dbid); - set_gpio_mode(GPIO_RX_BANK, rx_dboard); - rx_dboard->init(rx_dboard); - m = determine_rx_mux_value(rx_dboard); - dsp_rx_regs->rx_mux = m; - //printf("rx_mux = 0x%x\n", m); - rx_dboard->current_lo_offset = rx_dboard->default_lo_offset;*/ -} - -/*! - * 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; - -#if 0 - 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(); -#endif - - 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_set_lo_offset(struct db_base *db, u2_fxpt_freq_t offset) -{ - //db->current_lo_offset = offset; - return 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+lo_offset - bool ok = db->set_freq(db, target_freq+db->current_lo_offset, &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;*/return false; -} - -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; -} - -bool -db_set_gain(struct db_base *db, u2_fxpt_gain_t gain) -{ - return false;//db->set_gain(db, gain); -} diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index c56468c08..bd3302d95 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -86,7 +86,6 @@ u2_init(void) bp_init(); // buffer pool lsadc_init(); // low-speed ADCs lsdac_init(); // low-speed DACs - db_init(); // daughterboard init hal_enable_ints(); -- cgit v1.2.3