3 * Copyright 2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <vrt_quadradio_source_32fc.h>
25 #include <vrt/quadradio.h>
26 #include <vrt/rx_packet_handler.h>
29 vrt_quadradio_source_32fc_sptr
30 vrt_make_quadradio_source_32fc(const std::string &ip,
32 size_t samples_per_pkt,
35 return gnuradio::get_initial_sptr(new vrt_quadradio_source_32fc(ip,
41 vrt_quadradio_source_32fc::vrt_quadradio_source_32fc(const std::string &ip,
43 size_t samples_per_pkt,
45 : vrt_source_32fc("quadradio_source_32fc"),
46 d_samples_per_pkt(samples_per_pkt == 0 ? (rxdspno == 0 ? 800 : 200) : samples_per_pkt),
47 d_qr(vrt::quadradio::sptr(new vrt::quadradio(ip, rx_bufsize))),
52 vrt_quadradio_source_32fc::~vrt_quadradio_source_32fc()
54 d_qr->stop_streaming(d_rxdspno);
58 vrt_quadradio_source_32fc::vrt_rx() const
60 return d_qr->vrt_rx();
64 vrt_quadradio_source_32fc::start()
66 // throw away any stale packets before starting
67 vrt::rx_packet_handler nop;
68 vrt_rx()->rx_packets(&nop, true);
71 return d_qr->start_streaming(d_rxdspno, d_samples_per_pkt);
75 vrt_quadradio_source_32fc::stop()
77 return d_qr->stop_streaming(d_rxdspno);
81 vrt_quadradio_source_32fc::set_dboard_pins(int which_dboard, int v)
83 return d_qr->set_dboard_pins(which_dboard, v);
87 vrt_quadradio_source_32fc::set_center_freq(double target_freq)
89 return d_qr->set_center_freq(target_freq);
93 vrt_quadradio_source_32fc::set_band_select(int band)
95 return d_qr->set_band_select(static_cast<vrt_band_sel_t>(band));
99 vrt_quadradio_source_32fc::get_band_select(void)
101 return static_cast<int>(d_qr->get_band_select());
105 //vrt_quadradio_source_32fc::set_10dB_atten(bool on)
107 // return d_qr->set_10dB_atten(on);
111 vrt_quadradio_source_32fc::select_rx_antenna(const std::string &ant)
113 return d_qr->select_rx_antenna(ant);
117 vrt_quadradio_source_32fc::set_attenuation0(int attenuation)
119 return d_qr->set_attenuation0(attenuation);
123 vrt_quadradio_source_32fc::set_attenuation1(int attenuation)
125 return d_qr->set_attenuation1(attenuation);
129 vrt_quadradio_source_32fc::set_adc_gain(bool on){
130 d_qr->set_adc_gain(on);
134 vrt_quadradio_source_32fc::set_dc_offset_comp(bool on){
135 d_qr->set_dc_offset_comp(on);
139 vrt_quadradio_source_32fc::set_digital_gain(float gain){
140 d_qr->set_digital_gain(gain);
144 vrt_quadradio_source_32fc::set_test_signal(int type){
145 d_qr->set_test_signal(static_cast<vrt_test_sig_t>(type));
149 vrt_quadradio_source_32fc::set_setting_reg(int regno, int value)
151 return d_qr->set_setting_reg(regno, value);
155 vrt_quadradio_source_32fc::set_hsadc_conf(int which_dboard, int regno, int value)
157 return d_qr->set_hsadc_conf(which_dboard, regno, value);
161 vrt_quadradio_source_32fc::set_lsdac(int which_dboard, int which_dac, int value)
163 return d_qr->set_lsdac(which_dboard, which_dac, value);
167 vrt_quadradio_source_32fc::set_mem32(int addr, int value)
169 return d_qr->set_mem32(addr, value);
173 vrt_quadradio_source_32fc::set_lo_freq(double freq)
175 return d_qr->set_lo_freq(freq);
179 vrt_quadradio_source_32fc::set_cal_freq(double freq)
181 return d_qr->set_cal_freq(freq);
184 /*--------------------------------------------------------------------*/
185 #define IQ_IMBAL_NUM_TAPS 30
186 #define IQ_IMBAL_REG_NO 162
188 //helper function to set the iq imbalance register with a tap
189 static int get_iq_imbal_reg(bool real, bool init, float tap){
190 int val = int(round(tap));
191 val &= 0x1ffffff; //lower 25 bits for tap
192 val |= (real?0:1) << 30; //30th bit for filter type
193 val |= (init?1:0) << 31; //31st bit for initialization
194 printf("Reg %d Val %x\n", IQ_IMBAL_REG_NO, val);
199 vrt_quadradio_source_32fc::set_iq_imbal_taps(const std::vector<gr_complex> taps){
201 /* set the real part of the taps */
202 get_iq_imbal_reg(true, true, 0);
203 for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){
204 set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(true, false, taps[IQ_IMBAL_NUM_TAPS-i-1].real()));
206 get_iq_imbal_reg(false, true, 0);
207 /* set the imaginary part of the taps */
208 for (i = 0; i < IQ_IMBAL_NUM_TAPS; i++){
209 set_setting_reg(IQ_IMBAL_REG_NO, get_iq_imbal_reg(false, false, taps[IQ_IMBAL_NUM_TAPS-i-1].imag()));
214 vrt_quadradio_source_32fc::set_beamforming(std::vector<gr_complex> gains){
215 int32_t gains_ints[8];
216 for (int i = 0; i < 4; i++){
217 gains_ints[2*i] = int32_t(gains[i].real());
218 gains_ints[2*i+1] = int32_t(gains[i].imag());
220 return d_qr->set_beamforming(gains_ints);
224 vrt_quadradio_source_32fc::set_cal_enb(bool enb){
225 return d_qr->set_cal_enb(enb);