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