aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp_e/codec_ctrl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/usrp/usrp_e/codec_ctrl.cpp')
-rw-r--r--host/lib/usrp/usrp_e/codec_ctrl.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/host/lib/usrp/usrp_e/codec_ctrl.cpp b/host/lib/usrp/usrp_e/codec_ctrl.cpp
index ac61bc6b4..5322f94bd 100644
--- a/host/lib/usrp/usrp_e/codec_ctrl.cpp
+++ b/host/lib/usrp/usrp_e/codec_ctrl.cpp
@@ -31,6 +31,9 @@ using namespace uhd;
static const bool codec_debug = false;
+const gain_range_t usrp_e_codec_ctrl::tx_pga_gain_range(-20, 0, float(0.1));
+const gain_range_t usrp_e_codec_ctrl::rx_pga_gain_range(0, 20, 1);
+
/***********************************************************************
* Codec Control Implementation
**********************************************************************/
@@ -44,6 +47,12 @@ public:
float read_aux_adc(aux_adc_t which);
void write_aux_dac(aux_dac_t which, float volts);
+ //pga gain control
+ void set_tx_pga_gain(float);
+ float get_tx_pga_gain(void);
+ void set_rx_pga_gain(float, char);
+ float get_rx_pga_gain(char);
+
private:
usrp_e_iface::sptr _iface;
ad9862_regs_t _ad9862_regs;
@@ -120,6 +129,45 @@ usrp_e_codec_ctrl_impl::~usrp_e_codec_ctrl_impl(void){
}
/***********************************************************************
+ * Codec Control Gain Control Methods
+ **********************************************************************/
+void usrp_e_codec_ctrl_impl::set_tx_pga_gain(float gain){
+ int gain_word = int(63*(gain - tx_pga_gain_range.min)/(tx_pga_gain_range.max - tx_pga_gain_range.min));
+ _ad9862_regs.tx_pga_gain = std::clip(gain_word, 0, 63);
+ this->send_reg(16);
+}
+
+float usrp_e_codec_ctrl_impl::get_tx_pga_gain(void){
+ return (_ad9862_regs.tx_pga_gain*(tx_pga_gain_range.max - tx_pga_gain_range.min)/63) + tx_pga_gain_range.min;
+}
+
+void usrp_e_codec_ctrl_impl::set_rx_pga_gain(float gain, char which){
+ int gain_word = int(0x14*(gain - rx_pga_gain_range.min)/(rx_pga_gain_range.max - rx_pga_gain_range.min));
+ gain_word = std::clip(gain_word, 0, 0x14);
+ switch(which){
+ case 'A':
+ _ad9862_regs.rx_pga_a = gain_word;
+ this->send_reg(2);
+ return;
+ case 'B':
+ _ad9862_regs.rx_pga_b = gain_word;
+ this->send_reg(3);
+ return;
+ default: UHD_THROW_INVALID_CODE_PATH();
+ }
+}
+
+float usrp_e_codec_ctrl_impl::get_rx_pga_gain(char which){
+ int gain_word;
+ switch(which){
+ case 'A': gain_word = _ad9862_regs.rx_pga_a; break;
+ case 'B': gain_word = _ad9862_regs.rx_pga_b; break;
+ default: UHD_THROW_INVALID_CODE_PATH();
+ }
+ return (gain_word*(rx_pga_gain_range.max - rx_pga_gain_range.min)/0x14) + rx_pga_gain_range.min;
+}
+
+/***********************************************************************
* Codec Control AUX ADC Methods
**********************************************************************/
static float aux_adc_to_volts(boost::uint8_t high, boost::uint8_t low){