root/ossiedev/branches/ttsou/gnuradio/trunk/usrp/host/lib/usrp_basic.cc @ 9523

Revision 9523, 36.8 KB (checked in by ttsou, 4 years ago)

separated contexts, simulaneous tx-rx seems to be working

Line 
1/* -*- c++ -*- */
2/*
3 * Copyright 2003,2004,2008,2009 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
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)
10 * any later version.
11 *
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING.  If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <usrp/usrp_basic.h>
28#include "usrp/usrp_prims.h"
29#include "usrp_interfaces.h"
30#include "fpga_regs_common.h"
31#include "fpga_regs_standard.h"
32#include "fusb.h"
33#include "db_boards.h"
34#include <libusb-1.0/libusb.h>
35#include <stdexcept>
36#include <assert.h>
37#include <math.h>
38#include <ad9862.h>
39#include <string.h>
40#include <cstdio>
41
42using namespace ad9862;
43
44#define NELEM(x) (sizeof (x) / sizeof (x[0]))
45
46// These set the buffer size used for each end point using the fast
47// usb interface.  The kernel ends up locking down this much memory.
48
49static const int FUSB_BUFFER_SIZE = fusb_sysconfig::default_buffer_size();
50static const int FUSB_BLOCK_SIZE = fusb_sysconfig::max_block_size();
51static const int FUSB_NBLOCKS    = FUSB_BUFFER_SIZE / FUSB_BLOCK_SIZE;
52
53
54static const double POLLING_INTERVAL = 0.1;     // seconds
55
56////////////////////////////////////////////////////////////////
57
58static struct libusb_device_handle *
59open_rx_interface (struct libusb_device *dev)
60{
61  struct libusb_device_handle *udh = usrp_open_rx_interface (dev);
62  if (udh == 0){
63    fprintf (stderr, "usrp_basic_rx: can't open rx interface\n");
64  }
65  return udh;
66}
67
68static struct libusb_device_handle *
69open_tx_interface (struct libusb_device *dev)
70{
71  struct libusb_device_handle *udh = usrp_open_tx_interface (dev);
72  if (udh == 0){
73    fprintf (stderr, "usrp_basic_tx: can't open tx interface\n");
74  }
75  return udh;
76}
77
78
79//////////////////////////////////////////////////////////////////
80//
81//                      usrp_basic
82//
83////////////////////////////////////////////////////////////////
84
85
86// Given:
87//   CLKIN = 64 MHz
88//   CLKSEL pin = high
89//
90// These settings give us:
91//   CLKOUT1 = CLKIN = 64 MHz
92//   CLKOUT2 = CLKIN = 64 MHz
93//   ADC is clocked at  64 MHz
94//   DAC is clocked at 128 MHz
95
96static unsigned char common_regs[] = {
97  REG_GENERAL,          0,
98  REG_DLL,              (DLL_DISABLE_INTERNAL_XTAL_OSC
99                         | DLL_MULT_2X
100                         | DLL_FAST),
101  REG_CLKOUT,           CLKOUT2_EQ_DLL_OVER_2,
102  REG_AUX_ADC_CLK,      AUX_ADC_CLK_CLK_OVER_4
103};
104
105
106usrp_basic::usrp_basic (int which_board,
107                        struct libusb_device_handle *
108                        open_interface (struct libusb_device *dev),
109                        const std::string fpga_filename,
110                        const std::string firmware_filename)
111  : d_udh (0), d_ctx (0),
112    d_usb_data_rate (16000000), // SWAG, see below
113    d_bytes_per_poll ((int) (POLLING_INTERVAL * d_usb_data_rate)),
114    d_verbose (false), d_fpga_master_clock_freq(64000000), d_db(2)
115{
116  /*
117   * SWAG: Scientific Wild Ass Guess.
118   *
119   * d_usb_data_rate is used only to determine how often to poll for over- and under-runs.
120   * We defualt it to 1/2  of our best case.  Classes derived from usrp_basic (e.g.,
121   * usrp_standard_tx and usrp_standard_rx) call set_usb_data_rate() to tell us the
122   * actual rate.  This doesn't change our throughput, that's determined by the signal
123   * processing code in the FPGA (which we know nothing about), and the system limits
124   * determined by libusb, fusb_*, and the underlying drivers.
125   */
126  memset (d_fpga_shadows, 0, sizeof (d_fpga_shadows));
127
128  d_ctx = usrp_one_time_init(true);
129
130  if (!usrp_load_standard_bits (which_board, false, fpga_filename, firmware_filename, d_ctx))
131    throw std::runtime_error ("usrp_basic/usrp_load_standard_bits");
132
133  struct libusb_device *dev = usrp_find_device (which_board, false, d_ctx);
134  if (dev == 0){
135    fprintf (stderr, "usrp_basic: can't find usrp[%d]\n", which_board);
136    throw std::runtime_error ("usrp_basic/usrp_find_device");
137  }
138
139  if (!(usrp_usrp_p(dev) && usrp_hw_rev(dev) >= 1)){
140    fprintf (stderr, "usrp_basic: sorry, this code only works with USRP revs >= 1\n");
141    throw std::runtime_error ("usrp_basic/bad_rev");
142  }
143
144  if ((d_udh = open_interface (dev)) == 0)
145    throw std::runtime_error ("usrp_basic/open_interface");
146
147  // initialize registers that are common to rx and tx
148
149  if (!usrp_9862_write_many_all (d_udh, common_regs, sizeof (common_regs))){
150    fprintf (stderr, "usrp_basic: failed to init common AD9862 regs\n");
151    throw std::runtime_error ("usrp_basic/init_9862");
152  }
153
154  _write_fpga_reg (FR_MODE, 0);         // ensure we're in normal mode
155  _write_fpga_reg (FR_DEBUG_EN, 0);     // disable debug outputs
156
157}
158
159void
160usrp_basic::shutdown_daughterboards()
161{
162  // nuke d'boards before we close down USB in ~usrp_basic
163  // shutdown() will do any board shutdown while the USRP can still
164  // be talked to
165  for(size_t i = 0; i < d_db.size(); i++)
166    for(size_t j = 0; j < d_db[i].size(); j++)
167      d_db[i][j]->shutdown();
168}
169
170usrp_basic::~usrp_basic ()
171{
172  // shutdown_daughterboards();         // call from ~usrp_basic_{tx,rx}
173
174  d_db.resize(0); // forget db shared ptrs
175
176  if (d_udh)
177    libusb_close (d_udh);
178
179  // There's no reference count on the number of times libusb is initialized.
180  // libusb_init can be called multiple times, but libusb_exit shuts down
181  // everything. Leave libusb running for now. Need to add a count so that it
182  // exits nicely.
183
184  // Trying to keep this enabled with contexts
185
186  assert (d_ctx != NULL);
187
188  libusb_exit (d_ctx);
189}
190
191void
192usrp_basic::init_db(usrp_basic_sptr u)
193{
194  if (u.get() != this)
195    throw std::invalid_argument("u is not this");
196
197  d_db[0] = instantiate_dbs(d_dbid[0], u, 0);
198  d_db[1] = instantiate_dbs(d_dbid[1], u, 1);
199}
200
201std::vector<db_base_sptr>
202usrp_basic::db(int which_side)
203{
204  which_side &= 0x1;    // clamp it to avoid any reporting any errors
205  return d_db[which_side];
206}
207
208bool
209usrp_basic::is_valid(const usrp_subdev_spec &ss)
210{
211  if (ss.side < 0 || ss.side > 1)
212    return false;
213
214  if (ss.subdev < 0 || ss.subdev >= d_db[ss.side].size())
215    return false;
216
217  return true;
218}
219
220db_base_sptr
221usrp_basic::selected_subdev(const usrp_subdev_spec &ss)
222{
223  if (!is_valid(ss))
224    throw std::invalid_argument("invalid subdev_spec");
225
226  return d_db[ss.side][ss.subdev];
227}
228
229bool
230usrp_basic::start ()
231{
232  return true;          // nop
233}
234
235bool
236usrp_basic::stop ()
237{
238  return true;          // nop
239}
240
241void
242usrp_basic::set_usb_data_rate (int usb_data_rate)
243{
244  d_usb_data_rate = usb_data_rate;
245  d_bytes_per_poll = (int) (usb_data_rate * POLLING_INTERVAL);
246}
247
248bool
249usrp_basic::_write_aux_dac (int slot, int which_dac, int value)
250{
251  return usrp_write_aux_dac (d_udh, slot, which_dac, value);
252}
253
254bool
255usrp_basic::_read_aux_adc (int slot, int which_adc, int *value)
256{
257  return usrp_read_aux_adc (d_udh, slot, which_adc, value);
258}
259
260int
261usrp_basic::_read_aux_adc (int slot, int which_adc)
262{
263  int   value;
264  if (!_read_aux_adc (slot, which_adc, &value))
265    return READ_FAILED;
266
267  return value;
268}
269
270bool
271usrp_basic::write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf)
272{
273  return usrp_eeprom_write (d_udh, i2c_addr, eeprom_offset, buf.data (), buf.size ());
274}
275
276std::string
277usrp_basic::read_eeprom (int i2c_addr, int eeprom_offset, int len)
278{
279  if (len <= 0)
280    return "";
281
282  char buf[len];
283
284  if (!usrp_eeprom_read (d_udh, i2c_addr, eeprom_offset, buf, len))
285    return "";
286
287  return std::string (buf, len);
288}
289
290bool
291usrp_basic::write_i2c (int i2c_addr, const std::string buf)
292{
293  return usrp_i2c_write (d_udh, i2c_addr, buf.data (), buf.size ());
294}
295
296std::string
297usrp_basic::read_i2c (int i2c_addr, int len)
298{
299  if (len <= 0)
300    return "";
301
302  char buf[len];
303
304  if (!usrp_i2c_read (d_udh, i2c_addr, buf, len))
305    return "";
306
307  return std::string (buf, len);
308}
309
310std::string
311usrp_basic::serial_number()
312{
313  return usrp_serial_number(d_udh);
314}
315
316// ----------------------------------------------------------------
317
318bool
319usrp_basic::set_adc_offset (int which_adc, int offset)
320{
321  if (which_adc < 0 || which_adc > 3)
322    return false;
323
324  return _write_fpga_reg (FR_ADC_OFFSET_0 + which_adc, offset);
325}
326
327bool
328usrp_basic::set_dac_offset (int which_dac, int offset, int offset_pin)
329{
330  if (which_dac < 0 || which_dac > 3)
331    return false;
332
333  int which_codec = which_dac >> 1;
334  int tx_a = (which_dac & 0x1) == 0;
335  int lo = ((offset & 0x3) << 6) | (offset_pin & 0x1);
336  int hi = (offset >> 2);
337  bool ok;
338
339  if (tx_a){
340    ok =  _write_9862 (which_codec, REG_TX_A_OFFSET_LO, lo);
341    ok &= _write_9862 (which_codec, REG_TX_A_OFFSET_HI, hi);
342  }
343  else {
344    ok =  _write_9862 (which_codec, REG_TX_B_OFFSET_LO, lo);
345    ok &= _write_9862 (which_codec, REG_TX_B_OFFSET_HI, hi);
346  }
347  return ok;
348}
349
350bool
351usrp_basic::set_adc_buffer_bypass (int which_adc, bool bypass)
352{
353  if (which_adc < 0 || which_adc > 3)
354    return false;
355
356  int codec = which_adc >> 1;
357  int reg = (which_adc & 1) == 0 ? REG_RX_A : REG_RX_B;
358
359  unsigned char cur_rx;
360  unsigned char cur_pwr_dn;
361
362  // If the input buffer is bypassed, we need to power it down too.
363
364  bool ok = _read_9862 (codec, reg, &cur_rx);
365  ok &= _read_9862 (codec, REG_RX_PWR_DN, &cur_pwr_dn);
366  if (!ok)
367    return false;
368
369  if (bypass){
370    cur_rx |= RX_X_BYPASS_INPUT_BUFFER;
371    cur_pwr_dn |= ((which_adc & 1) == 0) ? RX_PWR_DN_BUF_A : RX_PWR_DN_BUF_B;
372  }
373  else {
374    cur_rx &= ~RX_X_BYPASS_INPUT_BUFFER;
375    cur_pwr_dn &= ~(((which_adc & 1) == 0) ? RX_PWR_DN_BUF_A : RX_PWR_DN_BUF_B);
376  }
377
378  ok &= _write_9862 (codec, reg, cur_rx);
379  ok &= _write_9862 (codec, REG_RX_PWR_DN, cur_pwr_dn);
380  return ok;
381}
382
383bool
384usrp_basic::set_dc_offset_cl_enable(int bits, int mask)
385{
386  return _write_fpga_reg(FR_DC_OFFSET_CL_EN,
387                         (d_fpga_shadows[FR_DC_OFFSET_CL_EN] & ~mask) | (bits & mask));
388}
389
390// ----------------------------------------------------------------
391
392bool
393usrp_basic::_write_fpga_reg (int regno, int value)
394{
395  if (d_verbose){
396    fprintf (stdout, "_write_fpga_reg(%3d, 0x%08x)\n", regno, value);
397    fflush (stdout);
398  }
399
400  if (regno >= 0 && regno < MAX_REGS)
401    d_fpga_shadows[regno] = value;
402
403  return usrp_write_fpga_reg (d_udh, regno, value);
404}
405
406bool
407usrp_basic::_write_fpga_reg_masked (int regno, int value, int mask)
408{
409  //Only use this for registers who actually use a mask in the verilog firmware, like FR_RX_MASTER_SLAVE
410  //value is a 16 bits value and mask is a 16 bits mask
411  if (d_verbose){
412    fprintf (stdout, "_write_fpga_reg_masked(%3d, 0x%04x,0x%04x)\n", regno, value, mask);
413    fflush (stdout);
414  }
415
416  if (regno >= 0 && regno < MAX_REGS)
417    d_fpga_shadows[regno] = value;
418
419  return usrp_write_fpga_reg (d_udh, regno, (value & 0xffff) | ((mask & 0xffff)<<16));
420}
421
422
423bool
424usrp_basic::_read_fpga_reg (int regno, int *value)
425{
426  return usrp_read_fpga_reg (d_udh, regno, value);
427}
428
429int
430usrp_basic::_read_fpga_reg (int regno)
431{
432  int value;
433  if (!_read_fpga_reg (regno, &value))
434    return READ_FAILED;
435  return value;
436}
437
438bool
439usrp_basic::_write_9862 (int which_codec, int regno, unsigned char value)
440{
441  if (0 && d_verbose){
442    // FIXME really want to enable logging in usrp_prims:usrp_9862_write
443    fprintf(stdout, "_write_9862(codec = %d, regno = %2d, val = 0x%02x)\n", which_codec, regno, value);
444    fflush(stdout);
445  }
446
447  return usrp_9862_write (d_udh, which_codec, regno, value);
448}
449
450
451bool
452usrp_basic::_read_9862 (int which_codec, int regno, unsigned char *value) const
453{
454  return usrp_9862_read (d_udh, which_codec, regno, value);
455}
456
457int
458usrp_basic::_read_9862 (int which_codec, int regno) const
459{
460  unsigned char value;
461  if (!_read_9862 (which_codec, regno, &value))
462    return READ_FAILED;
463  return value;
464}
465
466bool
467usrp_basic::_write_spi (int optional_header, int enables, int format, std::string buf)
468{
469  return usrp_spi_write (d_udh, optional_header, enables, format,
470                         buf.data(), buf.size());
471}
472
473std::string
474usrp_basic::_read_spi (int optional_header, int enables, int format, int len)
475{
476  if (len <= 0)
477    return "";
478 
479  char buf[len];
480
481  if (!usrp_spi_read (d_udh, optional_header, enables, format, buf, len))
482    return "";
483
484  return std::string (buf, len);
485}
486
487
488bool
489usrp_basic::_set_led (int which_led, bool on)
490{
491  return usrp_set_led (d_udh, which_led, on);
492}
493
494bool
495usrp_basic::write_atr_tx_delay(int value)
496{
497  return _write_fpga_reg(FR_ATR_TX_DELAY, value);
498}
499
500bool
501usrp_basic::write_atr_rx_delay(int value)
502{
503  return _write_fpga_reg(FR_ATR_RX_DELAY, value);
504}
505
506/*
507 * ----------------------------------------------------------------
508 * Routines to access and control daughterboard specific i/o
509 * ----------------------------------------------------------------
510 */
511static int
512slot_id_to_oe_reg (int slot_id)
513{
514  static int reg[4]  = { FR_OE_0, FR_OE_1, FR_OE_2, FR_OE_3 };
515  assert (0 <= slot_id && slot_id < 4);
516  return reg[slot_id];
517}
518
519static int
520slot_id_to_io_reg (int slot_id)
521{
522  static int reg[4]  = { FR_IO_0, FR_IO_1, FR_IO_2, FR_IO_3 };
523  assert (0 <= slot_id && slot_id < 4);
524  return reg[slot_id];
525}
526
527static int
528slot_id_to_refclk_reg(int slot_id)
529{
530  static int reg[4]  = { FR_TX_A_REFCLK, FR_RX_A_REFCLK, FR_TX_B_REFCLK, FR_RX_B_REFCLK };
531  assert (0 <= slot_id && slot_id < 4);
532  return reg[slot_id];
533}
534
535static int
536slot_id_to_atr_mask_reg(int slot_id)
537{
538  static int reg[4]  = { FR_ATR_MASK_0, FR_ATR_MASK_1, FR_ATR_MASK_2, FR_ATR_MASK_3 };
539  assert (0 <= slot_id && slot_id < 4);
540  return reg[slot_id];
541}
542
543static int
544slot_id_to_atr_txval_reg(int slot_id)
545{
546  static int reg[4]  = { FR_ATR_TXVAL_0, FR_ATR_TXVAL_1, FR_ATR_TXVAL_2, FR_ATR_TXVAL_3 };
547  assert (0 <= slot_id && slot_id < 4);
548  return reg[slot_id];
549}
550
551static int
552slot_id_to_atr_rxval_reg(int slot_id)
553{
554  static int reg[4]  = { FR_ATR_RXVAL_0, FR_ATR_RXVAL_1, FR_ATR_RXVAL_2, FR_ATR_RXVAL_3 };
555  assert (0 <= slot_id && slot_id < 4);
556  return reg[slot_id];
557}
558
559static int
560to_slot(txrx_t txrx, int which_side)
561{
562  // TX_A = 0
563  // RX_A = 1
564  // TX_B = 2
565  // RX_B = 3
566  return ((which_side & 0x1) << 1) | ((txrx & 0x1) == C_RX);
567}
568
569bool
570usrp_basic::common_set_pga(txrx_t txrx, int which_amp, double gain)
571{
572  if (which_amp < 0 || which_amp > 3)
573    return false;
574
575  gain = std::min(common_pga_max(txrx),
576                  std::max(common_pga_min(txrx), gain));
577
578  int codec = which_amp >> 1;   
579  int int_gain = (int) rint((gain - common_pga_min(txrx)) / common_pga_db_per_step(txrx));
580
581  if (txrx == C_TX){            // 0 and 1 are same, as are 2 and 3
582    return _write_9862(codec, REG_TX_PGA, int_gain);
583  }
584  else {
585    int reg = (which_amp & 1) == 0 ? REG_RX_A : REG_RX_B;
586
587    // read current value to get input buffer bypass flag.
588    unsigned char cur_rx;
589    if (!_read_9862(codec, reg, &cur_rx))
590      return false;
591
592    cur_rx = (cur_rx & RX_X_BYPASS_INPUT_BUFFER) | (int_gain & 0x7f);
593    return _write_9862(codec, reg, cur_rx);
594  }
595}
596
597double
598usrp_basic::common_pga(txrx_t txrx, int which_amp) const
599{
600  if (which_amp < 0 || which_amp > 3)
601    return READ_FAILED;
602
603  if (txrx == C_TX){
604    int codec = which_amp >> 1;
605    unsigned char v;
606    bool ok = _read_9862 (codec, REG_TX_PGA, &v);
607    if (!ok)
608      return READ_FAILED;
609
610    return (pga_db_per_step() * v) + pga_min();
611  }
612  else {
613    int codec = which_amp >> 1;
614    int reg = (which_amp & 1) == 0 ? REG_RX_A : REG_RX_B;
615    unsigned char v;
616    bool ok = _read_9862 (codec, reg, &v);
617    if (!ok)
618      return READ_FAILED;
619
620    return (pga_db_per_step() * (v & 0x1f)) + pga_min();
621  }
622}
623
624double
625usrp_basic::common_pga_min(txrx_t txrx) const
626{
627  if (txrx == C_TX)
628    return -20.0;
629  else
630    return   0.0;
631}
632
633double
634usrp_basic::common_pga_max(txrx_t txrx) const
635{
636  if (txrx == C_TX)
637    return   0.0;
638  else
639    return  20.0;
640}
641
642double
643usrp_basic::common_pga_db_per_step(txrx_t txrx) const
644{
645  if (txrx == C_TX)
646    return  20.0 / 255;
647  else
648    return  20.0 / 20;
649}
650
651bool
652usrp_basic::_common_write_oe(txrx_t txrx, int which_side, int value, int mask)
653{
654  if (! (0 <= which_side && which_side <= 1))
655    return false;
656
657  return _write_fpga_reg(slot_id_to_oe_reg(to_slot(txrx, which_side)),
658                         (mask << 16) | (value & 0xffff));
659}
660
661bool
662usrp_basic::common_write_io(txrx_t txrx, int which_side, int value, int mask)
663{
664  if (! (0 <= which_side && which_side <= 1))
665    return false;
666
667  return _write_fpga_reg(slot_id_to_io_reg(to_slot(txrx, which_side)),
668                         (mask << 16) | (value & 0xffff));
669}
670
671bool
672usrp_basic::common_read_io(txrx_t txrx, int which_side, int *value)
673{
674  if (! (0 <= which_side && which_side <= 1))
675    return false;
676
677  int t;
678  int reg = which_side + 1;     // FIXME, *very* magic number (fix in serial_io.v)
679  bool ok = _read_fpga_reg(reg, &t);
680  if (!ok)
681    return false;
682
683  if (txrx == C_TX){
684    *value = t & 0xffff;                // FIXME, more magic
685    return true;
686  }
687  else {
688    *value = (t >> 16) & 0xffff;        // FIXME, more magic
689    return true;
690  }
691}
692
693int
694usrp_basic::common_read_io(txrx_t txrx, int which_side)
695{
696  int   value;
697  if (!common_read_io(txrx, which_side, &value))
698    return READ_FAILED;
699  return value;
700}
701
702bool
703usrp_basic::common_write_refclk(txrx_t txrx, int which_side, int value)
704{
705  if (! (0 <= which_side && which_side <= 1))
706    return false;
707
708  return _write_fpga_reg(slot_id_to_refclk_reg(to_slot(txrx, which_side)),
709                         value);
710}
711
712bool
713usrp_basic::common_write_atr_mask(txrx_t txrx, int which_side, int value)
714{
715  if (! (0 <= which_side && which_side <= 1))
716    return false;
717
718  return _write_fpga_reg(slot_id_to_atr_mask_reg(to_slot(txrx, which_side)),
719                         value);
720}
721
722bool
723usrp_basic::common_write_atr_txval(txrx_t txrx, int which_side, int value)
724{
725  if (! (0 <= which_side && which_side <= 1))
726    return false;
727
728  return _write_fpga_reg(slot_id_to_atr_txval_reg(to_slot(txrx, which_side)),
729                         value);
730}
731
732bool
733usrp_basic::common_write_atr_rxval(txrx_t txrx, int which_side, int value)
734{
735  if (! (0 <= which_side && which_side <= 1))
736    return false;
737
738  return _write_fpga_reg(slot_id_to_atr_rxval_reg(to_slot(txrx, which_side)),
739                         value);
740}
741
742bool
743usrp_basic::common_write_aux_dac(txrx_t txrx, int which_side, int which_dac, int value)
744{
745  return _write_aux_dac(to_slot(txrx, which_side), which_dac, value);
746}
747
748bool
749usrp_basic::common_read_aux_adc(txrx_t txrx, int which_side, int which_adc, int *value)
750{
751  return _read_aux_adc(to_slot(txrx, which_side), which_adc, value);
752}
753
754int
755usrp_basic::common_read_aux_adc(txrx_t txrx, int which_side, int which_adc)
756{
757  return _read_aux_adc(to_slot(txrx, which_side), which_adc);
758}
759
760
761////////////////////////////////////////////////////////////////
762//
763//                         usrp_basic_rx
764//
765////////////////////////////////////////////////////////////////
766
767static unsigned char rx_init_regs[] = {
768  REG_RX_PWR_DN,        0,
769  REG_RX_A,             0,      // minimum gain = 0x00 (max gain = 0x14)
770  REG_RX_B,             0,      // minimum gain = 0x00 (max gain = 0x14)
771  REG_RX_MISC,          (RX_MISC_HS_DUTY_CYCLE | RX_MISC_CLK_DUTY),
772  REG_RX_IF,            (RX_IF_USE_CLKOUT1
773                         | RX_IF_2S_COMP),
774  REG_RX_DIGITAL,       (RX_DIGITAL_2_CHAN)
775};
776
777
778usrp_basic_rx::usrp_basic_rx (int which_board, int fusb_block_size, int fusb_nblocks,
779                              const std::string fpga_filename,
780                              const std::string firmware_filename
781                              )
782  : usrp_basic (which_board, open_rx_interface, fpga_filename, firmware_filename),
783    d_devhandle (0), d_ephandle (0),
784    d_bytes_seen (0), d_first_read (true),
785    d_rx_enable (false)
786{
787  // initialize rx specific registers
788
789  if (!usrp_9862_write_many_all (d_udh, rx_init_regs, sizeof (rx_init_regs))){
790    fprintf (stderr, "usrp_basic_rx: failed to init AD9862 RX regs\n");
791    throw std::runtime_error ("usrp_basic_rx/init_9862");
792  }
793
794  if (0){
795    // FIXME power down 2nd codec rx path
796    usrp_9862_write (d_udh, 1, REG_RX_PWR_DN, 0x1);     // power down everything
797  }
798
799  // Reset the rx path and leave it disabled.
800  set_rx_enable (false);
801  usrp_set_fpga_rx_reset (d_udh, true);
802  usrp_set_fpga_rx_reset (d_udh, false);
803
804  set_fpga_rx_sample_rate_divisor (2);  // usually correct
805
806  set_dc_offset_cl_enable(0xf, 0xf);    // enable DC offset removal control loops
807
808  probe_rx_slots (false);
809
810  //d_db[0] = instantiate_dbs(d_dbid[0], this, 0);
811  //d_db[1] = instantiate_dbs(d_dbid[1], this, 1);
812
813  // check fusb buffering parameters
814
815  if (fusb_block_size < 0 || fusb_block_size > FUSB_BLOCK_SIZE)
816    throw std::out_of_range ("usrp_basic_rx: invalid fusb_block_size");
817
818  if (fusb_nblocks < 0)
819    throw std::out_of_range ("usrp_basic_rx: invalid fusb_nblocks");
820 
821  if (fusb_block_size == 0)
822    fusb_block_size = fusb_sysconfig::default_block_size();
823
824  if (fusb_nblocks == 0)
825    fusb_nblocks = std::max (1, FUSB_BUFFER_SIZE / fusb_block_size);
826
827  d_devhandle = fusb_sysconfig::make_devhandle (d_udh, d_ctx);
828  d_ephandle = d_devhandle->make_ephandle (USRP_RX_ENDPOINT, true,
829                                           fusb_block_size, fusb_nblocks);
830
831  write_atr_mask(0, 0);         // zero Rx A Auto Transmit/Receive regs
832  write_atr_txval(0, 0);
833  write_atr_rxval(0, 0);
834  write_atr_mask(1, 0);         // zero Rx B Auto Transmit/Receive regs
835  write_atr_txval(1, 0);
836  write_atr_rxval(1, 0);
837}
838
839static unsigned char rx_fini_regs[] = {
840  REG_RX_PWR_DN,        0x1                             // power down everything
841};
842
843usrp_basic_rx::~usrp_basic_rx ()
844{
845  if (!set_rx_enable (false)){
846    fprintf (stderr, "usrp_basic_rx: set_fpga_rx_enable failed\n");
847  }
848
849  d_ephandle->stop ();
850  delete d_ephandle;
851  delete d_devhandle;
852
853  if (!usrp_9862_write_many_all (d_udh, rx_fini_regs, sizeof (rx_fini_regs))){
854    fprintf (stderr, "usrp_basic_rx: failed to fini AD9862 RX regs\n");
855  }
856
857  shutdown_daughterboards();
858}
859
860
861bool
862usrp_basic_rx::start ()
863{
864  if (!usrp_basic::start ())    // invoke parent's method
865    return false;
866
867  // fire off reads before asserting rx_enable
868
869  if (!d_ephandle->start ()){
870    fprintf (stderr, "usrp_basic_rx: failed to start end point streaming");
871    return false;
872  }
873
874  if (!set_rx_enable (true)){
875    fprintf (stderr, "usrp_basic_rx: set_rx_enable failed\n");
876    return false;
877  }
878 
879  return true;
880}
881
882bool
883usrp_basic_rx::stop ()
884{
885  bool ok = usrp_basic::stop();
886
887  if (!set_rx_enable(false)){
888    fprintf (stderr, "usrp_basic_rx: set_rx_enable(false) failed\n");
889    ok = false;
890  }
891
892  if (!d_ephandle->stop()){
893    fprintf (stderr, "usrp_basic_rx: failed to stop end point streaming");
894    ok = false;
895  }
896
897  return ok;
898}
899
900usrp_basic_rx *
901usrp_basic_rx::make (int which_board, int fusb_block_size, int fusb_nblocks,
902                     const std::string fpga_filename,
903                     const std::string firmware_filename)
904{
905  usrp_basic_rx *u = 0;
906 
907  try {
908    u = new usrp_basic_rx (which_board, fusb_block_size, fusb_nblocks,
909                           fpga_filename, firmware_filename);
910    return u;
911  }
912  catch (...){
913    delete u;
914    return 0;
915  }
916
917  return u;
918}
919
920bool
921usrp_basic_rx::set_fpga_rx_sample_rate_divisor (unsigned int div)
922{
923  return _write_fpga_reg (FR_RX_SAMPLE_RATE_DIV, div - 1);
924}
925
926
927/*
928 * \brief read data from the D/A's via the FPGA.
929 * \p len must be a multiple of 512 bytes.
930 *
931 * \returns the number of bytes read, or -1 on error.
932 *
933 * If overrun is non-NULL it will be set true iff an RX overrun is detected.
934 */
935int
936usrp_basic_rx::read (void *buf, int len, bool *overrun)
937{
938  int   r;
939 
940  if (overrun)
941    *overrun = false;
942 
943  if (len < 0 || (len % 512) != 0){
944    fprintf (stderr, "usrp_basic_rx::read: invalid length = %d\n", len);
945    return -1;
946  }
947
948  r = d_ephandle->read (buf, len);
949  if (r > 0)
950    d_bytes_seen += r;
951
952  /*
953   * In many cases, the FPGA reports an rx overrun right after we
954   * enable the Rx path.  If this is our first read, check for the
955   * overrun to clear the condition, then ignore the result.
956   */
957  if (0 && d_first_read){       // FIXME
958    d_first_read = false;
959    bool bogus_overrun;
960    usrp_check_rx_overrun (d_udh, &bogus_overrun);
961  }
962
963  if (overrun != 0 && d_bytes_seen >= d_bytes_per_poll){
964    d_bytes_seen = 0;
965    if (!usrp_check_rx_overrun (d_udh, overrun)){
966      fprintf (stderr, "usrp_basic_rx: usrp_check_rx_overrun failed\n");
967    }
968  }
969   
970  return r;
971}
972
973bool
974usrp_basic_rx::set_rx_enable (bool on)
975{
976  d_rx_enable = on;
977  return usrp_set_fpga_rx_enable (d_udh, on);
978}
979
980// conditional disable, return prev state
981bool
982usrp_basic_rx::disable_rx ()
983{
984  bool enabled = rx_enable ();
985  if (enabled)
986    set_rx_enable (false);
987  return enabled;
988}
989
990// conditional set
991void
992usrp_basic_rx::restore_rx (bool on)
993{
994  if (on != rx_enable ())
995    set_rx_enable (on);
996}
997
998void
999usrp_basic_rx::probe_rx_slots (bool verbose)
1000{
1001  struct usrp_dboard_eeprom     eeprom;
1002  static int slot_id_map[2] = { SLOT_RX_A, SLOT_RX_B };
1003  static const char *slot_name[2] = { "RX d'board A", "RX d'board B" };
1004
1005  for (int i = 0; i < 2; i++){
1006    int slot_id = slot_id_map [i];
1007    const char *msg = 0;
1008    usrp_dbeeprom_status_t s = usrp_read_dboard_eeprom (d_udh, slot_id, &eeprom);
1009
1010    switch (s){
1011    case UDBE_OK:
1012      d_dbid[i] = eeprom.id;
1013      msg = usrp_dbid_to_string (eeprom.id).c_str ();
1014      set_adc_offset (2*i+0, eeprom.offset[0]);
1015      set_adc_offset (2*i+1, eeprom.offset[1]);
1016      _write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | eeprom.oe);
1017      _write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000);
1018      break;
1019     
1020    case UDBE_NO_EEPROM:
1021      d_dbid[i] = -1;
1022      msg = "<none>";
1023      _write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | 0x0000);
1024      _write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000);
1025      break;
1026     
1027    case UDBE_INVALID_EEPROM:
1028      d_dbid[i] = -2;
1029      msg = "Invalid EEPROM contents";
1030      _write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | 0x0000);
1031      _write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000);
1032      break;
1033     
1034    case UDBE_BAD_SLOT:
1035    default:
1036      assert (0);
1037    }
1038
1039    if (verbose){
1040      fflush (stdout);
1041      fprintf (stderr, "%s: %s\n", slot_name[i], msg);
1042    }
1043  }
1044}
1045
1046bool
1047usrp_basic_rx::set_pga (int which_amp, double gain)
1048{
1049  return common_set_pga(C_RX, which_amp, gain);
1050}
1051
1052double
1053usrp_basic_rx::pga(int which_amp) const
1054{
1055  return common_pga(C_RX, which_amp);
1056}
1057
1058double
1059usrp_basic_rx::pga_min() const
1060{
1061  return common_pga_min(C_RX);
1062}
1063
1064double
1065usrp_basic_rx::pga_max() const
1066{
1067  return common_pga_max(C_RX);
1068}
1069
1070double
1071usrp_basic_rx::pga_db_per_step() const
1072{
1073  return common_pga_db_per_step(C_RX);
1074}
1075
1076bool
1077usrp_basic_rx::_write_oe (int which_side, int value, int mask)
1078{
1079  return _common_write_oe(C_RX, which_side, value, mask);
1080}
1081
1082bool
1083usrp_basic_rx::write_io (int which_side, int value, int mask)
1084{
1085  return common_write_io(C_RX, which_side, value, mask);
1086}
1087
1088bool
1089usrp_basic_rx::read_io (int which_side, int *value)
1090{
1091  return common_read_io(C_RX, which_side, value);
1092}
1093
1094int
1095usrp_basic_rx::read_io (int which_side)
1096{
1097  return common_read_io(C_RX, which_side);
1098}
1099
1100bool
1101usrp_basic_rx::write_refclk(int which_side, int value)
1102{
1103  return common_write_refclk(C_RX, which_side, value);
1104}
1105
1106bool
1107usrp_basic_rx::write_atr_mask(int which_side, int value)
1108{
1109  return common_write_atr_mask(C_RX, which_side, value);
1110}
1111
1112bool
1113usrp_basic_rx::write_atr_txval(int which_side, int value)
1114{
1115  return common_write_atr_txval(C_RX, which_side, value);
1116}
1117
1118bool
1119usrp_basic_rx::write_atr_rxval(int which_side, int value)
1120{
1121  return common_write_atr_rxval(C_RX, which_side, value);
1122}
1123
1124bool
1125usrp_basic_rx::write_aux_dac (int which_side, int which_dac, int value)
1126{
1127  return common_write_aux_dac(C_RX, which_side, which_dac, value);
1128}
1129
1130bool
1131usrp_basic_rx::read_aux_adc (int which_side, int which_adc, int *value)
1132{
1133  return common_read_aux_adc(C_RX, which_side, which_adc, value);
1134}
1135
1136int
1137usrp_basic_rx::read_aux_adc (int which_side, int which_adc)
1138{
1139  return common_read_aux_adc(C_RX, which_side, which_adc);
1140}
1141
1142int
1143usrp_basic_rx::block_size () const { return d_ephandle->block_size(); }
1144
1145////////////////////////////////////////////////////////////////
1146//
1147//                         usrp_basic_tx
1148//
1149////////////////////////////////////////////////////////////////
1150
1151
1152//
1153// DAC input rate 64 MHz interleaved for a total input rate of 128 MHz
1154// DAC input is latched on rising edge of CLKOUT2
1155// NCO is disabled
1156// interpolate 2x
1157// coarse modulator disabled
1158//
1159
1160static unsigned char tx_init_regs[] = {
1161  REG_TX_PWR_DN,        0,
1162  REG_TX_A_OFFSET_LO,   0,
1163  REG_TX_A_OFFSET_HI,   0,
1164  REG_TX_B_OFFSET_LO,   0,
1165  REG_TX_B_OFFSET_HI,   0,
1166  REG_TX_A_GAIN,        (TX_X_GAIN_COARSE_FULL | 0),
1167  REG_TX_B_GAIN,        (TX_X_GAIN_COARSE_FULL | 0),
1168  REG_TX_PGA,           0xff,                   // maximum gain (0 dB)
1169  REG_TX_MISC,          0,
1170  REG_TX_IF,            (TX_IF_USE_CLKOUT1
1171                         | TX_IF_I_FIRST
1172                         | TX_IF_INV_TX_SYNC
1173                         | TX_IF_2S_COMP
1174                         | TX_IF_INTERLEAVED),
1175  REG_TX_DIGITAL,       (TX_DIGITAL_2_DATA_PATHS
1176                         | TX_DIGITAL_INTERPOLATE_4X),
1177  REG_TX_MODULATOR,     (TX_MODULATOR_DISABLE_NCO
1178                         | TX_MODULATOR_COARSE_MODULATION_NONE),
1179  REG_TX_NCO_FTW_7_0,   0,
1180  REG_TX_NCO_FTW_15_8,  0,
1181  REG_TX_NCO_FTW_23_16, 0
1182};
1183
1184usrp_basic_tx::usrp_basic_tx (int which_board, int fusb_block_size, int fusb_nblocks,
1185                              const std::string fpga_filename,
1186                              const std::string firmware_filename)
1187  : usrp_basic (which_board, open_tx_interface, fpga_filename, firmware_filename),
1188    d_devhandle (0), d_ephandle (0),
1189    d_bytes_seen (0), d_first_write (true),
1190    d_tx_enable (false)
1191{
1192  if (!usrp_9862_write_many_all (d_udh, tx_init_regs, sizeof (tx_init_regs))){
1193    fprintf (stderr, "usrp_basic_tx: failed to init AD9862 TX regs\n");
1194    throw std::runtime_error ("usrp_basic_tx/init_9862");
1195  }
1196
1197  if (0){
1198    // FIXME power down 2nd codec tx path
1199    usrp_9862_write (d_udh, 1, REG_TX_PWR_DN,
1200                     (TX_PWR_DN_TX_DIGITAL
1201                      | TX_PWR_DN_TX_ANALOG_BOTH));
1202  }
1203
1204  // Reset the tx path and leave it disabled.
1205  set_tx_enable (false);
1206  usrp_set_fpga_tx_reset (d_udh, true);
1207  usrp_set_fpga_tx_reset (d_udh, false);
1208
1209  set_fpga_tx_sample_rate_divisor (4);  // we're using interp x4
1210
1211  probe_tx_slots (false);
1212
1213  //d_db[0] = instantiate_dbs(d_dbid[0], this, 0);
1214  //d_db[1] = instantiate_dbs(d_dbid[1], this, 1);
1215
1216  // check fusb buffering parameters
1217
1218  if (fusb_block_size < 0 || fusb_block_size > FUSB_BLOCK_SIZE)
1219    throw std::out_of_range ("usrp_basic_rx: invalid fusb_block_size");
1220
1221  if (fusb_nblocks < 0)
1222    throw std::out_of_range ("usrp_basic_rx: invalid fusb_nblocks");
1223 
1224  if (fusb_block_size == 0)
1225    fusb_block_size = FUSB_BLOCK_SIZE;
1226
1227  if (fusb_nblocks == 0)
1228    fusb_nblocks = std::max (1, FUSB_BUFFER_SIZE / fusb_block_size);
1229
1230  d_devhandle = fusb_sysconfig::make_devhandle (d_udh, d_ctx);
1231  d_ephandle = d_devhandle->make_ephandle (USRP_TX_ENDPOINT, false,
1232                                           fusb_block_size, fusb_nblocks);
1233
1234  write_atr_mask(0, 0);         // zero Tx A Auto Transmit/Receive regs
1235  write_atr_txval(0, 0);
1236  write_atr_rxval(0, 0);
1237  write_atr_mask(1, 0);         // zero Tx B Auto Transmit/Receive regs
1238  write_atr_txval(1, 0);
1239  write_atr_rxval(1, 0);
1240}
1241
1242
1243static unsigned char tx_fini_regs[] = {
1244  REG_TX_PWR_DN,        (TX_PWR_DN_TX_DIGITAL
1245                         | TX_PWR_DN_TX_ANALOG_BOTH),
1246  REG_TX_MODULATOR,     (TX_MODULATOR_DISABLE_NCO
1247                         | TX_MODULATOR_COARSE_MODULATION_NONE)
1248};
1249
1250usrp_basic_tx::~usrp_basic_tx ()
1251{
1252  d_ephandle->stop ();
1253  delete d_ephandle;
1254  delete d_devhandle;
1255
1256  if (!usrp_9862_write_many_all (d_udh, tx_fini_regs, sizeof (tx_fini_regs))){
1257    fprintf (stderr, "usrp_basic_tx: failed to fini AD9862 TX regs\n");
1258  }
1259
1260  shutdown_daughterboards();
1261}
1262
1263bool
1264usrp_basic_tx::start ()
1265{
1266  if (!usrp_basic::start ())
1267    return false;
1268
1269  if (!set_tx_enable (true)){
1270    fprintf (stderr, "usrp_basic_tx: set_tx_enable failed\n");
1271    return false;
1272  }
1273 
1274  if (!d_ephandle->start ()){
1275    fprintf (stderr, "usrp_basic_tx: failed to start end point streaming");
1276    return false;
1277  }
1278
1279  return true;
1280}
1281
1282bool
1283usrp_basic_tx::stop ()
1284{
1285  bool ok = usrp_basic::stop ();
1286
1287  if (!d_ephandle->stop ()){
1288    fprintf (stderr, "usrp_basic_tx: failed to stop end point streaming");
1289    ok = false;
1290  }
1291
1292  if (!set_tx_enable (false)){
1293    fprintf (stderr, "usrp_basic_tx: set_tx_enable(false) failed\n");
1294    ok = false;
1295  }
1296
1297  return ok;
1298}
1299
1300usrp_basic_tx *
1301usrp_basic_tx::make (int which_board, int fusb_block_size, int fusb_nblocks,
1302                     const std::string fpga_filename,
1303                     const std::string firmware_filename)
1304{
1305  usrp_basic_tx *u = 0;
1306 
1307  try {
1308    u = new usrp_basic_tx (which_board, fusb_block_size, fusb_nblocks,
1309                           fpga_filename, firmware_filename);
1310    return u;
1311  }
1312  catch (...){
1313    delete u;
1314    return 0;
1315  }
1316
1317  return u;
1318}
1319
1320bool
1321usrp_basic_tx::set_fpga_tx_sample_rate_divisor (unsigned int div)
1322{
1323  return _write_fpga_reg (FR_TX_SAMPLE_RATE_DIV, div - 1);
1324}
1325
1326/*!
1327 * \brief Write data to the A/D's via the FPGA.
1328 *
1329 * \p len must be a multiple of 512 bytes.
1330 * \returns number of bytes written or -1 on error.
1331 *
1332 * if \p underrun is non-NULL, it will be set to true iff
1333 * a transmit underrun condition is detected.
1334 */
1335int
1336usrp_basic_tx::write (const void *buf, int len, bool *underrun)
1337{
1338  int   r;
1339 
1340  if (underrun)
1341    *underrun = false;
1342 
1343  if (len < 0 || (len % 512) != 0){
1344    fprintf (stderr, "usrp_basic_tx::write: invalid length = %d\n", len);
1345    return -1;
1346  }
1347
1348  r = d_ephandle->write (buf, len);
1349  if (r > 0)
1350    d_bytes_seen += r;
1351   
1352  /*
1353   * In many cases, the FPGA reports an tx underrun right after we
1354   * enable the Tx path.  If this is our first write, check for the
1355   * underrun to clear the condition, then ignore the result.
1356   */
1357  if (d_first_write && d_bytes_seen >= 4 * FUSB_BLOCK_SIZE){
1358    d_first_write = false;
1359    bool bogus_underrun;
1360    usrp_check_tx_underrun (d_udh, &bogus_underrun);
1361  }
1362
1363  if (underrun != 0 && d_bytes_seen >= d_bytes_per_poll){
1364    d_bytes_seen = 0;
1365    if (!usrp_check_tx_underrun (d_udh, underrun)){
1366      fprintf (stderr, "usrp_basic_tx: usrp_check_tx_underrun failed\n");
1367    }
1368  }
1369
1370  return r;
1371}
1372
1373void
1374usrp_basic_tx::wait_for_completion ()
1375{
1376  d_ephandle->wait_for_completion ();
1377}
1378
1379bool
1380usrp_basic_tx::set_tx_enable (bool on)
1381{
1382  d_tx_enable = on;
1383  // fprintf (stderr, "set_tx_enable %d\n", on);
1384  return usrp_set_fpga_tx_enable (d_udh, on);
1385}
1386
1387// conditional disable, return prev state
1388bool
1389usrp_basic_tx::disable_tx ()
1390{
1391  bool enabled = tx_enable ();
1392  if (enabled)
1393    set_tx_enable (false);
1394  return enabled;
1395}
1396
1397// conditional set
1398void
1399usrp_basic_tx::restore_tx (bool on)
1400{
1401  if (on != tx_enable ())
1402    set_tx_enable (on);
1403}
1404
1405void
1406usrp_basic_tx::probe_tx_slots (bool verbose)
1407{
1408  struct usrp_dboard_eeprom     eeprom;
1409  static int slot_id_map[2] = { SLOT_TX_A, SLOT_TX_B };
1410  static const char *slot_name[2] = { "TX d'board A", "TX d'board B" };
1411
1412  for (int i = 0; i < 2; i++){
1413    int slot_id = slot_id_map [i];
1414    const char *msg = 0;
1415    usrp_dbeeprom_status_t s = usrp_read_dboard_eeprom (d_udh, slot_id, &eeprom);
1416
1417    switch (s){
1418    case UDBE_OK:
1419      d_dbid[i] = eeprom.id;
1420      msg = usrp_dbid_to_string (eeprom.id).c_str ();
1421      // FIXME, figure out interpretation of dc offset for TX d'boards
1422      // offset = (eeprom.offset[1] << 16) | (eeprom.offset[0] & 0xffff);
1423      _write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | eeprom.oe);
1424      _write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000);
1425      break;
1426     
1427    case UDBE_NO_EEPROM:
1428      d_dbid[i] = -1;
1429      msg = "<none>";
1430      _write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | 0x0000);
1431      _write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000);
1432      break;
1433     
1434    case UDBE_INVALID_EEPROM:
1435      d_dbid[i] = -2;
1436      msg = "Invalid EEPROM contents";
1437      _write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | 0x0000);
1438      _write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000);
1439      break;
1440     
1441    case UDBE_BAD_SLOT:
1442    default:
1443      assert (0);
1444    }
1445
1446    if (verbose){
1447      fflush (stdout);
1448      fprintf (stderr, "%s: %s\n", slot_name[i], msg);
1449    }
1450  }
1451}
1452
1453bool
1454usrp_basic_tx::set_pga (int which_amp, double gain)
1455{
1456  return common_set_pga(C_TX, which_amp, gain);
1457}
1458
1459double
1460usrp_basic_tx::pga (int which_amp) const
1461{
1462  return common_pga(C_TX, which_amp);
1463}
1464
1465double
1466usrp_basic_tx::pga_min() const
1467{
1468  return common_pga_min(C_TX);
1469}
1470
1471double
1472usrp_basic_tx::pga_max() const
1473{
1474  return common_pga_max(C_TX);
1475}
1476
1477double
1478usrp_basic_tx::pga_db_per_step() const
1479{
1480  return common_pga_db_per_step(C_TX);
1481}
1482
1483bool
1484usrp_basic_tx::_write_oe (int which_side, int value, int mask)
1485{
1486  return _common_write_oe(C_TX, which_side, value, mask);
1487}
1488
1489bool
1490usrp_basic_tx::write_io (int which_side, int value, int mask)
1491{
1492  return common_write_io(C_TX, which_side, value, mask);
1493}
1494
1495bool
1496usrp_basic_tx::read_io (int which_side, int *value)
1497{
1498  return common_read_io(C_TX, which_side, value);
1499}
1500
1501int
1502usrp_basic_tx::read_io (int which_side)
1503{
1504  return common_read_io(C_TX, which_side);
1505}
1506
1507bool
1508usrp_basic_tx::write_refclk(int which_side, int value)
1509{
1510  return common_write_refclk(C_TX, which_side, value);
1511}
1512
1513bool
1514usrp_basic_tx::write_atr_mask(int which_side, int value)
1515{
1516  return common_write_atr_mask(C_TX, which_side, value);
1517}
1518
1519bool
1520usrp_basic_tx::write_atr_txval(int which_side, int value)
1521{
1522  return common_write_atr_txval(C_TX, which_side, value);
1523}
1524
1525bool
1526usrp_basic_tx::write_atr_rxval(int which_side, int value)
1527{
1528  return common_write_atr_rxval(C_TX, which_side, value);
1529}
1530
1531bool
1532usrp_basic_tx::write_aux_dac (int which_side, int which_dac, int value)
1533{
1534  return common_write_aux_dac(C_TX, which_side, which_dac, value);
1535}
1536
1537bool
1538usrp_basic_tx::read_aux_adc (int which_side, int which_adc, int *value)
1539{
1540  return common_read_aux_adc(C_TX, which_side, which_adc, value);
1541}
1542
1543int
1544usrp_basic_tx::read_aux_adc (int which_side, int which_adc)
1545{
1546  return common_read_aux_adc(C_TX, which_side, which_adc);
1547}
1548
1549int
1550usrp_basic_tx::block_size () const { return d_ephandle->block_size(); }
1551
Note: See TracBrowser for help on using the browser.