2 * Copyright 2010 Free Software Foundation, Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <memory_map.h>
32 #define min(X,Y) ((X) < (Y) ? (X) : (Y))
33 #define max(X,Y) ((X) > (Y) ? (X) : (Y))
35 bool wbxng_init_rx(struct db_base *dbb);
36 bool wbxng_init_tx(struct db_base *dbb);
37 bool wbxng_set_freq(struct db_base *dbb, u2_fxpt_freq_t freq, u2_fxpt_freq_t *dc);
38 bool wbxng_set_gain_rx(struct db_base *dbb, u2_fxpt_gain_t gain);
39 bool wbxng_set_gain_tx(struct db_base *dbb, u2_fxpt_gain_t gain);
40 bool wbxng_set_tx_enable(struct db_base *dbb, bool on);
46 struct db_wbxng_rx db_wbxng_rx = {
49 .base.output_enables = RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5|PLL_CE|PLL_PDBRF|ATTN_MASK,
50 .base.used_pins = 0xFFFF,
51 .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(68.75e6),
52 .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2200e6),
53 .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
54 .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(31.5),
55 .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.5),
56 .base.is_quadrature = true,
57 .base.i_and_q_swapped = false,
58 .base.spectrum_inverted = false,
59 .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
60 .base.init = wbxng_init_rx,
61 .base.set_freq = wbxng_set_freq,
62 .base.set_gain = wbxng_set_gain_rx,
63 .base.set_tx_enable = 0,
64 .base.atr_mask = RXBB_EN | RX2_RX1N,
65 .base.atr_txval = RX2_RX1N,
66 .base.atr_rxval = RXBB_EN,
67 // .base.atr_tx_delay =
68 // .base.atr_rx_delay =
69 .base.set_antenna = 0,
70 .common.adf4350_regs_int = UINT16_C(100),
71 .common.adf4350_regs_frac = 0,
72 .common.adf4350_regs_prescaler = 1,
73 .common.adf4350_regs_mod = UINT16_C(0xfff),
74 .common.adf4350_regs_10_bit_r_counter = UINT16_C(1),
75 .common.adf4350_regs_divider_select = 0,
76 .common.adf4350_regs_8_bit_band_select_clock_divider_value = 0,
77 .common.spi_mask = SPI_SS_RX_DB,
82 struct db_wbxng_tx db_wbxng_tx = {
85 .base.output_enables = RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5|PLL_CE|PLL_PDBRF,
86 .base.used_pins = 0xFFFF,
87 .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(68.75e6),
88 .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2200e6),
89 .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0),
90 .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(25),
91 .base.gain_step_size = U2_DOUBLE_TO_FXPT_GAIN(0.1),
92 .base.is_quadrature = true,
93 .base.i_and_q_swapped = false,
94 .base.spectrum_inverted = false,
95 .base.default_lo_offset = U2_DOUBLE_TO_FXPT_FREQ(0),
96 .base.init = wbxng_init_tx,
97 .base.set_freq = wbxng_set_freq,
98 .base.set_gain = wbxng_set_gain_tx,
99 .base.set_tx_enable = wbxng_set_tx_enable,
100 .base.atr_mask = RX_TXN | TXMOD_EN,
101 .base.atr_txval = TXMOD_EN,
102 .base.atr_rxval = RX_TXN,
103 // .base.atr_tx_delay =
104 // .base.atr_rx_delay =
105 .base.set_antenna = 0,
106 .common.adf4350_regs_int = UINT16_C(100),
107 .common.adf4350_regs_frac = 0,
108 .common.adf4350_regs_prescaler = 1,
109 .common.adf4350_regs_mod = UINT16_C(0xfff),
110 .common.adf4350_regs_10_bit_r_counter = UINT16_C(1),
111 .common.adf4350_regs_divider_select = 0,
112 .common.adf4350_regs_8_bit_band_select_clock_divider_value = 0,
113 .common.spi_mask = SPI_SS_TX_DB,
114 .common.freq_mult = 2
119 wbxng_init_tx(struct db_base *dbb)
121 //struct db_wbxng_dummy *db = (struct db_wbxng_dummy *) dbb;
122 clocks_enable_tx_dboard(true, 0);
123 hal_gpio_write( GPIO_TX_BANK, ENABLE_5|ENABLE_33, ENABLE_5|ENABLE_33 );
127 // Set the freq now to get the one time 10ms delay out of the way.
129 dbb->set_freq(dbb, dbb->freq_min, &dc);
134 wbxng_init_rx(struct db_base *dbb)
136 //struct db_wbxng_dummy *db = (struct db_wbxng_dummy *) dbb;
137 clocks_enable_rx_dboard(true, 0);
138 hal_gpio_write( GPIO_RX_BANK, ENABLE_5|ENABLE_33, ENABLE_5|ENABLE_33 );
143 dbb->set_gain(dbb,U2_DOUBLE_TO_FXPT_GAIN(20.0));
145 // Set the freq now to get the one time 10ms delay out of the way.
147 dbb->set_freq(dbb, dbb->freq_min, &dc);
153 wbxng_set_freq(struct db_base *dbb, u2_fxpt_freq_t freq, u2_fxpt_freq_t *dc)
156 u2_fxpt_freq_t clamp_freq = max(dbb->freq_min, min(freq, dbb->freq_max));
157 //printf("Requested LO freq = %u", (uint32_t) ((clamp_freq >> U2_FPF_RP)/1000));
158 bool ok = adf4350_set_freq(clamp_freq<<1,dbb);
159 *dc = adf4350_get_freq(dbb)>>1;
165 wbxng_set_gain_tx(struct db_base *dbb, u2_fxpt_gain_t gain)
167 struct db_wbxng_dummy *db = (struct db_wbxng_dummy *) dbb;
170 //gain = max(db->gain_min, min(gain, db->gain_max));
172 int offset_q8 = (int)(1.4/3.3*4096*(1<<15));
173 int range_q15 = (int)(-0.9*4096/3.3*256*128);
174 int slope_q8 = range_q15/db->base.gain_max;
176 int dacword = ((slope_q8 * gain) + offset_q8)>>15;
177 //printf("DACWORD 0x%x\n",dacword);
178 lsdac_write_tx(0,dacword);
183 wbxng_set_gain_rx(struct db_base *dbb, u2_fxpt_gain_t gain)
185 struct db_wbxng_dummy *db = (struct db_wbxng_dummy *) dbb;
188 //gain = max(db->gain_min, min(gain, db->gain_max));
190 int iobits = (int) ((~((db->base.gain_max - gain) << 2)) & ATTN_MASK);
191 //printf("gain %d, gainmax %d, RX_ATTN_MASK = 0x%x, RX_ATTN_WORD = 0x%x\n", gain, db->base.gain_max, (int) (ATTN_MASK), (int) (iobits));
193 hal_gpio_write( GPIO_RX_BANK, (int) (iobits), ATTN_MASK );
199 wbxng_set_tx_enable(struct db_base *dbb, bool on)
201 struct db_wbxng_dummy *db = (struct db_wbxng_dummy *) dbb;
209 wbxng_lock_detect(struct db_base *dbb)
211 struct db_wbxng_dummy *db = (struct db_wbxng_dummy *) dbb;
214 pins = hal_gpio_read( db->base.is_tx ? GPIO_TX_BANK : GPIO_RX_BANK );
215 if(pins & PLL_LOCK_DETECT)
216 //printf("Got Locked Status from Synth");
219 //printf("Got Unlocked Status from Synth");