summaryrefslogtreecommitdiffstats
path: root/api/Philips_TDA18291HN.c
blob: 160349e97e70f5044e2cae45926c9b29ba66f0c7 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
 * @(#)Philips_TDA18291HN.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 "TDA18291local.h"
#include "TDA18291.h"
#include "Philips_TDA18291HN_Script.h"


extern tm18291object_t g18291Instance[];


Dword TDA18291HN_open (
    IN  Demodulator*    demodulator,
    IN  Byte            chip
) {
    Dword error = Error_NO_ERROR;

    /** U/V band switch **/
    error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh2_o, 1);
    if (error) goto exit;

    error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh2_on, 1);
    if (error) goto exit;

    error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh2_en, 1);
    if (error) goto exit;

    /** Set registers for driving power **/    
    error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh8_on, 1);
    if (error) goto exit;

    error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh8_en, 1);
    if (error) goto exit;

exit:
    return (error);
}


Dword TDA18291HN_close (
    IN  Demodulator*    demodulator,
    IN  Byte            chip
) {
    Dword error = Error_NO_ERROR;

    /** Set registers for driving power **/  
    /** set to GPI **/
    error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh8_on, 0);   
    if (error) goto exit;

    error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh8_en, 0);
    if (error) goto exit;

exit:
    return (error);
}


Dword TDA18291HN_set (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Word            bandwidth,
    IN  Dword           frequency
) {
    Dword           error = Error_NO_ERROR;
    tmbslTuParam_t  param;
    Byte            fc = 1;

    if (bandwidth == 5000)
    {
        fc = CUTOFF_FREQ_FOR_5MHZ;
    }
    else if (bandwidth == 6000)
    {
        fc = CUTOFF_FREQ_FOR_6MHZ;
    }
    else if (bandwidth == 7000)
    {
        fc = CUTOFF_FREQ_FOR_7MHZ;
    }
    else if (bandwidth == 8000)
    {
        fc = CUTOFF_FREQ_FOR_8MHZ;
    }
    else
    {
        error = Error_INVALID_BW;
        goto exit;
    }

    if (frequency > 300000)
    {
        error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh2_o, 1);
        if (error) goto exit;
    }
    else
    {
        error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpioh2_o, 0);
        if (error) goto exit;
    }

    g18291Instance[0].AFAInfo.demodulator = demodulator;
    g18291Instance[0].AFAInfo.chip = chip;

    param.systemFunc.SY_Read  = SY_Read2;
    param.systemFunc.SY_Write = SY_Write2;
    param.uHwAddress = 0xC0ul;

    /** Init tuner */
    error = tmbslTDA18291Init(0, param);
    if (error) goto exit;

    /** Select board */
    error = tmbslTDA18291SetConfig(0, BOARD, OM5768_BOARD_DEF);
    if (error) goto exit;    	

    /** Set cut-off frequency */
    error = tmbslTDA18291SetConfig(0, SET_CUTOFF_FREQ, fc);
    if (error) goto exit;

    /** Set frequency */
    error = tmbslTDA18291SetRf(0, frequency * 1000);
    if (error) goto exit;

exit:
    return (error);

}


TunerDescription tuner_TDA18291HN = {
    TDA18291HN_open,
    TDA18291HN_close,
    TDA18291HN_set,
    TDA18291HN_scripts,
    TDA18291HN_scriptSets,
    TDA18291HN_ADDRESS,             /** tuner i2c address */
    1,                              /** length of tuner register address */
    0,                              /** tuner if */
    (Bool)True,                     /** spectrum inverse */
    0x22,                           /** tuner id */
};