Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / io / microtune_4702_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_4702_eval_board.h"
24 #include "microtune_eval_board_defs.h"
25 #include "ppio.h"
26 #include "microtune_4702.h"
27
28 static const int TUNER_I2C_ADDR = 0x60;
29
30 microtune_4702_eval_board::microtune_4702_eval_board (int which_pp)
31   : microtune_xxxx_eval_board (which_pp)
32 {
33   d_tuner = new microtune_4702 (d_i2c, TUNER_I2C_ADDR);
34 }
35
36 microtune_4702_eval_board::~microtune_4702_eval_board ()
37 {
38   // default is OK
39 }
40
41 static const float RF_MIN_V = 1.0;      // RF AGC control voltages
42 static const float RF_MAX_V = 4.0;
43 static const float IF_MIN_V = 2.0;      // IF AGC control voltages
44 static const float IF_MAX_V = 4.0;
45
46 static const float MIN_AGC  =    0;     // bottom of synthetic range
47 static const float MAX_AGC  = 1000;     // top of synthetic range
48
49 static const float CUTOVER_POINT = 667;
50
51
52 // linear is in the range MIN_AGC to MAX_AGC
53
54 static float
55 linear_to_RF_AGC_voltage (float linear)
56 {
57   if (linear >= CUTOVER_POINT)
58     return RF_MAX_V;
59
60   float slope = (RF_MAX_V - RF_MIN_V) / CUTOVER_POINT;
61   return RF_MIN_V + linear * slope;
62 }
63
64 static float
65 linear_to_IF_AGC_voltage (float linear)
66 {
67   if (linear < CUTOVER_POINT)
68     return IF_MIN_V;
69
70   float slope = (IF_MAX_V - IF_MIN_V) / (MAX_AGC - CUTOVER_POINT);
71   return IF_MIN_V + (linear - CUTOVER_POINT) * slope;
72 }
73
74 void
75 microtune_4702_eval_board::set_AGC (float v)
76 {
77   if (v < MIN_AGC)
78     v = MIN_AGC;
79
80   if (v > MAX_AGC)
81     v = MAX_AGC;
82
83   float rf_agc_voltage = linear_to_RF_AGC_voltage (v);
84   float if_agc_voltage = linear_to_IF_AGC_voltage (v);
85
86   set_RF_AGC_voltage (rf_agc_voltage);
87   set_IF_AGC_voltage (if_agc_voltage);
88 }