summaryrefslogtreecommitdiff
path: root/usrp/host/lib/db_base.cc
blob: b4fb45c517a9a1fa1979fd0ffb8622e0039f2499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//
// Copyright 2008,2009 Free Software Foundation, Inc.
// 
// This file is part of GNU Radio
// 
// GNU Radio 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 asversion 3, or (at your option)
// any later version.
// 
// GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street,
// Boston, MA 02110-1301, USA.
//

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <usrp/db_base.h>
#include <db_base_impl.h>

#if 0
tune_result::tune_result(double baseband, double dxc, double residual, bool inv)
  : ok(false), baseband_freq(baseband), dxc_freq(dxc), 
    residual_freq(residual), inverted(inv)
{
}

tune_result::~tune_result()
{ 
}
#endif


/*****************************************************************************/

db_base::db_base(usrp_basic_sptr usrp, int which)
  : d_is_shutdown(false), d_raw_usrp(usrp.get()), d_which(which), d_lo_offset(0.0)
{
}

db_base::~db_base()
{
  shutdown();
}

void
db_base::shutdown()
{
  if (!d_is_shutdown){
    d_is_shutdown = true;
    // do whatever there is to do to shutdown
  }
}

int 
db_base::dbid()
{
  return usrp()->daughterboard_id(d_which);
}

std::string 
db_base::name()
{
  return usrp_dbid_to_string(dbid());
}

std::string 
db_base::side_and_name()
{
  if(d_which == 0)
    return "A: " + name();
  else
    return "B: " + name();
}

// Function to bypass ADC buffers. Any board which is DC-coupled
// should bypass the buffers

bool
db_base::bypass_adc_buffers(bool bypass)
{
  //if(d_tx) {
  //  throw  std::runtime_error("TX Board has no adc buffers\n");
  //}

  bool ok = true;
  if(d_which==0) {
    ok &= usrp()->set_adc_buffer_bypass(0, bypass);
    ok &= usrp()->set_adc_buffer_bypass(1, bypass);
  }
  else {
    ok &= usrp()->set_adc_buffer_bypass(2, bypass);
    ok &= usrp()->set_adc_buffer_bypass(3, bypass);
  }
  return ok;
}

bool 
db_base::set_atr_mask(int v)
{
  // Set Auto T/R mask.
  return usrp()->write_atr_mask(d_which, v);
}

bool 
db_base::set_atr_txval(int v)
{
  // Set Auto T/R register value to be used when transmitting.
  return usrp()->write_atr_txval(d_which, v);
}
  
bool 
db_base::set_atr_rxval(int v)
{
  // Set Auto T/R register value to be used when receiving.
  return usrp()->write_atr_rxval(d_which, v);
}
  
bool 
db_base::set_atr_tx_delay(int v)
{
  // Set Auto T/R delay (in clock ticks) from when Tx fifo gets data to 
  // when T/R switches.
  return usrp()->write_atr_tx_delay(v);
}

bool 
db_base::set_atr_rx_delay(int v)
{
  // Set Auto T/R delay (in clock ticks) from when Tx fifo goes empty to 
  // when T/R switches.
  return usrp()->write_atr_rx_delay(v);
}

bool
db_base::i_and_q_swapped()
{
  // Return True if this is a quadrature device and (for RX) ADC 0 is Q
  // or (for TX) DAC 0 is Q
  return false;
}

bool 
db_base::spectrum_inverted()
{
  // Return True if the dboard gives an inverted spectrum
  
  return false;
}

bool
db_base::set_enable(bool on)
{
  // For tx daughterboards, this controls the transmitter enable.

  return true;	// default is nop
}

bool
db_base::set_auto_tr(bool on)
{
  // Enable automatic Transmit/Receive switching (ATR).
  // 
  // Should be overridden in subclasses that care.  This will typically
  // set the atr_mask, txval and rxval.

  return true;
}

bool
db_base::set_lo_offset(double offset)
{
  // Set how much LO is offset from requested frequency

  d_lo_offset = offset;
  return true;
}

bool
db_base::select_rx_antenna(int which_antenna)
{
  // Specify which antenna port to use for reception.
  // Should be overriden by daughterboards that care.

  return which_antenna == 0;
}

bool
db_base::select_rx_antenna(const std::string &which_antenna)
{
  // Specify which antenna port to use for reception.
  // Should be overriden by daughterboards that care.

  return which_antenna == "";
}


// Reference Clock section
//
// Control whether a reference clock is sent to the daughterboards,
// and what frequency
//
// Bit 7  -- 1 turns on refclk, 0 allows IO use
// Bits 6:0 Divider value
//
    
double
db_base::_refclk_freq() 
{
  return usrp()->fpga_master_clock_freq() / _refclk_divisor();
}

void 
db_base::_enable_refclk(bool enable)
{
  int CLOCK_OUT = 1;   // Clock is on lowest bit
  int REFCLK_ENABLE = 0x80;
  int REFCLK_DIVISOR_MASK = 0x7f;

  if(enable) {
    usrp()->_write_oe(d_which, CLOCK_OUT, CLOCK_OUT); // output enable
    usrp()->write_refclk(d_which, (_refclk_divisor() & REFCLK_DIVISOR_MASK) | REFCLK_ENABLE);
  }
  else {
    usrp()->write_refclk(d_which, 0);
  }
}

int 
db_base::_refclk_divisor()
{
  // Return value to stick in REFCLK_DIVISOR register
  throw std::runtime_error("_refclk_divisor() called from base class\n");;
}

bool
db_base::set_bw(float bw)
{
  // Set baseband bandwidth (board specific)
  // Should be overriden by boards that implement variable IF filtering (e.g., DBSRX)
  return false;
}

std::ostream &operator<<(std::ostream &os, db_base &x)
{
  os << x.side_and_name();
  return os;
}