Changeset 9743
- Timestamp:
- 10/07/08 22:11:42
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_basic.cc
r9742 r9743 1 1 /* -*- c++ -*- */ 2 2 /* 3 * Copyright 2003,2004 Free Software Foundation, Inc.3 * Copyright 2003,2004,2008 Free Software Foundation, Inc. 4 4 * 5 5 * This file is part of GNU Radio … … 251 251 252 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;253 usrp_basic::set_adc_offset (int which_adc, int offset) 254 { 255 if (which_adc < 0 || which_adc > 3) 256 return false; 257 258 return _write_fpga_reg (FR_ADC_OFFSET_0 + which_adc, offset); 259 } 260 261 bool 262 usrp_basic::set_dac_offset (int which_dac, int offset, int offset_pin) 263 { 264 if (which_dac < 0 || which_dac > 3) 265 return false; 266 267 int which_codec = which_dac >> 1; 268 int tx_a = (which_dac & 0x1) == 0; 269 269 int lo = ((offset & 0x3) << 6) | (offset_pin & 0x1); 270 270 int hi = (offset >> 2); … … 283 283 284 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;285 usrp_basic::set_adc_buffer_bypass (int which_adc, bool bypass) 286 { 287 if (which_adc < 0 || which_adc > 3) 288 return false; 289 290 int codec = which_adc >> 1; 291 int reg = (which_adc & 1) == 0 ? REG_RX_A : REG_RX_B; 292 292 293 293 unsigned char cur_rx; … … 303 303 if (bypass){ 304 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;305 cur_pwr_dn |= ((which_adc & 1) == 0) ? RX_PWR_DN_BUF_A : RX_PWR_DN_BUF_B; 306 306 } 307 307 else { 308 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);309 cur_pwr_dn &= ~(((which_adc & 1) == 0) ? RX_PWR_DN_BUF_A : RX_PWR_DN_BUF_B); 310 310 } 311 311 … … 414 414 415 415 bool 416 usrp_basic::_set_led (int which , bool on)417 { 418 return usrp_set_led (d_udh, which , on);416 usrp_basic::_set_led (int which_led, bool on) 417 { 418 return usrp_set_led (d_udh, which_led, on); 419 419 } 420 420 … … 658 658 659 659 bool 660 usrp_basic_rx::set_pga (int which , double gain)661 { 662 if (which < 0 || which> 3)660 usrp_basic_rx::set_pga (int which_amp, double gain) 661 { 662 if (which_amp < 0 || which_amp > 3) 663 663 return false; 664 664 … … 666 666 gain = std::min (pga_max (), gain); 667 667 668 int codec = which >> 1;669 int reg = (which & 1) == 0 ? REG_RX_A : REG_RX_B;668 int codec = which_amp >> 1; 669 int reg = (which_amp & 1) == 0 ? REG_RX_A : REG_RX_B; 670 670 671 671 // read current value to get input buffer bypass flag. … … 681 681 682 682 double 683 usrp_basic_rx::pga (int which ) const684 { 685 if (which < 0 || which> 3)683 usrp_basic_rx::pga (int which_amp) const 684 { 685 if (which_amp < 0 || which_amp > 3) 686 686 return READ_FAILED; 687 687 688 int codec = which >> 1;689 int reg = (which & 1) == 0 ? REG_RX_A : REG_RX_B;688 int codec = which_amp >> 1; 689 int reg = (which_amp & 1) == 0 ? REG_RX_A : REG_RX_B; 690 690 unsigned char v; 691 691 bool ok = _read_9862 (codec, reg, &v); … … 761 761 762 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)),763 usrp_basic_rx::_write_oe (int which_side, int value, int mask) 764 { 765 if (! (0 <= which_side && which_side <= 1)) 766 return false; 767 768 return _write_fpga_reg (slot_id_to_oe_reg (dboard_to_slot (which_side)), 769 769 (mask << 16) | (value & 0xffff)); 770 770 } 771 771 772 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)),773 usrp_basic_rx::write_io (int which_side, int value, int mask) 774 { 775 if (! (0 <= which_side && which_side <= 1)) 776 return false; 777 778 return _write_fpga_reg (slot_id_to_io_reg (dboard_to_slot (which_side)), 779 779 (mask << 16) | (value & 0xffff)); 780 780 } 781 781 782 782 bool 783 usrp_basic_rx::read_io (int which_ dboard, int *value)784 { 785 if (! (0 <= which_ dboard && which_dboard<= 1))783 usrp_basic_rx::read_io (int which_side, int *value) 784 { 785 if (! (0 <= which_side && which_side <= 1)) 786 786 return false; 787 787 788 788 int t; 789 int reg = which_ dboard+ 1; // FIXME, *very* magic number (fix in serial_io.v)789 int reg = which_side + 1; // FIXME, *very* magic number (fix in serial_io.v) 790 790 bool ok = _read_fpga_reg (reg, &t); 791 791 if (!ok) … … 797 797 798 798 int 799 usrp_basic_rx::read_io (int which_ dboard)799 usrp_basic_rx::read_io (int which_side) 800 800 { 801 801 int value; 802 if (!read_io (which_ dboard, &value))802 if (!read_io (which_side, &value)) 803 803 return READ_FAILED; 804 804 return value; … … 806 806 807 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),808 usrp_basic_rx::write_aux_dac (int which_side, int which_dac, int value) 809 { 810 return usrp_basic::write_aux_dac (dboard_to_slot (which_side), 811 811 which_dac, value); 812 812 } 813 813 814 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),815 usrp_basic_rx::read_aux_adc (int which_side, int which_adc, int *value) 816 { 817 return usrp_basic::read_aux_adc (dboard_to_slot (which_side), 818 818 which_adc, value); 819 819 } 820 820 821 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);822 usrp_basic_rx::read_aux_adc (int which_side, int which_adc) 823 { 824 return usrp_basic::read_aux_adc (dboard_to_slot (which_side), which_adc); 825 825 } 826 826 … … 1096 1096 1097 1097 bool 1098 usrp_basic_tx::set_pga (int which , double gain)1099 { 1100 if (which < 0 || which> 3)1098 usrp_basic_tx::set_pga (int which_amp, double gain) 1099 { 1100 if (which_amp < 0 || which_amp > 3) 1101 1101 return false; 1102 1102 … … 1104 1104 gain = std::min (pga_max (), gain); 1105 1105 1106 int codec = which >> 1; // 0 and 1 are same, as are 2 and 31106 int codec = which_amp >> 1; // 0 and 1 are same, as are 2 and 3 1107 1107 1108 1108 int int_gain = (int) rint ((gain - pga_min ()) / pga_db_per_step()); … … 1112 1112 1113 1113 double 1114 usrp_basic_tx::pga (int which ) const1115 { 1116 if (which < 0 || which> 3)1114 usrp_basic_tx::pga (int which_amp) const 1115 { 1116 if (which_amp < 0 || which_amp > 3) 1117 1117 return READ_FAILED; 1118 1118 1119 int codec = which >> 1;1119 int codec = which_amp >> 1; 1120 1120 unsigned char v; 1121 1121 bool ok = _read_9862 (codec, REG_TX_PGA, &v); … … 1175 1175 1176 1176 bool 1177 usrp_basic_tx::_write_oe (int which_ dboard, int value, int mask)1178 { 1179 if (! (0 <= which_ dboard && which_dboard<= 1))1180 return false; 1181 1182 return _write_fpga_reg (slot_id_to_oe_reg (dboard_to_slot (which_ dboard)),1177 usrp_basic_tx::_write_oe (int which_side, int value, int mask) 1178 { 1179 if (! (0 <= which_side && which_side <= 1)) 1180 return false; 1181 1182 return _write_fpga_reg (slot_id_to_oe_reg (dboard_to_slot (which_side)), 1183 1183 (mask << 16) | (value & 0xffff)); 1184 1184 } 1185 1185 1186 1186 bool 1187 usrp_basic_tx::write_io (int which_ dboard, int value, int mask)1188 { 1189 if (! (0 <= which_ dboard && which_dboard<= 1))1190 return false; 1191 1192 return _write_fpga_reg (slot_id_to_io_reg (dboard_to_slot (which_ dboard)),1187 usrp_basic_tx::write_io (int which_side, int value, int mask) 1188 { 1189 if (! (0 <= which_side && which_side <= 1)) 1190 return false; 1191 1192 return _write_fpga_reg (slot_id_to_io_reg (dboard_to_slot (which_side)), 1193 1193 (mask << 16) | (value & 0xffff)); 1194 1194 } 1195 1195 1196 1196 bool 1197 usrp_basic_tx::read_io (int which_ dboard, int *value)1198 { 1199 if (! (0 <= which_ dboard && which_dboard<= 1))1197 usrp_basic_tx::read_io (int which_side, int *value) 1198 { 1199 if (! (0 <= which_side && which_side <= 1)) 1200 1200 return false; 1201 1201 1202 1202 int t; 1203 int reg = which_ dboard+ 1; // FIXME, *very* magic number (fix in serial_io.v)1203 int reg = which_side + 1; // FIXME, *very* magic number (fix in serial_io.v) 1204 1204 bool ok = _read_fpga_reg (reg, &t); 1205 1205 if (!ok) … … 1211 1211 1212 1212 int 1213 usrp_basic_tx::read_io (int which_ dboard)1213 usrp_basic_tx::read_io (int which_side) 1214 1214 { 1215 1215 int value; 1216 if (!read_io (which_ dboard, &value))1216 if (!read_io (which_side, &value)) 1217 1217 return READ_FAILED; 1218 1218 return value; … … 1220 1220 1221 1221 bool 1222 usrp_basic_tx::write_aux_dac (int which_ dboard, int which_dac, int value)1223 { 1224 return usrp_basic::write_aux_dac (dboard_to_slot (which_ dboard),1222 usrp_basic_tx::write_aux_dac (int which_side, int which_dac, int value) 1223 { 1224 return usrp_basic::write_aux_dac (dboard_to_slot (which_side), 1225 1225 which_dac, value); 1226 1226 } 1227 1227 1228 1228 bool 1229 usrp_basic_tx::read_aux_adc (int which_ dboard, int which_adc, int *value)1230 { 1231 return usrp_basic::read_aux_adc (dboard_to_slot (which_ dboard),1229 usrp_basic_tx::read_aux_adc (int which_side, int which_adc, int *value) 1230 { 1231 return usrp_basic::read_aux_adc (dboard_to_slot (which_side), 1232 1232 which_adc, value); 1233 1233 } 1234 1234 1235 1235 int 1236 usrp_basic_tx::read_aux_adc (int which_ dboard, int which_adc)1237 { 1238 return usrp_basic::read_aux_adc (dboard_to_slot (which_ dboard), which_adc);1236 usrp_basic_tx::read_aux_adc (int which_side, int which_adc) 1237 { 1238 return usrp_basic::read_aux_adc (dboard_to_slot (which_side), which_adc); 1239 1239 } 1240 1240 gnuradio/branches/developers/eb/cppdb-wip/usrp/host/lib/legacy/usrp_basic.h
r9742 r9743 1 1 /* -*- c++ -*- */ 2 2 /* 3 * Copyright 2003,2004 Free Software Foundation, Inc.3 * Copyright 2003,2004,2008 Free Software Foundation, Inc. 4 4 * 5 5 * This file is part of GNU Radio … … 173 173 * \param offset 16-bit value to subtract from raw ADC input. 174 174 */ 175 bool set_adc_offset (int which , int offset);175 bool set_adc_offset (int which_adc, int offset); 176 176 177 177 /*! … … 182 182 * If 1 offset applied to +ve differential pin. 183 183 */ 184 bool set_dac_offset (int which , int offset, int offset_pin);184 bool set_dac_offset (int which_dac, int offset, int offset_pin); 185 185 186 186 /*! … … 190 190 * directly to switched cap SHA input of RxPGA. 191 191 */ 192 bool set_adc_buffer_bypass (int which , bool bypass);192 bool set_adc_buffer_bypass (int which_adc, bool bypass); 193 193 194 194 … … 205 205 // 206 206 207 bool _set_led (int which , bool on);207 bool _set_led (int which_led, bool on); 208 208 209 209 /*! … … 400 400 * \brief Return daughterboard ID for given Rx daughterboard slot [0,1]. 401 401 * 402 * \param which_ dboard[0,1] which Rx daughterboard402 * \param which_side [0,1] which Rx daughterboard 403 403 * 404 404 * \return daughterboard id >= 0 if successful … … 406 406 * \return -2 if invalid EEPROM on daughterboard 407 407 */ 408 int daughterboard_id (int which_ dboard) const { return d_dbid[which_dboard& 0x1]; }408 int daughterboard_id (int which_side) const { return d_dbid[which_side & 0x1]; } 409 409 410 410 // ---------------------------------------------------------------- … … 413 413 * \brief Set Programmable Gain Amplifier (PGA) 414 414 * 415 * \param which which A/D [0,3]415 * \param which_amp which A/D [0,3] 416 416 * \param gain_in_db gain value (linear in dB) 417 417 * … … 422 422 * \sa pga_min(), pga_max(), pga_db_per_step() 423 423 */ 424 bool set_pga (int which , double gain_in_db);424 bool set_pga (int which_amp, double gain_in_db); 425 425 426 426 /*! 427 427 * \brief Return programmable gain amplifier gain setting in dB. 428 428 * 429 * \param which which A/D [0,3]430 */ 431 double pga (int which ) const;429 * \param which_amp which A/D [0,3] 430 */ 431 double pga (int which_amp) const; 432 432 433 433 /*! … … 449 449 * \brief Write direction register (output enables) for pins that go to daughterboard. 450 450 * 451 * \param which_ dboard[0,1] which d'board452 * \param value value to write into register453 * \param mask which bits of value to write into reg451 * \param which_side [0,1] which d'board 452 * \param value value to write into register 453 * \param mask which bits of value to write into reg 454 454 * 455 455 * Each d'board has 16-bits of general purpose i/o. … … 461 461 * kill your USRP motherboard and/or daughterboard. 462 462 */ 463 bool _write_oe (int which_ dboard, int value, int mask);463 bool _write_oe (int which_side, int value, int mask); 464 464 465 465 /*! 466 466 * \brief Write daughterboard i/o pin value 467 467 * 468 * \param which_ dboard[0,1] which d'board469 * \param value value to write into register470 * \param mask which bits of value to write into reg471 */ 472 bool write_io (int which_ dboard, int value, int mask);468 * \param which_side [0,1] which d'board 469 * \param value value to write into register 470 * \param mask which bits of value to write into reg 471 */ 472 bool write_io (int which_side, int value, int mask); 473 473 474 474 /*! 475 475 * \brief Read daughterboard i/o pin value 476 476 * 477 * \param which_ dboard[0,1] which d'board478 * \param value output479 */ 480 bool read_io (int which_ dboard, int *value);477 * \param which_side [0,1] which d'board 478 * \param value output 479 */ 480 bool read_io (int which_side, int *value); 481 481 482 482 /*! 483 483 * \brief Read daughterboard i/o pin value 484 484 * 485 * \param which_ dboard[0,1] which d'board485 * \param which_side [0,1] which d'board 486 486 * \returns register value if successful, else READ_FAILED 487 487 */ 488 int read_io (int which_ dboard);488 int read_io (int which_side); 489 489 490 490 /*! 491 491 * \brief Write auxiliary digital to analog converter. 492 492 * 493 * \param which_ dboard[0,1] which d'board494 * N.B., SLOT_TX_A and SLOT_RX_A share the same AUX DAC's.495 * SLOT_TX_B and SLOT_RX_B share the same AUX DAC's.496 * \param which_dac [2,3] TX slots must use only 2 and 3.497 * \param value [0,4095]498 * \returns true iff successful 499 */ 500 bool write_aux_dac (int which_ board, int which_dac, int value);493 * \param which_side [0,1] which d'board 494 * N.B., SLOT_TX_A and SLOT_RX_A share the same AUX DAC's. 495 * SLOT_TX_B and SLOT_RX_B share the same AUX DAC's. 496 * \param which_dac [2,3] TX slots must use only 2 and 3. 497 * \param value [0,4095] 498 * \returns true iff successful 499 */ 500 bool write_aux_dac (int which_side, int which_dac, int value); 501 501 502 502 /*! 503 503 * \brief Read auxiliary analog to digital converter. 504 504 * 505 * \param which_ dboard[0,1] which d'board506 * \param which_adc [0,1]507 * \param value return 12-bit value [0,4095]508 * \returns true iff successful 509 */ 510 bool read_aux_adc (int which_ dboard, int which_adc, int *value);505 * \param which_side [0,1] which d'board 506 * \param which_adc [0,1] 507 * \param value return 12-bit value [0,4095] 508 * \returns true iff successful 509 */ 510 bool read_aux_adc (int which_side, int which_adc, int *value); 511 511 512 512 /*! 513 513 * \brief Read auxiliary analog to digital converter. 514 514 * 515 * \param which_ dboard[0,1] which d'board515 * \param which_side [0,1] which d'board 516 516 * \param which_adc [0,1] 517 517 * \returns value in the range [0,4095] if successful, else READ_FAILED. 518 518 */ 519 int read_aux_adc (int which_ dboard, int which_adc);519 int read_aux_adc (int which_side, int which_adc); 520 520 521 521 /*! … … 649 649 * \return -2 if invalid EEPROM on daughterboard 650 650 */ 651 int daughterboard_id (int which_ dboard) const { return d_dbid[which_dboard& 0x1]; }651 int daughterboard_id (int which_side) const { return d_dbid[which_side & 0x1]; } 652 652 653 653 // ---------------------------------------------------------------- … … 656 656 * \brief Set Programmable Gain Amplifier (PGA) 657 657 * 658 * \param which which D/A [0,3]658 * \param which_amp which D/A [0,3] 659 659 * \param gain_in_db gain value (linear in dB) 660 660 * … … 667 667 * \sa pga_min(), pga_max(), pga_db_per_step() 668 668 */ 669 bool set_pga (int which , double gain_in_db);669 bool set_pga (int which_amp, double gain_in_db); 670 670 671 671 /*! 672 672 * \brief Return programmable gain amplifier gain in dB. 673 673 * 674 * \param which which D/A [0,3]675 */ 676 double pga (int which ) const;674 * \param which_amp which D/A [0,3] 675 */ 676 double pga (int which_amp) const; 677 677 678 678 /*! … … 694 694 * \brief Write direction register (output enables) for pins that go to daughterboard. 695 695 * 696 * \param which_ dboard[0,1] which d'board697 * \param value value to write into register698 * \param mask which bits of value to write into reg696 * \param which_side [0,1] which d'board 697 * \param value value to write into register 698 * \param mask which bits of value to write into reg 699 699 * 700 700 * Each d'board has 16-bits of general purpose i/o. … … 706 706 * kill your USRP motherboard and/or daughterboard. 707 707 */ 708 bool _write_oe (int which_ dboard, int value, int mask);708 bool _write_oe (int which_side, int value, int mask); 709 709 710 710 /*! 711 711 * \brief Write daughterboard i/o pin value 712 712 * 713 * \param which_ dboard[0,1] which d'board713 * \param which_side [0,1] which d'board 714 714 * \param value value to write into register 715 715 * \param mask which bits of value to write into reg 716 716 */ 717 bool write_io (int which_ dboard, int value, int mask);717 bool write_io (int which_side, int value, int mask); 718 718 719 719 /*! 720 720 * \brief Read daughterboard i/o pin value 721 721 * 722 * \param which_ dboard[0,1] which d'board722 * \param which_side [0,1] which d'board 723 723 * \param value return value 724 724 */ 725 bool read_io (int which_ dboard, int *value);725 bool read_io (int which_side, int *value); 726 726 727 727 /*! 728 728 * \brief Read daughterboard i/o pin value 729 729 * 730 * \param which_ dboard[0,1] which d'board730 * \param which_side [0,1] which d'board 731 731 * \returns register value if successful, else READ_FAILED 732 732 */ 733 int read_io (int which_ dboard);733 int read_io (int which_side); 734 734 735 735 /*! 736 736 * \brief Write auxiliary digital to analog converter. 737 737 * 738 * \param which_ dboard[0,1] which d'board739 * N.B., SLOT_TX_A and SLOT_RX_A share the same AUX DAC's.740 * SLOT_TX_B and SLOT_RX_B share the same AUX DAC's.741 * \param which_dac [2,3] TX slots must use only 2 and 3.742 * \param value [0,4095]743 * \returns true iff successful 744 */ 745 bool write_aux_dac (int which_ board, int which_dac, int value);738 * \param which_side [0,1] which d'board 739 * N.B., SLOT_TX_A and SLOT_RX_A share the same AUX DAC's. 740 * SLOT_TX_B and SLOT_RX_B share the same AUX DAC's. 741 * \param which_dac [2,3] TX slots must use only 2 and 3. 742 * \param value [0,4095] 743 * \returns true iff successful 744 */ 745 bool write_aux_dac (int which_side, int which_dac, int value); 746 746 747 747 /*! 748 748 * \brief Read auxiliary analog to digital converter. 749 749 * 750 * \param which_ dboard[0,1] which d'board751 * \param which_adc [0,1]752 * \param value return 12-bit value [0,4095]753 * \returns true iff successful 754 */ 755 bool read_aux_adc (int which_ dboard, int which_adc, int *value);750 * \param which_side [0,1] which d'board 751 * \param which_adc [0,1] 752 * \param value return 12-bit value [0,4095] 753 * \returns true iff successful 754 */ 755 bool read_aux_adc (int which_side, int which_adc, int *value); 756 756 757 757 /*! 758 758 * \brief Read auxiliary analog to digital converter. 759 759 * 760 * \param which_ dboard[0,1] which d'board761 * \param which_adc [0,1]760 * \param which_side [0,1] which d'board 761 * \param which_adc [0,1] 762 762 * \returns value in the range [0,4095] if successful, else READ_FAILED. 763 763 */ 764 int read_aux_adc (int which_ dboard, int which_adc);764 int read_aux_adc (int which_side, int which_adc); 765 765 766 766 /*!
