xref: /utopia/UTPA2-700.0.x/modules/demodulator/drv/demod/drvDMD_ISDBT.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
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 yor any information; or
62 //    (c) conferring any license or right under any intellectual property right.
63 //
64 // 7. These terms shall be governed by and construed in accordance with the laws
65 //    of Taiwan, R.O.C., excluding its conflict of law rules.
66 //    Any and all dispute arising out hereof or related hereto shall be finally
67 //    settled by arbitration referred to the Chinese Arbitration Association,
68 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
69 //    Rules of the Association by three (3) arbitrators appointed in accordance
70 //    with the said Rules.
71 //    The place of arbitra��cordance
72 //    with the said Rules.
73 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
74 //    be English.
75 //    The arbitration award shall be final and binding to both parties.
76 //
77 //******************************************************************************
78 //<MStar Software>
79 ////////////////////////////////////////////////////////////////////////////////
80 //
81 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
82 // All rights reserved.
83 //
84 // Unless otherwise stipulated in writing, any and all information contained
85 // herein regardless in any format shall remain the sole proprietary of
86 // MStar Semiconductor Inc. and be kept in strict confidence
87 // ("MStar Confidential Information") by the recipient.
88 // Any unauthorized act including without limitation unauthorized disclosure,
89 // copying, use, reproduction, sale, distribution, modification, disassembling,
90 // reverse engineering and compiling of the contents of MStar Confidential
91 // Information is unlawful and strictly prohibited. MStar hereby reserves the
92 // rights to any and all damages, losses, costs and expenses resulting therefrom.
93 //
94 ////////////////////////////////////////////////////////////////////////////////
95 
96 ///////////////////////////////////////////////////////////////////////////////////////////////////
97 ///
98 /// file    drvDMD_ISDBT.c
99 /// @brief  DMD ISDBT Driver Interface
100 /// @author MStar Semiconductor Inc.
101 ///////////////////////////////////////////////////////////////////////////////////////////////////
102 
103 //-------------------------------------------------------------------------------------------------
104 //  Driver Compiler Options
105 //-------------------------------------------------------------------------------------------------
106 
107 #ifdef UTPA2
108 #undef DONT_USE_CMA
109 #define DONT_USE_CMA
110 #endif
111 
112 //-------------------------------------------------------------------------------------------------
113 //  Include Files
114 //-------------------------------------------------------------------------------------------------
115 
116 #ifdef MSOS_TYPE_LINUX_KERNEL
117 #include <linux/string.h>
118 #else
119 #include <string.h>
120 #include <stdio.h>
121 #include <math.h>
122 #endif
123 
124 #include "drvDMD_ISDBT.h"
125 #ifdef UTPA2
126 #include "drvDMD_ISDBT_v2.h"
127 #endif
128 
129 #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
130 #include "MsOS.h"
131 #include "drvMMIO.h"
132 #endif
133 
134 #ifndef DONT_USE_CMA
135 #ifdef MSOS_TYPE_LINUX_KERNEL
136 #include "drvCMAPool_v2.h"
137 #else
138 #include "drvCMAPool.h"
139 #endif //#ifdef MSOS_TYPE_LINUX_KERNEL
140 #include "halCHIP.h"
141 #endif // #ifndef DONT_USE_CMA
142 
143 #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
_DEFAULT_IOCTL_CMD(DMD_ISDBT_HAL_COMMAND eCmd,void * pArgs)144 static MS_BOOL _DEFAULT_IOCTL_CMD(DMD_ISDBT_HAL_COMMAND eCmd, void *pArgs)
145 {
146     #ifdef REMOVE_HAL_INTERN_ISDBT
147     printf("LINK ERROR: REMOVE_HAL_INTERN_ISDBT \n");
148     #else
149     printf("LINK ERROR: Please link ext demod library \n");
150     #endif
151 
152     return TRUE;
153 }
154 
155 #ifdef REMOVE_HAL_INTERN_ISDBT
156 MS_BOOL HAL_INTERN_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_COMMAND eCmd, void *pArgs)  __attribute__((weak, alias ("_DEFAULT_IOCTL_CMD")));
157 #else
158 MS_BOOL HAL_INTERN_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_COMMAND eCmd, void *pArgs);
159 #endif
160 MS_BOOL HAL_EXTERN_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_COMMAND eCmd, void *pArgs)  __attribute__((weak, alias ("_DEFAULT_IOCTL_CMD")));
161 #else
162 MS_BOOL HAL_EXTERN_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_COMMAND eCmd, void *pArgs);
163 #endif
164 
165 //-------------------------------------------------------------------------------------------------
166 //  Local Defines
167 //-------------------------------------------------------------------------------------------------
168 
169 #if DMD_ISDBT_UTOPIA_EN && !DMD_ISDBT_UTOPIA2_EN
170  #define DMD_LOCK()      \
171      do {                         \
172         MS_ASSERT(MsOS_In_Interrupt() == FALSE); \
173         if (_s32DMD_ISDBT_Mutex == -1) return FALSE; \
174         if (_u8DMD_ISDBT_DbgLevel == DMD_ISDBT_DBGLV_DEBUG) printf("%s lock mutex\n", __FUNCTION__);\
175         MsOS_ObtainMutex(_s32DMD_ISDBT_Mutex, MSOS_WAIT_FOREVER);\
176         } while(0)
177 
178  #define DMD_UNLOCK()      \
179      do {                         \
180         MsOS_ReleaseMutex(_s32DMD_ISDBT_Mutex);\
181         if (_u8DMD_ISDBT_DbgLevel == DMD_ISDBT_DBGLV_DEBUG) printf("%s unlock mutex\n", __FUNCTION__); \
182         } while(0)
183 #elif (!DMD_ISDBT_UTOPIA_EN && !DMD_ISDBT_UTOPIA2_EN && DMD_ISDBT_MULTI_THREAD_SAFE)
184  #define DMD_LOCK()    do { pRes->sDMD_ISDBT_InitData.LockDMD(TRUE); } while(0)
185  #define DMD_UNLOCK()  do { pRes->sDMD_ISDBT_InitData.LockDMD(FALSE); } while(0)
186 #else
187  #define DMD_LOCK()
188  #define DMD_UNLOCK()
189 #endif
190 
191 #ifdef MS_DEBUG
192 #define DMD_DBG(x)          (x)
193 #else
194 #define DMD_DBG(x)          //(x)
195 #endif
196 
197 //-------------------------------------------------------------------------------------------------
198 //  Local Structurs
199 //-------------------------------------------------------------------------------------------------
200 
201 //-------------------------------------------------------------------------------------------------
202 //  Global Variables
203 //-------------------------------------------------------------------------------------------------
204 
205 MS_U8 u8DMD_ISDBT_DMD_ID = 0;
206 
207 #if !DMD_ISDBT_UTOPIA2_EN
208 DMD_ISDBT_ResData sDMD_ISDBT_ResData[DMD_ISDBT_MAX_DEMOD_NUM] = { { {0} , {0} , {0} } };
209 
210 DMD_ISDBT_ResData *psDMD_ISDBT_ResData = sDMD_ISDBT_ResData;
211 #else
212 DMD_ISDBT_ResData *psDMD_ISDBT_ResData;
213 #endif
214 
215 #ifdef UTPA2
216 static void* _ppISDBTInstant = NULL;
217 #endif
218 //-------------------------------------------------------------------------------------------------
219 //  Local Variables
220 //-------------------------------------------------------------------------------------------------
221 
222 #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
223 static MSIF_Version _drv_dmd_isdbt_version;/* = {
224     .MW = { DMD_ISDBT_VER, },
225 };*/
226 #endif
227 
228 #if DMD_ISDBT_UTOPIA_EN && !DMD_ISDBT_UTOPIA2_EN
229 static MS_S32 _s32DMD_ISDBT_Mutex = -1;
230 #endif
231 
232 #ifndef DONT_USE_CMA
233 static struct CMA_Pool_Init_Param  _ISDBT_CMA_Pool_Init_PARAM; // for MApi_CMA_Pool_Init
234 static struct CMA_Pool_Alloc_Param _ISDBT_CMA_Alloc_PARAM;     // for MApi_CMA_Pool_GetMem
235 static struct CMA_Pool_Free_Param  _ISDBT_CMA_Free_PARAM;      // for MApi_CMA_Pool_PutMem
236 #endif
237 
238 #ifdef UTPA2
239 static MS_U32 _u32ISDBTopen = 0;
240 #endif
241 
242 static DMD_ISDBT_DbgLv _u8DMD_ISDBT_DbgLevel = DMD_ISDBT_DBGLV_NONE;
243 
244 //-------------------------------------------------------------------------------------------------
245 //  Debug Functions
246 //-------------------------------------------------------------------------------------------------
247 
248 
249 
250 //-------------------------------------------------------------------------------------------------
251 //  Local Functions
252 //-------------------------------------------------------------------------------------------------
253 
_ISDBT_CheckLock(void)254 static DMD_ISDBT_LOCK_STATUS _ISDBT_CheckLock(void)
255 {
256     MS_BOOL (*ioctl)(DMD_ISDBT_HAL_COMMAND eCmd, void *pPara);
257 
258     DMD_ISDBT_ResData  *pRes  = psDMD_ISDBT_ResData + u8DMD_ISDBT_DMD_ID;
259     DMD_ISDBT_InitData *pInit = &(pRes->sDMD_ISDBT_InitData);
260     DMD_ISDBT_Info     *pInfo = &(pRes->sDMD_ISDBT_Info);
261 
262     ioctl = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD;
263 
264     if (ioctl(DMD_ISDBT_HAL_CMD_Check_FEC_Lock, NULL))
265     {
266         pInfo->u32ISDBTLockStatus |= DMD_ISDBT_LOCK_FEC_LOCK;
267         #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
268         pInfo->u32ISDBTFECLockTime = MsOS_GetSystemTime();
269         #else
270         pInfo->u32ISDBTFECLockTime = pInit->GetSystemTimeMS();
271         #endif
272         return DMD_ISDBT_LOCK;
273     }
274     else
275     {
276         #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
277         if ((pInfo->u32ISDBTLockStatus & DMD_ISDBT_LOCK_FEC_LOCK) && ((MsOS_GetSystemTime()-pInfo->u32ISDBTFECLockTime) < 100))
278         #else
279         if ((pInfo->u32ISDBTLockStatus & DMD_ISDBT_LOCK_FEC_LOCK) && ((pInit->GetSystemTimeMS()-pInfo->u32ISDBTFECLockTime) < 100))
280         #endif
281         {
282             return DMD_ISDBT_LOCK;
283         }
284         else
285         {
286             pInfo->u32ISDBTLockStatus &= (~DMD_ISDBT_LOCK_FEC_LOCK);
287         }
288 
289         if (pInfo->u32ISDBTLockStatus & DMD_ISDBT_LOCK_ICFO_CH_EXIST_LOCK) //STEP 3
290         {
291             #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
292             if ((MsOS_GetSystemTime()-pInfo->u32ISDBTScanTimeStart) < pInit->u16ISDBTFECLockCheckTime)
293             #else
294             if ((pInit->GetSystemTimeMS()-pInfo->u32ISDBTScanTimeStart) < pInit->u16ISDBTFECLockCheckTime)
295             #endif
296             {
297                 return DMD_ISDBT_CHECKING;
298             }
299         }
300         else //STEP 1,2
301         {
302             if (ioctl(DMD_ISDBT_HAL_CMD_Check_ICFO_CH_EXIST_Lock, NULL))
303             {
304                 pInfo->u32ISDBTLockStatus |= DMD_ISDBT_LOCK_ICFO_CH_EXIST_LOCK;
305                 #ifdef MS_DEBUG
306                 if (_u8DMD_ISDBT_DbgLevel >= DMD_ISDBT_DBGLV_DEBUG)
307                 {
308                     printf("DMD_ISDBT_LOCK_ICFO_CH_EXIST_LOCK\n");
309                 }
310                 #endif
311                 return DMD_ISDBT_CHECKING;
312             }
313             else
314             {
315                 #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
316                 if ((MsOS_GetSystemTime()-pInfo->u32ISDBTScanTimeStart) < pInit->u16ISDBTIcfoChExistCheckTime)
317                 #else
318                 if ((pInit->GetSystemTimeMS()-pInfo->u32ISDBTScanTimeStart) < pInit->u16ISDBTIcfoChExistCheckTime)
319                 #endif
320                 {
321                     return DMD_ISDBT_CHECKING;
322                 }
323             }
324         }
325         return DMD_ISDBT_UNLOCK;
326     }
327 }
328 
329 //-------------------------------------------------------------------------------------------------
330 //  Global Functions
331 //-------------------------------------------------------------------------------------------------
332 
333 #ifdef UTPA2
_MDrv_DMD_ISDBT_SetDbgLevel(DMD_ISDBT_DbgLv u8DbgLevel)334 MS_BOOL _MDrv_DMD_ISDBT_SetDbgLevel(DMD_ISDBT_DbgLv u8DbgLevel)
335 #else
336 MS_BOOL MDrv_DMD_ISDBT_SetDbgLevel(DMD_ISDBT_DbgLv u8DbgLevel)
337 #endif
338 {
339     _u8DMD_ISDBT_DbgLevel = u8DbgLevel;
340 
341     return TRUE;
342 }
343 
344 #ifdef UTPA2
_MDrv_DMD_ISDBT_GetInfo(void)345 DMD_ISDBT_Info* _MDrv_DMD_ISDBT_GetInfo(void)
346 #else
347 DMD_ISDBT_Info* MDrv_DMD_ISDBT_GetInfo(void)
348 #endif
349 {
350     psDMD_ISDBT_ResData->sDMD_ISDBT_Info.u8Version = 0;
351 
352     return &(psDMD_ISDBT_ResData->sDMD_ISDBT_Info);
353 }
354 
355 #ifdef UTPA2
_MDrv_DMD_ISDBT_GetLibVer(const MSIF_Version ** ppVersion)356 MS_BOOL _MDrv_DMD_ISDBT_GetLibVer(const MSIF_Version **ppVersion)
357 #else
358 MS_BOOL MDrv_DMD_ISDBT_GetLibVer(const MSIF_Version **ppVersion)
359 #endif
360 {
361     if (!ppVersion) return FALSE;
362 
363     #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
364     *ppVersion = &_drv_dmd_isdbt_version;
365     #else
366     *ppVersion = NULL;
367     #endif
368 
369     return TRUE;
370 }
371 
372 ////////////////////////////////////////////////////////////////////////////////
373 ///                            SINGLE DEMOD API                              ///
374 ////////////////////////////////////////////////////////////////////////////////
375 
376 #ifndef MSOS_TYPE_LINUX_KERNEL
MDrv_DMD_ISDBT_Init(DMD_ISDBT_InitData * pDMD_ISDBT_InitData,MS_U32 u32InitDataLen)377 MS_BOOL MDrv_DMD_ISDBT_Init(DMD_ISDBT_InitData *pDMD_ISDBT_InitData, MS_U32 u32InitDataLen)
378 {
379     return MDrv_DMD_ISDBT_MD_Init(0, pDMD_ISDBT_InitData, u32InitDataLen);
380 }
381 
MDrv_DMD_ISDBT_Exit(void)382 MS_BOOL MDrv_DMD_ISDBT_Exit(void)
383 {
384     return MDrv_DMD_ISDBT_MD_Exit(0);
385 }
386 
MDrv_DMD_ISDBT_GetConfig(DMD_ISDBT_InitData * psDMD_ISDBT_InitData)387 MS_U32 MDrv_DMD_ISDBT_GetConfig(DMD_ISDBT_InitData *psDMD_ISDBT_InitData)
388 {
389     return MDrv_DMD_ISDBT_MD_GetConfig(0, psDMD_ISDBT_InitData);
390 }
391 
MDrv_DMD_ISDBT_GetFwVer(MS_U16 * pu16FwVer)392 MS_BOOL MDrv_DMD_ISDBT_GetFwVer(MS_U16 *pu16FwVer)
393 {
394     return TRUE;
395 }
396 
MDrv_DMD_ISDBT_SetReset(void)397 void MDrv_DMD_ISDBT_SetReset(void)
398 {
399     return MDrv_DMD_ISDBT_MD_SetReset(0);
400 }
401 
MDrv_DMD_ISDBT_AdvSetConfig(DMD_ISDBT_DEMOD_TYPE eType,MS_BOOL bEnable)402 MS_BOOL MDrv_DMD_ISDBT_AdvSetConfig(DMD_ISDBT_DEMOD_TYPE eType, MS_BOOL bEnable)
403 {
404     return MDrv_DMD_ISDBT_MD_AdvSetConfig(0, eType, bEnable);
405 }
406 
MDrv_DMD_ISDBT_SetConfig(MS_BOOL bEnable)407 MS_BOOL MDrv_DMD_ISDBT_SetConfig(MS_BOOL bEnable)
408 {
409     return MDrv_DMD_ISDBT_MD_SetConfig(0, bEnable);
410 }
411 
MDrv_DMD_ISDBT_SetActive(MS_BOOL bEnable)412 MS_BOOL MDrv_DMD_ISDBT_SetActive(MS_BOOL bEnable)
413 {
414     return MDrv_DMD_ISDBT_MD_SetActive(0, bEnable);
415 }
416 
417 #if DMD_ISDBT_STR_EN
MDrv_DMD_ISDBT_SetPowerState(EN_POWER_MODE u16PowerState)418 MS_U32 MDrv_DMD_ISDBT_SetPowerState(EN_POWER_MODE u16PowerState)
419 {
420     return MDrv_DMD_ISDBT_MD_SetPowerState(0, u16PowerState);
421 }
422 #endif
423 
MDrv_DMD_ISDBT_GetLock(DMD_ISDBT_GETLOCK_TYPE eType)424 DMD_ISDBT_LOCK_STATUS MDrv_DMD_ISDBT_GetLock(DMD_ISDBT_GETLOCK_TYPE eType)
425 {
426     return MDrv_DMD_ISDBT_MD_GetLock(0, eType);
427 }
428 
MDrv_DMD_ISDBT_GetModulationMode(EN_ISDBT_Layer eLayerIndex,sISDBT_MODULATION_MODE * sIsdbtModulationMode)429 MS_BOOL MDrv_DMD_ISDBT_GetModulationMode(EN_ISDBT_Layer eLayerIndex, sISDBT_MODULATION_MODE *sIsdbtModulationMode)
430 {
431     return MDrv_DMD_ISDBT_MD_GetModulationMode(0, eLayerIndex, sIsdbtModulationMode);
432 }
433 
MDrv_DMD_ISDBT_GetSignalStrength(MS_U16 * u16Strength)434 MS_BOOL MDrv_DMD_ISDBT_GetSignalStrength(MS_U16 *u16Strength)
435 {
436     return MDrv_DMD_ISDBT_MD_GetSignalStrength(0, u16Strength);
437 }
438 
MDrv_DMD_ISDBT_GetFreqOffset(float * pFreqOff)439 MS_BOOL MDrv_DMD_ISDBT_GetFreqOffset(float *pFreqOff)
440 {
441     return MDrv_DMD_ISDBT_MD_GetFreqOffset(0, pFreqOff);
442 }
443 
MDrv_DMD_ISDBT_GetSignalQuality(void)444 MS_U16 MDrv_DMD_ISDBT_GetSignalQuality(void)
445 {
446     return MDrv_DMD_ISDBT_MD_GetSignalQuality(0);
447 }
448 
MDrv_DMD_ISDBT_GetSignalQualityOfLayerA(void)449 MS_U16 MDrv_DMD_ISDBT_GetSignalQualityOfLayerA(void)
450 {
451     return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(0);
452 }
453 
MDrv_DMD_ISDBT_GetSignalQualityOfLayerB(void)454 MS_U16 MDrv_DMD_ISDBT_GetSignalQualityOfLayerB(void)
455 {
456     return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB(0);
457 }
458 
MDrv_DMD_ISDBT_GetSignalQualityOfLayerC(void)459 MS_U16 MDrv_DMD_ISDBT_GetSignalQualityOfLayerC(void)
460 {
461     return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(0);
462 }
463 
MDrv_DMD_ISDBT_GetSignalQualityCombine(void)464 MS_U16 MDrv_DMD_ISDBT_GetSignalQualityCombine(void)
465 {
466     return MDrv_DMD_ISDBT_MD_GetSignalQualityCombine(0);
467 }
468 
MDrv_DMD_ISDBT_GetSNR(float * f_snr)469 MS_BOOL MDrv_DMD_ISDBT_GetSNR(float *f_snr)
470 {
471     return MDrv_DMD_ISDBT_MD_GetSNR(0, f_snr);
472 }
473 
MDrv_DMD_ISDBT_GetPreViterbiBer(EN_ISDBT_Layer eLayerIndex,float * fber)474 MS_BOOL MDrv_DMD_ISDBT_GetPreViterbiBer(EN_ISDBT_Layer eLayerIndex, float *fber)
475 {
476     return MDrv_DMD_ISDBT_MD_GetPreViterbiBer(0, eLayerIndex, fber);
477 }
478 
MDrv_DMD_ISDBT_GetPostViterbiBer(EN_ISDBT_Layer eLayerIndex,float * fber)479 MS_BOOL MDrv_DMD_ISDBT_GetPostViterbiBer(EN_ISDBT_Layer eLayerIndex, float *fber)
480 {
481     return MDrv_DMD_ISDBT_MD_GetPostViterbiBer(0, eLayerIndex, fber);
482 }
483 
MDrv_DMD_ISDBT_Read_PKT_ERR(EN_ISDBT_Layer eLayerIndex,MS_U16 * u16PacketErr)484 MS_BOOL MDrv_DMD_ISDBT_Read_PKT_ERR(EN_ISDBT_Layer eLayerIndex, MS_U16 *u16PacketErr)
485 {
486     return MDrv_DMD_ISDBT_MD_Read_PKT_ERR(0, eLayerIndex, u16PacketErr);
487 }
488 
MDrv_DMD_ISDBT_SetSerialControl(MS_U8 u8TsConfigData)489 MS_BOOL MDrv_DMD_ISDBT_SetSerialControl(MS_U8 u8TsConfigData)
490 {
491     return MDrv_DMD_ISDBT_MD_SetSerialControl(0, u8TsConfigData);
492 }
493 
MDrv_DMD_ISDBT_IIC_BYPASS_MODE(MS_BOOL bEnable)494 MS_BOOL MDrv_DMD_ISDBT_IIC_BYPASS_MODE(MS_BOOL bEnable)
495 {
496     return MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE(0, bEnable);
497 }
498 
MDrv_DMD_ISDBT_SWITCH_SSPI_GPIO(MS_BOOL bEnable)499 MS_BOOL MDrv_DMD_ISDBT_SWITCH_SSPI_GPIO(MS_BOOL bEnable)
500 {
501     return MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO(0, bEnable);
502 }
503 
MDrv_DMD_ISDBT_GPIO_GET_LEVEL(MS_U8 u8Pin,MS_BOOL * bLevel)504 MS_BOOL MDrv_DMD_ISDBT_GPIO_GET_LEVEL(MS_U8 u8Pin, MS_BOOL *bLevel)
505 {
506     return MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL(0, u8Pin, bLevel);
507 }
508 
MDrv_DMD_ISDBT_GPIO_SET_LEVEL(MS_U8 u8Pin,MS_BOOL bLevel)509 MS_BOOL MDrv_DMD_ISDBT_GPIO_SET_LEVEL(MS_U8 u8Pin, MS_BOOL bLevel)
510 {
511     return MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL(0, u8Pin, bLevel);
512 }
513 
MDrv_DMD_ISDBT_GPIO_OUT_ENABLE(MS_U8 u8Pin,MS_BOOL bEnableOut)514 MS_BOOL MDrv_DMD_ISDBT_GPIO_OUT_ENABLE(MS_U8 u8Pin, MS_BOOL bEnableOut)
515 {
516     return MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE(0, u8Pin, bEnableOut);
517 }
518 
MDrv_DMD_ISDBT_DoIQSwap(MS_BOOL bIsQPad)519 MS_BOOL MDrv_DMD_ISDBT_DoIQSwap(MS_BOOL bIsQPad)
520 {
521     return MDrv_DMD_ISDBT_MD_DoIQSwap(0, bIsQPad);
522 }
523 
MDrv_DMD_ISDBT_GetReg(MS_U16 u16Addr,MS_U8 * pu8Data)524 MS_BOOL MDrv_DMD_ISDBT_GetReg(MS_U16 u16Addr, MS_U8 *pu8Data)
525 {
526     return MDrv_DMD_ISDBT_MD_GetReg(0, u16Addr, pu8Data);
527 }
528 
MDrv_DMD_ISDBT_SetReg(MS_U16 u16Addr,MS_U8 u8Data)529 MS_BOOL MDrv_DMD_ISDBT_SetReg(MS_U16 u16Addr, MS_U8 u8Data)
530 {
531     return MDrv_DMD_ISDBT_MD_SetReg(0, u16Addr, u8Data);
532 }
533 #endif // #ifndef MSOS_TYPE_LINUX_KERNEL
534 
535 ////////////////////////////////////////////////////////////////////////////////
536 ///                            MULTI DEMOD API                               ///
537 ////////////////////////////////////////////////////////////////////////////////
538 
539 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_Init(MS_U8 id,DMD_ISDBT_InitData * pDMD_ISDBT_InitData,MS_U32 u32InitDataLen)540 MS_BOOL _MDrv_DMD_ISDBT_MD_Init(MS_U8 id, DMD_ISDBT_InitData *pDMD_ISDBT_InitData, MS_U32 u32InitDataLen)
541 #else
542 MS_BOOL MDrv_DMD_ISDBT_MD_Init(MS_U8 id, DMD_ISDBT_InitData *pDMD_ISDBT_InitData, MS_U32 u32InitDataLen)
543 #endif
544 {
545     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
546     MS_PHY phyNonPMBankSize;
547     #ifndef DONT_USE_CMA
548     MS_U32  u32PhysicalAddr_FromVA = 0, u32HeapStartPAAddress = 0;
549     #endif
550 
551     #if DMD_ISDBT_UTOPIA_EN && !DMD_ISDBT_UTOPIA2_EN
552     if (_s32DMD_ISDBT_Mutex == -1)
553     {
554         if ((_s32DMD_ISDBT_Mutex = MsOS_CreateMutex(E_MSOS_FIFO, "Mutex DMD ISDBT", MSOS_PROCESS_SHARED)) == -1)
555         {
556             DMD_DBG(printf("MDrv_DMD_ISDBT_Init Create Mutex Fail\n"));
557             return FALSE;
558         }
559     }
560     #elif (!DMD_ISDBT_UTOPIA_EN && !DMD_ISDBT_UTOPIA2_EN && DMD_ISDBT_MULTI_THREAD_SAFE)
561     if (!pRes->sDMD_ISDBT_InitData.CreateMutex(TRUE))
562     {
563         DMD_DBG(printf("MDrv_DMD_ISDBT_Init Create Mutex Fail\n"));
564         return FALSE;
565     }
566     #endif
567 
568     DMD_LOCK();
569     if (pRes->sDMD_ISDBT_PriData.bInit)
570     {
571         DMD_DBG(printf("MDrv_DMD_ISDBT_Init more than once\n"));
572         return FALSE;
573     }
574 
575     #ifdef MS_DEBUG
576     if (_u8DMD_ISDBT_DbgLevel >= DMD_ISDBT_DBGLV_INFO)
577     {
578         printf("MDrv_DMD_ISDBT_Init\n");
579     }
580     #endif
581 
582     #ifndef MSOS_TYPE_LINUX_KERNEL
583     if (sizeof(DMD_ISDBT_InitData) == u32InitDataLen)
584     {
585         memcpy(&(pRes->sDMD_ISDBT_InitData), pDMD_ISDBT_InitData, u32InitDataLen);
586     }
587     else
588     {
589         DMD_DBG(printf("MDrv_DMD_ISDBT_Init input data structure incorrect\n"));
590         return FALSE;
591     }
592     #else
593     memcpy(&(pRes->sDMD_ISDBT_InitData), pDMD_ISDBT_InitData, sizeof(DMD_ISDBT_InitData));
594     #endif
595 
596     if (!MDrv_MMIO_GetBASE(&(pRes->sDMD_ISDBT_PriData.virtDMDBaseAddr), &phyNonPMBankSize, MS_MODULE_PM))
597     {
598         #ifdef MS_DEBUG
599         printf("HAL_DMD_RegInit failure to get MS_MODULE_PM\n");
600         #endif
601         return FALSE;
602     }
603 
604     pRes->sDMD_ISDBT_PriData.bInit = TRUE;
605 
606     #ifndef DONT_USE_CMA
607     _ISDBT_CMA_Pool_Init_PARAM.heap_id = 26;
608     _ISDBT_CMA_Pool_Init_PARAM.flags = CMA_FLAG_MAP_VMA;
609 
610     if (MApi_CMA_Pool_Init(&_ISDBT_CMA_Pool_Init_PARAM) == FALSE)
611     {
612         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, get MApi_CMA_Pool_Init ERROR!!!\n", __PRETTY_FUNCTION__, __LINE__));
613     }
614     else
615     {
616         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, get pool_handle_id is %u\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Pool_Init_PARAM.pool_handle_id));
617         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, get miu is %u\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Pool_Init_PARAM.miu));
618         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, get heap_miu_start_offset is 0x%llX\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Pool_Init_PARAM.heap_miu_start_offset));
619         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, get heap_length is 0x%X\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Pool_Init_PARAM.heap_length));
620     }
621 
622     _miu_offset_to_phy(_ISDBT_CMA_Pool_Init_PARAM.miu, _ISDBT_CMA_Pool_Init_PARAM.heap_miu_start_offset, u32HeapStartPAAddress);
623 
624     _ISDBT_CMA_Alloc_PARAM.pool_handle_id = _ISDBT_CMA_Pool_Init_PARAM.pool_handle_id;
625     _ISDBT_CMA_Alloc_PARAM.offset_in_pool = (pRes->sDMD_ISDBT_InitData.u32TdiStartAddr * 16) - u32HeapStartPAAddress;	// offset_in_pool means the start_ask_addr with respect to the pool_start_addr(BA) => this will specify the start_ask_ba_addr
626     _ISDBT_CMA_Alloc_PARAM.length = 0x500000UL;
627     _ISDBT_CMA_Alloc_PARAM.flags = CMA_FLAG_VIRT_ADDR;										// we will get a start_va with respect to the start_ask_ba_addr if using CMA_FLAG_VIRT_ADDR flag
628 
629     if(MApi_CMA_Pool_GetMem(&_ISDBT_CMA_Alloc_PARAM) == FALSE)
630     {
631         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, CMA_Pool_GetMem ERROR!!\033[m\n", __PRETTY_FUNCTION__, __LINE__));
632     }
633     else
634     {
635         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, get from heap_id %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Alloc_PARAM.pool_handle_id));
636         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, ask offset 0x%llX\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Alloc_PARAM.offset_in_pool));
637         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, ask length 0x%X\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Alloc_PARAM.length));
638         DMD_DBG(printf("\033[37mFunction = %s, Line = %d, return va is 0x%X\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Alloc_PARAM.virt_addr));
639     }
640 
641     u32PhysicalAddr_FromVA = MsOS_MPool_VA2PA(_ISDBT_CMA_Alloc_PARAM.virt_addr);
642 
643     DMD_DBG(printf("#######u32PhysicalAddr_FromVA1 = [0x%x]\n", u32PhysicalAddr_FromVA));
644 
645     _miu_offset_to_phy(_ISDBT_CMA_Pool_Init_PARAM.miu,
646                        _ISDBT_CMA_Pool_Init_PARAM.heap_miu_start_offset + _ISDBT_CMA_Alloc_PARAM.offset_in_pool,
647                        u32PhysicalAddr_FromVA);
648 
649     DMD_DBG(printf("#######u32PhysicalAddr_FromVA2 = [0x%x]\n", u32PhysicalAddr_FromVA));
650 
651     DMD_DBG(printf("#######pRes->sDMD_ISDBT_InitData.u32TdiStartAddr = [0x%x]\n", (pRes->sDMD_ISDBT_InitData.u32TdiStartAddr * 16)));
652     #endif // #ifndef DONT_USE_CMA
653 
654     #if DMD_ISDBT_STR_EN
655     pRes->sDMD_ISDBT_PriData.eLastState = E_POWER_RESUME;
656     #endif
657 
658     pRes->sDMD_ISDBT_PriData.eLastType  = DMD_ISDBT_DEMOD;
659 
660     #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
661     if (pRes->sDMD_ISDBT_InitData.bIsExtDemod)
662         pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD = HAL_EXTERN_ISDBT_IOCTL_CMD;
663     else
664         pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD = HAL_INTERN_ISDBT_IOCTL_CMD;
665     #else
666     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD = HAL_EXTERN_ISDBT_IOCTL_CMD;
667     #endif
668 
669     u8DMD_ISDBT_DMD_ID = id;
670     if (!MDrv_MMIO_GetBASE(&(pRes->sDMD_ISDBT_PriData.virtDMDBaseAddr), &phyNonPMBankSize, MS_MODULE_PM))
671     {
672         #ifdef MS_DEBUG
673         printf("HAL_DMD_RegInit failure to get MS_MODULE_PM\n");
674         #endif
675         return FALSE;
676     }
677 
678     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_InitClk, NULL);
679 
680     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_Download, NULL);
681 
682     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_FWVERSION, NULL);
683     DMD_UNLOCK();
684 
685     return TRUE;
686 }
687 
688 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_Exit(MS_U8 id)689 MS_BOOL _MDrv_DMD_ISDBT_MD_Exit(MS_U8 id)
690 #else
691 MS_BOOL MDrv_DMD_ISDBT_MD_Exit(MS_U8 id)
692 #endif
693 {
694     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
695     MS_BOOL bRet = TRUE;
696 
697     DMD_LOCK();
698     u8DMD_ISDBT_DMD_ID = id;
699 
700     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_Exit, NULL);
701 
702     pRes->sDMD_ISDBT_PriData.bInit = FALSE;
703 
704     #ifndef DONT_USE_CMA
705     _ISDBT_CMA_Free_PARAM.pool_handle_id = _ISDBT_CMA_Pool_Init_PARAM.pool_handle_id;
706     _ISDBT_CMA_Free_PARAM.offset_in_pool = _ISDBT_CMA_Alloc_PARAM.offset_in_pool;
707     _ISDBT_CMA_Free_PARAM.length = 0x500000UL;;
708 
709     if(MApi_CMA_Pool_PutMem(&_ISDBT_CMA_Free_PARAM) == FALSE)
710     {
711         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, MsOS_CMA_Pool_Release ERROR!!\033[m\n", __PRETTY_FUNCTION__, __LINE__));
712     }
713     else
714     {
715         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, get from heap_id %d\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Free_PARAM.pool_handle_id));
716         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, ask offset 0x%llX\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Free_PARAM.offset_in_pool));
717         DMD_DBG(printf("\033[35mFunction = %s, Line = %d, ask length 0x%X\033[m\n", __PRETTY_FUNCTION__, __LINE__, _ISDBT_CMA_Free_PARAM.length));
718     }
719     #endif
720 
721     DMD_UNLOCK();
722 
723     #if DMD_ISDBT_UTOPIA_EN && !DMD_ISDBT_UTOPIA2_EN
724     MsOS_DeleteMutex(_s32DMD_ISDBT_Mutex);
725 
726     _s32DMD_ISDBT_Mutex = -1;
727     #elif (!DMD_ISDBT_UTOPIA_EN && !DMD_ISDBT_UTOPIA2_EN && DMD_ISDBT_MULTI_THREAD_SAFE)
728     pRes->sDMD_ISDBT_InitData.CreateMutex(FALSE);
729     #endif
730 
731     return bRet;
732 }
733 
734 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetConfig(MS_U8 id,DMD_ISDBT_InitData * psDMD_ISDBT_InitData)735 MS_U32 _MDrv_DMD_ISDBT_MD_GetConfig(MS_U8 id, DMD_ISDBT_InitData *psDMD_ISDBT_InitData)
736 #else
737 MS_U32 MDrv_DMD_ISDBT_MD_GetConfig(MS_U8 id, DMD_ISDBT_InitData *psDMD_ISDBT_InitData)
738 #endif
739 {
740     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
741 
742     DMD_LOCK();
743     memcpy (psDMD_ISDBT_InitData, &(pRes->sDMD_ISDBT_InitData), sizeof(DMD_ISDBT_InitData));
744     DMD_UNLOCK();
745 
746     return UTOPIA_STATUS_SUCCESS;
747 }
748 
749 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetFwVer(MS_U8 id,MS_U16 * pu16FwVer)750 MS_BOOL _MDrv_DMD_ISDBT_MD_GetFwVer(MS_U8 id, MS_U16 *pu16FwVer)
751 #else
752 MS_BOOL MDrv_DMD_ISDBT_MD_GetFwVer(MS_U8 id, MS_U16 *pu16FwVer)
753 #endif
754 {
755     return TRUE;
756 }
757 
MDrv_DMD_ISDBT_MD_SetReset(MS_U8 id)758 void MDrv_DMD_ISDBT_MD_SetReset(MS_U8 id)
759 {
760     return;
761 }
762 
763 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_AdvSetConfig(MS_U8 id,DMD_ISDBT_DEMOD_TYPE eType,MS_BOOL bEnable)764 MS_BOOL _MDrv_DMD_ISDBT_MD_AdvSetConfig(MS_U8 id, DMD_ISDBT_DEMOD_TYPE eType, MS_BOOL bEnable)
765 #else
766 MS_BOOL MDrv_DMD_ISDBT_MD_AdvSetConfig(MS_U8 id, DMD_ISDBT_DEMOD_TYPE eType, MS_BOOL bEnable)
767 #endif
768 {
769     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
770     MS_BOOL bRet = TRUE;
771 
772     DMD_LOCK();
773     u8DMD_ISDBT_DMD_ID = id;
774 
775     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_SoftReset, NULL);
776 
777     if (bEnable)
778     {
779         switch (eType)
780         {
781             case DMD_ISDBT_DEMOD_6M:
782             case DMD_ISDBT_DEMOD_7M:
783             case DMD_ISDBT_DEMOD_8M:
784                 if (eType != pRes->sDMD_ISDBT_PriData.eLastType)
785                 {
786                     pRes->sDMD_ISDBT_PriData.eLastType = DMD_ISDBT_DEMOD_6M;
787                     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_SetACICoef, NULL);
788                 }
789                 bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_SetISDBTMode, NULL);
790                 break;
791             default:
792                 pRes->sDMD_ISDBT_PriData.eLastType = DMD_ISDBT_DEMOD_NULL;
793                 bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_SetModeClean, NULL);
794                 break;
795         }
796     }
797 
798     #if DMD_ISDBT_UTOPIA_EN || DMD_ISDBT_UTOPIA2_EN
799     pRes->sDMD_ISDBT_Info.u32ISDBTScanTimeStart = MsOS_GetSystemTime();
800     #else
801     pRes->sDMD_ISDBT_Info.u32ISDBTScanTimeStart = psDMD_ISDBT_ResData->sDMD_ISDBT_InitData.GetSystemTimeMS();
802     #endif
803     pRes->sDMD_ISDBT_Info.u32ISDBTLockStatus    = 0;
804     DMD_UNLOCK();
805 
806     return bRet;
807 }
808 
MDrv_DMD_ISDBT_MD_SetConfig(MS_U8 id,MS_BOOL bEnable)809 MS_BOOL MDrv_DMD_ISDBT_MD_SetConfig(MS_U8 id, MS_BOOL bEnable)
810 {
811     #ifdef UTPA2
812     return _MDrv_DMD_ISDBT_MD_AdvSetConfig(id , DMD_ISDBT_DEMOD_6M, bEnable);
813     #else
814     return MDrv_DMD_ISDBT_MD_AdvSetConfig(id , DMD_ISDBT_DEMOD_6M, bEnable);
815     #endif
816 }
817 
MDrv_DMD_ISDBT_MD_SetActive(MS_U8 id,MS_BOOL bEnable)818 MS_BOOL MDrv_DMD_ISDBT_MD_SetActive(MS_U8 id, MS_BOOL bEnable)
819 {
820     return TRUE;
821 }
822 
823 #if DMD_ISDBT_STR_EN
824 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_SetPowerState(MS_U8 id,EN_POWER_MODE u16PowerState)825 MS_U32 _MDrv_DMD_ISDBT_MD_SetPowerState(MS_U8 id, EN_POWER_MODE u16PowerState)
826 #else
827 MS_U32 MDrv_DMD_ISDBT_MD_SetPowerState(MS_U8 id, EN_POWER_MODE u16PowerState)
828 #endif
829 {
830     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
831     MS_U32 u32Return = UTOPIA_STATUS_FAIL;
832 
833     if (u16PowerState == E_POWER_SUSPEND)
834     {
835         pRes->sDMD_ISDBT_PriData.bDownloaded = FALSE;
836         pRes->sDMD_ISDBT_PriData.bIsDTV      = pRes->sDMD_ISDBT_PriData.bInit;
837         pRes->sDMD_ISDBT_PriData.eLastState  = u16PowerState;
838 
839         if(pRes->sDMD_ISDBT_PriData.bInit)
840         {
841             #ifdef UTPA2
842             _MDrv_DMD_ISDBT_MD_Exit(id);
843             #else
844             MDrv_DMD_ISDBT_MD_Exit(id);
845             #endif
846         }
847 
848         u32Return = UTOPIA_STATUS_SUCCESS;
849     }
850     else if (u16PowerState == E_POWER_RESUME)
851     {
852         if (pRes->sDMD_ISDBT_PriData.eLastState == E_POWER_SUSPEND)
853         {
854             printf("\nVT: (Check Mode In DRV:) DTV Mode=%d\n", pRes->sDMD_ISDBT_PriData.bIsDTV);
855 
856             if (pRes->sDMD_ISDBT_PriData.bIsDTV)
857             {
858                 #ifdef UTPA2
859                 _MDrv_DMD_ISDBT_MD_Init(id, &(pRes->sDMD_ISDBT_InitData), sizeof(DMD_ISDBT_InitData));
860                 _MDrv_DMD_ISDBT_MD_DoIQSwap(id, pRes->sDMD_ISDBT_PriData.bIsQPad);
861                 _MDrv_DMD_ISDBT_MD_AdvSetConfig(id, pRes->sDMD_ISDBT_PriData.eLastType, TRUE);
862                 #else
863                 MDrv_DMD_ISDBT_MD_Init(id, &(pRes->sDMD_ISDBT_InitData), sizeof(DMD_ISDBT_InitData));
864                 MDrv_DMD_ISDBT_MD_DoIQSwap(id, pRes->sDMD_ISDBT_PriData.bIsQPad);
865                 MDrv_DMD_ISDBT_MD_AdvSetConfig(id, pRes->sDMD_ISDBT_PriData.eLastType, TRUE);
866                 #endif
867             }
868 
869             pRes->sDMD_ISDBT_PriData.eLastState = u16PowerState;
870 
871             u32Return = UTOPIA_STATUS_SUCCESS;
872         }
873         else
874         {
875             printf("[%s,%5d]It is not suspended yet. We shouldn't resume\n",__FUNCTION__,__LINE__);
876 
877             u32Return = UTOPIA_STATUS_FAIL;
878 	    }
879     }
880     else
881     {
882         printf("[%s,%5d]Do Nothing: %d\n",__FUNCTION__,__LINE__, u16PowerState);
883 
884         u32Return = UTOPIA_STATUS_FAIL;
885     }
886 
887     return u32Return;
888 }
889 #endif
890 
891 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetLock(MS_U8 id,DMD_ISDBT_GETLOCK_TYPE eType)892 DMD_ISDBT_LOCK_STATUS _MDrv_DMD_ISDBT_MD_GetLock(MS_U8 id, DMD_ISDBT_GETLOCK_TYPE eType)
893 #else
894 DMD_ISDBT_LOCK_STATUS MDrv_DMD_ISDBT_MD_GetLock(MS_U8 id, DMD_ISDBT_GETLOCK_TYPE eType)
895 #endif
896 {
897     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
898     DMD_ISDBT_LOCK_STATUS status  = DMD_ISDBT_UNLOCK;
899 
900     DMD_LOCK();
901     u8DMD_ISDBT_DMD_ID = id;
902 
903     switch (eType)
904     {
905         case DMD_ISDBT_GETLOCK:
906             status = _ISDBT_CheckLock();
907             break;
908         case DMD_ISDBT_GETLOCK_FSA_TRACK_LOCK:
909             status = (pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_Check_FSA_TRACK_Lock, NULL)) ? DMD_ISDBT_LOCK : DMD_ISDBT_UNLOCK;
910             break;
911         case DMD_ISDBT_GETLOCK_PSYNC_LOCK:
912             status = (pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_Check_PSYNC_Lock, NULL)) ? DMD_ISDBT_LOCK : DMD_ISDBT_UNLOCK;
913             break;
914         case DMD_ISDBT_GETLOCK_ICFO_CH_EXIST_LOCK:
915             status = (pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_Check_ICFO_CH_EXIST_Lock, NULL)) ? DMD_ISDBT_LOCK : DMD_ISDBT_UNLOCK;
916             break;
917         case DMD_ISDBT_GETLOCK_FEC_LOCK:
918             status = (pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_Check_FEC_Lock, NULL)) ? DMD_ISDBT_LOCK : DMD_ISDBT_UNLOCK;
919             break;
920         default:
921             status = DMD_ISDBT_UNLOCK;
922             break;
923     }
924     DMD_UNLOCK();
925 
926     return status;
927 }
928 
929 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetModulationMode(MS_U8 id,EN_ISDBT_Layer eLayerIndex,sISDBT_MODULATION_MODE * sIsdbtModulationMode)930 MS_BOOL _MDrv_DMD_ISDBT_MD_GetModulationMode(MS_U8 id, EN_ISDBT_Layer eLayerIndex, sISDBT_MODULATION_MODE *sIsdbtModulationMode)
931 #else
932 MS_BOOL MDrv_DMD_ISDBT_MD_GetModulationMode(MS_U8 id, EN_ISDBT_Layer eLayerIndex, sISDBT_MODULATION_MODE *sIsdbtModulationMode)
933 #endif
934 {
935     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
936     MS_BOOL bRet = TRUE;
937 
938     DMD_ISDBT_GET_MODULATION       sIsdbtGetModulationMode;
939     DMD_ISDBT_GET_TimeInterleaving sIsdbtGetTimeInterleaving;
940     DMD_ISDBT_GET_CodeRate         sIsdbtGetCodeRate;
941 
942     sIsdbtGetModulationMode.eIsdbtLayer   = eLayerIndex;
943     sIsdbtGetTimeInterleaving.eIsdbtLayer = eLayerIndex;
944     sIsdbtGetCodeRate.eIsdbtLayer         = eLayerIndex;
945 
946     DMD_LOCK();
947     u8DMD_ISDBT_DMD_ID = id;
948 
949     bRet &= pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalCodeRate, &sIsdbtGetCodeRate);
950     sIsdbtModulationMode->eIsdbtCodeRate = sIsdbtGetCodeRate.eCodeRate;
951     bRet &= pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalGuardInterval, &(sIsdbtModulationMode->eIsdbtGI));
952     bRet &= pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalTimeInterleaving, &sIsdbtGetTimeInterleaving);
953     sIsdbtModulationMode->eIsdbtTDI = sIsdbtGetTimeInterleaving.eTimeInterleaving;
954     bRet &= pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalFFTValue, &(sIsdbtModulationMode->eIsdbtFFT));
955     bRet &= pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalModulation, &sIsdbtGetModulationMode);
956     sIsdbtModulationMode->eIsdbtConstellation = sIsdbtGetModulationMode.eConstellation;
957     DMD_UNLOCK();
958 
959     return bRet;
960 }
961 
962 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetSignalStrength(MS_U8 id,MS_U16 * u16Strength)963 MS_BOOL _MDrv_DMD_ISDBT_MD_GetSignalStrength(MS_U8 id, MS_U16 *u16Strength)
964 #else
965 MS_BOOL MDrv_DMD_ISDBT_MD_GetSignalStrength(MS_U8 id, MS_U16 *u16Strength)
966 #endif
967 {
968     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
969     MS_BOOL bRet = TRUE;
970 
971     DMD_LOCK();
972     u8DMD_ISDBT_DMD_ID = id;
973 
974     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_ReadIFAGC, u16Strength);
975     DMD_UNLOCK();
976 
977     return bRet;
978 }
979 
980 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetFreqOffset(MS_U8 id,DMD_ISDBT_CFO_DATA * cfo)981 MS_BOOL _MDrv_DMD_ISDBT_MD_GetFreqOffset(MS_U8 id, DMD_ISDBT_CFO_DATA *cfo)
982 #else
983 MS_BOOL MDrv_DMD_ISDBT_MD_GetFreqOffset(MS_U8 id, float *cfo)
984 #endif
985 {
986     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
987     MS_BOOL bRet = TRUE;
988 
989     DMD_LOCK();
990     u8DMD_ISDBT_DMD_ID = id;
991 
992     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetFreqOffset, cfo);
993     DMD_UNLOCK();
994 
995     return bRet;
996 }
997 
998 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetSignalQuality(MS_U8 id)999 MS_U16 _MDrv_DMD_ISDBT_MD_GetSignalQuality(MS_U8 id)
1000 #else
1001 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQuality(MS_U8 id)
1002 #endif
1003 {
1004     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1005     MS_U16 u16SignalQuality = 0;
1006 
1007     DMD_LOCK();
1008     u8DMD_ISDBT_DMD_ID = id;
1009 
1010     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalQuality, &u16SignalQuality);
1011     DMD_UNLOCK();
1012 
1013     return u16SignalQuality;
1014 }
1015 
1016 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(MS_U8 id)1017 MS_U16 _MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(MS_U8 id)
1018 #else
1019 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(MS_U8 id)
1020 #endif
1021 {
1022     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1023     MS_U16 u16SignalQuality = 0;
1024 
1025     DMD_LOCK();
1026     u8DMD_ISDBT_DMD_ID = id;
1027 
1028     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalQualityOfLayerA, &u16SignalQuality);
1029     DMD_UNLOCK();
1030 
1031     return u16SignalQuality;
1032 }
1033 
1034 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB(MS_U8 id)1035 MS_U16 _MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB(MS_U8 id)
1036 #else
1037 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB(MS_U8 id)
1038 #endif
1039 {
1040     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1041     MS_U16 u16SignalQuality = 0;
1042 
1043     DMD_LOCK();
1044     u8DMD_ISDBT_DMD_ID = id;
1045 
1046     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalQualityOfLayerB, &u16SignalQuality);
1047     DMD_UNLOCK();
1048 
1049     return u16SignalQuality;
1050 }
1051 
1052 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(MS_U8 id)1053 MS_U16 _MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(MS_U8 id)
1054 #else
1055 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(MS_U8 id)
1056 #endif
1057 {
1058     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1059     MS_U16 u16SignalQuality = 0;
1060 
1061     DMD_LOCK();
1062     u8DMD_ISDBT_DMD_ID = id;
1063 
1064     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalQualityOfLayerC, &u16SignalQuality);
1065     DMD_UNLOCK();
1066 
1067     return u16SignalQuality;
1068 }
1069 
1070 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetSignalQualityCombine(MS_U8 id)1071 MS_U16 _MDrv_DMD_ISDBT_MD_GetSignalQualityCombine(MS_U8 id)
1072 #else
1073 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityCombine(MS_U8 id)
1074 #endif
1075 {
1076     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1077     MS_U16 u16SignalQuality = 0;
1078 
1079     DMD_LOCK();
1080     u8DMD_ISDBT_DMD_ID = id;
1081 
1082     pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSignalQualityCombine, &u16SignalQuality);
1083     DMD_UNLOCK();
1084 
1085     return u16SignalQuality;
1086 }
1087 
1088 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetSNR(MS_U8 id,DMD_ISDBT_SNR_DATA * f_snr)1089 MS_BOOL _MDrv_DMD_ISDBT_MD_GetSNR(MS_U8 id, DMD_ISDBT_SNR_DATA *f_snr)
1090 #else
1091 MS_BOOL MDrv_DMD_ISDBT_MD_GetSNR(MS_U8 id, float *f_snr)
1092 #endif
1093 {
1094     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1095     MS_BOOL bRet = TRUE;
1096 
1097     DMD_LOCK();
1098     u8DMD_ISDBT_DMD_ID = id;
1099 
1100     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetSNR, f_snr);
1101     DMD_UNLOCK();
1102 
1103     return bRet;
1104 }
1105 
1106 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetPreViterbiBer(MS_U8 id,DMD_ISDBT_GET_BER_VALUE * ber)1107 MS_BOOL _MDrv_DMD_ISDBT_MD_GetPreViterbiBer(MS_U8 id, DMD_ISDBT_GET_BER_VALUE *ber)
1108 #else
1109 MS_BOOL MDrv_DMD_ISDBT_MD_GetPreViterbiBer(MS_U8 id, EN_ISDBT_Layer eLayerIndex, float *fber)
1110 #endif
1111 {
1112     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1113     MS_BOOL bRet = TRUE;
1114 
1115     #ifndef UTPA2
1116     DMD_ISDBT_GET_BER_VALUE sIsdbtGetBerValue;
1117     sIsdbtGetBerValue.eIsdbtLayer = eLayerIndex;
1118     #endif
1119 
1120     DMD_LOCK();
1121     u8DMD_ISDBT_DMD_ID = id;
1122 
1123     #ifdef UTPA2
1124     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetPreViterbiBer, ber);
1125     #else
1126     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetPreViterbiBer, &sIsdbtGetBerValue);
1127     #endif
1128     DMD_UNLOCK();
1129 
1130     #ifndef UTPA2
1131     *fber = sIsdbtGetBerValue.fBerValue;
1132     #endif
1133 
1134     return bRet;
1135 }
1136 
1137 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetPostViterbiBer(MS_U8 id,DMD_ISDBT_GET_BER_VALUE * ber)1138 MS_BOOL _MDrv_DMD_ISDBT_MD_GetPostViterbiBer(MS_U8 id, DMD_ISDBT_GET_BER_VALUE *ber)
1139 #else
1140 MS_BOOL MDrv_DMD_ISDBT_MD_GetPostViterbiBer(MS_U8 id, EN_ISDBT_Layer eLayerIndex, float *fber)
1141 #endif
1142 {
1143     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1144     MS_BOOL bRet = TRUE;
1145 
1146     #ifndef UTPA2
1147     DMD_ISDBT_GET_BER_VALUE sIsdbtGetBerValue;
1148     sIsdbtGetBerValue.eIsdbtLayer = eLayerIndex;
1149     #endif
1150 
1151     DMD_LOCK();
1152     u8DMD_ISDBT_DMD_ID = id;
1153 
1154     #ifdef UTPA2
1155     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetPostViterbiBer, ber);
1156     #else
1157     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GetPostViterbiBer, &sIsdbtGetBerValue);
1158     #endif
1159     DMD_UNLOCK();
1160 
1161     #ifndef UTPA2
1162     *fber = sIsdbtGetBerValue.fBerValue;
1163     #endif
1164 
1165     return bRet;
1166 }
1167 
1168 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_Read_PKT_ERR(MS_U8 id,EN_ISDBT_Layer eLayerIndex,MS_U16 * u16PacketErr)1169 MS_BOOL _MDrv_DMD_ISDBT_MD_Read_PKT_ERR(MS_U8 id, EN_ISDBT_Layer eLayerIndex, MS_U16 *u16PacketErr)
1170 #else
1171 MS_BOOL MDrv_DMD_ISDBT_MD_Read_PKT_ERR(MS_U8 id, EN_ISDBT_Layer eLayerIndex, MS_U16 *u16PacketErr)
1172 #endif
1173 {
1174     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1175     MS_BOOL bRet = TRUE;
1176 
1177     DMD_ISDBT_GET_PKT_ERR sIsdbtGetPktErr;
1178 
1179     sIsdbtGetPktErr.eIsdbtLayer = eLayerIndex;
1180 
1181     DMD_LOCK();
1182     u8DMD_ISDBT_DMD_ID = id;
1183 
1184     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_Read_PKT_ERR, &sIsdbtGetPktErr);
1185     DMD_UNLOCK();
1186 
1187     *u16PacketErr = sIsdbtGetPktErr.u16PacketErr;
1188 
1189     return bRet;
1190 }
1191 
1192 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_SetSerialControl(MS_U8 id,MS_U8 u8TsConfigData)1193 MS_BOOL _MDrv_DMD_ISDBT_MD_SetSerialControl(MS_U8 id, MS_U8 u8TsConfigData)
1194 #else
1195 MS_BOOL MDrv_DMD_ISDBT_MD_SetSerialControl(MS_U8 id, MS_U8 u8TsConfigData)
1196 #endif
1197 {
1198     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1199     MS_BOOL bRet = TRUE;
1200 
1201     DMD_LOCK();
1202     pRes->sDMD_ISDBT_InitData.u1TsConfigByte_SerialMode = u8TsConfigData;
1203     pRes->sDMD_ISDBT_InitData.u1TsConfigByte_DataSwap   = u8TsConfigData >> 1;
1204     pRes->sDMD_ISDBT_InitData.u1TsConfigByte_ClockInv   = u8TsConfigData >> 2;
1205     pRes->sDMD_ISDBT_InitData.u5TsConfigByte_DivNum     = u8TsConfigData >> 3;
1206 
1207     u8DMD_ISDBT_DMD_ID = id;
1208 
1209     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_TS_INTERFACE_CONFIG, NULL);
1210     DMD_UNLOCK();
1211 
1212     return bRet;
1213 }
1214 
1215 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE(MS_U8 id,MS_BOOL bEnable)1216 MS_BOOL _MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE(MS_U8 id, MS_BOOL bEnable)
1217 #else
1218 MS_BOOL MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE(MS_U8 id, MS_BOOL bEnable)
1219 #endif
1220 {
1221     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1222     MS_BOOL bRet = TRUE;
1223 
1224     DMD_LOCK();
1225     u8DMD_ISDBT_DMD_ID = id;
1226 
1227     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_IIC_Bypass_Mode, &bEnable);
1228     DMD_UNLOCK();
1229 
1230     return bRet;
1231 }
1232 
1233 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO(MS_U8 id,MS_BOOL bEnable)1234 MS_BOOL _MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO(MS_U8 id, MS_BOOL bEnable)
1235 #else
1236 MS_BOOL MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO(MS_U8 id, MS_BOOL bEnable)
1237 #endif
1238 {
1239     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1240     MS_BOOL bRet = TRUE;
1241 
1242     DMD_LOCK();
1243     u8DMD_ISDBT_DMD_ID = id;
1244 
1245     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_SSPI_TO_GPIO, &bEnable);
1246     DMD_UNLOCK();
1247 
1248     return bRet;
1249 }
1250 
1251 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL(MS_U8 id,MS_U8 u8Pin,MS_BOOL * bLevel)1252 MS_BOOL _MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL(MS_U8 id, MS_U8 u8Pin, MS_BOOL *bLevel)
1253 #else
1254 MS_BOOL MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL(MS_U8 id, MS_U8 u8Pin, MS_BOOL *bLevel)
1255 #endif
1256 {
1257     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1258     DMD_ISDBT_GPIO_PIN_DATA sPin;
1259     MS_BOOL bRet = TRUE;
1260 
1261     sPin.u8Pin = u8Pin;
1262 
1263     DMD_LOCK();
1264     u8DMD_ISDBT_DMD_ID = id;
1265 
1266     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GPIO_GET_LEVEL, &sPin);
1267     DMD_UNLOCK();
1268 
1269     *bLevel = sPin.bLevel;
1270 
1271     return bRet;
1272 }
1273 
1274 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL(MS_U8 id,MS_U8 u8Pin,MS_BOOL bLevel)1275 MS_BOOL _MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL(MS_U8 id, MS_U8 u8Pin, MS_BOOL bLevel)
1276 #else
1277 MS_BOOL MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL(MS_U8 id, MS_U8 u8Pin, MS_BOOL bLevel)
1278 #endif
1279 {
1280     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1281     DMD_ISDBT_GPIO_PIN_DATA sPin;
1282     MS_BOOL bRet = TRUE;
1283 
1284     sPin.u8Pin  = u8Pin;
1285     sPin.bLevel = bLevel;
1286 
1287     DMD_LOCK();
1288     u8DMD_ISDBT_DMD_ID = id;
1289 
1290     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GPIO_SET_LEVEL, &sPin);
1291     DMD_UNLOCK();
1292 
1293     return bRet;
1294 }
1295 
1296 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE(MS_U8 id,MS_U8 u8Pin,MS_BOOL bEnableOut)1297 MS_BOOL _MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE(MS_U8 id, MS_U8 u8Pin, MS_BOOL bEnableOut)
1298 #else
1299 MS_BOOL MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE(MS_U8 id, MS_U8 u8Pin, MS_BOOL bEnableOut)
1300 #endif
1301 {
1302     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1303     DMD_ISDBT_GPIO_PIN_DATA sPin;
1304     MS_BOOL bRet = TRUE;
1305 
1306     sPin.u8Pin  = u8Pin;
1307     sPin.bIsOut = bEnableOut;
1308 
1309     DMD_LOCK();
1310     u8DMD_ISDBT_DMD_ID = id;
1311 
1312     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GPIO_OUT_ENABLE, &sPin);
1313     DMD_UNLOCK();
1314 
1315     return bRet;
1316 }
1317 
1318 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_DoIQSwap(MS_U8 id,MS_BOOL bIsQPad)1319 MS_BOOL _MDrv_DMD_ISDBT_MD_DoIQSwap(MS_U8 id, MS_BOOL bIsQPad)
1320 #else
1321 MS_BOOL MDrv_DMD_ISDBT_MD_DoIQSwap(MS_U8 id, MS_BOOL bIsQPad)
1322 #endif
1323 {
1324     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1325     MS_BOOL bRet = TRUE;
1326 
1327     DMD_LOCK();
1328     u8DMD_ISDBT_DMD_ID = id;
1329 
1330     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_DoIQSwap, &bIsQPad);
1331     DMD_UNLOCK();
1332 
1333     return bRet;
1334 }
1335 
1336 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_GetReg(MS_U8 id,MS_U16 u16Addr,MS_U8 * pu8Data)1337 MS_BOOL _MDrv_DMD_ISDBT_MD_GetReg(MS_U8 id, MS_U16 u16Addr, MS_U8 *pu8Data)
1338 #else
1339 MS_BOOL MDrv_DMD_ISDBT_MD_GetReg(MS_U8 id, MS_U16 u16Addr, MS_U8 *pu8Data)
1340 #endif
1341 {
1342     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1343     DMD_ISDBT_REG_DATA reg;
1344     MS_BOOL bRet = TRUE;
1345 
1346     reg.u16Addr = u16Addr;
1347 
1348     DMD_LOCK();
1349     u8DMD_ISDBT_DMD_ID = id;
1350 
1351     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_GET_REG, &reg);
1352     DMD_UNLOCK();
1353 
1354     *pu8Data = reg.u8Data;
1355 
1356     return bRet;
1357 }
1358 
1359 #ifdef UTPA2
_MDrv_DMD_ISDBT_MD_SetReg(MS_U8 id,MS_U16 u16Addr,MS_U8 u8Data)1360 MS_BOOL _MDrv_DMD_ISDBT_MD_SetReg(MS_U8 id, MS_U16 u16Addr, MS_U8 u8Data)
1361 #else
1362 MS_BOOL MDrv_DMD_ISDBT_MD_SetReg(MS_U8 id, MS_U16 u16Addr, MS_U8 u8Data)
1363 #endif
1364 {
1365     DMD_ISDBT_ResData *pRes = psDMD_ISDBT_ResData + id;
1366     DMD_ISDBT_REG_DATA reg;
1367     MS_BOOL bRet = TRUE;
1368 
1369     reg.u16Addr = u16Addr;
1370     reg.u8Data  = u8Data;
1371 
1372     DMD_LOCK();
1373     u8DMD_ISDBT_DMD_ID = id;
1374 
1375     bRet = pRes->sDMD_ISDBT_PriData.HAL_DMD_ISDBT_IOCTL_CMD(DMD_ISDBT_HAL_CMD_SET_REG, &reg);
1376     DMD_UNLOCK();
1377 
1378     return bRet;
1379 }
1380 
1381 
1382 #ifdef UTPA2
1383 ////////////////////////////////////////////////////////////////////////////////
1384 ///                            Utopia2 Interface                             ///
1385 ////////////////////////////////////////////////////////////////////////////////
1386 #ifndef MSOS_TYPE_LINUX_KERNEL
1387 
1388 #ifndef MSOS_TYPE_LINUX
1389 static const float _LogApproxTableX[80] =
1390 { 1.00, 1.30, 1.69, 2.20, 2.86, 3.71, 4.83, 6.27, 8.16, 10.60, 13.79,
1391   17.92, 23.30, 30.29, 39.37, 51.19, 66.54, 86.50, 112.46, 146.19,
1392   190.05, 247.06, 321.18, 417.54, 542.80, 705.64, 917.33, 1192.53,
1393   1550.29, 2015.38, 2620.00, 3405.99, 4427.79, 5756.13, 7482.97,
1394   9727.86, 12646.22, 16440.08, 21372.11, 27783.74, 36118.86,
1395   46954.52, 61040.88, 79353.15, 103159.09, 134106.82, 174338.86,
1396   226640.52, 294632.68, 383022.48, 497929.22, 647307.99, 841500.39, 1093950.50,
1397   1422135.65, 1848776.35, 2403409.25, 3124432.03, 4061761.64, 5280290.13,
1398   6864377.17, 8923690.32, 11600797.42, 15081036.65, 19605347.64, 25486951.94,
1399   33133037.52, 43072948.77, 55994833.40, 72793283.42, 94631268.45,
1400   123020648.99, 159926843.68, 207904896.79, 270276365.82, 351359275.57,
1401   456767058.24, 593797175.72, 771936328.43, 1003517226.96
1402 };
1403 
1404 static const float _LogApproxTableY[80] =
1405 { 0.00, 0.11, 0.23, 0.34, 0.46, 0.57, 0.68, 0.80, 0.91, 1.03, 1.14, 1.25,
1406   1.37, 1.48, 1.60, 1.71, 1.82, 1.94, 2.05, 2.16, 2.28, 2.39, 2.51, 2.62,
1407   2.73, 2.85, 2.96, 3.08, 3.19, 3.30, 3.42, 3.53, 3.65, 3.76, 3.87, 3.99,
1408   4.10, 4.22, 4.33, 4.44, 4.56, 4.67, 4.79, 4.90, 5.01, 5.13, 5.24, 5.36,
1409   5.47, 5.58, 5.70, 5.81, 5.93, 6.04, 6.15, 6.27, 6.04, 6.15, 6.27, 6.38,
1410   6.49, 6.61, 6.72, 6.84, 6.95, 7.06, 7.18, 7.29, 7.41, 7.52, 7.63, 7.75,
1411   7.86, 7.98, 8.09, 8.20, 8.32, 8.43, 8.55, 8.66
1412 };
1413 
Log10Approx(float flt_x)1414 static float Log10Approx(float flt_x)
1415 {
1416     MS_U8  indx = 0;
1417 
1418     do {
1419         if (flt_x < _LogApproxTableX[indx])
1420             break;
1421         indx++;
1422     }while (indx < 79);   //stop at indx = 80
1423 
1424     return _LogApproxTableY[indx];
1425 }
1426 #endif
1427 
CALCULATE_SQI(float fber)1428 static MS_U16 CALCULATE_SQI(float fber)
1429 {
1430     float flog_ber;
1431     MS_U16 u16SQI;
1432 
1433     #ifdef MSOS_TYPE_LINUX
1434     flog_ber = (float)log10((double)fber);
1435     #else
1436     if (fber != 0.0)
1437         flog_ber = (float)(-1.0*Log10Approx((double)(1.0 / fber)));
1438     else
1439         flog_ber = -8.0;//when fber=0 means u16SQI=100
1440     #endif
1441 
1442     if (flog_ber <= ( - 7.0))
1443     {
1444         u16SQI = 100;    //*quality = 100;
1445     }
1446     else if (flog_ber < -6.0)
1447     {
1448         u16SQI = (90+((( - 6.0) - flog_ber) / (( - 6.0) - ( - 7.0))*(100-90)));
1449     }
1450     else if (flog_ber < -5.5)
1451     {
1452         u16SQI = (80+((( - 5.5) - flog_ber) / (( - 5.5) - ( - 6.0))*(90-80)));
1453     }
1454     else if (flog_ber < -5.0)
1455     {
1456         u16SQI = (70+((( - 5.0) - flog_ber) / (( - 5.0) - ( - 5.5))*(80-70)));
1457     }
1458     else if (flog_ber < -4.5)
1459     {
1460         u16SQI = (60+((( - 4.5) - flog_ber) / (( -4.5) - ( - 5.0))*(70-50)));
1461     }
1462     else if (flog_ber < -4.0)
1463     {
1464         u16SQI = (50+((( - 4.0) - flog_ber) / (( - 4.0) - ( - 45))*(60-50)));
1465     }
1466     else if (flog_ber < -3.5)
1467     {
1468         u16SQI = (40+((( - 3.5) - flog_ber) / (( - 3.5) - ( - 4.0))*(50-40)));
1469     }
1470     else if (flog_ber < -3.0)
1471     {
1472         u16SQI = (30+((( - 3.0) - flog_ber) / (( - 3.0) - ( - 3.5))*(40-30)));
1473     }
1474     else if (flog_ber < -2.5)
1475     {
1476         u16SQI = (20+((( - 2.5) - flog_ber) / (( - 2.5) - ( -3.0))*(30-20)));
1477     }
1478     else if (flog_ber < -2.0)
1479     {
1480         u16SQI = (0+((( - 2.0) - flog_ber) / (( - 2.0) - ( - 2.5))*(20-0)));
1481     }
1482     else
1483     {
1484         u16SQI = 0;
1485     }
1486 
1487     return u16SQI;
1488 }
1489 
1490 
MDrv_DMD_ISDBT_SetDbgLevel(DMD_ISDBT_DbgLv u8DbgLevel)1491 MS_BOOL MDrv_DMD_ISDBT_SetDbgLevel(DMD_ISDBT_DbgLv u8DbgLevel)
1492 {
1493     ISDBT_DBG_LEVEL_PARAM DbgLevelParam = {0};
1494 
1495     if (!_u32ISDBTopen) return FALSE;
1496 
1497     DbgLevelParam.u8DbgLevel = u8DbgLevel;
1498 
1499     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_SetDbgLevel, &DbgLevelParam) == UTOPIA_STATUS_SUCCESS)
1500     {
1501         return TRUE;
1502     }
1503     else
1504     {
1505         return FALSE;
1506     }
1507 }
1508 
MDrv_DMD_ISDBT_GetInfo(void)1509 DMD_ISDBT_Info* MDrv_DMD_ISDBT_GetInfo(void)
1510 {
1511     ISDBT_GET_INFO_PARAM GetInfoParam = {0};
1512 
1513     if (!_u32ISDBTopen) return NULL;
1514 
1515     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_GetInfo, &GetInfoParam) == UTOPIA_STATUS_SUCCESS)
1516     {
1517         return GetInfoParam.pInfo;
1518     }
1519     else
1520     {
1521         return NULL;
1522     }
1523 }
1524 
MDrv_DMD_ISDBT_GetLibVer(const MSIF_Version ** ppVersion)1525 MS_BOOL MDrv_DMD_ISDBT_GetLibVer(const MSIF_Version **ppVersion)
1526 {
1527     ISDBT_GET_LIB_VER_PARAM GetLibVerParam = {0};
1528 
1529     if (!_u32ISDBTopen) return FALSE;
1530 
1531     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_GetLibVer, &GetLibVerParam) == UTOPIA_STATUS_SUCCESS)
1532     {
1533         *ppVersion = NULL;//*GetLibVerParam.ppVersion;
1534 
1535         return TRUE;
1536     }
1537     else
1538     {
1539         return FALSE;
1540     }
1541 }
1542 
MDrv_DMD_ISDBT_MD_Init(MS_U8 id,DMD_ISDBT_InitData * pDMD_ISDBT_InitData,MS_U32 u32InitDataLen)1543 MS_BOOL MDrv_DMD_ISDBT_MD_Init(MS_U8 id, DMD_ISDBT_InitData *pDMD_ISDBT_InitData, MS_U32 u32InitDataLen)
1544 {
1545     void* pAttribte = NULL;
1546     ISDBT_INIT_PARAM InitParam = {0};
1547 
1548     if (_u32ISDBTopen == 0)
1549     {
1550         if (UtopiaOpen(MODULE_ISDBT /*| KERNEL_MODE*/, &_ppISDBTInstant, 0, pAttribte) == UTOPIA_STATUS_SUCCESS)
1551             _u32ISDBTopen = 1;
1552         else
1553             return FALSE;
1554     }
1555 
1556     if (!_u32ISDBTopen) return FALSE;
1557 
1558     InitParam.id = id;
1559     InitParam.pDMD_ISDBT_InitData = pDMD_ISDBT_InitData;
1560     InitParam.u32InitDataLen = u32InitDataLen;
1561 
1562     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_Init, &InitParam) == UTOPIA_STATUS_SUCCESS)
1563     {
1564         return TRUE;
1565     }
1566     else
1567     {
1568         return FALSE;
1569     }
1570 }
1571 
MDrv_DMD_ISDBT_MD_Exit(MS_U8 id)1572 MS_BOOL MDrv_DMD_ISDBT_MD_Exit(MS_U8 id)
1573 {
1574     ISDBT_ID_PARAM IdParam = {0};
1575 
1576     if (!_u32ISDBTopen) return FALSE;
1577 
1578     IdParam.id = id;
1579 
1580     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_Exit, &IdParam) == UTOPIA_STATUS_SUCCESS)
1581     {
1582         return TRUE;
1583     }
1584     else
1585     {
1586         return FALSE;
1587     }
1588 }
1589 
MDrv_DMD_ISDBT_MD_GetConfig(MS_U8 id,DMD_ISDBT_InitData * psDMD_ISDBT_InitData)1590 MS_U32 MDrv_DMD_ISDBT_MD_GetConfig(MS_U8 id, DMD_ISDBT_InitData *psDMD_ISDBT_InitData)
1591 {
1592     ISDBT_INIT_PARAM InitParam = {0};
1593 
1594     if (!_u32ISDBTopen) return FALSE;
1595 
1596     InitParam.id = id;
1597     InitParam.pDMD_ISDBT_InitData = psDMD_ISDBT_InitData;
1598 
1599     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetConfig, &InitParam) == UTOPIA_STATUS_SUCCESS)
1600     {
1601         return UTOPIA_STATUS_SUCCESS;
1602     }
1603     else
1604     {
1605         return UTOPIA_STATUS_ERR_NOT_AVAIL;
1606     }
1607 }
1608 
MDrv_DMD_ISDBT_MD_AdvSetConfig(MS_U8 id,DMD_ISDBT_DEMOD_TYPE eType,MS_BOOL bEnable)1609 MS_BOOL MDrv_DMD_ISDBT_MD_AdvSetConfig(MS_U8 id, DMD_ISDBT_DEMOD_TYPE eType, MS_BOOL bEnable)
1610 {
1611     ISDBT_SET_CONFIG_PARAM SetConfigParam = {0};
1612 
1613     if (!_u32ISDBTopen) return FALSE;
1614 
1615     SetConfigParam.id = id;
1616     SetConfigParam.eType = eType;
1617     SetConfigParam.bEnable = bEnable;
1618 
1619     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_AdvSetConfig, &SetConfigParam) == UTOPIA_STATUS_SUCCESS)
1620     {
1621         return TRUE;
1622     }
1623     else
1624     {
1625         return FALSE;
1626     }
1627 }
1628 
1629 #if DMD_ISDBT_STR_EN
MDrv_DMD_ISDBT_MD_SetPowerState(MS_U8 id,EN_POWER_MODE u16PowerState)1630 MS_U32 MDrv_DMD_ISDBT_MD_SetPowerState(MS_U8 id, EN_POWER_MODE u16PowerState)
1631 {
1632     ISDBT_SET_POWER_STATE_PARAM SetPowerStateParam = {0};
1633 
1634     if (!_u32ISDBTopen) return FALSE;
1635 
1636     SetPowerStateParam.id = id;
1637     SetPowerStateParam.u16PowerState = u16PowerState;
1638 
1639     return UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_SetPowerState, &SetPowerStateParam);
1640 }
1641 #endif
1642 
MDrv_DMD_ISDBT_MD_GetLock(MS_U8 id,DMD_ISDBT_GETLOCK_TYPE eType)1643 DMD_ISDBT_LOCK_STATUS MDrv_DMD_ISDBT_MD_GetLock(MS_U8 id, DMD_ISDBT_GETLOCK_TYPE eType)
1644 {
1645     ISDBT_GET_LOCK_PARAM GetLockParam = {0};
1646 
1647     if (!_u32ISDBTopen) return DMD_ISDBT_NULL;
1648 
1649     GetLockParam.id = id;
1650     GetLockParam.eType = eType;
1651 
1652     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetLock, &GetLockParam) == UTOPIA_STATUS_SUCCESS)
1653     {
1654         return GetLockParam.status;
1655     }
1656     else
1657     {
1658         return DMD_ISDBT_NULL;
1659     }
1660 }
1661 
MDrv_DMD_ISDBT_MD_GetModulationMode(MS_U8 id,EN_ISDBT_Layer eLayerIndex,sISDBT_MODULATION_MODE * sIsdbtModulationMode)1662 MS_BOOL MDrv_DMD_ISDBT_MD_GetModulationMode(MS_U8 id, EN_ISDBT_Layer eLayerIndex, sISDBT_MODULATION_MODE *sIsdbtModulationMode)
1663 {
1664     ISDBT_GET_MODULATION_MODE_PARAM GetModulationModeParam = {0};
1665 
1666     if (!_u32ISDBTopen) return FALSE;
1667 
1668     GetModulationModeParam.eLayerIndex = eLayerIndex;
1669     GetModulationModeParam.id = id;
1670 
1671     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetModulationMode, &GetModulationModeParam) == UTOPIA_STATUS_SUCCESS)
1672     {
1673         *sIsdbtModulationMode = GetModulationModeParam.IsdbtModulationMode;
1674         return TRUE;
1675     }
1676     else
1677     {
1678         return FALSE;
1679     }
1680 }
1681 
MDrv_DMD_ISDBT_MD_GetSignalStrength(MS_U8 id,MS_U16 * u16Strength)1682 MS_BOOL MDrv_DMD_ISDBT_MD_GetSignalStrength(MS_U8 id, MS_U16 *u16Strength)
1683 {
1684     ISDBT_GET_SIGNAL_STRENGTH_PARAM GetSignalStrengthParam = {0};
1685 
1686     if (!_u32ISDBTopen) return FALSE;
1687 
1688     GetSignalStrengthParam.id = id;
1689 
1690     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetSignalStrength, &GetSignalStrengthParam) == UTOPIA_STATUS_SUCCESS)
1691     {
1692         *u16Strength = GetSignalStrengthParam.u16Strength;
1693 
1694         return TRUE;
1695     }
1696     else
1697     {
1698         return FALSE;
1699     }
1700 }
1701 
MDrv_DMD_ISDBT_MD_GetFreqOffset(MS_U8 id,float * cfo)1702 MS_BOOL MDrv_DMD_ISDBT_MD_GetFreqOffset(MS_U8 id, float *cfo)
1703 {
1704     ISDBT_GET_FREQ_OFFSET_PARAM GetFreqOffsetParam = {0};
1705     float   fTdCfoFreq = 0.0;
1706     float   fFdCfoFreq = 0.0;
1707     float   fICfoFreq = 0.0;
1708 
1709     if (!_u32ISDBTopen) return FALSE;
1710 
1711     GetFreqOffsetParam.id = id;
1712 
1713     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetFreqOffset, &GetFreqOffsetParam) == UTOPIA_STATUS_SUCCESS)
1714     {
1715         fTdCfoFreq = ((float)GetFreqOffsetParam.cfo.TdCfoRegValue) / 17179869184.0; //<25,34>
1716         fTdCfoFreq = fTdCfoFreq * 8126980.0;
1717 
1718         fFdCfoFreq = ((float)GetFreqOffsetParam.cfo.FdCfoRegValue) / 17179869184.0;
1719         fFdCfoFreq = fFdCfoFreq * 8126980.0;
1720 
1721         if((GetFreqOffsetParam.cfo.FFT_Mode & 0x30) == 0x0000) // 2k
1722             fICfoFreq = (float)GetFreqOffsetParam.cfo.IcfoRegValue*250000.0/63.0;
1723         else if((GetFreqOffsetParam.cfo.FFT_Mode & 0x0030) == 0x0010)	// 4k
1724             fICfoFreq = (float)GetFreqOffsetParam.cfo.IcfoRegValue*125000.0/63.0;
1725         else //if(u16data & 0x0030 == 0x0020) // 8k
1726             fICfoFreq = (float)GetFreqOffsetParam.cfo.IcfoRegValue*125000.0/126.0;
1727 
1728         *cfo = fTdCfoFreq + fFdCfoFreq + fICfoFreq;
1729 
1730         return TRUE;
1731     }
1732     else
1733     {
1734         *cfo = 0;
1735 
1736         return FALSE;
1737     }
1738 }
1739 
MDrv_DMD_ISDBT_MD_GetSignalQuality(MS_U8 id)1740 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQuality(MS_U8 id)
1741 {
1742     return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(id);
1743 }
1744 
MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(MS_U8 id)1745 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(MS_U8 id)
1746 {
1747     ISDBT_GET_BER_PARAM GetBerParam = {0};
1748     ISDBT_GET_LOCK_PARAM GetLockParam = {0};
1749 
1750     if (!_u32ISDBTopen) return 0;
1751 
1752     GetLockParam.id = GetBerParam.id = id;
1753     GetLockParam.eType = DMD_ISDBT_GETLOCK_FEC_LOCK;
1754     GetBerParam.ber.eIsdbtLayer= E_ISDBT_Layer_A;
1755 
1756     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetLock, &GetLockParam) == UTOPIA_STATUS_SUCCESS)
1757     {
1758         if(GetLockParam.status == DMD_ISDBT_LOCK)
1759         {
1760             if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetPostViterbiBer, &GetBerParam) == UTOPIA_STATUS_SUCCESS)
1761             {
1762                 if(GetBerParam.ber.BerPeriod == 0) GetBerParam.ber.BerPeriod = 1;
1763 
1764                 return CALCULATE_SQI((float)GetBerParam.ber.BerValue/GetBerParam.ber.BerPeriod/(128.0*188.0*8.0));
1765             }
1766         }
1767     }
1768 
1769     return 0;
1770 
1771 }
1772 
MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB(MS_U8 id)1773 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB(MS_U8 id)
1774 {
1775     ISDBT_GET_BER_PARAM GetBerParam = {0};
1776     ISDBT_GET_LOCK_PARAM GetLockParam = {0};
1777 
1778     if (!_u32ISDBTopen) return 0;
1779 
1780     GetLockParam.id = GetBerParam.id = id;
1781     GetLockParam.eType = DMD_ISDBT_GETLOCK_FEC_LOCK;
1782     GetBerParam.ber.eIsdbtLayer= E_ISDBT_Layer_B;
1783 
1784     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetLock, &GetLockParam) == UTOPIA_STATUS_SUCCESS)
1785     {
1786         if(GetLockParam.status == DMD_ISDBT_LOCK)
1787         {
1788             if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetPostViterbiBer, &GetBerParam) == UTOPIA_STATUS_SUCCESS)
1789             {
1790                 if(GetBerParam.ber.BerPeriod == 0) GetBerParam.ber.BerPeriod = 1;
1791 
1792                 return CALCULATE_SQI((float)GetBerParam.ber.BerValue/GetBerParam.ber.BerPeriod/(128.0*188.0*8.0));
1793             }
1794         }
1795     }
1796 
1797     return 0;
1798 
1799 }
1800 
MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(MS_U8 id)1801 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(MS_U8 id)
1802 {
1803     ISDBT_GET_BER_PARAM GetBerParam = {0};
1804     ISDBT_GET_LOCK_PARAM GetLockParam = {0};
1805 
1806     if (!_u32ISDBTopen) return 0;
1807 
1808     GetLockParam.id = GetBerParam.id = id;
1809     GetLockParam.eType = DMD_ISDBT_GETLOCK_FEC_LOCK;
1810     GetBerParam.ber.eIsdbtLayer= E_ISDBT_Layer_C;
1811 
1812     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetLock, &GetLockParam) == UTOPIA_STATUS_SUCCESS)
1813     {
1814         if(GetLockParam.status == DMD_ISDBT_LOCK)
1815         {
1816             if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetPostViterbiBer, &GetBerParam) == UTOPIA_STATUS_SUCCESS)
1817             {
1818                 if(GetBerParam.ber.BerPeriod == 0) GetBerParam.ber.BerPeriod = 1;
1819 
1820                 return CALCULATE_SQI((float)GetBerParam.ber.BerValue/GetBerParam.ber.BerPeriod/(128.0*188.0*8.0));
1821             }
1822         }
1823     }
1824 
1825     return 0;
1826 
1827 }
1828 
MDrv_DMD_ISDBT_MD_GetSignalQualityCombine(MS_U8 id)1829 MS_U16 MDrv_DMD_ISDBT_MD_GetSignalQualityCombine(MS_U8 id)
1830 {
1831     ISDBT_GET_MODULATION_MODE_PARAM GetModulationModeParam = {0};
1832     MS_S8  s8LayerAValue = 0, s8LayerBValue = 0, s8LayerCValue = 0;
1833     EN_ISDBT_CONSTEL_TYPE eIsdbtConstellationA = E_ISDBT_QAM_INVALID, eIsdbtConstellationB = E_ISDBT_QAM_INVALID, eIsdbtConstellationC = E_ISDBT_QAM_INVALID;
1834 
1835     if (!_u32ISDBTopen) return FALSE;
1836 
1837     GetModulationModeParam.id = id;
1838 
1839     GetModulationModeParam.eLayerIndex = E_ISDBT_Layer_A;
1840     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetModulationMode, &GetModulationModeParam) != UTOPIA_STATUS_SUCCESS) return 0;
1841     s8LayerAValue = eIsdbtConstellationA == E_ISDBT_QAM_INVALID ? -1 : (MS_S8)GetModulationModeParam.IsdbtModulationMode.eIsdbtConstellation;
1842 
1843     GetModulationModeParam.eLayerIndex = E_ISDBT_Layer_B;
1844     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetModulationMode, &GetModulationModeParam) != UTOPIA_STATUS_SUCCESS) return 0;
1845     s8LayerBValue = eIsdbtConstellationB == E_ISDBT_QAM_INVALID ? -1 : (MS_S8)GetModulationModeParam.IsdbtModulationMode.eIsdbtConstellation;
1846 
1847     GetModulationModeParam.eLayerIndex = E_ISDBT_Layer_C;
1848     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetModulationMode, &GetModulationModeParam) != UTOPIA_STATUS_SUCCESS) return 0;
1849     s8LayerCValue = eIsdbtConstellationC == E_ISDBT_QAM_INVALID ? -1 : (MS_S8)GetModulationModeParam.IsdbtModulationMode.eIsdbtConstellation;
1850 
1851     if (s8LayerAValue >= s8LayerBValue)
1852     {
1853         if (s8LayerCValue >= s8LayerAValue)
1854         {
1855             return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(id);
1856         }
1857         else  //A>C
1858         {
1859             return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA(id);
1860         }
1861     }
1862     else  // B >= A
1863     {
1864         if (s8LayerCValue >= s8LayerBValue)
1865         {
1866             return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC(id);
1867         }
1868         else  //B>C
1869         {
1870             return MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB(id);
1871         }
1872     }
1873 
1874 }
1875 
MDrv_DMD_ISDBT_MD_GetSNR(MS_U8 id,float * f_snr)1876 MS_BOOL MDrv_DMD_ISDBT_MD_GetSNR(MS_U8 id, float *f_snr)
1877 {
1878     ISDBT_GET_SNR_PARAM GetSnrParam = {0};
1879     float fSNRAvg = 0.0;
1880 
1881     if (!_u32ISDBTopen) return FALSE;
1882 
1883     GetSnrParam.id = id;
1884 
1885     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetSNR, &GetSnrParam) == UTOPIA_STATUS_SUCCESS)
1886     {
1887         fSNRAvg = (float)GetSnrParam.snr.RegSNR/GetSnrParam.snr.RegSnrObsNum;
1888 
1889         if (fSNRAvg == 0)
1890             fSNRAvg = 0.01;
1891 
1892         #ifdef MSOS_TYPE_LINUX
1893         *f_snr = 10*(float)log10f((double)fSNRAvg/2);
1894         #else
1895         *f_snr = 10*(float)Log10Approx((double)fSNRAvg/2);
1896         #endif
1897 
1898         return TRUE;
1899     }
1900     else
1901     {
1902         *f_snr = 0;
1903 
1904         return FALSE;
1905     }}
1906 
MDrv_DMD_ISDBT_MD_GetPreViterbiBer(MS_U8 id,EN_ISDBT_Layer eLayerIndex,float * fber)1907 MS_BOOL MDrv_DMD_ISDBT_MD_GetPreViterbiBer(MS_U8 id, EN_ISDBT_Layer eLayerIndex, float *fber)
1908 {
1909     ISDBT_GET_BER_PARAM GetBerParam = {0};
1910 
1911     if (!_u32ISDBTopen) return FALSE;
1912 
1913     GetBerParam.id = id;
1914     GetBerParam.ber.eIsdbtLayer= eLayerIndex;
1915     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetPreViterbiBer, &GetBerParam) == UTOPIA_STATUS_SUCCESS)
1916     {
1917         GetBerParam.ber.BerPeriod <<= 8; // *256
1918 
1919         if(GetBerParam.ber.BerPeriod == 0) GetBerParam.ber.BerPeriod = 1;
1920 
1921         *fber = (float)GetBerParam.ber.BerValue/GetBerParam.ber.BerPeriod;
1922 
1923         return TRUE;
1924     }
1925     else
1926     {
1927         *fber = 0;
1928 
1929         return FALSE;
1930     }
1931 }
1932 
MDrv_DMD_ISDBT_MD_GetPostViterbiBer(MS_U8 id,EN_ISDBT_Layer eLayerIndex,float * fber)1933 MS_BOOL MDrv_DMD_ISDBT_MD_GetPostViterbiBer(MS_U8 id, EN_ISDBT_Layer eLayerIndex, float *fber)
1934 {
1935     ISDBT_GET_BER_PARAM GetBerParam = {0};
1936 
1937     if (!_u32ISDBTopen) return FALSE;
1938 
1939     GetBerParam.id = id;
1940     GetBerParam.ber.eIsdbtLayer= eLayerIndex;
1941     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetPreViterbiBer, &GetBerParam) == UTOPIA_STATUS_SUCCESS)
1942     {
1943         if(GetBerParam.ber.BerPeriod == 0) GetBerParam.ber.BerPeriod = 1;
1944 
1945         *fber = (float)GetBerParam.ber.BerValue/GetBerParam.ber.BerPeriod/(128.0*188.0*8.0);
1946 
1947         return TRUE;
1948     }
1949     else
1950     {
1951         *fber = 0;
1952 
1953         return FALSE;
1954     }
1955 }
1956 
MDrv_DMD_ISDBT_MD_Read_PKT_ERR(MS_U8 id,EN_ISDBT_Layer eLayerIndex,MS_U16 * u16PacketErr)1957 MS_BOOL MDrv_DMD_ISDBT_MD_Read_PKT_ERR(MS_U8 id, EN_ISDBT_Layer eLayerIndex, MS_U16 *u16PacketErr)
1958 {
1959     ISDBT_READ_PKT_ERR_PARAM ReadpktErrParam = {0};
1960 
1961     if (!_u32ISDBTopen) return FALSE;
1962 
1963     ReadpktErrParam.id = id;
1964     ReadpktErrParam.eIsdbtLayer = eLayerIndex;
1965 
1966     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_Read_PKT_ERR, &ReadpktErrParam) == UTOPIA_STATUS_SUCCESS)
1967     {
1968         *u16PacketErr = ReadpktErrParam.u16PacketErr;
1969 
1970         return TRUE;
1971     }
1972     else
1973     {
1974         return FALSE;
1975     }
1976 }
1977 
MDrv_DMD_ISDBT_MD_SetSerialControl(MS_U8 id,MS_U8 u8TsConfigData)1978 MS_BOOL MDrv_DMD_ISDBT_MD_SetSerialControl(MS_U8 id, MS_U8 u8TsConfigData)
1979 {
1980     ISDBT_SET_SERIAL_CONTROL_PARAM SetSerialControlParam = {0};
1981 
1982     if (!_u32ISDBTopen) return FALSE;
1983 
1984     SetSerialControlParam.id = id;
1985     SetSerialControlParam.u8TsConfigData = u8TsConfigData;
1986 
1987     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_SetSerialControl, &SetSerialControlParam) == UTOPIA_STATUS_SUCCESS)
1988     {
1989         return TRUE;
1990     }
1991     else
1992     {
1993         return FALSE;
1994     }
1995 }
1996 
MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE(MS_U8 id,MS_BOOL bEnable)1997 MS_BOOL MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE(MS_U8 id, MS_BOOL bEnable)
1998 {
1999     ISDBT_IIC_BYPASS_MODE_PARAM IicBypassModeParam = {0};
2000 
2001     if (!_u32ISDBTopen) return FALSE;
2002 
2003     IicBypassModeParam.id = id;
2004     IicBypassModeParam.bEnable = bEnable;
2005 
2006     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_IIC_BYPASS_MODE, &IicBypassModeParam) == UTOPIA_STATUS_SUCCESS)
2007     {
2008         return TRUE;
2009     }
2010     else
2011     {
2012         return FALSE;
2013     }
2014 }
2015 
MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO(MS_U8 id,MS_BOOL bEnable)2016 MS_BOOL MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO(MS_U8 id, MS_BOOL bEnable)
2017 {
2018     ISDBT_SWITCH_SSPI_GPIO_PARAM SwitchSspiGpioParam = {0};
2019 
2020     if (!_u32ISDBTopen) return FALSE;
2021 
2022     SwitchSspiGpioParam.id = id;
2023     SwitchSspiGpioParam.bEnable = bEnable;
2024 
2025     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_SWITCH_SSPI_GPIO, &SwitchSspiGpioParam) == UTOPIA_STATUS_SUCCESS)
2026     {
2027         return TRUE;
2028     }
2029     else
2030     {
2031         return FALSE;
2032     }
2033 }
2034 
MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL(MS_U8 id,MS_U8 u8Pin,MS_BOOL * bLevel)2035 MS_BOOL MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL(MS_U8 id, MS_U8 u8Pin, MS_BOOL *bLevel)
2036 {
2037     ISDBT_GPIO_LEVEL_PARAM GpioLevelParam = {0};
2038 
2039     if (!_u32ISDBTopen) return FALSE;
2040 
2041     GpioLevelParam.id = id;
2042     GpioLevelParam.u8Pin = u8Pin;
2043 
2044     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GPIO_GET_LEVEL, &GpioLevelParam) == UTOPIA_STATUS_SUCCESS)
2045     {
2046         *bLevel = GpioLevelParam.bLevel;
2047 
2048         return TRUE;
2049     }
2050     else
2051     {
2052         return FALSE;
2053     }
2054 }
2055 
MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL(MS_U8 id,MS_U8 u8Pin,MS_BOOL bLevel)2056 MS_BOOL MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL(MS_U8 id, MS_U8 u8Pin, MS_BOOL bLevel)
2057 {
2058     ISDBT_GPIO_LEVEL_PARAM GpioLevelParam = {0};
2059 
2060     if (!_u32ISDBTopen) return FALSE;
2061 
2062     GpioLevelParam.id = id;
2063     GpioLevelParam.u8Pin = u8Pin;
2064     GpioLevelParam.bLevel = bLevel;
2065 
2066     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GPIO_SET_LEVEL, &GpioLevelParam) == UTOPIA_STATUS_SUCCESS)
2067     {
2068         return TRUE;
2069     }
2070     else
2071     {
2072         return FALSE;
2073     }
2074 }
2075 
MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE(MS_U8 id,MS_U8 u8Pin,MS_BOOL bEnableOut)2076 MS_BOOL MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE(MS_U8 id, MS_U8 u8Pin, MS_BOOL bEnableOut)
2077 {
2078     ISDBT_GPIO_OUT_ENABLE_PARAM GpioOutEnableParam = {0};
2079 
2080     if (!_u32ISDBTopen) return FALSE;
2081 
2082     GpioOutEnableParam.id = id;
2083     GpioOutEnableParam.u8Pin = u8Pin;
2084     GpioOutEnableParam.bEnableOut = bEnableOut;
2085 
2086     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GPIO_OUT_ENABLE, &GpioOutEnableParam) == UTOPIA_STATUS_SUCCESS)
2087     {
2088         return TRUE;
2089     }
2090     else
2091     {
2092         return FALSE;
2093     }
2094 }
2095 
MDrv_DMD_ISDBT_MD_DoIQSwap(MS_U8 id,MS_BOOL bIsQPad)2096 MS_BOOL MDrv_DMD_ISDBT_MD_DoIQSwap(MS_U8 id, MS_BOOL bIsQPad)
2097 {
2098     ISDBT_DO_IQ_SWAP_PARAM DoIQSwapParam = {0};
2099 
2100     if (!_u32ISDBTopen) return FALSE;
2101 
2102     DoIQSwapParam.id = id;
2103     DoIQSwapParam.bIsQPad = bIsQPad;
2104 
2105     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_DoIQSwap, &DoIQSwapParam) == UTOPIA_STATUS_SUCCESS)
2106     {
2107         return TRUE;
2108     }
2109     else
2110     {
2111         return FALSE;
2112     }
2113 }
2114 
MDrv_DMD_ISDBT_MD_GetReg(MS_U8 id,MS_U16 u16Addr,MS_U8 * pu8Data)2115 MS_BOOL MDrv_DMD_ISDBT_MD_GetReg(MS_U8 id, MS_U16 u16Addr, MS_U8 *pu8Data)
2116 {
2117     ISDBT_REG_PARAM RegParam = {0};
2118 
2119     if (!_u32ISDBTopen) return FALSE;
2120 
2121     RegParam.id = id;
2122     RegParam.u16Addr = u16Addr;
2123 
2124     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_GetReg, &RegParam) == UTOPIA_STATUS_SUCCESS)
2125     {
2126         *pu8Data = RegParam.u8Data;
2127 
2128         return TRUE;
2129     }
2130     else
2131     {
2132         return FALSE;
2133     }
2134 }
2135 
MDrv_DMD_ISDBT_MD_SetReg(MS_U8 id,MS_U16 u16Addr,MS_U8 u8Data)2136 MS_BOOL MDrv_DMD_ISDBT_MD_SetReg(MS_U8 id, MS_U16 u16Addr, MS_U8 u8Data)
2137 {
2138     ISDBT_REG_PARAM RegParam = {0};
2139 
2140     if (!_u32ISDBTopen) return FALSE;
2141 
2142     RegParam.id = id;
2143     RegParam.u16Addr = u16Addr;
2144     RegParam.u8Data = u8Data;
2145 
2146     if (UtopiaIoctl(_ppISDBTInstant, DMD_ISDBT_DRV_CMD_MD_SetReg, &RegParam) == UTOPIA_STATUS_SUCCESS)
2147     {
2148         return TRUE;
2149     }
2150     else
2151     {
2152         return FALSE;
2153     }
2154 }
2155 #endif // #ifndef MSOS_TYPE_LINUX_KERNEL
2156 
2157 #endif // #ifdef UTPA2
2158 
2159