summaryrefslogtreecommitdiffstats
path: root/api/FCI_FC2580.c
blob: 0d03e3c13ffef466e5e54151142b835949113c89 (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
/**
 * @(#)FCI_FC2580.h
 *
 * ==========================================================
 * Version: 2.4
 * Date:    2009.01.06
 * ==========================================================
 *
 * ==========================================================
 * History:
 *
 * Date         Author      Description
 * ----------------------------------------------------------
 *
 * 2008.07.02   Tom Lin     added tuner version
 * 2008.10.27	Tom Lin     1. update tuner code
 *                          2. modify AGC control to internal
 * 2008.12.02   Tom Lin     update tuner code to 1.4
 * 2009.01.06   Tom Lin     modify tuner registers 0x6b & 0x6c
 *                          to be 0x0f & 0x11 for better per-
 *                          formance
 * 2009.03.23   Yinding     turn on gpiot2 before tuner is opened
 * ==========================================================
 *
 * Copyright 2008 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 "fc2580.h"
#include "FCI_FC2580_Script.h"


Demodulator* FCI_FC2580_demodulator;
Byte FCI_FC2580_chip;


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

    FCI_FC2580_demodulator = demodulator;
    FCI_FC2580_chip = chip;

	error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpiot2_on, 1);
	if (error) goto exit;
	error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpiot2_en, 1);
	if (error) goto exit;
	error = Standard_writeRegister (demodulator, chip, Processor_LINK, p_reg_top_gpiot2_o, 1);
	if (error) goto exit;

    fc2580_set_init (1);

exit :
    return (error);
}


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


Dword FC2580_set (
    IN  Demodulator*    demodulator,
    IN  Byte            chip,
    IN  Word            bandwidth,
    IN  Dword           frequency
) {
    Dword error = Error_NO_ERROR;
    Byte bw;

    FCI_FC2580_demodulator = demodulator;
    FCI_FC2580_chip = chip;

    if (bandwidth < 5000) {
        bw = 1;
    } else if (bandwidth < 6000) {
        bw = 5;
    } else if (bandwidth < 7000) {
        bw = 6;
    } else if (bandwidth < 8000) {
        bw = 7;
    } else if (bandwidth < 9000) {
        bw = 8;
    } else {
        bw = 9;
    }

    fc2580_set_filter (bw);
    fc2580_set_freq (frequency);

    return (error);
}


TunerDescription tuner_FC2580 = {
    FC2580_open,                /** Function to open tuner.            */
    FC2580_close,               /** Function to close tuner.           */
    FC2580_set,                 /** Function set frequency.            */
    FC2580_scripts,             /** Scripts.                           */
    FC2580_scriptSets,          /** Length of scripts.                 */
    FC2580_ADDRESS,             /** The I2C address of tuner.          */
    1,                          /** Valid length of tuner register.    */
    0,                          /** IF frequency of tuner.             */
    True,                       /** Spectrum inversion.                */
    0x32,                       /** tuner id                           */
};