Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / io / microtune_4937_eval_board.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2001,2004 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 2, 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 #include "microtune_4937_eval_board.h"
24 #include "microtune_eval_board_defs.h"
25 #include "ppio.h"
26 #include "microtune_4937.h"
27
28 static const int TUNER_I2C_ADDR = 0x61;
29
30 microtune_4937_eval_board::microtune_4937_eval_board (int which_pp)
31   : microtune_xxxx_eval_board (which_pp)
32 {
33   d_tuner = new microtune_4937 (d_i2c, TUNER_I2C_ADDR);
34
35   // disable upstream amplifier
36   d_ppio->lock ();
37   int   t = d_ppio->read_data ();
38   t &= ~(UT_DP_TX_ENABLE | UT_DP_TX_SDA | UT_DP_TX_SCL);
39   t |= UT_DP_TX_AS;
40   d_ppio->write_data (t);
41   d_ppio->unlock ();
42 }
43
44 microtune_4937_eval_board::~microtune_4937_eval_board ()
45 {
46   // Default action is OK
47 }
48
49
50 static const float RF_MIN_V = 1.5;      // RF AGC control voltages
51 static const float RF_MAX_V = 4.0;
52 static const float IF_MIN_V = 2.0;      // IF AGC control voltages
53 static const float IF_MAX_V = 4.0;
54
55 static const float MIN_AGC  =    0;     // bottom of synthetic range
56 static const float MAX_AGC  = 1000;     // top of synthetic range
57
58 static const float CUTOVER_POINT = 667;
59
60
61 // linear is in the range MIN_AGC to MAX_AGC
62
63 static float
64 linear_to_RF_AGC_voltage (float linear)
65 {
66   if (linear >= CUTOVER_POINT)
67     return RF_MAX_V;
68
69   float slope = (RF_MAX_V - RF_MIN_V) / CUTOVER_POINT;
70   return RF_MIN_V + linear * slope;
71 }
72
73 static float
74 linear_to_IF_AGC_voltage (float linear)
75 {
76   if (linear < CUTOVER_POINT)
77     return IF_MIN_V;
78
79   float slope = (IF_MAX_V - IF_MIN_V) / (MAX_AGC - CUTOVER_POINT);
80   return IF_MIN_V + (linear - CUTOVER_POINT) * slope;
81 }
82
83 void
84 microtune_4937_eval_board::set_AGC (float v)
85 {
86   if (v < MIN_AGC)
87     v = MIN_AGC;
88
89   if (v > MAX_AGC)
90     v = MAX_AGC;
91
92   float rf_agc_voltage = linear_to_RF_AGC_voltage (v);
93   float if_agc_voltage = linear_to_IF_AGC_voltage (v);
94
95   set_RF_AGC_voltage (rf_agc_voltage);
96   set_IF_AGC_voltage (if_agc_voltage);
97 }