| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
#ifdef HAVE_CONFIG_H |
|---|
| 24 |
#include "config.h" |
|---|
| 25 |
#endif |
|---|
| 26 |
|
|---|
| 27 |
#include "usrp_basic.h" |
|---|
| 28 |
#include "usrp_prims.h" |
|---|
| 29 |
#include "usrp_interfaces.h" |
|---|
| 30 |
#include "fpga_regs_common.h" |
|---|
| 31 |
#include "fusb.h" |
|---|
| 32 |
#include <usb.h> |
|---|
| 33 |
#include <stdexcept> |
|---|
| 34 |
#include <assert.h> |
|---|
| 35 |
#include <math.h> |
|---|
| 36 |
#include <ad9862.h> |
|---|
| 37 |
#include <string.h> |
|---|
| 38 |
|
|---|
| 39 |
using namespace ad9862; |
|---|
| 40 |
|
|---|
| 41 |
#define NELEM(x) (sizeof (x) / sizeof (x[0])) |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
static const int FUSB_BUFFER_SIZE = fusb_sysconfig::default_buffer_size(); |
|---|
| 47 |
static const int FUSB_BLOCK_SIZE = fusb_sysconfig::max_block_size(); |
|---|
| 48 |
static const int FUSB_NBLOCKS = FUSB_BUFFER_SIZE / FUSB_BLOCK_SIZE; |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
static const double POLLING_INTERVAL = 0.1; |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
static struct usb_dev_handle * |
|---|
| 56 |
open_rx_interface (struct usb_device *dev) |
|---|
| 57 |
{ |
|---|
| 58 |
struct usb_dev_handle *udh = usrp_open_rx_interface (dev); |
|---|
| 59 |
if (udh == 0){ |
|---|
| 60 |
fprintf (stderr, "usrp_basic_rx: can't open rx interface\n"); |
|---|
| 61 |
usb_strerror (); |
|---|
| 62 |
} |
|---|
| 63 |
return udh; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
static struct usb_dev_handle * |
|---|
| 67 |
open_tx_interface (struct usb_device *dev) |
|---|
| 68 |
{ |
|---|
| 69 |
struct usb_dev_handle *udh = usrp_open_tx_interface (dev); |
|---|
| 70 |
if (udh == 0){ |
|---|
| 71 |
fprintf (stderr, "usrp_basic_tx: can't open tx interface\n"); |
|---|
| 72 |
usb_strerror (); |
|---|
| 73 |
} |
|---|
| 74 |
return udh; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
static unsigned char common_regs[] = { |
|---|
| 96 |
REG_GENERAL, 0, |
|---|
| 97 |
REG_DLL, (DLL_DISABLE_INTERNAL_XTAL_OSC |
|---|
| 98 |
| DLL_MULT_2X |
|---|
| 99 |
| DLL_FAST), |
|---|
| 100 |
REG_CLKOUT, CLKOUT2_EQ_DLL_OVER_2, |
|---|
| 101 |
REG_AUX_ADC_CLK, AUX_ADC_CLK_CLK_OVER_4 |
|---|
| 102 |
}; |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
usrp_basic::usrp_basic (int which_board, |
|---|
| 106 |
struct usb_dev_handle * |
|---|
| 107 |
open_interface (struct usb_device *dev), |
|---|
| 108 |
const std::string fpga_filename, |
|---|
| 109 |
const std::string firmware_filename) |
|---|
| 110 |
: d_udh (0), |
|---|
| 111 |
d_usb_data_rate (16000000), |
|---|
| 112 |
d_bytes_per_poll ((int) (POLLING_INTERVAL * d_usb_data_rate)), |
|---|
| 113 |
d_verbose (false) |
|---|
| 114 |
{ |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
memset (d_fpga_shadows, 0, sizeof (d_fpga_shadows)); |
|---|
| 126 |
|
|---|
| 127 |
usrp_one_time_init (); |
|---|
| 128 |
|
|---|
| 129 |
if (!usrp_load_standard_bits (which_board, false, fpga_filename, firmware_filename)) |
|---|
| 130 |
throw std::runtime_error ("usrp_basic/usrp_load_standard_bits"); |
|---|
| 131 |
|
|---|
| 132 |
struct usb_device *dev = usrp_find_device (which_board); |
|---|
| 133 |
if (dev == 0){ |
|---|
| 134 |
fprintf (stderr, "usrp_basic: can't find usrp[%d]\n", which_board); |
|---|
| 135 |
throw std::runtime_error ("usrp_basic/usrp_find_device"); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
if (!(usrp_usrp_p(dev) && usrp_hw_rev(dev) >= 1)){ |
|---|
| 139 |
fprintf (stderr, "usrp_basic: sorry, this code only works with USRP revs >= 1\n"); |
|---|
| 140 |
throw std::runtime_error ("usrp_basic/bad_rev"); |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
if ((d_udh = open_interface (dev)) == 0) |
|---|
| 144 |
throw std::runtime_error ("usrp_basic/open_interface"); |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
if (!usrp_9862_write_many_all (d_udh, common_regs, sizeof (common_regs))){ |
|---|
| 149 |
fprintf (stderr, "usrp_basic: failed to init common AD9862 regs\n"); |
|---|
| 150 |
throw std::runtime_error ("usrp_basic/init_9862"); |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
_write_fpga_reg (FR_MODE, 0); |
|---|
| 154 |
_write_fpga_reg (FR_DEBUG_EN, 0); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
usrp_basic::~usrp_basic () |
|---|
| 158 |
{ |
|---|
| 159 |
if (d_udh) |
|---|
| 160 |
usb_close (d_udh); |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
bool |
|---|
| 164 |
usrp_basic::start () |
|---|
| 165 |
{ |
|---|
| 166 |
return true; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
bool |
|---|
| 170 |
usrp_basic::stop () |
|---|
| 171 |
{ |
|---|
| 172 |
return true; |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
void |
|---|
| 176 |
usrp_basic::set_usb_data_rate (int usb_data_rate) |
|---|
| 177 |
{ |
|---|
| 178 |
d_usb_data_rate = usb_data_rate; |
|---|
| 179 |
d_bytes_per_poll = (int) (usb_data_rate * POLLING_INTERVAL); |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
bool |
|---|
| 183 |
usrp_basic::write_aux_dac (int slot, int which_dac, int value) |
|---|
| 184 |
{ |
|---|
| 185 |
return usrp_write_aux_dac (d_udh, slot, which_dac, value); |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
bool |
|---|
| 189 |
usrp_basic::read_aux_adc (int slot, int which_adc, int *value) |
|---|
| 190 |
{ |
|---|
| 191 |
return usrp_read_aux_adc (d_udh, slot, which_adc, value); |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
int |
|---|
| 195 |
usrp_basic::read_aux_adc (int slot, int which_adc) |
|---|
| 196 |
{ |
|---|
| 197 |
int value; |
|---|
| 198 |
if (!read_aux_adc (slot, which_adc, &value)) |
|---|
| 199 |
return READ_FAILED; |
|---|
| 200 |
|
|---|
| 201 |
return value; |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
bool |
|---|
| 205 |
usrp_basic::write_eeprom (int i2c_addr, int eeprom_offset, const std::string buf) |
|---|
| 206 |
{ |
|---|
| 207 |
return usrp_eeprom_write (d_udh, i2c_addr, eeprom_offset, buf.data (), buf.size ()); |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
std::string |
|---|
| 211 |
usrp_basic::read_eeprom (int i2c_addr, int eeprom_offset, int len) |
|---|
| 212 |
{ |
|---|
| 213 |
if (len <= 0) |
|---|
| 214 |
return ""; |
|---|
| 215 |
|
|---|
| 216 |
char buf[len]; |
|---|
| 217 |
|
|---|
| 218 |
if (!usrp_eeprom_read (d_udh, i2c_addr, eeprom_offset, buf, len)) |
|---|
| 219 |
return ""; |
|---|
| 220 |
|
|---|
| 221 |
return std::string (buf, len); |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
bool |
|---|
| 225 |
usrp_basic::write_i2c (int i2c_addr, const std::string buf) |
|---|
| 226 |
{ |
|---|
| 227 |
return usrp_i2c_write (d_udh, i2c_addr, buf.data (), buf.size ()); |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
std::string |
|---|
| 231 |
usrp_basic::read_i2c (int i2c_addr, int len) |
|---|
| 232 |
{ |
|---|
| 233 |
if (len <= 0) |
|---|
| 234 |
return ""; |
|---|
| 235 |
|
|---|
| 236 |
char buf[len]; |
|---|
| 237 |
|
|---|
| 238 |
if (!usrp_i2c_read (d_udh, i2c_addr, buf, len)) |
|---|
| 239 |
return ""; |
|---|
| 240 |
|
|---|
| 241 |
return std::string (buf, len); |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
std::string |
|---|
| 245 |
usrp_basic::serial_number() |
|---|
| 246 |
{ |
|---|
| 247 |
return usrp_serial_number(d_udh); |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
bool |
|---|
| 253 |
usrp_basic::set_adc_offset (int which, int offset) |
|---|
| 254 |
{ |
|---|
| 255 |
if (which < 0 || which > 3) |
|---|
| 256 |
return false; |
|---|
| 257 |
|
|---|
| 258 |
return _write_fpga_reg (FR_ADC_OFFSET_0 + which, offset); |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
bool |
|---|
| 262 |
usrp_basic::set_dac_offset (int which, int offset, int offset_pin) |
|---|
| 263 |
{ |
|---|
| 264 |
if (which < 0 || which > 3) |
|---|
| 265 |
return false; |
|---|
| 266 |
|
|---|
| 267 |
int which_codec = which >> 1; |
|---|
| 268 |
int tx_a = (which & 0x1) == 0; |
|---|
| 269 |
int lo = ((offset & 0x3) << 6) | (offset_pin & 0x1); |
|---|
| 270 |
int hi = (offset >> 2); |
|---|
| 271 |
bool ok; |
|---|
| 272 |
|
|---|
| 273 |
if (tx_a){ |
|---|
| 274 |
ok = _write_9862 (which_codec, REG_TX_A_OFFSET_LO, lo); |
|---|
| 275 |
ok &= _write_9862 (which_codec, REG_TX_A_OFFSET_HI, hi); |
|---|
| 276 |
} |
|---|
| 277 |
else { |
|---|
| 278 |
ok = _write_9862 (which_codec, REG_TX_B_OFFSET_LO, lo); |
|---|
| 279 |
ok &= _write_9862 (which_codec, REG_TX_B_OFFSET_HI, hi); |
|---|
| 280 |
} |
|---|
| 281 |
return ok; |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|
| 284 |
bool |
|---|
| 285 |
usrp_basic::set_adc_buffer_bypass (int which, bool bypass) |
|---|
| 286 |
{ |
|---|
| 287 |
if (which < 0 || which > 3) |
|---|
| 288 |
return false; |
|---|
| 289 |
|
|---|
| 290 |
int codec = which >> 1; |
|---|
| 291 |
int reg = (which & 1) == 0 ? REG_RX_A : REG_RX_B; |
|---|
| 292 |
|
|---|
| 293 |
unsigned char cur_rx; |
|---|
| 294 |
unsigned char cur_pwr_dn; |
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
bool ok = _read_9862 (codec, reg, &cur_rx); |
|---|
| 299 |
ok &= _read_9862 (codec, REG_RX_PWR_DN, &cur_pwr_dn); |
|---|
| 300 |
if (!ok) |
|---|
| 301 |
return false; |
|---|
| 302 |
|
|---|
| 303 |
if (bypass){ |
|---|
| 304 |
cur_rx |= RX_X_BYPASS_INPUT_BUFFER; |
|---|
| 305 |
cur_pwr_dn |= ((which & 1) == 0) ? RX_PWR_DN_BUF_A : RX_PWR_DN_BUF_B; |
|---|
| 306 |
} |
|---|
| 307 |
else { |
|---|
| 308 |
cur_rx &= ~RX_X_BYPASS_INPUT_BUFFER; |
|---|
| 309 |
cur_pwr_dn &= ~(((which & 1) == 0) ? RX_PWR_DN_BUF_A : RX_PWR_DN_BUF_B); |
|---|
| 310 |
} |
|---|
| 311 |
|
|---|
| 312 |
ok &= _write_9862 (codec, reg, cur_rx); |
|---|
| 313 |
ok &= _write_9862 (codec, REG_RX_PWR_DN, cur_pwr_dn); |
|---|
| 314 |
return ok; |
|---|
| 315 |
} |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
bool |
|---|
| 320 |
usrp_basic::_write_fpga_reg (int regno, int value) |
|---|
| 321 |
{ |
|---|
| 322 |
if (d_verbose){ |
|---|
| 323 |
fprintf (stdout, "_write_fpga_reg(%3d, 0x%08x)\n", regno, value); |
|---|
| 324 |
fflush (stdout); |
|---|
| 325 |
} |
|---|
| 326 |
|
|---|
| 327 |
if (regno >= 0 && regno < MAX_REGS) |
|---|
| 328 |
d_fpga_shadows[regno] = value; |
|---|
| 329 |
|
|---|
| 330 |
return usrp_write_fpga_reg (d_udh, regno, value); |
|---|
| 331 |
} |
|---|
| 332 |
|
|---|
| 333 |
bool |
|---|
| 334 |
usrp_basic::_write_fpga_reg_masked (int regno, int value, int mask) |
|---|
| 335 |
{ |
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
if (d_verbose){ |
|---|
| 339 |
fprintf (stdout, "_write_fpga_reg_masked(%3d, 0x%04x,0x%04x)\n", regno, value, mask); |
|---|
| 340 |
fflush (stdout); |
|---|
| 341 |
} |
|---|
| 342 |
|
|---|
| 343 |
if (regno >= 0 && regno < MAX_REGS) |
|---|
| 344 |
d_fpga_shadows[regno] = value; |
|---|
| 345 |
|
|---|
| 346 |
return usrp_write_fpga_reg (d_udh, regno, (value & 0xffff) | ((mask & 0xffff)<<16)); |
|---|
| 347 |
} |
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
bool |
|---|
| 351 |
usrp_basic::_read_fpga_reg (int regno, int *value) |
|---|
| 352 |
{ |
|---|
| 353 |
return usrp_read_fpga_reg (d_udh, regno, value); |
|---|
| 354 |
} |
|---|
| 355 |
|
|---|
| 356 |
int |
|---|
| 357 |
usrp_basic::_read_fpga_reg (int regno) |
|---|
| 358 |
{ |
|---|
| 359 |
int value; |
|---|
| 360 |
if (!_read_fpga_reg (regno, &value)) |
|---|
| 361 |
return READ_FAILED; |
|---|
| 362 |
return value; |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
bool |
|---|
| 366 |
usrp_basic::_write_9862 (int which_codec, int regno, unsigned char value) |
|---|
| 367 |
{ |
|---|
| 368 |
if (0 && d_verbose){ |
|---|
| 369 |
|
|---|
| 370 |
fprintf(stdout, "_write_9862(codec = %d, regno = %2d, val = 0x%02x)\n", which_codec, regno, value); |
|---|
| 371 |
fflush(stdout); |
|---|
| 372 |
} |
|---|
| 373 |
|
|---|
| 374 |
return usrp_9862_write (d_udh, which_codec, regno, value); |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
bool |
|---|
| 379 |
usrp_basic::_read_9862 (int which_codec, int regno, unsigned char *value) const |
|---|
| 380 |
{ |
|---|
| 381 |
return usrp_9862_read (d_udh, which_codec, regno, value); |
|---|
| 382 |
} |
|---|
| 383 |
|
|---|
| 384 |
int |
|---|
| 385 |
usrp_basic::_read_9862 (int which_codec, int regno) const |
|---|
| 386 |
{ |
|---|
| 387 |
unsigned char value; |
|---|
| 388 |
if (!_read_9862 (which_codec, regno, &value)) |
|---|
| 389 |
return READ_FAILED; |
|---|
| 390 |
return value; |
|---|
| 391 |
} |
|---|
| 392 |
|
|---|
| 393 |
bool |
|---|
| 394 |
usrp_basic::_write_spi (int optional_header, int enables, int format, std::string buf) |
|---|
| 395 |
{ |
|---|
| 396 |
return usrp_spi_write (d_udh, optional_header, enables, format, |
|---|
| 397 |
buf.data(), buf.size()); |
|---|
| 398 |
} |
|---|
| 399 |
|
|---|
| 400 |
std::string |
|---|
| 401 |
usrp_basic::_read_spi (int optional_header, int enables, int format, int len) |
|---|
| 402 |
{ |
|---|
| 403 |
if (len <= 0) |
|---|
| 404 |
return ""; |
|---|
| 405 |
|
|---|
| 406 |
char buf[len]; |
|---|
| 407 |
|
|---|
| 408 |
if (!usrp_spi_read (d_udh, optional_header, enables, format, buf, len)) |
|---|
| 409 |
return ""; |
|---|
| 410 |
|
|---|
| 411 |
return std::string (buf, len); |
|---|
| 412 |
} |
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
bool |
|---|
| 416 |
usrp_basic::_set_led (int which, bool on) |
|---|
| 417 |
{ |
|---|
| 418 |
return usrp_set_led (d_udh, which, on); |
|---|
| 419 |
} |
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
static unsigned char rx_init_regs[] = { |
|---|
| 428 |
REG_RX_PWR_DN, 0, |
|---|
| 429 |
REG_RX_A, 0, |
|---|
| 430 |
REG_RX_B, 0, |
|---|
| 431 |
REG_RX_MISC, (RX_MISC_HS_DUTY_CYCLE | RX_MISC_CLK_DUTY), |
|---|
| 432 |
REG_RX_IF, (RX_IF_USE_CLKOUT1 |
|---|
| 433 |
| RX_IF_2S_COMP), |
|---|
| 434 |
REG_RX_DIGITAL, (RX_DIGITAL_2_CHAN) |
|---|
| 435 |
}; |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
usrp_basic_rx::usrp_basic_rx (int which_board, int fusb_block_size, int fusb_nblocks, |
|---|
| 439 |
const std::string fpga_filename, |
|---|
| 440 |
const std::string firmware_filename |
|---|
| 441 |
) |
|---|
| 442 |
: usrp_basic (which_board, open_rx_interface, fpga_filename, firmware_filename), |
|---|
| 443 |
d_devhandle (0), d_ephandle (0), |
|---|
| 444 |
d_bytes_seen (0), d_first_read (true), |
|---|
| 445 |
d_rx_enable (false) |
|---|
| 446 |
{ |
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
if (!usrp_9862_write_many_all (d_udh, rx_init_regs, sizeof (rx_init_regs))){ |
|---|
| 450 |
fprintf (stderr, "usrp_basic_rx: failed to init AD9862 RX regs\n"); |
|---|
| 451 |
throw std::runtime_error ("usrp_basic_rx/init_9862"); |
|---|
| 452 |
} |
|---|
| 453 |
|
|---|
| 454 |
if (0){ |
|---|
| 455 |
|
|---|
| 456 |
usrp_9862_write (d_udh, 1, REG_RX_PWR_DN, 0x1); |
|---|
| 457 |
} |
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
set_rx_enable (false); |
|---|
| 461 |
usrp_set_fpga_rx_reset (d_udh, true); |
|---|
| 462 |
usrp_set_fpga_rx_reset (d_udh, false); |
|---|
| 463 |
|
|---|
| 464 |
set_fpga_rx_sample_rate_divisor (2); |
|---|
| 465 |
|
|---|
| 466 |
set_dc_offset_cl_enable(0xf, 0xf); |
|---|
| 467 |
|
|---|
| 468 |
probe_rx_slots (false); |
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
if (fusb_block_size < 0 || fusb_block_size > FUSB_BLOCK_SIZE) |
|---|
| 473 |
throw std::out_of_range ("usrp_basic_rx: invalid fusb_block_size"); |
|---|
| 474 |
|
|---|
| 475 |
if (fusb_nblocks < 0) |
|---|
| 476 |
throw std::out_of_range ("usrp_basic_rx: invalid fusb_nblocks"); |
|---|
| 477 |
|
|---|
| 478 |
if (fusb_block_size == 0) |
|---|
| 479 |
fusb_block_size = fusb_sysconfig::default_block_size(); |
|---|
| 480 |
|
|---|
| 481 |
if (fusb_nblocks == 0) |
|---|
| 482 |
fusb_nblocks = std::max (1, FUSB_BUFFER_SIZE / fusb_block_size); |
|---|
| 483 |
|
|---|
| 484 |
d_devhandle = fusb_sysconfig::make_devhandle (d_udh); |
|---|
| 485 |
d_ephandle = d_devhandle->make_ephandle (USRP_RX_ENDPOINT, true, |
|---|
| 486 |
fusb_block_size, fusb_nblocks); |
|---|
| 487 |
|
|---|
| 488 |
_write_fpga_reg(FR_ATR_MASK_1, 0); |
|---|
| 489 |
_write_fpga_reg(FR_ATR_TXVAL_1, 0); |
|---|
| 490 |
_write_fpga_reg(FR_ATR_RXVAL_1, 0); |
|---|
| 491 |
_write_fpga_reg(FR_ATR_MASK_3, 0); |
|---|
| 492 |
_write_fpga_reg(FR_ATR_TXVAL_3, 0); |
|---|
| 493 |
_write_fpga_reg(FR_ATR_RXVAL_3, 0); |
|---|
| 494 |
} |
|---|
| 495 |
|
|---|
| 496 |
static unsigned char rx_fini_regs[] = { |
|---|
| 497 |
REG_RX_PWR_DN, 0x1 |
|---|
| 498 |
}; |
|---|
| 499 |
|
|---|
| 500 |
usrp_basic_rx::~usrp_basic_rx () |
|---|
| 501 |
{ |
|---|
| 502 |
if (!set_rx_enable (false)){ |
|---|
| 503 |
fprintf (stderr, "usrp_basic_rx: set_fpga_rx_enable failed\n"); |
|---|
| 504 |
usb_strerror (); |
|---|
| 505 |
} |
|---|
| 506 |
|
|---|
| 507 |
d_ephandle->stop (); |
|---|
| 508 |
delete d_ephandle; |
|---|
| 509 |
delete d_devhandle; |
|---|
| 510 |
|
|---|
| 511 |
if (!usrp_9862_write_many_all (d_udh, rx_fini_regs, sizeof (rx_fini_regs))){ |
|---|
| 512 |
fprintf (stderr, "usrp_basic_rx: failed to fini AD9862 RX regs\n"); |
|---|
| 513 |
} |
|---|
| 514 |
} |
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
bool |
|---|
| 518 |
usrp_basic_rx::start () |
|---|
| 519 |
{ |
|---|
| 520 |
if (!usrp_basic::start ()) |
|---|
| 521 |
return false; |
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
if (!d_ephandle->start ()){ |
|---|
| 526 |
fprintf (stderr, "usrp_basic_rx: failed to start end point streaming"); |
|---|
| 527 |
usb_strerror (); |
|---|
| 528 |
return false; |
|---|
| 529 |
} |
|---|
| 530 |
|
|---|
| 531 |
if (!set_rx_enable (true)){ |
|---|
| 532 |
fprintf (stderr, "usrp_basic_rx: set_rx_enable failed\n"); |
|---|
| 533 |
usb_strerror (); |
|---|
| 534 |
return false; |
|---|
| 535 |
} |
|---|
| 536 |
|
|---|
| 537 |
return true; |
|---|
| 538 |
} |
|---|
| 539 |
|
|---|
| 540 |
bool |
|---|
| 541 |
usrp_basic_rx::stop () |
|---|
| 542 |
{ |
|---|
| 543 |
bool ok = usrp_basic::stop(); |
|---|
| 544 |
|
|---|
| 545 |
if (!set_rx_enable(false)){ |
|---|
| 546 |
fprintf (stderr, "usrp_basic_rx: set_rx_enable(false) failed\n"); |
|---|
| 547 |
usb_strerror (); |
|---|
| 548 |
ok = false; |
|---|
| 549 |
} |
|---|
| 550 |
|
|---|
| 551 |
if (!d_ephandle->stop()){ |
|---|
| 552 |
fprintf (stderr, "usrp_basic_rx: failed to stop end point streaming"); |
|---|
| 553 |
usb_strerror (); |
|---|
| 554 |
ok = false; |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
return ok; |
|---|
| 558 |
} |
|---|
| 559 |
|
|---|
| 560 |
usrp_basic_rx * |
|---|
| 561 |
usrp_basic_rx::make (int which_board, int fusb_block_size, int fusb_nblocks, |
|---|
| 562 |
const std::string fpga_filename, |
|---|
| 563 |
const std::string firmware_filename) |
|---|
| 564 |
{ |
|---|
| 565 |
usrp_basic_rx *u = 0; |
|---|
| 566 |
|
|---|
| 567 |
try { |
|---|
| 568 |
u = new usrp_basic_rx (which_board, fusb_block_size, fusb_nblocks, |
|---|
| 569 |
fpga_filename, firmware_filename); |
|---|
| 570 |
return u; |
|---|
| 571 |
} |
|---|
| 572 |
catch (...){ |
|---|
| 573 |
delete u; |
|---|
| 574 |
return 0; |
|---|
| 575 |
} |
|---|
| 576 |
|
|---|
| 577 |
return u; |
|---|
| 578 |
} |
|---|
| 579 |
|
|---|
| 580 |
bool |
|---|
| 581 |
usrp_basic_rx::set_fpga_rx_sample_rate_divisor (unsigned int div) |
|---|
| 582 |
{ |
|---|
| 583 |
return _write_fpga_reg (FR_RX_SAMPLE_RATE_DIV, div - 1); |
|---|
| 584 |
} |
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
int |
|---|
| 596 |
usrp_basic_rx::read (void *buf, int len, bool *overrun) |
|---|
| 597 |
{ |
|---|
| 598 |
int r; |
|---|
| 599 |
|
|---|
| 600 |
if (overrun) |
|---|
| 601 |
*overrun = false; |
|---|
| 602 |
|
|---|
| 603 |
if (len < 0 || (len % 512) != 0){ |
|---|
| 604 |
fprintf (stderr, "usrp_basic_rx::read: invalid length = %d\n", len); |
|---|
| 605 |
return -1; |
|---|
| 606 |
} |
|---|
| 607 |
|
|---|
| 608 |
r = d_ephandle->read (buf, len); |
|---|
| 609 |
if (r > 0) |
|---|
| 610 |
d_bytes_seen += r; |
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
if (0 && d_first_read){ |
|---|
| 618 |
d_first_read = false; |
|---|
| 619 |
bool bogus_overrun; |
|---|
| 620 |
usrp_check_rx_overrun (d_udh, &bogus_overrun); |
|---|
| 621 |
} |
|---|
| 622 |
|
|---|
| 623 |
if (overrun != 0 && d_bytes_seen >= d_bytes_per_poll){ |
|---|
| 624 |
d_bytes_seen = 0; |
|---|
| 625 |
if (!usrp_check_rx_overrun (d_udh, overrun)){ |
|---|
| 626 |
fprintf (stderr, "usrp_basic_rx: usrp_check_rx_overrun failed\n"); |
|---|
| 627 |
usb_strerror (); |
|---|
| 628 |
} |
|---|
| 629 |
} |
|---|
| 630 |
|
|---|
| 631 |
return r; |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
bool |
|---|
| 635 |
usrp_basic_rx::set_rx_enable (bool on) |
|---|
| 636 |
{ |
|---|
| 637 |
d_rx_enable = on; |
|---|
| 638 |
return usrp_set_fpga_rx_enable (d_udh, on); |
|---|
| 639 |
} |
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 |
bool |
|---|
| 643 |
usrp_basic_rx::disable_rx () |
|---|
| 644 |
{ |
|---|
| 645 |
bool enabled = rx_enable (); |
|---|
| 646 |
if (enabled) |
|---|
| 647 |
set_rx_enable (false); |
|---|
| 648 |
return enabled; |
|---|
| 649 |
} |
|---|
| 650 |
|
|---|
| 651 |
|
|---|
| 652 |
void |
|---|
| 653 |
usrp_basic_rx::restore_rx (bool on) |
|---|
| 654 |
{ |
|---|
| 655 |
if (on != rx_enable ()) |
|---|
| 656 |
set_rx_enable (on); |
|---|
| 657 |
} |
|---|
| 658 |
|
|---|
| 659 |
bool |
|---|
| 660 |
usrp_basic_rx::set_pga (int which, double gain) |
|---|
| 661 |
{ |
|---|
| 662 |
if (which < 0 || which > 3) |
|---|
| 663 |
return false; |
|---|
| 664 |
|
|---|
| 665 |
gain = std::max (pga_min (), gain); |
|---|
| 666 |
gain = std::min (pga_max (), gain); |
|---|
| 667 |
|
|---|
| 668 |
int codec = which >> 1; |
|---|
| 669 |
int reg = (which & 1) == 0 ? REG_RX_A : REG_RX_B; |
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
unsigned char cur_rx; |
|---|
| 673 |
if (!_read_9862 (codec, reg, &cur_rx)) |
|---|
| 674 |
return false; |
|---|
| 675 |
|
|---|
| 676 |
int int_gain = (int) rint ((gain - pga_min ()) / pga_db_per_step()); |
|---|
| 677 |
|
|---|
| 678 |
cur_rx = (cur_rx & RX_X_BYPASS_INPUT_BUFFER) | (int_gain & 0x7f); |
|---|
| 679 |
return _write_9862 (codec, reg, cur_rx); |
|---|
| 680 |
} |
|---|
| 681 |
|
|---|
| 682 |
double |
|---|
| 683 |
usrp_basic_rx::pga (int which) const |
|---|
| 684 |
{ |
|---|
| 685 |
if (which < 0 || which > 3) |
|---|
| 686 |
return READ_FAILED; |
|---|
| 687 |
|
|---|
| 688 |
int codec = which >> 1; |
|---|
| 689 |
int reg = (which & 1) == 0 ? REG_RX_A : REG_RX_B; |
|---|
| 690 |
unsigned char v; |
|---|
| 691 |
bool ok = _read_9862 (codec, reg, &v); |
|---|
| 692 |
if (!ok) |
|---|
| 693 |
return READ_FAILED; |
|---|
| 694 |
|
|---|
| 695 |
return (pga_db_per_step() * (v & 0x1f)) + pga_min(); |
|---|
| 696 |
} |
|---|
| 697 |
|
|---|
| 698 |
static int |
|---|
| 699 |
slot_id_to_oe_reg (int slot_id) |
|---|
| 700 |
{ |
|---|
| 701 |
static int reg[4] = { FR_OE_0, FR_OE_1, FR_OE_2, FR_OE_3 }; |
|---|
| 702 |
assert (0 <= slot_id && slot_id < 4); |
|---|
| 703 |
return reg[slot_id]; |
|---|
| 704 |
} |
|---|
| 705 |
|
|---|
| 706 |
static int |
|---|
| 707 |
slot_id_to_io_reg (int slot_id) |
|---|
| 708 |
{ |
|---|
| 709 |
static int reg[4] = { FR_IO_0, FR_IO_1, FR_IO_2, FR_IO_3 }; |
|---|
| 710 |
assert (0 <= slot_id && slot_id < 4); |
|---|
| 711 |
return reg[slot_id]; |
|---|
| 712 |
} |
|---|
| 713 |
|
|---|
| 714 |
void |
|---|
| 715 |
usrp_basic_rx::probe_rx_slots (bool verbose) |
|---|
| 716 |
{ |
|---|
| 717 |
struct usrp_dboard_eeprom eeprom; |
|---|
| 718 |
static int slot_id_map[2] = { SLOT_RX_A, SLOT_RX_B }; |
|---|
| 719 |
static const char *slot_name[2] = { "RX d'board A", "RX d'board B" }; |
|---|
| 720 |
|
|---|
| 721 |
for (int i = 0; i < 2; i++){ |
|---|
| 722 |
int slot_id = slot_id_map [i]; |
|---|
| 723 |
const char *msg = 0; |
|---|
| 724 |
usrp_dbeeprom_status_t s = usrp_read_dboard_eeprom (d_udh, slot_id, &eeprom); |
|---|
| 725 |
|
|---|
| 726 |
switch (s){ |
|---|
| 727 |
case UDBE_OK: |
|---|
| 728 |
d_dbid[i] = eeprom.id; |
|---|
| 729 |
msg = usrp_dbid_to_string (eeprom.id).c_str (); |
|---|
| 730 |
set_adc_offset (2*i+0, eeprom.offset[0]); |
|---|
| 731 |
set_adc_offset (2*i+1, eeprom.offset[1]); |
|---|
| 732 |
_write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | eeprom.oe); |
|---|
| 733 |
_write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000); |
|---|
| 734 |
break; |
|---|
| 735 |
|
|---|
| 736 |
case UDBE_NO_EEPROM: |
|---|
| 737 |
d_dbid[i] = -1; |
|---|
| 738 |
msg = "<none>"; |
|---|
| 739 |
_write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | 0x0000); |
|---|
| 740 |
_write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000); |
|---|
| 741 |
break; |
|---|
| 742 |
|
|---|
| 743 |
case UDBE_INVALID_EEPROM: |
|---|
| 744 |
d_dbid[i] = -2; |
|---|
| 745 |
msg = "Invalid EEPROM contents"; |
|---|
| 746 |
_write_fpga_reg (slot_id_to_oe_reg(slot_id), (0xffff << 16) | 0x0000); |
|---|
| 747 |
_write_fpga_reg (slot_id_to_io_reg(slot_id), (0xffff << 16) | 0x0000); |
|---|
| 748 |
break; |
|---|
| 749 |
|
|---|
| 750 |
case UDBE_BAD_SLOT: |
|---|
| 751 |
default: |
|---|
| 752 |
assert (0); |
|---|
| 753 |
} |
|---|
| 754 |
|
|---|
| 755 |
if (verbose){ |
|---|
| 756 |
fflush (stdout); |
|---|
| 757 |
fprintf (stderr, "%s: %s\n", slot_name[i], msg); |
|---|
| 758 |
} |
|---|
| 759 |
} |
|---|
| 760 |
} |
|---|
| 761 |
|
|---|
| 762 |
bool |
|---|
| 763 |
usrp_basic_rx::_write_oe (int which_dboard, int value, int mask) |
|---|
| 764 |
{ |
|---|
| 765 |
if (! (0 <= which_dboard && which_dboard <= 1)) |
|---|
| 766 |
return false; |
|---|
| 767 |
|
|---|
| 768 |
return _write_fpga_reg (slot_id_to_oe_reg (dboard_to_slot (which_dboard)), |
|---|
| 769 |
(mask << 16) | (value & 0xffff)); |
|---|
| 770 |
} |
|---|
| 771 |
|
|---|
| 772 |
bool |
|---|
| 773 |
usrp_basic_rx::write_io (int which_dboard, int value, int mask) |
|---|
| 774 |
{ |
|---|
| 775 |
if (! (0 <= which_dboard && which_dboard <= 1)) |
|---|
| 776 |
return false; |
|---|
| 777 |
|
|---|
| 778 |
return _write_fpga_reg (slot_id_to_io_reg (dboard_to_slot (which_dboard)), |
|---|
| 779 |
(mask << 16) | (value & 0xffff)); |
|---|
| 780 |
} |
|---|
| 781 |
|
|---|
| 782 |
bool |
|---|
| 783 |
usrp_basic_rx::read_io (int which_dboard, int *value) |
|---|
| 784 |
{ |
|---|
| 785 |
if (! (0 <= which_dboard && which_dboard <= 1)) |
|---|
| 786 |
return false; |
|---|
| 787 |
|
|---|
| 788 |
int t; |
|---|
| 789 |
int reg = which_dboard + 1; |
|---|
| 790 |
bool ok = _read_fpga_reg (reg, &t); |
|---|
| 791 |
if (!ok) |
|---|
| 792 |
return false; |
|---|
| 793 |
|
|---|
| 794 |
*value = (t >> 16) & 0xffff; |
|---|
| 795 |
return true; |
|---|
| 796 |
} |
|---|
| 797 |
|
|---|
| 798 |
int |
|---|
| 799 |
usrp_basic_rx::read_io (int which_dboard) |
|---|
| 800 |
{ |
|---|
| 801 |
int value; |
|---|
| 802 |
if (!read_io (which_dboard, &value)) |
|---|
| 803 |
return READ_FAILED; |
|---|
| 804 |
return value; |
|---|
| 805 |
} |
|---|
| 806 |
|
|---|
| 807 |
bool |
|---|
| 808 |
usrp_basic_rx::write_aux_dac (int which_dboard, int which_dac, int value) |
|---|
| 809 |
{ |
|---|
| 810 |
return usrp_basic::write_aux_dac (dboard_to_slot (which_dboard), |
|---|
| 811 |
which_dac, value); |
|---|
| 812 |
} |
|---|
| 813 |
|
|---|
| 814 |
bool |
|---|
| 815 |
usrp_basic_rx::read_aux_adc (int which_dboard, int which_adc, int *value) |
|---|
| 816 |
{ |
|---|
| 817 |
return usrp_basic::read_aux_adc (dboard_to_slot (which_dboard), |
|---|
| 818 |
which_adc, value); |
|---|
| 819 |
} |
|---|
| 820 |
|
|---|
| 821 |
int |
|---|
| 822 |
usrp_basic_rx::read_aux_adc (int which_dboard, int which_adc) |
|---|
| 823 |
{ |
|---|
| 824 |
return usrp_basic::read_aux_adc (dboard_to_slot (which_dboard), which_adc); |
|---|
| 825 |
} |
|---|
| 826 |
|
|---|
| 827 |
int |
|---|
| 828 |
usrp_basic_rx::block_size () const { return d_ephandle->block_size(); } |
|---|
| 829 |
|
|---|
| 830 |
bool |
|---|
| 831 |
usrp_basic_rx::set_dc_offset_cl_enable(int bits, int mask) |
|---|
| 832 |
{ |
|---|
| 833 |
return _write_fpga_reg(FR_DC_OFFSET_CL_EN, |
|---|
| 834 |
(d_fpga_shadows[FR_DC_OFFSET_CL_EN] & ~mask) | (bits & mask)); |
|---|
| 835 |
} |
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
|
|---|
| 845 |
|
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
static unsigned char tx_init_regs[] = { |
|---|
| 853 |
REG_TX_PWR_DN, 0, |
|---|
| 854 |
REG_TX_A_OFFSET_LO, 0, |
|---|
| 855 |
REG_TX_A_OFFSET_HI, 0, |
|---|
| 856 |
REG_TX_B_OFFSET_LO, 0, |
|---|
| 857 |
REG_TX_B_OFFSET_HI, 0, |
|---|
| 858 |
REG_TX_A_GAIN, (TX_X_GAIN_COARSE_FULL | 0), |
|---|
| 859 |
REG_TX_B_GAIN, (TX_X_GAIN_COARSE_FULL | 0), |
|---|
| 860 |
REG_TX_PGA, 0xff, |
|---|
| 861 |
REG_TX_MISC, 0, |
|---|
| 862 |
REG_TX_IF, (TX_IF_USE_CLKOUT1 |
|---|
| 863 |
| TX_IF_I_FIRST |
|---|
| 864 |
| TX_IF_INV_TX_SYNC |
|---|
| 865 |
| TX_IF_2S_COMP |
|---|
| 866 |
| TX_IF_INTERLEAVED), |
|---|
| 867 |
REG_TX_DIGITAL, (TX_DIGITAL_2_DATA_PATHS |
|---|
| 868 |
| TX_DIGITAL_INTERPOLATE_4X), |
|---|
| 869 |
REG_TX_MODULATOR, (TX_MODULATOR_DISABLE_NCO |
|---|
| 870 |
| TX_MODULATOR_COARSE_MODULATION_NONE), |
|---|
| 871 |
REG_TX_NCO_FTW_7_0, 0, |
|---|
| 872 |
REG_TX_NCO_FTW_15_8, 0, |
|---|
| 873 |
REG_TX_NCO_FTW_23_16, 0 |
|---|
| 874 |
}; |
|---|
| 875 |
|
|---|
| 876 |
usrp_basic_tx::usrp_basic_tx (int which_board, int fusb_block_size, int fusb_nblocks, |
|---|
| 877 |
const std::string fpga_filename, |
|---|
| 878 |
const std::string firmware_filename) |
|---|
| 879 |
: usrp_basic (which_board, open_tx_interface, fpga_filename, firmware_filename), |
|---|
| 880 |
d_devhandle (0), d_ephandle (0), |
|---|
| 881 |
d_bytes_seen (0), d_first_write (true), |
|---|
| 882 |
d_tx_enable (false) |
|---|
| 883 |
{ |
|---|
| 884 |
if (!usrp_9862_write_many_all (d_udh, tx_init_regs, sizeof (tx_init_regs))){ |
|---|
| 885 |
fprintf (stderr, "usrp_basic_tx: failed to init AD9862 TX regs\n"); |
|---|
| 886 |
throw std::runtime_error ("usrp_basic_tx/init_9862"); |
|---|
| 887 |
} |
|---|
| 888 |
|
|---|
| 889 |
if (0){ |
|---|
| 890 |
|
|---|
| 891 |
usrp_9862_write (d_udh, 1, REG_TX_PWR_DN, |
|---|
| 892 |
(TX_PWR_DN_TX_DIGITAL |
|---|
| 893 |
| TX_PWR_DN_TX_ANALOG_BOTH)); |
|---|
| 894 |
} |
|---|
| 895 |
|
|---|
| 896 |
|
|---|
| 897 |
set_tx_enable (false); |
|---|
| 898 |
usrp_set_fpga_tx_reset (d_udh, true); |
|---|
| 899 |
usrp_set_fpga_tx_reset (d_udh, false); |
|---|
| 900 |
|
|---|
| 901 |
set_fpga_tx_sample_rate_divisor (4); |
|---|
| 902 |
|
|---|
| 903 |
probe_tx_slots (false); |
|---|
| 904 |
|
|---|
| 905 |
|
|---|
| 906 |
|
|---|
| 907 |
if (fusb_block_size < 0 || fusb_block_size > FUSB_BLOCK_SIZE) |
|---|
| 908 |
throw std::out_of_range ("usrp_basic_rx: invalid fusb_block_size"); |
|---|
| 909 |
|
|---|
| 910 |
if (fusb_nblocks < 0) |
|---|
| 911 |
throw std::out_of_range ("usrp_basic_rx: invalid fusb_nblocks"); |
|---|
| 912 |
|
|---|
| 913 |
if (fusb_block_size == 0) |
|---|
| 914 |
fusb_block_size = FUSB_BLOCK_SIZE; |
|---|
| 915 |
|
|---|
| 916 |
if (fusb_nblocks == 0) |
|---|
| 917 |
fusb_nblocks = std::max (1, FUSB_BUFFER_SIZE / fusb_block_size); |
|---|
| 918 |
|
|---|
| 919 |
d_devhandle = fusb_sysconfig::make_devhandle (d_udh); |
|---|
| 920 |
d_ephandle = d_devhandle->make_ephandle (USRP_TX_ENDPOINT, false, |
|---|
| 921 |
fusb_block_size, fusb_nblocks); |
|---|
| 922 |
|
|---|
| 923 |
_write_fpga_reg(FR_ATR_MASK_0, 0); |
|---|
| 924 |
_write_fpga_reg(FR_ATR_TXVAL_0, 0); |
|---|
| 925 |
_write_fpga_reg(FR_ATR_RXVAL_0, 0); |
|---|
| 926 |
_write_fpga_reg(FR_ATR_MASK_2, 0); |
|---|
| 927 |
_write_fpga_reg(FR_ATR_TXVAL_2, 0); |
|---|
| 928 |
_write_fpga_reg(FR_ATR_RXVAL_2, 0); |
|---|
| 929 |
} |
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 |
static unsigned char tx_fini_regs[] = { |
|---|
| 933 |
REG_TX_PWR_DN, (TX_PWR_DN_TX_DIGITAL |
|---|
| 934 |
| TX_PWR_DN_TX_ANALOG_BOTH), |
|---|
| 935 |
REG_TX_MODULATOR, (TX_MODULATOR_DISABLE_NCO |
|---|
| 936 |
| TX_MODULATOR_COARSE_MODULATION_NONE) |
|---|
| 937 |
}; |
|---|
| 938 |
|
|---|
| 939 |
usrp_basic_tx::~usrp_basic_tx () |
|---|
| 940 |
{ |
|---|
| 941 |
d_ephandle->stop (); |
|---|
| 942 |
delete d_ephandle; |
|---|
| 943 |
delete d_devhandle; |
|---|
| 944 |
|
|---|
| 945 |
if (!usrp_9862_write_many_all (d_udh, tx_fini_regs, sizeof (tx_fini_regs))){ |
|---|
| 946 |
fprintf (stderr, "usrp_basic_tx: failed to fini AD9862 TX regs\n"); |
|---|
| 947 |
} |
|---|
| 948 |
} |
|---|
| 949 |
|
|---|
| 950 |
bool |
|---|
| 951 |
usrp_basic_tx::start () |
|---|
| 952 |
{ |
|---|
| 953 |
if (!usrp_basic::start ()) |
|---|
| 954 |
return false; |
|---|
| 955 |
|
|---|
| 956 |
if (!set_tx_enable (true)){ |
|---|
| 957 |
fprintf (stderr, "usrp_basic_tx: set_tx_enable failed\n"); |
|---|
| 958 |
usb_strerror (); |
|---|
| 959 |
return false; |
|---|
| 960 |
} |
|---|
| 961 |
|
|---|
| 962 |
if (!d_ephandle->start ()){ |
|---|
| 963 |
fprintf (stderr, "usrp_basic_tx: failed to start end point streaming"); |
|---|
| 964 |
usb_strerror (); |
|---|
| 965 |
return false; |
|---|
| 966 |
} |
|---|
| 967 |
|
|---|
| 968 |
return true; |
|---|
| 969 |
} |
|---|
| 970 |
|
|---|
| 971 |
bool |
|---|
| 972 |
usrp_basic_tx::stop () |
|---|
| 973 |
{ |
|---|
| 974 |
bool ok = usrp_basic::stop (); |
|---|
| 975 |
|
|---|
| 976 |
if (!d_ephandle->stop ()){ |
|---|
| 977 |
fprintf (stderr, "usrp_basic_tx: failed to stop end point streaming"); |
|---|
| 978 |
usb_strerror (); |
|---|
| 979 |
ok = false; |
|---|
| 980 |
} |
|---|
| 981 |
|
|---|
| 982 |
if (!set_tx_enable (false)){ |
|---|
| 983 |
fprintf (stderr, "usrp_basic_tx: set_tx_enable(false) failed\n"); |
|---|
| 984 |
usb_strerror (); |
|---|
| 985 |
ok = false; |
|---|
| 986 |
} |
|---|
| 987 |
|
|---|
| 988 |
return ok; |
|---|
| 989 |
} |
|---|
| 990 |
|
|---|
| 991 |
usrp_basic_tx * |
|---|
| 992 |
usrp_basic_tx::make (int which_board, int fusb_block_size, int fusb_nblocks, |
|---|
| 993 |
const std::string fpga_filename, |
|---|
| 994 |
const std::string firmware_filename) |
|---|
| 995 |
{ |
|---|
| 996 |
usrp_basic_tx *u = 0; |
|---|
| 997 |
|
|---|
| 998 |
try { |
|---|
| 999 |
u = new usrp_basic_tx (which_board, fusb_block_size, fusb_nblocks, |
|---|
| 1000 |
fpga_filename, firmware_filename); |
|---|
| 1001 |
return u; |
|---|
| 1002 |
} |
|---|
| 1003 |
catch (...){ |
|---|
| 1004 |
delete u; |
|---|
| 1005 |
return 0; |
|---|
| 1006 |
} |
|---|
| 1007 |
|
|---|
| 1008 |
return u; |
|---|
| 1009 |
} |
|---|
| 1010 |
|
|---|
| 1011 |
bool |
|---|
| 1012 |
usrp_basic_tx::set_fpga_tx_sample_rate_divisor (unsigned int div) |
|---|
| 1013 |
{ |
|---|
| 1014 |
return _write_fpga_reg (FR_TX_SAMPLE_RATE_DIV, div - 1); |
|---|