1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (��MStar Confidential Information��) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 #include "Board.h"
96 #include "QAM_Demodulator.h"
97 #include "GPIO.h"
98 #include "MsTypes.h"
99 #include "drvBDMA.h"
100 //#include "SWI2C.h"
101 #include"drvIIC.h"
102 #include "drvUartDebug.h" //For OTHER_TUNER_DEBUG
103 #include "msAPI_CI.h"
104 #include "msAPI_Timer.h"
105 #include "apiXC.h"
106 #include "apiXC_Adc.h"
107
108 #include "MsCommon.h"
109 #include "MsIRQ.h"
110 #include "MsOS.h"
111
112 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
113 #include "MApp_GlobalFunction.h"
114 #include "INTERN_DVBC.c"
115 #include "drvVIF.h"
116 #endif
117
118 #define QAM_DBG(x) //x
119 #if ENABLE_AUTOTEST
120 extern BOOLEAN g_bAutobuildDebug;
121 #endif
122 extern U16 u16ScanDtvChNum;
123
devQAM_Init(void)124 void devQAM_Init(void)
125 {
126 // hard-wire reset pin
127 Demodulator_OFF();
128 MsOS_DelayTask(20);
129 Demodulator_ON();
130 MsOS_DelayTask(30);
131
132 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
133 INTERN_DVBC_Power_On_Initialization();
134 #endif
135
136 devDigitalTuner_Init();
137 }
138
devQAM_ControlPowerOnOff(BOOLEAN bPowerOn)139 void devQAM_ControlPowerOnOff(BOOLEAN bPowerOn)
140 {
141
142 #if (FRONTEND_IF_DEMODE_TYPE == MSTAR_VIF || FRONTEND_IF_DEMODE_TYPE == MSTAR_VIF_MSB1210 || FRONTEND_IF_DEMODE_TYPE == MSTAR_INTERN_VIF)
143 if (bPowerOn == ENABLE) // DTV mode
144 {
145 EXT_RF_AGC_OFF();
146 printf("KKK: (Temp)EXT_RF_AGC_OFF...for DTV\n");
147 }
148 else
149 {
150 EXT_RF_AGC_ON();
151 printf("KKK: (Temp)EXT_RF_AGC_On...for ATV\n");
152 }
153 #endif
154
155 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
156 INTERN_DVBC_Power_ON_OFF(bPowerOn);
157 #endif
158 }
159
devQAM_PowerSave(void)160 FUNCTION_RESULT devQAM_PowerSave(void)
161 {
162 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
163 if (INTERN_DVBC_Power_Save() == TRUE)
164 return E_RESULT_SUCCESS;
165 else
166 return E_RESULT_FAILURE;
167 #else
168 return E_RESULT_SUCCESS;
169 #endif
170 }
171
devQAM_TunerProgramming(U8 * cTunerData)172 void devQAM_TunerProgramming(U8 *cTunerData)
173 {
174 *cTunerData=*cTunerData;
175 }
176
177 #if DTV_SCAN_AUTO_FINE_TUNE_ENABLE
devQAM_GetFrequencyOffset(float * pFreqOff,RF_CHANNEL_BANDWIDTH u8BW)178 BOOLEAN devQAM_GetFrequencyOffset(float *pFreqOff, RF_CHANNEL_BANDWIDTH u8BW)
179 {
180 *pFreqOff = 0; //Temp Solution;;
181 u8BW = u8BW; //To avoid compiler warning
182 return 1;
183 }
devQAM_SetAfcEnable(BOOLEAN bEnable)184 BOOLEAN devQAM_SetAfcEnable(BOOLEAN bEnable)
185 {
186 bEnable = bEnable; //To avoid compiler warning
187 return 1;
188 }
189 #endif
190
devQAM_SetFrequency(DWORD dwFrequency,U8 u8QamMode,U16 u16SymbolRate,BOOLEAN bSpecInv)191 void devQAM_SetFrequency(DWORD dwFrequency, U8 u8QamMode, U16 u16SymbolRate, BOOLEAN bSpecInv)
192 {
193 //dwFrequency = 562000; // << Ken 20090629
194 //eBandWidth = E_RF_CH_BAND_8MHz; // << Ken 20090629
195
196 //printf("====dwFrequency = %lu \n", dwFrequency/1000);
197 //printf("====eBandWidth = %bx\n", eBandWidth);
198 #if ENABLE_AUTOTEST
199 if(g_bAutobuildDebug && (dwFrequency/1000 == 850))
200 {
201 printf("31_DTV_Tuning_End_%d\n", u16ScanDtvChNum);
202 }
203 #endif
204
205 #if (ENABLE_AUTOTEST || ENABLE_BOOTTIME)
206 #if (ENABLE_BOOTTIME==DISABLE)
207 if (g_bAutobuildDebug == TRUE)
208 #endif
209 {
210 gU32TmpTime = msAPI_Timer_DiffTimeFromNow(gU32BootTime);
211 printf("[boot time]QAM set RF = %ld\n", gU32TmpTime);
212 }
213 #endif
214
215 devDigitalTuner_SetFreq((double)(dwFrequency/1000.0), E_RF_CH_BAND_8MHz);
216
217 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
218 //MsOS_DelayTask(10); //waiting for tuner write
219
220 #if ENABLE_CI
221 if ( msAPI_CI_CardDetect())
222 INTERN_DVBC_Config (u16SymbolRate, u8QamMode, 36167, bSpecInv, FALSE);
223 else
224 #endif
225 INTERN_DVBC_Config (u16SymbolRate, u8QamMode, 36167, bSpecInv, TRUE);
226
227 INTERN_DVBC_Active(ENABLE);
228 #else
229 UNUSED(dwFrequency);
230 UNUSED(u8QamMode);
231 UNUSED(u16SymbolRate);
232 UNUSED(bSpecInv);
233 #endif
234
235 }
236
devQAM_GetLockStatus(QAM_LOCK_STATUS eStatus)237 BOOLEAN devQAM_GetLockStatus(QAM_LOCK_STATUS eStatus)
238 {
239 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
240 return INTERN_DVBC_Lock(eStatus);
241 #else
242 UNUSED(eStatus);
243 return TRUE;
244 #endif
245 }
246
devQAM_GetSignalToNoiseRatio(void)247 BYTE devQAM_GetSignalToNoiseRatio(void)
248 {
249 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
250 return (BYTE)INTERN_DVBC_GetSNR();
251 #else
252 return 1;
253 #endif
254 }
255
devQAM_PassThroughI2C(BOOLEAN bEnable)256 void devQAM_PassThroughI2C(BOOLEAN bEnable)
257 {
258 bEnable=bEnable;
259 }
260
devQAM_SwitchTransportSteamInferface(QAM_TS_INTERFACE interface)261 void devQAM_SwitchTransportSteamInferface(QAM_TS_INTERFACE interface)
262 {
263 BOOLEAN bEnable;
264
265 if ( interface == E_QAM_SERIAL_INTERFACE )
266 {
267 bEnable = TRUE;
268 }
269 else
270 {
271 bEnable = FALSE;
272 }
273 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
274 INTERN_DVBC_Serial_Control(bEnable);
275 #endif
276
277 }
278
devQAM_GetSignal_Vit(DWORD * vit)279 FUNCTION_RESULT devQAM_GetSignal_Vit( DWORD *vit )
280 {
281 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
282 float ber;
283 *vit = *vit;
284 if (INTERN_DVBC_GetPostViterbiBer(&ber)==TRUE)
285 return E_RESULT_SUCCESS;
286 else
287 return E_RESULT_FAILURE;
288 #else
289 *vit = *vit;
290 return E_RESULT_FAILURE;
291 #endif
292 }
293
devQAM_GetSignalStrength(WORD * strength)294 FUNCTION_RESULT devQAM_GetSignalStrength(WORD *strength)
295 {
296 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
297 return INTERN_DVBC_GetSignalStrength(strength);
298 #else
299 *strength = 80;
300 return E_RESULT_SUCCESS;
301 #endif
302
303 }
304
305
devQAM_GetSignalQuality(WORD * quality)306 FUNCTION_RESULT devQAM_GetSignalQuality(WORD *quality)
307 {
308 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
309 return INTERN_DVBC_GetSignalQuality(quality);
310 #else
311 *quality = 80;
312 return E_RESULT_SUCCESS;
313 #endif
314 }
315
devQAM_PassThroughI2C_ReadBytes(U8 u8SlaveID,U8 u8AddrNum,U8 * paddr,U16 u16size,U8 * pu8data)316 BOOLEAN devQAM_PassThroughI2C_ReadBytes(U8 u8SlaveID, U8 u8AddrNum, U8* paddr, U16 u16size, U8* pu8data)
317 {
318 UNUSED(u8SlaveID);
319 UNUSED(u8AddrNum);
320 UNUSED(paddr);
321 UNUSED(u16size);
322 UNUSED(pu8data);
323 return TRUE;
324 }
325
devQAM_PassThroughI2C_WriteBytes(U8 u8SlaveID,U8 u8AddrNum,U8 * paddr,U16 u16size,U8 * pu8data)326 BOOLEAN devQAM_PassThroughI2C_WriteBytes(U8 u8SlaveID, U8 u8AddrNum, U8* paddr, U16 u16size, U8* pu8data)
327 {
328 UNUSED(u8SlaveID);
329 UNUSED(u8AddrNum);
330 UNUSED(paddr);
331 UNUSED(u16size);
332 UNUSED(pu8data);
333 return TRUE;
334 }
devQAM_GetSpecInv(void)335 BOOLEAN devQAM_GetSpecInv(void)
336 {
337 #if ((FRONTEND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD) || (FRONTEND_SECOND_DEMOD_TYPE == EMBEDDED_DVBC_DEMOD))
338 return TRUE;
339 #endif
340 return TRUE;
341 }
342