gr-baz Package

rtl2832-tuner_e4000.h
Go to the documentation of this file.
1#ifndef __TUNER_E4000_H
2#define __TUNER_E4000_H
3
4#include "rtl2832.h"
5
6 namespace RTL2832_NAMESPACE { namespace TUNERS_NAMESPACE {
7
8 class e4000 : public RTL2832_NAMESPACE::tuner_skeleton
9{
10 IMPLEMENT_INLINE_TUNER_FACTORY(e4000)
11 public:
12 e4000(demod* p);
13 public:
14 inline virtual const char* name() const
15 { return "Elonics E4000"; }
16 public:
17 int initialise(tuner::PPARAMS params = NULL);
18 int set_frequency(double freq);
19 int set_bandwidth(double bw);
20 int set_gain(double gain);
21 int set_gain_mode(int mode);
22 int set_auto_gain_mode(bool on = true);
23 bool calc_appropriate_gain_mode(int& mode)/* const*/;
24 private:
25 int update_gain_mode();
26};
27
28} } // TUNERS_NAMESPACE, RTL2832_NAMESPACE
29
30/**
31
32@file
33
34@brief E4000 tuner module declaration
35 One can manipulate E4000 tuner through E4000 module.
36 E4000 module is derived from tuner module.
37
38@par Example:
39@code
40
41// The example is the same as the tuner example in tuner_base.h except the listed lines.
42
43#include "tuner_e4000.h"
44...
45 int main(void)
46{
47 TUNER_MODULE *pTuner;
48 E4000_EXTRA_MODULE *pTunerExtra;
49
50 TUNER_MODULE TunerModuleMemory;
51 BASE_INTERFACE_MODULE BaseInterfaceModuleMemory;
52// I2C_BRIDGE_MODULE I2cBridgeModuleMemory;
53
54 unsigned long BandwidthMode;
55
56 ...
57
58 // Build E4000 tuner module.
59 BuildE4000Module(
60 &pTuner,
61 &TunerModuleMemory,
62 &BaseInterfaceModuleMemory,
63 &I2cBridgeModuleMemory,
64 0xac, // I2C device address is 0xac in 8-bit format.
65 CRYSTAL_FREQ_16384000HZ, // Crystal frequency is 16.384 MHz.
66 E4000_AGC_INTERNAL // The E4000 AGC mode is internal AGC mode.
67 );
68
69 // Get E4000 tuner extra module.
70 pTunerExtra = (T2266_EXTRA_MODULE *)(pTuner->pExtra);
71
72 // ==== Initialize tuner and set its parameters =====
73 ...
74
75 // Set E4000 bandwidth.
76 pTunerExtra->SetBandwidthMode(pTuner, E4000_BANDWIDTH_6MHZ);
77
78 // ==== Get tuner information =====
79 ...
80
81 // Get E4000 bandwidth.
82 pTunerExtra->GetBandwidthMode(pTuner, &BandwidthMode);
83
84 // See the example for other tuner functions in tuner_base.h
85
86 return 0;
87}
88@endcode
89*/
90
91//#include "tuner_base.h"
92
93// The following context is implemented for E4000 source code.
94
95// Definition (implemeted for E4000)
96#define E4000_1_SUCCESS 1
97#define E4000_1_FAIL 0
98#define E4000_I2C_SUCCESS 1
99#define E4000_I2C_FAIL 0
100/*
101// Function (implemeted for E4000)
102 int
103 I2CReadByte(
104 RTL2832_NAMESPACE::tuner* pTuner,
105 unsigned char NoUse,
106 unsigned char RegAddr,
107 unsigned char *pReadingByte
108 );
109
110 int
111 I2CWriteByte(
112 RTL2832_NAMESPACE::tuner* pTuner,
113 unsigned char NoUse,
114 unsigned char RegAddr,
115 unsigned char WritingByte
116 );
117
118 int
119 I2CWriteArray(
120 RTL2832_NAMESPACE::tuner* pTuner,
121 unsigned char NoUse,
122 unsigned char RegStartAddr,
123 unsigned char ByteNum,
124 unsigned char *pWritingBytes
125 );
126*/
127// Functions (from E4000 source code)
128 int tunerreset (RTL2832_NAMESPACE::tuner* pTuner);
129 int Tunerclock(RTL2832_NAMESPACE::tuner* pTuner);
130 int Qpeak(RTL2832_NAMESPACE::tuner* pTuner);
131 int DCoffloop(RTL2832_NAMESPACE::tuner* pTuner);
132 int GainControlinit(RTL2832_NAMESPACE::tuner* pTuner);
133
134 int Gainmanual(RTL2832_NAMESPACE::tuner* pTuner);
135 int E4000_gain_freq(RTL2832_NAMESPACE::tuner* pTuner, int frequency);
136 int PLL(RTL2832_NAMESPACE::tuner* pTuner, int Ref_clk, int Freq);
137 int LNAfilter(RTL2832_NAMESPACE::tuner* pTuner, int Freq);
138 int IFfilter(RTL2832_NAMESPACE::tuner* pTuner, int bandwidth, int Ref_clk);
139 int freqband(RTL2832_NAMESPACE::tuner* pTuner, int Freq);
140 int DCoffLUT(RTL2832_NAMESPACE::tuner* pTuner);
141 int GainControlauto(RTL2832_NAMESPACE::tuner* pTuner);
142
143 int E4000_sensitivity(RTL2832_NAMESPACE::tuner* pTuner, int Freq, int bandwidth);
144 int E4000_linearity(RTL2832_NAMESPACE::tuner* pTuner, int Freq, int bandwidth);
145 int E4000_high_linearity(RTL2832_NAMESPACE::tuner* pTuner);
146 int E4000_nominal(RTL2832_NAMESPACE::tuner* pTuner, int Freq, int bandwidth);
147
148// The following context is E4000 tuner API source code
149
150// Definitions
151/*
152// Bandwidth in Hz
153 enum E4000_BANDWIDTH_HZ
154{
155 E4000_BANDWIDTH_6000000HZ = 6000000,
156 E4000_BANDWIDTH_7000000HZ = 7000000,
157 E4000_BANDWIDTH_8000000HZ = 8000000,
158};
159*/
160// Manipulaing functions
161 void
162 e4000_GetTunerType(
163 RTL2832_NAMESPACE::tuner* pTuner,
164 int *pTunerType
165 );
166
167 void
168 e4000_GetDeviceAddr(
169 RTL2832_NAMESPACE::tuner* pTuner,
170 unsigned char *pDeviceAddr
171 );
172
173 int
174 e4000_Initialize(
175 RTL2832_NAMESPACE::tuner* pTuner,
176 bool enable_dc_offset_loop = true,
177 bool set_manual_gain = false
178 );
179
180 int
181 e4000_SetRfFreqHz(
182 RTL2832_NAMESPACE::tuner* pTuner,
183 unsigned long RfFreqHz,
184 bool update_gain_control = true,
185 bool enable_dc_offset_lut = true
186 );
187
188 int
189 e4000_GetRfFreqHz(
190 RTL2832_NAMESPACE::tuner* pTuner,
191 unsigned long *pRfFreqHz
192 );
193
194// Extra manipulaing functions
195 int
196 e4000_GetRegByte(
197 RTL2832_NAMESPACE::tuner* pTuner,
198 unsigned char RegAddr,
199 unsigned char *pReadingByte
200 );
201
202 int
203 e4000_SetBandwidthHz(
204 RTL2832_NAMESPACE::tuner* pTuner,
205 unsigned long BandwidthHz
206 );
207
208 int
209 e4000_GetBandwidthHz(
210 RTL2832_NAMESPACE::tuner* pTuner,
211 unsigned long *pBandwidthHz
212 );
213
214///////////////////////////////////////////////////////////////////////////////
215// Definitions
216
217#define RTL2832_E4000_ADDITIONAL_INIT_REG_TABLE_LEN 34
218
219#define RTL2832_E4000_LNA_GAIN_TABLE_LEN 16
220#define RTL2832_E4000_LNA_GAIN_ADD_TABLE_LEN 8
221#define RTL2832_E4000_MIXER_GAIN_TABLE_LEN 2
222#define RTL2832_E4000_IF_STAGE_1_GAIN_TABLE_LEN 2
223#define RTL2832_E4000_IF_STAGE_2_GAIN_TABLE_LEN 4
224#define RTL2832_E4000_IF_STAGE_3_GAIN_TABLE_LEN 4
225#define RTL2832_E4000_IF_STAGE_4_GAIN_TABLE_LEN 4
226#define RTL2832_E4000_IF_STAGE_5_GAIN_TABLE_LEN 8
227#define RTL2832_E4000_IF_STAGE_6_GAIN_TABLE_LEN 8
228
229#define RTL2832_E4000_LNA_GAIN_BAND_NUM 2
230#define RTL2832_E4000_MIXER_GAIN_BAND_NUM 2
231
232#define RTL2832_E4000_RF_BAND_BOUNDARY_HZ 300000000
233
234#define RTL2832_E4000_LNA_GAIN_ADDR 0x14
235#define RTL2832_E4000_LNA_GAIN_MASK 0xf
236#define RTL2832_E4000_LNA_GAIN_SHIFT 0
237
238#define RTL2832_E4000_LNA_GAIN_ADD_ADDR 0x24
239#define RTL2832_E4000_LNA_GAIN_ADD_MASK 0x7
240#define RTL2832_E4000_LNA_GAIN_ADD_SHIFT 0
241
242#define RTL2832_E4000_MIXER_GAIN_ADDR 0x15
243#define RTL2832_E4000_MIXER_GAIN_MASK 0x1
244#define RTL2832_E4000_MIXER_GAIN_SHIFT 0
245
246#define RTL2832_E4000_IF_STAGE_1_GAIN_ADDR 0x16
247#define RTL2832_E4000_IF_STAGE_1_GAIN_MASK 0x1
248#define RTL2832_E4000_IF_STAGE_1_GAIN_SHIFT 0
249
250#define RTL2832_E4000_IF_STAGE_2_GAIN_ADDR 0x16
251#define RTL2832_E4000_IF_STAGE_2_GAIN_MASK 0x6
252#define RTL2832_E4000_IF_STAGE_2_GAIN_SHIFT 1
253
254#define RTL2832_E4000_IF_STAGE_3_GAIN_ADDR 0x16
255#define RTL2832_E4000_IF_STAGE_3_GAIN_MASK 0x18
256#define RTL2832_E4000_IF_STAGE_3_GAIN_SHIFT 3
257
258#define RTL2832_E4000_IF_STAGE_4_GAIN_ADDR 0x16
259#define RTL2832_E4000_IF_STAGE_4_GAIN_MASK 0x60
260#define RTL2832_E4000_IF_STAGE_4_GAIN_SHIFT 5
261
262#define RTL2832_E4000_IF_STAGE_5_GAIN_ADDR 0x17
263#define RTL2832_E4000_IF_STAGE_5_GAIN_MASK 0x7
264#define RTL2832_E4000_IF_STAGE_5_GAIN_SHIFT 0
265
266#define RTL2832_E4000_IF_STAGE_6_GAIN_ADDR 0x17
267#define RTL2832_E4000_IF_STAGE_6_GAIN_MASK 0x38
268#define RTL2832_E4000_IF_STAGE_6_GAIN_SHIFT 3
269
270#define RTL2832_E4000_TUNER_OUTPUT_POWER_UNIT_0P1_DBM -100
271
272#define RTL2832_E4000_TUNER_MODE_UPDATE_WAIT_TIME_MS 1000
273
274// Tuner gain mode
275 enum RTL2832_E4000_TUNER_GAIN_MODE
276{
277 RTL2832_E4000_TUNER_GAIN_SENSITIVE = RTL2832_NAMESPACE::tuner::DEFAULT,
278 RTL2832_E4000_TUNER_GAIN_NORMAL,
279 RTL2832_E4000_TUNER_GAIN_LINEAR,
280};
281
282#endif
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::set_gain_mode
int set_gain_mode(int mode)
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::set_bandwidth
int set_bandwidth(double bw)
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::e4000
e4000(demod *p)
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::set_auto_gain_mode
int set_auto_gain_mode(bool on=true)
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::calc_appropriate_gain_mode
bool calc_appropriate_gain_mode(int &mode)
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::set_gain
int set_gain(double gain)
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::name
virtual const char * name() const
Definition rtl2832-tuner_e4000.h:14
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::initialise
int initialise(tuner::PPARAMS params=NULL)
RTL2832_NAMESPACE::TUNERS_NAMESPACE::e4000::set_frequency
int set_frequency(double freq)
RTL2832_NAMESPACE::demod
Definition rtl2832.h:310
RTL2832_NAMESPACE::tuner_skeleton::gain
virtual double gain() const
Definition rtl2832.h:228
RTL2832_NAMESPACE::tuner::PPARAMS
struct RTL2832_NAMESPACE::tuner::params * PPARAMS
RTL2832_NAMESPACE::TUNERS_NAMESPACE
Definition rtl2832-tuner_e4000.h:6
RTL2832_NAMESPACE
Definition rtl2832-tuner_e4000.h:6
RTL2832_E4000_TUNER_GAIN_MODE
RTL2832_E4000_TUNER_GAIN_MODE
Definition rtl2832-tuner_e4000.h:276
RTL2832_E4000_TUNER_GAIN_NORMAL
@ RTL2832_E4000_TUNER_GAIN_NORMAL
Definition rtl2832-tuner_e4000.h:278
RTL2832_E4000_TUNER_GAIN_LINEAR
@ RTL2832_E4000_TUNER_GAIN_LINEAR
Definition rtl2832-tuner_e4000.h:279
RTL2832_E4000_TUNER_GAIN_SENSITIVE
@ RTL2832_E4000_TUNER_GAIN_SENSITIVE
Definition rtl2832-tuner_e4000.h:277
E4000_high_linearity
int E4000_high_linearity(RTL2832_NAMESPACE::tuner *pTuner)
tunerreset
int tunerreset(RTL2832_NAMESPACE::tuner *pTuner)
E4000_linearity
int E4000_linearity(RTL2832_NAMESPACE::tuner *pTuner, int Freq, int bandwidth)
GainControlauto
int GainControlauto(RTL2832_NAMESPACE::tuner *pTuner)
e4000_Initialize
int e4000_Initialize(RTL2832_NAMESPACE::tuner *pTuner, bool enable_dc_offset_loop=true, bool set_manual_gain=false)
Tunerclock
int Tunerclock(RTL2832_NAMESPACE::tuner *pTuner)
Qpeak
int Qpeak(RTL2832_NAMESPACE::tuner *pTuner)
e4000_GetBandwidthHz
int e4000_GetBandwidthHz(RTL2832_NAMESPACE::tuner *pTuner, unsigned long *pBandwidthHz)
E4000_nominal
int E4000_nominal(RTL2832_NAMESPACE::tuner *pTuner, int Freq, int bandwidth)
e4000_SetBandwidthHz
int e4000_SetBandwidthHz(RTL2832_NAMESPACE::tuner *pTuner, unsigned long BandwidthHz)
E4000_gain_freq
int E4000_gain_freq(RTL2832_NAMESPACE::tuner *pTuner, int frequency)
LNAfilter
int LNAfilter(RTL2832_NAMESPACE::tuner *pTuner, int Freq)
DCoffLUT
int DCoffLUT(RTL2832_NAMESPACE::tuner *pTuner)
IFfilter
int IFfilter(RTL2832_NAMESPACE::tuner *pTuner, int bandwidth, int Ref_clk)
DCoffloop
int DCoffloop(RTL2832_NAMESPACE::tuner *pTuner)
Gainmanual
int Gainmanual(RTL2832_NAMESPACE::tuner *pTuner)
e4000_GetRfFreqHz
int e4000_GetRfFreqHz(RTL2832_NAMESPACE::tuner *pTuner, unsigned long *pRfFreqHz)
e4000_GetDeviceAddr
void e4000_GetDeviceAddr(RTL2832_NAMESPACE::tuner *pTuner, unsigned char *pDeviceAddr)
E4000_sensitivity
int E4000_sensitivity(RTL2832_NAMESPACE::tuner *pTuner, int Freq, int bandwidth)
e4000_GetRegByte
int e4000_GetRegByte(RTL2832_NAMESPACE::tuner *pTuner, unsigned char RegAddr, unsigned char *pReadingByte)
e4000_SetRfFreqHz
int e4000_SetRfFreqHz(RTL2832_NAMESPACE::tuner *pTuner, unsigned long RfFreqHz, bool update_gain_control=true, bool enable_dc_offset_lut=true)
e4000_GetTunerType
void e4000_GetTunerType(RTL2832_NAMESPACE::tuner *pTuner, int *pTunerType)
PLL
int PLL(RTL2832_NAMESPACE::tuner *pTuner, int Ref_clk, int Freq)
GainControlinit
int GainControlinit(RTL2832_NAMESPACE::tuner *pTuner)
freqband
int freqband(RTL2832_NAMESPACE::tuner *pTuner, int Freq)
rtl2832.h
IMPLEMENT_INLINE_TUNER_FACTORY
#define IMPLEMENT_INLINE_TUNER_FACTORY(class_name)
Definition rtl2832.h:77
RTL2832_NAMESPACE::tuner::params
Definition rtl2832.h:145