summaryrefslogtreecommitdiffstats
path: root/api/Philips_TDA18271.c
blob: d047f009a598e0ec44a4546dbef0db0f7852c59d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
 * @(#)Philips_TDA18271.cpp
 *
 * ==========================================================
 * Version: 2.0
 * Date:    2008.07.02
 * ==========================================================
 *
 * ==========================================================
 * History:
 *
 * Date         Author      Description
 * ----------------------------------------------------------
 *
 * 2008.07.02   Tom Lin     added tuner version
 * ==========================================================
 *
 * Copyright 2007 Afatech, Inc. All rights reserved.
 *
 */


//#include <stdio.h> //for Linux
#include "type.h"
#include "error.h"
#include "user.h"
#include "register.h"
#include "standard.h"
#include "TDA18271Local.h"
#include "TDA18271.h"
#include "Philips_TDA18271_Script.h"


extern tmTDA18271Object_t gTDA18271Instance[];

Dword Standard_computeFcw (
    IN  Demodulator*    demodulator,
    IN  Long            adcFrequency,       /** ADC frequency (Hz)    */
    IN  Long            ifFrequency,        /** IF frequency (Hz)     */
    IN  Bool            inversion,          /** RF spectrum inversion */
    OUT Dword*          fcw
);


Dword TDA18271_open (
	IN  Demodulator*	demodulator,
	IN  Byte			chip
) {
    return (Error_NO_ERROR);
}


Dword TDA18271_close (
	IN  Demodulator*	demodulator,
	IN  Byte			chip
) {
	return (Error_NO_ERROR);
}


Dword TDA18271_set (
	IN  Demodulator*	demodulator,
	IN  Byte			chip,
	IN  Word			bandwidth,
	IN  Dword			frequency
) {

	Dword           error = Error_NO_ERROR;
    tmbslTuParam_t  param;
    Byte			fc = 1;
    Long            IfFreq;
	Dword           fcw;
    Byte            buffer[3];
	Ganymede* ganymede;		
	ganymede = (Ganymede*) demodulator;

	gTDA18271Instance[0].AFAInfo.demodulator = demodulator;
	gTDA18271Instance[0].AFAInfo.chip = chip;
 
    param.systemFunc.SY_Read  = SY_Read;
    param.systemFunc.SY_Write = SY_Write;
    param.uHwAddress = 0xC0ul;

    
    switch(bandwidth)
	{
	case 6000:
        IfFreq = 3300000;
        fc = tmDigital_TV_ATSC_6MHz;
		break;
	case 7000:
        IfFreq = 3800000;
        fc = tmDigital_TV_DVBT_7MHz;
		break;
	case 8000:
        IfFreq = 4300000;
        fc = tmDigital_TV_DVBT_8MHz;
		break;
	default:
        error = Error_INVALID_BW;
        goto exit;
	}

    error = Standard_computeFcw (demodulator, (Long) ganymede->adcFrequency, IfFreq, ganymede->tunerDescription->inversion, &fcw);
    if (error) goto exit;
    ganymede->fcw = fcw;
   
    buffer[0] = (Byte) (fcw & 0x000000FF);
    buffer[1] = (Byte) ((fcw & 0x0000FF00) >> 8);
    buffer[2] = (Byte) ((fcw & 0x007F0000) >> 16);
    error = Standard_writeRegisters (demodulator, chip, Processor_OFDM, bfs_fcw_7_0, bfs_fcw_22_16 - bfs_fcw_7_0 + 1, buffer);    
    if (error) goto exit;

    
    error = tmbslTDA18271Init(0, param);
    if (error) goto exit;

    error = tmbslTDA18271SetConfig(0, STANDARDMODE, fc);
    if (error) goto exit;
	
	error = tmbslTDA18271SetRf(0, frequency * 1000);

exit:
    return (error);    
}


TunerDescription tuner_TDA18271 = {
    TDA18271_open,
    TDA18271_close,
    TDA18271_set,
    TDA18271_scripts,
    TDA18271_scriptSets,
    TDA18271_ADDRESS,               /** tuner i2c address */
    1,                              /** length of tuner register address */
    0,                              /** tuner if */
    (Bool)True,                     /** spectrum inverse */
    0x1B,                           /** tuner id */
};