source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/thd/7552/bthd_api.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 79.0 KB
Line 
1/*************************************************************************
2*     (c)2005-2011 Broadcom Corporation
3
4*  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5*  and may only be used, duplicated, modified or distributed pursuant to the terms and
6*  conditions of a separate, written license agreement executed between you and Broadcom
7*  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8*  no license (express or implied), right to use, or waiver of any kind with respect to the
9*  Software, and Broadcom expressly reserves all rights in and to the Software and all
10*  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11*  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12*  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. 
13*   
14*  Except as expressly set forth in the Authorized License,
15*   
16*  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17*  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18*  and to use this information only in connection with your use of Broadcom integrated circuit products.
19*   
20*  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21*  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22*  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23*  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24*  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25*  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26*  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27*  USE OR PERFORMANCE OF THE SOFTWARE.
28
29*  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30*  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31*  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32*  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33*  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34*  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35*  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36*  ANY LIMITED REMEDY.
37*
38* $brcm_Workfile: bthd_api.c $
39* $brcm_Revision: Hydra_Software_Devel/16 $
40* $brcm_Date: 3/29/12 8:53p $
41*
42* [File Description:]
43*
44* Revision History:
45*
46* $brcm_Log: /magnum/portinginterface/thd/7552/bthd_api.c $
47*
48* Hydra_Software_Devel/16   3/29/12 8:53p farshidf
49* SW7552-239: remove printf
50*
51* Hydra_Software_Devel/15   3/27/12 4:08p farshidf
52* SW7552-207: fix BBS interface
53*
54* Hydra_Software_Devel/14   3/27/12 12:03p farshidf
55* SW3461-1: update to version 4.6
56*
57* Hydra_Software_Devel/13   3/27/12 11:51a farshidf
58* SW7552-207: fix the ews
59*
60* Hydra_Software_Devel/12   3/21/12 1:46p farshidf
61* SW7552-207: move the timer outside
62*
63* Hydra_Software_Devel/11   3/5/12 4:56p farshidf
64* SW7552-223:  THD power up/down clean up
65*
66* Hydra_Software_Devel/10   3/2/12 2:10p farshidf
67* SW7552-223: implement 7552 THD Frontend PM
68*
69* Hydra_Software_Devel/9   2/9/12 2:57p farshidf
70* SW7552-205: add the new flag
71*
72* Hydra_Software_Devel/8   2/8/12 5:14p farshidf
73* SW7552-205: update to 4.0 release
74*
75* Hydra_Software_Devel/7   2/7/12 5:41p atanugul
76* SW3461-144: Change signalstrength units to 1/100th of a dBmV
77*
78* Hydra_Software_Devel/6   11/21/11 11:18p farshidf
79* SW7552-139: adapt to the new THD header API file
80*
81* Hydra_Software_Devel/5   11/9/11 6:04p farshidf
82* SW7552-145: add OFDM signa strength
83*
84* Hydra_Software_Devel/4   11/3/11 3:22p farshidf
85* SW7552-142: fix compile
86*
87* Hydra_Software_Devel/3   11/3/11 3:20p farshidf
88* SW7552-142: fix the print  msg
89*
90* Hydra_Software_Devel/2   11/1/11 5:44p farshidf
91* SW7552-61: add extra lock callback for Scan
92*
93* Hydra_Software_Devel/1   10/10/11 2:14p farshidf
94* SW7552-134: update to 2.0 of 3461 code
95*
96* Hydra_Software_Devel/58   10/10/11 1:52p farshidf
97* SW7552-134: update to match V2_0 of 3461
98*
99* Hydra_Software_Devel/57   8/30/11 3:43p farshidf
100* SWDTV-8464: stop HW to write to memory after clsoe
101*
102* Hydra_Software_Devel/56   8/26/11 6:00p farshidf
103* SW7552-60: clean up
104*
105* Hydra_Software_Devel/55   8/26/11 5:39p farshidf
106* SW7552-60: fix isdbt flag
107*
108* Hydra_Software_Devel/54   8/26/11 5:05p farshidf
109* SW7552-60: fix the isdbt soft decision
110*
111* Hydra_Software_Devel/53   8/22/11 12:48p farshidf
112* SWDTV-8318: zero the memory
113*
114* Hydra_Software_Devel/52   8/22/11 12:15p farshidf
115* SWDTV-8318: update the size
116*
117* Hydra_Software_Devel/51   8/22/11 11:07a farshidf
118* SWDTV-8318: Correct ISDB-T memory allocation and update SWDTV-7671
119*
120* Hydra_Software_Devel/49   8/19/11 12:39p farshidf
121* SW3461-1: pull status for the specfic mode only
122*
123* Hydra_Software_Devel/48   8/17/11 6:12p farshidf
124* SW3461-1: remove warning
125*
126* Hydra_Software_Devel/47   8/16/11 6:12p farshidf
127* SW7552-105: update the frontend with 3461_V1_0_RC0 label
128*
129* Hydra_Software_Devel/46   8/16/11 6:04p farshidf
130* SW7552-105: update the frontend with 3461_V1_0_RC0 label
131*
132* Hydra_Software_Devel/45   8/12/11 12:39p farshidf
133* SWDTV-8160: add the DQPSK status reporting
134*
135* Hydra_Software_Devel/44   7/28/11 11:37a farshidf
136* SWDTV-7620: change printf from WRN to MSG
137*
138* Hydra_Software_Devel/43   7/27/11 5:42p farshidf
139* SWDTV-8112: clean up
140*
141* Hydra_Software_Devel/42   7/26/11 6:12p farshidf
142* SWDTV-7399: fix the switch between DVB-T and ISDB-T
143*
144* Hydra_Software_Devel/41   7/26/11 4:04p farshidf
145* SWDTV-7399: remove warning
146*
147* Hydra_Software_Devel/40   7/26/11 3:48p farshidf
148* SWDTV-8085: remove warning
149*
150* Hydra_Software_Devel/39   7/25/11 4:25p farshidf
151* SWDTV-7399: new mode added for GuardMode to support more mode  in ISDBT
152*
153* Hydra_Software_Devel/38   7/25/11 3:40p farshidf
154* SWDTV-8085: do not overwrite the dvbt-t settings
155*
156* Hydra_Software_Devel/37   7/20/11 12:40p farshidf
157* SWDTV-7620: clean up
158*
159* Hydra_Software_Devel/36   7/20/11 12:17p farshidf
160* SWDTV-7620: merge to main
161*
162* Hydra_Software_Devel/SWDTV-7620/2   7/20/11 12:14p jchien
163* SWDTV-7620: Modified RS_SYNC Interrupt logic. Add EWS.
164*
165* Hydra_Software_Devel/SWDTV-7620/1   6/21/11 6:53p jchien
166* SWDTV-7620:  Add EWS Event
167*
168* Hydra_Software_Devel/29   6/10/11 5:42p farshidf
169* SWDTV-7471: update the compile flag
170*
171* Hydra_Software_Devel/28   6/10/11 12:17p farshidf
172* SW7552-36: allocate the ISDBT memory if it is set by nexus
173*
174* Hydra_Software_Devel/27   6/6/11 10:12a farshidf
175* SW7552-36: fix compile issue
176*
177* Hydra_Software_Devel/26   6/3/11 5:14p farshidf
178* SW7552-36: merge main
179*
180* Hydra_Software_Devel/25   6/1/11 11:50a farshidf
181* SW7552-36: clean up
182*
183* Hydra_Software_Devel/24   6/1/11 11:45a farshidf
184* SW7552-36: clean up the code
185*
186* Hydra_Software_Devel/23   5/31/11 7:38p farshidf
187* SW7552-36: remove ISDB-T warning
188*
189* Hydra_Software_Devel/22   5/27/11 10:52a farshidf
190* SW7552-36: compiel fix
191*
192* Hydra_Software_Devel/21   5/24/11 2:31p farshidf
193* SWDTV-7146: merge to main
194*
195***************************************************************************/
196#include "bstd.h"
197#include "bkni.h"
198#include "btmr.h"
199#include "bthd.h"
200#include "bthd_priv.h"
201#include "bthd_3x7x.h"
202#include "bthd_api.h"
203#include "bthd_acq.h"
204#include "bthd_acq_dvbt.h"
205#include "bthd_acq_isdbt.h"
206#include "bchp_thd_core.h"
207#include "bchp_thd_intr2.h"
208#include "bchp_thd_intr2b.h"
209#include "bchp_int_id_thd_intr2.h"
210#include "bchp_int_id_thd_intr2b.h"
211
212#ifdef BCHP_PWR_SUPPORT
213#include "bchp_pwr_resources.h"
214#include "bchp_pwr.h"
215#endif
216
217BDBG_MODULE(bthd_api);
218
219
220/***************************************************************************
221 * BTHD_P_EventIsdbtIsr()
222 ***************************************************************************/
223#ifdef BTHD_ISDBT_SUPPORT
224void BTHD_P_EventIsdbtIsr(void *p, int param)
225{
226  BTHD_3x7x_Handle pHandle = (BTHD_3x7x_Handle)p;
227  uint32_t              segs_b=0, segs_c=0;
228  uint32_t              lock_acq0, lock_acq1, lock_acq;
229  uint32_t              lock_chk, clr_chk;
230  uint32_t              a, ra;
231
232  if (pHandle->pStatus->PowerStatus != THD_ePower_On)
233      return;
234  segs_b = BREG_ReadField(pHandle->hRegister, THD_CORE_TMCC_OV_1, LAYERB_SEG);
235  segs_c = BREG_ReadField(pHandle->hRegister, THD_CORE_TMCC_OV_1, LAYERC_SEG);
236  a = (pHandle->pInternalAcquireParam->AllowRsSyncEvent);
237  ra = (pHandle->pStatus->ReacquireCount % 2);
238  pHandle->pAcquireParam->IsdbtLocaleParam.phase = !a * pHandle->pAcquireParam->IsdbtLocaleParam.phase + a * ra;
239  switch(param) {                   
240  case THD_EVENT_RS_SYNC:       
241    pHandle->pAcquireParam->IsdbtLocaleParam.set_a  = 1;
242/*      clean   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_NBERC);
243        cberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_CBERC);
244        uberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_UBERC);
245    BDBG_WRN(("clean=%0d, cberc=%0d, uberc=%0d", clean, cberc, uberc)); */
246    break;
247  case THD_EVENT_RS_SYNC_B:     
248    pHandle->pAcquireParam->IsdbtLocaleParam.set_b = 1;
249/*      clean   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_NBERC_B);
250        cberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_CBERC_B);
251        uberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_UBERC_B);
252    BDBG_WRN(("clean=%0d, cberc=%0d, uberc=%0d", clean, cberc, uberc));   */
253    break;
254  case THD_EVENT_RS_SYNC_C:     
255    pHandle->pAcquireParam->IsdbtLocaleParam.set_c = 1;
256/*      clean   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_NBERC_C);
257        cberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_CBERC_C);
258        uberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_UBERC_C);
259    BDBG_WRN(("clean=%0d, cberc=%0d, uberc=%0d", clean, cberc, uberc)); */
260    break;
261  case THD_EVENT_RS_SYNC_LOSS: 
262    pHandle->pAcquireParam->IsdbtLocaleParam.clr_a = 1;
263/*      clean   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_NBERC);
264        cberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_CBERC);
265        uberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_UBERC);
266    BDBG_WRN(("clean=%0d, cberc=%0d, uberc=%0d", clean, cberc, uberc)); */
267    break;     
268  case THD_EVENT_RS_SYNC_B_LOSS:
269    pHandle->pAcquireParam->IsdbtLocaleParam.clr_b = 1;
270/*      clean   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_NBERC_B);
271        cberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_CBERC_B);
272        uberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_UBERC_B);
273    BDBG_WRN(("clean=%0d, cberc=%0d, uberc=%0d", clean, cberc, uberc)); */
274    break;
275  case THD_EVENT_RS_SYNC_C_LOSS:
276    pHandle->pAcquireParam->IsdbtLocaleParam.clr_c = 1;
277/*      clean   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_NBERC_C);
278        cberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_CBERC_C);
279        uberc   = BREG_Read32(pHandle->hRegister, BCHP_THD_CORE_RS_UBERC_C);
280    BDBG_WRN(("clean=%0d, cberc=%0d, uberc=%0d", clean, cberc, uberc));*/
281    break;
282  }
283
284  /* On tuning, first try to lock all layers.  Then accept whatever will lock with the exception of 1-seg for layerA.  lock_acq is used from init to trk state */
285  lock_acq0 = ( (pHandle->pAcquireParam->IsdbtLocaleParam.set_a || (segs_b + segs_c == 12))  &&  (!segs_b || pHandle->pAcquireParam->IsdbtLocaleParam.set_b)  &&  (!segs_c || pHandle->pAcquireParam->IsdbtLocaleParam.set_c) );
286  lock_acq1 = ( (pHandle->pAcquireParam->IsdbtLocaleParam.set_a && (segs_b + segs_c != 12))  ||   (segs_b && pHandle->pAcquireParam->IsdbtLocaleParam.set_b)  ||  (segs_c && pHandle->pAcquireParam->IsdbtLocaleParam.set_c) );
287  lock_acq  = (lock_acq0 && !pHandle->pAcquireParam->IsdbtLocaleParam.phase) || (lock_acq1 && pHandle->pAcquireParam->IsdbtLocaleParam.phase);
288
289  clr_chk   = pHandle->pAcquireParam->IsdbtLocaleParam.clr_a || pHandle->pAcquireParam->IsdbtLocaleParam.clr_b || pHandle->pAcquireParam->IsdbtLocaleParam.clr_c;
290
291  lock_chk  = ( (pHandle->pAcquireParam->IsdbtLocaleParam.set_a && (segs_b + segs_c != 12))  ||   (segs_b && pHandle->pAcquireParam->IsdbtLocaleParam.set_b)  ||  (segs_c && pHandle->pAcquireParam->IsdbtLocaleParam.set_c) ); 
292/*  lock_chk = (lock_chk0 && !pHandle->pAcquireParam->IsdbtLocaleParam.phase) || (lock_chk1 && pHandle->pAcquireParam->IsdbtLocaleParam. phase); */
293
294  BDBG_MSG(("lock_acq=%0x, lock_chk=%0x, set_a=%0d, set_b=%0d, set_c=%0d, clr_a=%0d, clr_b=%0d, clr_c=%0d, phase=%0d", lock_acq, lock_chk, pHandle->pAcquireParam->IsdbtLocaleParam.set_a, pHandle->pAcquireParam->IsdbtLocaleParam.set_b, 
295                    pHandle->pAcquireParam->IsdbtLocaleParam.set_c,pHandle->pAcquireParam->IsdbtLocaleParam.clr_a, pHandle->pAcquireParam->IsdbtLocaleParam.clr_b, pHandle->pAcquireParam->IsdbtLocaleParam.clr_c, pHandle->pAcquireParam->IsdbtLocaleParam.phase));
296
297  if (pHandle->pInternalAcquireParam->AllowRsSyncEvent) {
298    if (lock_acq)
299      BKNI_SetEvent(pHandle->hRsSyncEvent); 
300  }
301  else {
302    if (lock_chk) {
303      pHandle->ThdLockStatus |= (1 << THD_LockStatusBit_SystemLock);   
304      if (pHandle->LockStatusTracking != ((pHandle->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1)) {
305            BDBG_MSG(("locked %0x",  ((pHandle->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1)));
306            pHandle->LockStatusTracking = ((pHandle->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1); 
307            BKNI_SetEvent(pHandle->hLockEvent);
308          }
309    } 
310    else if (clr_chk) {                                   /* enabled @ state_checklock stage */
311      pHandle->ThdLockStatus &= (0xffffffff ^ (1 << THD_LockStatusBit_SystemLock)); 
312      BDBG_MSG(("loose lock. ThdLockStatus: %0x", pHandle->ThdLockStatus));
313      BKNI_SetEvent(pHandle->hInterruptEvent);
314        }
315        BTHD_P_IsdbtResetLockSetClrFlag(pHandle); 
316  }
317 
318return;
319}
320#endif
321
322/***************************************************************************
323 * BTHD_P_EventIsr()
324 ***************************************************************************/
325void BTHD_P_EventIsr(void *p, int param)
326{
327  BTHD_3x7x_Handle pHandle = (BTHD_3x7x_Handle)p;
328
329  if (pHandle->pStatus->PowerStatus != THD_ePower_On)
330      return;
331
332  switch(param) { 
333  case THD_EVENT_FFT_SYNC:
334    BKNI_SetEvent(pHandle->hFwSyncEvent);
335    break;
336  case THD_EVENT_SP_SYNC:
337    BKNI_SetEvent(pHandle->hSpSyncEvent);
338    break;
339  case THD_EVENT_TPS_SYNC:
340    BKNI_SetEvent(pHandle->hTpsSyncEvent);
341    break;
342  case THD_EVENT_FEC_SYNC:
343    BKNI_SetEvent(pHandle->hFecSyncEvent);
344    break;
345  case THD_EVENT_FW_CORR_MAX_RDY:
346    BKNI_SetEvent(pHandle->hFwCorrMaxEvent);
347    break;
348#ifdef BTHD_ISDBT_SUPPORT
349  case THD_EVENT_TMCC_SYNC:
350    BKNI_SetEvent(pHandle->hTmccSyncEvent);
351    break;
352#endif
353  case THD_EVENT_FBCNT_ZERO:
354    BKNI_SetEvent(pHandle->hFbcntZeroEvent);
355    break;
356  case THD_EVENT_RS_SYNC:
357    if (pHandle->pInternalAcquireParam->AllowRsSyncEvent)
358      BKNI_SetEvent(pHandle->hRsSyncEvent);
359    else
360        {
361      pHandle->ThdLockStatus |= (1 << THD_LockStatusBit_SystemLock);   
362          if (pHandle->LockStatusTracking != ((pHandle->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1)) 
363          {
364                BDBG_MSG(("locked %0x",  ((pHandle->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1)));
365                pHandle->LockStatusTracking = ((pHandle->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1); 
366                BKNI_SetEvent(pHandle->hLockEvent);
367          }
368        }
369    break;
370  case THD_EVENT_RS_SYNC_LOSS:
371    pHandle->ThdLockStatus &= (0xffffffff ^ (1 << THD_LockStatusBit_SystemLock)); 
372    BKNI_SetEvent(pHandle->hInterruptEvent);
373    break;
374  }
375}
376/******************************************************************************
377 * BTHD_P_ResetEvent()
378 ******************************************************************************/
379BERR_Code BTHD_P_ResetEvent(BTHD_3x7x_Handle h)
380{
381  /* BDBG_WRN(("ResetThdEvent")); */
382  BKNI_ResetEvent(h->hFwCorrMaxEvent);
383  BKNI_ResetEvent(h->hFwSyncEvent);
384  BKNI_ResetEvent(h->hSpSyncEvent);
385  BKNI_ResetEvent(h->hTpsSyncEvent);
386  BKNI_ResetEvent(h->hFecSyncEvent);
387  BKNI_ResetEvent(h->hFbcntZeroEvent);
388  BKNI_ResetEvent(h->hRsSyncEvent);
389#ifdef BTHD_ISDBT_SUPPORT
390  BKNI_ResetEvent(h->hTmccSyncEvent);
391#endif
392 
393  return BERR_SUCCESS;
394}
395
396
397/******************************************************************************
398BTHD_P_BBSTimerFunc()
399******************************************************************************/
400BERR_Code BTHD_P_BBSTimerFunc(BTHD_Handle h)
401{
402  BTHD_3x7x_P_Handle *p3x7x;
403  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
404  /*BDBG_MSG(("BTHD_P_TimerFunc")); */
405  BKNI_SetEvent(p3x7x->hBBSInterruptEvent);
406  return BERR_SUCCESS;
407}
408
409
410/******************************************************************************
411BTHD_P_TimerFunc()
412******************************************************************************/
413BERR_Code BTHD_P_TimerFunc(BTHD_Handle h)
414{
415  BTHD_3x7x_P_Handle *p3x7x;
416  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
417  /*BDBG_MSG(("BTHD_P_TimerFunc")); */
418  BKNI_SetEvent(p3x7x->hInterruptEvent);
419  return BERR_SUCCESS;
420}
421
422
423/******************************************************************************
424 * BTHD_Open()
425 ******************************************************************************/
426BERR_Code BTHD_3x7x_Open(       BTHD_Handle *pthd,       /* [out] BTHD handle */
427                                                        BCHP_Handle hChip,    /* [in] chip handle */
428                                                        void* hRegister,              /* Register handle */
429                                                        BINT_Handle hInterrupt,             /* Interrupt handle */
430                                                        const BTHD_Settings *pDefSettings /* [in] default settings */
431                       )
432{
433  BERR_Code retCode;
434  BTHD_Handle hDev;
435  BTHD_3x7x_P_Handle *p3x7x=NULL;
436  uint32_t BufSrc;
437  BTMR_Settings sTimerSettings;
438  BDBG_ASSERT(hInterrupt);
439  BDBG_ASSERT(hChip);
440  BDBG_ASSERT(hRegister);
441  BDBG_ASSERT(pDefSettings);
442  BDBG_ASSERT(pDefSettings->hTmr);
443
444  /* allocate memory for the handle */
445  hDev = (BTHD_Handle)BKNI_Malloc(sizeof(BTHD_P_Handle));
446  if( hDev == NULL )
447  {
448     retCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
449     BDBG_ERR(("BADS_Open: BKNI_malloc() failed"));
450     goto done;
451  }
452  BKNI_Memcpy(&hDev->settings, pDefSettings, sizeof(*pDefSettings));
453   /* allocate memory for the handle */
454  p3x7x = (BTHD_3x7x_P_Handle *)BKNI_Malloc(sizeof(BTHD_3x7x_P_Handle));
455  if( p3x7x == NULL )
456  {
457     retCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
458     BDBG_ERR(("BADS_Open: BKNI_malloc() failed"));
459     goto done;
460  }
461  hDev->pImpl = (void*)p3x7x;
462  BDBG_MSG(("BTHD_3x7x_Open \n"));
463  /* initialize our handle */
464  p3x7x->hRegister = (BREG_Handle)hRegister;
465  p3x7x->hChip = hChip;
466  p3x7x->hInterrupt = hInterrupt;
467#ifdef BCHP_PWR_RESOURCE_THD_TOP
468    BCHP_PWR_AcquireResource(p3x7x->hChip, BCHP_PWR_RESOURCE_THD_TOP);
469#endif   
470
471  /*BREG_AtomicUpdate32(p3x7x->hRegister, BCHP_SUN_TOP_CTRL_SW_RESET,            BCHP_MASK(SUN_TOP_CTRL_SW_RESET, thd_sw_reset),                 BCHP_FIELD_DATA(SUN_TOP_CTRL_SW_RESET, thd_sw_reset, 1));     
472  BREG_AtomicUpdate32(p3x7x->hRegister, BCHP_SUN_TOP_CTRL_SW_RESET,              BCHP_MASK(SUN_TOP_CTRL_SW_RESET, thd_sw_reset),                 BCHP_FIELD_DATA(SUN_TOP_CTRL_SW_RESET, thd_sw_reset, 0));
473*/
474
475#ifdef BTHD_ISDBT_SUPPORT
476 if (hDev->settings.supportIsdbt) 
477  { 
478        p3x7x->pIsdbtMemory = (uint32_t *)BMEM_AllocAligned(hDev->settings.hHeap, 2334720, 3, 0 );
479        if (! p3x7x->pIsdbtMemory )
480        {
481                        retCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
482                        goto done;
483        }
484        BMEM_ConvertAddressToOffset(hDev->settings.hHeap, p3x7x->pIsdbtMemory, &BufSrc );
485        BKNI_Memset( p3x7x->pIsdbtMemory, 0x00,  2334720);
486        BufSrc = BufSrc >> 3;
487        BREG_Write32(p3x7x->hRegister,  BCHP_THD_CORE_SCB_ADDR_OFFSET, BufSrc);
488  }   
489#endif
490  p3x7x->pAcquireParam = (THD_3x7x_AcquireParam_t *)BMEM_AllocAligned(hDev->settings.hHeap, sizeof(THD_3x7x_AcquireParam_t), 0, 0 ); 
491  if (! p3x7x->pAcquireParam ) {
492    retCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
493        BDBG_ERR(("BERR_OUT_OF_SYSTEM_MEMORY"));
494    goto done;
495  }
496  BKNI_Memset( p3x7x->pAcquireParam, 0x00, sizeof( THD_3x7x_AcquireParam_t ) );
497  BMEM_ConvertAddressToOffset(hDev->settings.hHeap,  p3x7x->pAcquireParam, &BufSrc );
498  BREG_Write32(p3x7x->hRegister, BCHP_THD_CORE_SWSPARE1, BufSrc);
499#ifdef BTHD_ISDBT_SUPPORT
500  p3x7x->pAcquireParam->IsdbtLocaleParam.set_a = 0;
501  p3x7x->pAcquireParam->IsdbtLocaleParam.set_b = 0;
502  p3x7x->pAcquireParam->IsdbtLocaleParam.set_c = 0;
503  p3x7x->pAcquireParam->IsdbtLocaleParam.clr_a = 0;
504  p3x7x->pAcquireParam->IsdbtLocaleParam.clr_b = 0;
505  p3x7x->pAcquireParam->IsdbtLocaleParam.clr_c = 0;
506  p3x7x->pAcquireParam->IsdbtLocaleParam.phase = 0; 
507#endif
508  p3x7x->pStatus = (THD_3x7x_Status_t *)BMEM_AllocAligned(hDev->settings.hHeap, sizeof(THD_3x7x_Status_t), 0, 0 ); 
509  if (! p3x7x->pStatus ) {
510        retCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
511    BDBG_ERR(("BERR_OUT_OF_SYSTEM_MEMORY"));
512    goto done;
513  }
514  BKNI_Memset( p3x7x->pStatus, 0x00, sizeof( THD_3x7x_Status_t ));
515  BMEM_ConvertAddressToOffset(hDev->settings.hHeap,  p3x7x->pStatus, &BufSrc );
516  BREG_Write32(p3x7x->hRegister, BCHP_THD_CORE_SWSPARE4, BufSrc);
517
518  p3x7x->pInternalAcquireParam = (THD_InternalAcquireParam_t *)BMEM_AllocAligned(hDev->settings.hHeap, sizeof(THD_InternalAcquireParam_t), 0, 0 ); 
519  if (! p3x7x->pInternalAcquireParam ) {
520    retCode = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
521    BDBG_ERR(("BERR_OUT_OF_SYSTEM_MEMORY"));
522    goto done;
523  }
524  BKNI_Memset( p3x7x->pInternalAcquireParam, 0x00, sizeof( THD_InternalAcquireParam_t ));
525  BMEM_ConvertAddressToOffset(hDev->settings.hHeap,  p3x7x->pInternalAcquireParam, &BufSrc );
526  BREG_Write32(p3x7x->hRegister, BCHP_THD_CORE_SWSPARE5, BufSrc);
527
528  BDBG_MSG(("THD:Creating THD Core interrupts\n"));
529
530  /* THD interrupts */
531  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hFwCorrMaxCallback), hInterrupt, 
532    BCHP_INT_ID_FW_CORR_MAX_RDY_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_FW_CORR_MAX_RDY ));
533  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hFwSyncCallback), hInterrupt, 
534    BCHP_INT_ID_FW_SYNC_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_FFT_SYNC));
535  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hSpSyncCallback), hInterrupt, 
536    BCHP_INT_ID_SP_SYNC_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_SP_SYNC ));
537  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hTpsSyncCallback), hInterrupt, 
538    BCHP_INT_ID_TPS_SYNC_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_TPS_SYNC ));
539  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hFecSyncCallback), hInterrupt, 
540    BCHP_INT_ID_FEC_SYNC_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_FEC_SYNC ));
541  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hFbcCntCallback), hInterrupt, 
542    BCHP_INT_ID_FBCNT_ZERO_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_FBCNT_ZERO ));
543  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hRsSyncCallback), hInterrupt, 
544    BCHP_INT_ID_RS_SYNC_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_RS_SYNC ));
545  BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hRsSyncLossCallback), hInterrupt, 
546    BCHP_INT_ID_RS_SYNC_LOSS_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_RS_SYNC_LOSS ));
547#ifdef BTHD_ISDBT_SUPPORT
548        BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hTmccSyncCallback), hInterrupt,
549                BCHP_INT_ID_TMCC_SYNC_INTR, BTHD_P_EventIsr, (void*)p3x7x, THD_EVENT_TMCC_SYNC ));
550        BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hRsSyncBCallback), hInterrupt,
551                BCHP_INT_ID_RS_SYNC_B_INTR, BTHD_P_EventIsdbtIsr, (void*)p3x7x, THD_EVENT_RS_SYNC_B ));
552        BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hRsSyncCCallback), hInterrupt,
553                BCHP_INT_ID_RS_SYNC_C_INTR, BTHD_P_EventIsdbtIsr, (void*)p3x7x, THD_EVENT_RS_SYNC_C ));
554        BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hRsSyncLossBCallback), hInterrupt, 
555                BCHP_INT_ID_RS_SYNC_LOSS_B_INTR, BTHD_P_EventIsdbtIsr, (void*)p3x7x, THD_EVENT_RS_SYNC_B_LOSS ));
556        BTHD_CHK_RETCODE(BINT_CreateCallback( &(p3x7x->hRsSyncLossCCallback), hInterrupt, 
557                BCHP_INT_ID_RS_SYNC_LOSS_C_INTR, BTHD_P_EventIsdbtIsr, (void*)p3x7x, THD_EVENT_RS_SYNC_C_LOSS ));
558#endif
559
560  /* Create timer for status lock check */
561  BTMR_GetDefaultTimerSettings(&sTimerSettings);
562  sTimerSettings.type = BTMR_Type_eCountDown;
563  sTimerSettings.cb_isr = (BTMR_CallbackFunc)BTHD_P_TimerFunc;
564  sTimerSettings.pParm1 = (void*)hDev;
565  sTimerSettings.parm2 = 0;
566  sTimerSettings.exclusive = false;
567
568  retCode = BTMR_CreateTimer (hDev->settings.hTmr, &p3x7x->hTimer, &sTimerSettings);
569  if ( retCode != BERR_SUCCESS )
570  {
571    BDBG_ERR(("BTHD_Open: Create Timer Failed"));
572    retCode = BERR_TRACE(retCode);
573    goto done;
574  }     
575
576    /* Create timer for status lock check */
577  BTMR_GetDefaultTimerSettings(&sTimerSettings);
578  sTimerSettings.type = BTMR_Type_eCountDown;
579  sTimerSettings.cb_isr = (BTMR_CallbackFunc)BTHD_P_BBSTimerFunc;
580  sTimerSettings.pParm1 = (void*)hDev;
581  sTimerSettings.parm2 = 0;
582  sTimerSettings.exclusive = false;
583
584  retCode = BTMR_CreateTimer (hDev->settings.hTmr, &p3x7x->hBBSTimer, &sTimerSettings);
585  if ( retCode != BERR_SUCCESS )
586  {
587    BDBG_ERR(("BTHD_Open: Create Timer Failed"));
588    retCode = BERR_TRACE(retCode);
589    goto done;
590  }     
591
592  p3x7x->LockStatusTracking = 0xFFFFFFFF;
593
594  /* create events */
595  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hFwCorrMaxEvent)));
596  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hFwSyncEvent)));
597  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hSpSyncEvent)));
598  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hTpsSyncEvent)));
599  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hFecSyncEvent)));
600  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hFbcntZeroEvent)));
601  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hRsSyncEvent)));
602  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hInterruptEvent)));
603#ifdef BTHD_ISDBT_SUPPORT
604  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hTmccSyncEvent)));
605#endif
606  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hEWSEvent)));
607  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hLockEvent)));
608  BTHD_CHK_RETCODE(BKNI_CreateEvent(&(p3x7x->hBBSInterruptEvent))); 
609
610  *pthd = hDev;
611done:
612#ifdef BCHP_PWR_RESOURCE_THD_TOP
613    BCHP_PWR_ReleaseResource(p3x7x->hChip, BCHP_PWR_RESOURCE_THD_TOP);
614#endif
615   if( retCode != BERR_SUCCESS )   /* clean up the memory free */
616    {
617       if (! p3x7x->pInternalAcquireParam )
618                        BMEM_Free(hDev->settings.hHeap, p3x7x->pInternalAcquireParam);
619           if (! p3x7x->pStatus )
620                        BMEM_Free(hDev->settings.hHeap, p3x7x->pStatus);
621                if (! p3x7x->pStatus )
622                        BMEM_Free(hDev->settings.hHeap, p3x7x->pAcquireParam);
623                if (! p3x7x->pStatus )
624                        BMEM_Free(hDev->settings.hHeap, p3x7x->pAcquireParam);
625#ifdef BTHD_ISDBT_SUPPORT
626                if (! p3x7x->pIsdbtMemory )
627                        BMEM_Free(hDev->settings.hHeap, p3x7x->pIsdbtMemory);
628#endif
629                if( p3x7x != NULL )
630                          BKNI_Free( p3x7x );
631                 if( hDev != NULL )
632                          BKNI_Free( hDev );
633               
634                *pthd = NULL;
635    }
636  return retCode;
637}
638/******************************************************************************
639 * BTHD_Close()
640 ******************************************************************************/
641BERR_Code BTHD_3x7x_Close(BTHD_Handle h)
642{ 
643 
644  BTHD_3x7x_P_Handle *p3x7x;
645  BTHD_Settings DefSettings;
646  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
647  DefSettings = h->settings;
648  if (p3x7x->hTimer != NULL)
649        BTMR_DestroyTimer(p3x7x->hTimer);
650  if (p3x7x->hBBSTimer != NULL)
651        BTMR_DestroyTimer(p3x7x->hBBSTimer);
652
653   BREG_WriteField(p3x7x->hRegister, THD_CORE_GLB, BE_MODE, 0 );                   /* stop the ISDB-T dump to memory*/
654
655
656  BINT_DisableCallback( p3x7x->hFwCorrMaxCallback);
657  BINT_DisableCallback( p3x7x->hFwSyncCallback);
658  BINT_DisableCallback( p3x7x->hSpSyncCallback);
659  BINT_DisableCallback( p3x7x->hTpsSyncCallback);
660  BINT_DisableCallback( p3x7x->hFecSyncCallback);
661  BINT_DisableCallback( p3x7x->hFbcCntCallback);
662  BINT_DisableCallback( p3x7x->hRsSyncCallback);
663  BINT_DisableCallback( p3x7x->hRsSyncLossCallback);
664#ifdef BTHD_ISDBT_SUPPORT
665  BINT_DisableCallback( p3x7x->hTmccSyncCallback);
666  BINT_DisableCallback( p3x7x->hRsSyncBCallback);
667  BINT_DisableCallback( p3x7x->hRsSyncCCallback);
668  BINT_DisableCallback( p3x7x->hRsSyncLossBCallback);
669  BINT_DisableCallback( p3x7x->hRsSyncLossCCallback);
670#endif
671  /* since those events might already be deleted by ResetEvent function */
672  BKNI_DestroyEvent(p3x7x->hFwCorrMaxEvent);
673  BKNI_DestroyEvent(p3x7x->hFwSyncEvent);
674  BKNI_DestroyEvent(p3x7x->hSpSyncEvent);
675  BKNI_DestroyEvent(p3x7x->hTpsSyncEvent);
676  BKNI_DestroyEvent(p3x7x->hFecSyncEvent);
677  BKNI_DestroyEvent(p3x7x->hFbcntZeroEvent);
678  BKNI_DestroyEvent(p3x7x->hRsSyncEvent);
679  BKNI_DestroyEvent(p3x7x->hInterruptEvent);
680  BKNI_DestroyEvent(p3x7x->hBBSInterruptEvent);
681  BKNI_DestroyEvent(p3x7x->hLockEvent);
682  BKNI_DestroyEvent(p3x7x->hEWSEvent); 
683#ifdef BTHD_ISDBT_SUPPORT
684  BKNI_DestroyEvent(p3x7x->hTmccSyncEvent);
685#endif
686 
687
688#ifdef BTHD_ISDBT_SUPPORT
689  if (p3x7x->pIsdbtMemory != NULL)
690     BMEM_Free(DefSettings.hHeap, p3x7x->pIsdbtMemory);
691#endif
692  if (p3x7x->pAcquireParam != NULL)
693    BMEM_Free(DefSettings.hHeap, p3x7x->pAcquireParam);
694  if (p3x7x->pInternalAcquireParam != NULL)
695    BMEM_Free(DefSettings.hHeap, p3x7x->pInternalAcquireParam);
696  if (p3x7x->pStatus != NULL)
697    BMEM_Free(DefSettings.hHeap, p3x7x->pStatus);
698  if (p3x7x != NULL)
699    BKNI_Free((void*)p3x7x);
700  if (h != NULL)
701    BKNI_Free((void*)h);
702 
703  return BERR_SUCCESS;
704}
705
706/***************************************************************************
707 * BTHD_InitializeParams()
708 ***************************************************************************/
709BERR_Code BTHD_3x7x_InitializeParams(BTHD_Handle h, const uint8_t *var1, uint32_t var2)   
710{   
711  BTHD_3x7x_P_Handle *p3x7x;
712  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
713  BSTD_UNUSED(var1);
714  BSTD_UNUSED(var2);
715
716  /* General Parameters (Public) */
717  p3x7x->pAcquireParam->CommonAcquireParam.Standard          = THD_Standard_DVBT;
718  p3x7x->pAcquireParam->CommonAcquireParam.Bandwidth         = THD_Bandwidth_8MHz;
719  p3x7x->pAcquireParam->CommonAcquireParam.CenterFreq        = 0;
720  p3x7x->pAcquireParam->CommonAcquireParam.TransGuardMode    = THD_TransGuardMode_Auto_DVBT;
721  p3x7x->pAcquireParam->CommonAcquireParam.TransmissionMode  = THD_TransmissionMode_2k;
722  p3x7x->pAcquireParam->CommonAcquireParam.GuardInterval     = THD_GuardInterval_1_32;
723  p3x7x->pAcquireParam->CommonAcquireParam.CoChannelMode     = THD_CoChannelMode_Auto;
724  p3x7x->pAcquireParam->CommonAcquireParam.CarrierRange      = THD_CarrierRange_Narrow; 
725
726  /* General Paramters (Private) */
727  p3x7x->pInternalAcquireParam->FrontEndMode           = THD_FrontEndMode_Baseband;
728  p3x7x->pInternalAcquireParam->ChannelEstimatorMode   = THD_ChannelEstimatorMode_Auto;
729  p3x7x->pInternalAcquireParam->FFTWindowMode          = THD_FFTWindowMode_Auto;
730  p3x7x->pInternalAcquireParam->ImpulseMode            = THD_ImpulseMode_None; 
731  p3x7x->pInternalAcquireParam->TSMode                 = THD_TSMode_Serial;
732  p3x7x->pInternalAcquireParam->SampleFreq             = 54000000;
733  p3x7x->pInternalAcquireParam->AllowRsSyncEvent       = false; 
734  p3x7x->pInternalAcquireParam->TransGuardMaxThreshold            = 0x00050000;
735  p3x7x->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[0] = 296;
736  p3x7x->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[1] = 210;
737  p3x7x->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[2] = 150;
738  p3x7x->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[3] = 104;
739
740  /* DVB-T Specific Parameters (Public) */
741  p3x7x->pAcquireParam->DvbtAcquireParam.TPSMode       = THD_DvbtTPSMode_Auto;
742  p3x7x->pAcquireParam->DvbtAcquireParam.PriorityMode  = THD_DvbtPriorityMode_High;
743  p3x7x->pAcquireParam->DvbtAcquireParam.Qam           = THD_Qam_16Qam;
744  p3x7x->pAcquireParam->DvbtAcquireParam.Hierarchy     = THD_DvbtHierarchy_None;
745  p3x7x->pAcquireParam->DvbtAcquireParam.CodeRateHP    = THD_CodeRate_3_4;
746  p3x7x->pAcquireParam->DvbtAcquireParam.CodeRateLP    = THD_CodeRate_1_2;
747#ifdef BTHD_ISDBT_SUPPORT
748  /* ISDB-T Specific Parameters (Public) */
749  p3x7x->pAcquireParam->IsdbtAcquireParam.TMCCMode     = THD_IsdbtTMCCMode_Auto;
750  p3x7x->pAcquireParam->IsdbtAcquireParam.Pr           = THD_IsdbtPr_Disable;
751  p3x7x->pAcquireParam->IsdbtAcquireParam.Qam[0]       = THD_Qam_16Qam;
752  p3x7x->pAcquireParam->IsdbtAcquireParam.Qam[1]       = THD_Qam_16Qam;
753  p3x7x->pAcquireParam->IsdbtAcquireParam.Qam[2]       = THD_Qam_16Qam;
754  p3x7x->pAcquireParam->IsdbtAcquireParam.CodeRate[0]  = THD_CodeRate_1_2;
755  p3x7x->pAcquireParam->IsdbtAcquireParam.CodeRate[1]  = THD_CodeRate_1_2;
756  p3x7x->pAcquireParam->IsdbtAcquireParam.CodeRate[2]  = THD_CodeRate_1_2;
757  p3x7x->pAcquireParam->IsdbtAcquireParam.TimeInt[0]   = THD_IsdbtTimeInt_0X;
758  p3x7x->pAcquireParam->IsdbtAcquireParam.TimeInt[1]   = THD_IsdbtTimeInt_0X;
759  p3x7x->pAcquireParam->IsdbtAcquireParam.TimeInt[2]   = THD_IsdbtTimeInt_0X;
760  p3x7x->pAcquireParam->IsdbtAcquireParam.Segments[0]  = 13;
761  p3x7x->pAcquireParam->IsdbtAcquireParam.Segments[1]  = 0;
762  p3x7x->pAcquireParam->IsdbtAcquireParam.Segments[2]  = 0;
763#endif
764  return BERR_SUCCESS;
765}
766
767
768/***************************************************************************
769* BTHD_P_AppDVBTSettings()
770***************************************************************************/
771void BTHD_P_AppDVBTSettings(BTHD_3x7x_Handle h, const BTHD_InbandParams *pParams)
772{
773  BERR_Code retCode;
774  BDBG_ASSERT(h);
775  BDBG_ASSERT(pParams);
776
777
778  BDBG_MSG(("BTHD_P_AppDVBTSettings"));
779
780  BKNI_ResetEvent(h->hRsSyncEvent);
781  BINT_DisableCallback( h->hRsSyncCallback);
782  BINT_DestroyCallback( h->hRsSyncCallback);
783  BINT_DisableCallback( h->hRsSyncLossCallback);
784  BINT_DestroyCallback( h->hRsSyncLossCallback);
785
786  BTHD_CHK_RETCODE(BINT_CreateCallback( &(h->hRsSyncCallback), h->hInterrupt, 
787    BCHP_INT_ID_RS_SYNC_INTR, BTHD_P_EventIsr, (void*)h, THD_EVENT_RS_SYNC ));
788  BTHD_CHK_RETCODE(BINT_CreateCallback( &(h->hRsSyncLossCallback), h->hInterrupt, 
789    BCHP_INT_ID_RS_SYNC_LOSS_INTR, BTHD_P_EventIsr, (void*)h, THD_EVENT_RS_SYNC_LOSS ));
790
791  switch (pParams->decodeMode)
792  {
793  case BTHD_Decode_Lp:
794   h->pAcquireParam->DvbtAcquireParam.PriorityMode  = THD_DvbtPriorityMode_Low;
795    break;
796  default:
797    BDBG_WRN(("Unrecognized PriorityMode setting - defaulting to THD_PriorityMode_High"));
798    /* fall through */
799  case BTHD_Decode_Hp:
800   h->pAcquireParam->DvbtAcquireParam.PriorityMode  = THD_DvbtPriorityMode_High;
801    break;
802  }
803  if (pParams->bTpsAcquire == false)
804  {
805   h->pAcquireParam->DvbtAcquireParam.TPSMode = THD_DvbtTPSMode_Manual;
806
807    switch (pParams->eModulation)
808    {
809    case BTHD_Modulation_eQpsk:
810     h->pAcquireParam->DvbtAcquireParam.Qam  = THD_Qam_Qpsk;
811      break;
812    case BTHD_Modulation_e16Qam:
813     h->pAcquireParam->DvbtAcquireParam.Qam  = THD_Qam_16Qam;
814      break;
815    default:
816      BDBG_WRN(("Unrecognized modulaton setting - defaulting to THD_Qam_64Qam"));
817      /* fall through */
818    case BTHD_Modulation_e64Qam:
819     h->pAcquireParam->DvbtAcquireParam.Qam  = THD_Qam_64Qam;
820      break;
821    }
822
823    switch (pParams->eCodeRateHP)
824    {
825    case BTHD_CodeRate_e2_3:
826     h->pAcquireParam->DvbtAcquireParam.CodeRateHP  = THD_CodeRate_2_3;
827      break;
828    case BTHD_CodeRate_e3_4:
829     h->pAcquireParam->DvbtAcquireParam.CodeRateHP  = THD_CodeRate_3_4;
830      break;
831    case BTHD_CodeRate_e5_6:
832     h->pAcquireParam->DvbtAcquireParam.CodeRateHP  = THD_CodeRate_5_6;
833      break;
834    case BTHD_CodeRate_e7_8:
835     h->pAcquireParam->DvbtAcquireParam.CodeRateHP  = THD_CodeRate_7_8;
836      break;
837    default:
838      BDBG_WRN(("Unrecognized CodeRateHP setting - defaulting to BTHD_CodeRate_e1_2"));
839      /* fall through */
840    case BTHD_CodeRate_e1_2:
841     h->pAcquireParam->DvbtAcquireParam.CodeRateHP  = THD_CodeRate_1_2;
842      break;
843    }
844
845    switch (pParams->eCodeRateLP)
846    {
847    case BTHD_CodeRate_e2_3:
848     h->pAcquireParam->DvbtAcquireParam.CodeRateLP  = THD_CodeRate_2_3;
849      break;
850    case BTHD_CodeRate_e3_4:
851     h->pAcquireParam->DvbtAcquireParam.CodeRateLP  = THD_CodeRate_3_4;
852      break;
853    case BTHD_CodeRate_e5_6:
854     h->pAcquireParam->DvbtAcquireParam.CodeRateLP  = THD_CodeRate_5_6;
855      break;
856    case BTHD_CodeRate_e7_8:
857     h->pAcquireParam->DvbtAcquireParam.CodeRateLP  = THD_CodeRate_7_8;
858      break;
859    default:
860      BDBG_WRN(("Unrecognized CodeRateLP setting - defaulting to BTHD_CodeRate_e1_2"));
861      /* fall through */
862    case BTHD_CodeRate_e1_2:
863     h->pAcquireParam->DvbtAcquireParam.CodeRateLP  = THD_CodeRate_1_2;
864      break;
865    }
866
867
868    switch (pParams->eHierarchy)
869    {
870    case BTHD_Hierarchy_1:
871     h->pAcquireParam->DvbtAcquireParam.Hierarchy  = THD_DvbtHierarchy_1;
872      break;
873    case BTHD_Hierarchy_2:
874     h->pAcquireParam->DvbtAcquireParam.Hierarchy  = THD_DvbtHierarchy_2;
875      break;
876    case BTHD_Hierarchy_4:
877     h->pAcquireParam->DvbtAcquireParam.Hierarchy  = THD_DvbtHierarchy_4;
878      break;
879    default:
880      BDBG_WRN(("Unrecognized Hierarchy setting - defaulting to THD_DvbtHierarchy_None"));
881      /* fall through */
882    case BTHD_Hierarchy_0:
883     h->pAcquireParam->DvbtAcquireParam.Hierarchy  = THD_DvbtHierarchy_None;
884      break;
885    }
886  }
887  else
888   h->pAcquireParam->DvbtAcquireParam.TPSMode = THD_DvbtTPSMode_Auto;
889done:
890  return;
891}
892/***************************************************************************
893* BTHD_P_AppISDBTSettings()
894***************************************************************************/
895#ifdef BTHD_ISDBT_SUPPORT
896void BTHD_P_AppISDBTSettings(BTHD_3x7x_Handle h, const BTHD_InbandParams *pParams)
897{
898  BERR_Code retCode; 
899  BDBG_ASSERT(h);
900  BDBG_ASSERT(pParams);
901  BDBG_MSG(("BTHD_P_AppISDBTSettings"));
902
903  BKNI_ResetEvent(h->hRsSyncEvent);
904  BINT_DisableCallback( h->hRsSyncCallback);
905  BINT_DisableCallback( h->hRsSyncLossCallback);
906  BINT_DestroyCallback( h->hRsSyncCallback);
907  BINT_DestroyCallback( h->hRsSyncLossCallback);
908
909  BTHD_CHK_RETCODE(BINT_CreateCallback( &(h->hRsSyncCallback), h->hInterrupt, 
910                BCHP_INT_ID_RS_SYNC_INTR, BTHD_P_EventIsdbtIsr, (void*)h, THD_EVENT_RS_SYNC ));
911  BTHD_CHK_RETCODE(BINT_CreateCallback( &(h->hRsSyncLossCallback), h->hInterrupt, 
912                BCHP_INT_ID_RS_SYNC_LOSS_INTR, BTHD_P_EventIsdbtIsr, (void*)h, THD_EVENT_RS_SYNC_LOSS ));
913
914  if (pParams->bTmccAcquire == false)
915  {
916   h->pAcquireParam->IsdbtAcquireParam.TMCCMode = THD_IsdbtTMCCMode_Manual;
917
918    switch (pParams->bTmccAcquire)
919    {
920    case 0:
921     h->pAcquireParam->IsdbtAcquireParam.Pr  = THD_IsdbtPr_Disable;
922      break;
923    default:
924      BDBG_WRN(("Unrecognized TmccAcquire setting - defaulting to THD_Pr_Enable"));
925           /* fall through */
926    case 1:
927     h->pAcquireParam->IsdbtAcquireParam.Pr  = THD_IsdbtPr_Enable;
928      break;
929    }
930
931    switch (pParams->eIsdbtAModulation)
932    {
933    case BTHD_Modulation_eQpsk:
934     h->pAcquireParam->IsdbtAcquireParam.Qam[0]  = THD_Qam_Qpsk;
935      break;
936    case BTHD_Modulation_e64Qam:
937     h->pAcquireParam->IsdbtAcquireParam.Qam[0]  = THD_Qam_64Qam;
938      break;
939    default:
940      BDBG_WRN(("Unrecognized A modulaton setting - defaulting to THD_Qam_16Qam"));
941      /* fall through */
942    case BTHD_Modulation_e16Qam:
943     h->pAcquireParam->IsdbtAcquireParam.Qam[0]  = THD_Qam_16Qam;
944      break;
945    }
946
947    switch (pParams->eIsdbtACodeRate)
948    {
949    case BTHD_CodeRate_e2_3:
950     h->pAcquireParam->IsdbtAcquireParam.CodeRate[0]  = THD_CodeRate_2_3;
951      break;
952    case BTHD_CodeRate_e3_4:
953     h->pAcquireParam->IsdbtAcquireParam.CodeRate[0]  = THD_CodeRate_3_4;
954      break;
955    case BTHD_CodeRate_e5_6:
956     h->pAcquireParam->IsdbtAcquireParam.CodeRate[0]  = THD_CodeRate_5_6;
957      break;
958    case BTHD_CodeRate_e7_8:
959     h->pAcquireParam->IsdbtAcquireParam.CodeRate[0]  = THD_CodeRate_7_8;
960      break;
961    default:
962      BDBG_WRN(("Unrecognized ISDBT_A_CodeRate setting - defaulting to BTHD_CodeRate_e1_2"));
963      /* fall through */
964    case BTHD_CodeRate_e1_2:
965     h->pAcquireParam->IsdbtAcquireParam.CodeRate[0]  = THD_CodeRate_1_2;
966      break;
967    }
968
969    switch (pParams->eIsdbtATimeInterleaving)
970    {
971    case BTHD_IsdbtTimeInterleaving_1X:
972     h->pAcquireParam->IsdbtAcquireParam.TimeInt[0]  = THD_IsdbtTimeInt_1X;
973      break;
974    case BTHD_IsdbtTimeInterleaving_2X:
975     h->pAcquireParam->IsdbtAcquireParam.TimeInt[0]  = THD_IsdbtTimeInt_2X;
976      break;
977    case BTHD_IsdbtTimeInterleaving_3X:
978     h->pAcquireParam->IsdbtAcquireParam.TimeInt[0]  = THD_IsdbtTimeInt_4X;
979      break;
980    default:
981      BDBG_WRN(("Unrecognized ISDBT_A_TimeInt setting - defaulting to THD_TimeInt_0X"));
982      /* fall through */
983    case BTHD_IsdbtTimeInterleaving_0X:
984     h->pAcquireParam->IsdbtAcquireParam.TimeInt[0]  = THD_IsdbtTimeInt_0X;
985      break;
986    }
987   h->pAcquireParam->IsdbtAcquireParam.Segments[0] = pParams->eIsdbtASegments;
988
989    /********************************** B ****************************/
990    switch (pParams->eIsdbtBModulation)
991    {
992     case BTHD_Modulation_eQpsk:
993     h->pAcquireParam->IsdbtAcquireParam.Qam[1]  = THD_Qam_Qpsk;
994      break;
995    case BTHD_Modulation_e64Qam:
996     h->pAcquireParam->IsdbtAcquireParam.Qam[1]  = THD_Qam_64Qam;
997      break;
998    default:
999      BDBG_WRN(("Unrecognized A modulaton setting - defaulting to THD_Qam_16Qam"));
1000      /* fall through */
1001    case BTHD_Modulation_e16Qam:
1002     h->pAcquireParam->IsdbtAcquireParam.Qam[1]  = THD_Qam_16Qam;
1003      break;
1004    }
1005
1006    switch (pParams->eIsdbtBCodeRate)
1007    {
1008    case BTHD_CodeRate_e2_3:
1009     h->pAcquireParam->IsdbtAcquireParam.CodeRate[1]  = THD_CodeRate_2_3;
1010      break;
1011    case BTHD_CodeRate_e3_4:
1012     h->pAcquireParam->IsdbtAcquireParam.CodeRate[1]  = THD_CodeRate_3_4;
1013      break;
1014    case BTHD_CodeRate_e5_6:
1015     h->pAcquireParam->IsdbtAcquireParam.CodeRate[1]  = THD_CodeRate_5_6;
1016      break;
1017    case BTHD_CodeRate_e7_8:
1018     h->pAcquireParam->IsdbtAcquireParam.CodeRate[1]  = THD_CodeRate_7_8;
1019      break;
1020    default:
1021      BDBG_WRN(("Unrecognized ISDBT_A_CodeRate setting - defaulting to BTHD_CodeRate_e1_2"));
1022      /* fall through */
1023    case BTHD_CodeRate_e1_2:
1024     h->pAcquireParam->IsdbtAcquireParam.CodeRate[1]  = THD_CodeRate_1_2;
1025      break;
1026    }
1027
1028    switch (pParams->eIsdbtBTimeInterleaving)
1029    {
1030    case BTHD_IsdbtTimeInterleaving_1X:
1031     h->pAcquireParam->IsdbtAcquireParam.TimeInt[1]  = THD_IsdbtTimeInt_1X;
1032      break;
1033    case BTHD_IsdbtTimeInterleaving_2X:
1034     h->pAcquireParam->IsdbtAcquireParam.TimeInt[1]  = THD_IsdbtTimeInt_2X;
1035      break;
1036    case BTHD_IsdbtTimeInterleaving_3X:
1037     h->pAcquireParam->IsdbtAcquireParam.TimeInt[1]  = THD_IsdbtTimeInt_4X;
1038      break;
1039    default:
1040      BDBG_WRN(("Unrecognized ISDBT_A_TimeInt setting - defaulting to THD_TimeInt_0X"));
1041      /* fall through */
1042    case BTHD_IsdbtTimeInterleaving_0X:
1043     h->pAcquireParam->IsdbtAcquireParam.TimeInt[1]  = THD_IsdbtTimeInt_0X;
1044      break;
1045    }
1046
1047   h->pAcquireParam->IsdbtAcquireParam.Segments[1] = pParams->eIsdbtBSegments;
1048    /********************************** C ****************************/
1049    switch (pParams->eIsdbtCModulation)
1050    {
1051     case BTHD_Modulation_eQpsk:
1052     h->pAcquireParam->IsdbtAcquireParam.Qam[2]  = THD_Qam_Qpsk;
1053      break;
1054    case BTHD_Modulation_e64Qam:
1055     h->pAcquireParam->IsdbtAcquireParam.Qam[2]  = THD_Qam_64Qam;
1056      break;
1057    default:
1058      BDBG_WRN(("Unrecognized A modulaton setting - defaulting to THD_Qam_16Qam"));
1059      /* fall through */
1060    case BTHD_Modulation_e16Qam:
1061     h->pAcquireParam->IsdbtAcquireParam.Qam[2]  = THD_Qam_16Qam;
1062      break;
1063    }
1064
1065    switch (pParams->eIsdbtCCodeRate)
1066    {
1067    case BTHD_CodeRate_e2_3:
1068     h->pAcquireParam->IsdbtAcquireParam.CodeRate[2]  = THD_CodeRate_2_3;
1069      break;
1070    case BTHD_CodeRate_e3_4:
1071     h->pAcquireParam->IsdbtAcquireParam.CodeRate[2]  = THD_CodeRate_3_4;
1072      break;
1073    case BTHD_CodeRate_e5_6:
1074     h->pAcquireParam->IsdbtAcquireParam.CodeRate[2]  = THD_CodeRate_5_6;
1075      break;
1076    case BTHD_CodeRate_e7_8:
1077     h->pAcquireParam->IsdbtAcquireParam.CodeRate[2]  = THD_CodeRate_7_8;
1078      break;
1079    default:
1080      BDBG_WRN(("Unrecognized ISDBT_A_CodeRate setting - defaulting to BTHD_CodeRate_e1_2"));
1081      /* fall through */
1082    case BTHD_CodeRate_e1_2:
1083     h->pAcquireParam->IsdbtAcquireParam.CodeRate[2]  = THD_CodeRate_1_2;
1084      break;
1085    }
1086
1087    switch (pParams->eIsdbtCTimeInterleaving)
1088    {
1089    case BTHD_IsdbtTimeInterleaving_1X:
1090     h->pAcquireParam->IsdbtAcquireParam.TimeInt[2]  = THD_IsdbtTimeInt_1X;
1091      break;
1092    case BTHD_IsdbtTimeInterleaving_2X:
1093     h->pAcquireParam->IsdbtAcquireParam.TimeInt[2]  = THD_IsdbtTimeInt_2X;
1094      break;
1095    case BTHD_IsdbtTimeInterleaving_3X:
1096     h->pAcquireParam->IsdbtAcquireParam.TimeInt[2]  = THD_IsdbtTimeInt_4X;
1097      break;
1098    default:
1099      BDBG_WRN(("Unrecognized ISDBT_A_TimeInt setting - defaulting to THD_TimeInt_0X"));
1100      /* fall through */
1101    case BTHD_IsdbtTimeInterleaving_0X:
1102     h->pAcquireParam->IsdbtAcquireParam.TimeInt[2]  = THD_IsdbtTimeInt_0X;
1103      break;
1104    }
1105
1106   h->pAcquireParam->IsdbtAcquireParam.Segments[2] = pParams->eIsdbtCSegments;
1107  }
1108  else
1109   h->pAcquireParam->IsdbtAcquireParam.TMCCMode = THD_IsdbtTMCCMode_Auto;
1110done:
1111  return;
1112}
1113
1114#endif
1115/*******************************************************************************
1116*   BTHD_SetAcqSettings
1117*******************************************************************************/
1118BERR_Code BTHD_P_SetAcqSettings(BTHD_3x7x_Handle h, const BTHD_InbandParams *pParams)       
1119{
1120        BERR_Code eResult = BERR_SUCCESS;
1121        BDBG_MSG(("BTHD_3x7x_SetAcqSettings"));
1122 
1123  /* Clear and set Acquisition Start Mode bits */
1124  h->pAcquireParam->CommonAcquireParam.AcquireMode &= (~THD_AcquireMode_Auto & ~THD_AcquireMode_Scan & ~THD_AcquireMode_Manual); 
1125  switch ( pParams->eAcquisitionMode )
1126  {
1127  case BTHD_ThdAcquisitionMode_eManual:
1128    break;
1129  case BTHD_ThdAcquisitionMode_eScan:
1130    h->pAcquireParam->CommonAcquireParam.AcquireMode  |= THD_AcquireMode_Scan;
1131    break;
1132  default:
1133    BDBG_WRN(("Unrecognized mode setting - defaulting to THD_AcquireMode_Auto"));
1134    /* fall through */
1135  case BTHD_ThdAcquisitionMode_eAuto:
1136    h->pAcquireParam->CommonAcquireParam.AcquireMode  |= THD_AcquireMode_Auto;
1137    break;
1138  }
1139 
1140  switch ( pParams->mode )
1141  {
1142  case BTHD_InbandMode_eIsdbt:
1143    h->pAcquireParam->CommonAcquireParam.Standard  = THD_Standard_ISDBT;
1144    break;
1145  default:
1146    BDBG_WRN(("Unrecognized mode setting - defaulting to THD_Standard_DVBT"));
1147    /* fall through */
1148  case BTHD_InbandMode_eDvbt:
1149    h->pAcquireParam->CommonAcquireParam.Standard  = THD_Standard_DVBT;
1150    break;
1151  }
1152
1153  switch ( pParams->bandwidth )
1154  {
1155  case BTHD_Bandwidth_5Mhz:
1156    h->pAcquireParam->CommonAcquireParam.Bandwidth  = THD_Bandwidth_5MHz;
1157    break;
1158  case BTHD_Bandwidth_6Mhz:
1159    h->pAcquireParam->CommonAcquireParam.Bandwidth  = THD_Bandwidth_6MHz;
1160    break;
1161  case BTHD_Bandwidth_7Mhz:
1162    h->pAcquireParam->CommonAcquireParam.Bandwidth  = THD_Bandwidth_7MHz;
1163    break;
1164  default:
1165    BDBG_WRN(("Unrecognized bandwidth setting - defaulting to THD_Bandwidth_8MHz"));
1166    /* fall through */
1167  case BTHD_Bandwidth_8Mhz:
1168    h->pAcquireParam->CommonAcquireParam.Bandwidth  = THD_Bandwidth_8MHz;
1169    break;
1170  }
1171  h->pAcquireParam->CommonAcquireParam.CenterFreq     = pParams->ifFreq;
1172  switch (pParams->cciMode)
1173  {
1174  case BTHD_CCI_None:
1175    h->pAcquireParam->CommonAcquireParam.CoChannelMode  = THD_CoChannelMode_None;
1176    break;
1177  default:
1178    BDBG_WRN(("Unrecognized CoChannelMode setting - defaulting to THD_CoChannelMode_Auto"));
1179    /* fall through */
1180  case BTHD_CCI_Auto:
1181    h->pAcquireParam->CommonAcquireParam.CoChannelMode  = THD_CoChannelMode_Auto;
1182    break;
1183  }
1184
1185  switch (pParams->ePullinRange)
1186  {
1187  case BTHD_PullInRange_eNarrow:
1188    h->pAcquireParam->CommonAcquireParam.CarrierRange  = THD_CarrierRange_Narrow;
1189    break;
1190  default:
1191    BDBG_WRN(("Unrecognized CarrierRange setting - defaulting to THD_CarrierRange_Wide"));
1192    /* fall through */
1193  case BTHD_PullInRange_eWide:
1194    h->pAcquireParam->CommonAcquireParam.CarrierRange  = THD_CarrierRange_Wide;
1195    break;
1196  }
1197
1198  switch (pParams->eModeGuardAcquire)
1199  {
1200        case BTHD_ModeGuard_eManual:
1201                h->pAcquireParam->CommonAcquireParam.TransGuardMode = THD_TransGuardMode_Manual;
1202                switch (pParams->eTransmissionMode)
1203                {
1204                        case BTHD_TransmissionMode_e4K:
1205                                h->pAcquireParam->CommonAcquireParam.TransmissionMode  = THD_TransmissionMode_4k;
1206                                break;
1207                        case BTHD_TransmissionMode_e8K:
1208                                h->pAcquireParam->CommonAcquireParam.TransmissionMode  = THD_TransmissionMode_8k;
1209                                break;
1210                        default:
1211                                BDBG_WRN(("Unrecognized TransmissionMode setting - defaulting to BTHD_TransmissionMode_e2K"));
1212                                /* fall through */
1213                                case BTHD_TransmissionMode_e2K:
1214                                h->pAcquireParam->CommonAcquireParam.TransmissionMode  = THD_TransmissionMode_2k;
1215                                break;
1216                }
1217                switch (pParams->eGuardInterval)
1218                {
1219                        case BTHD_GuardInterval_e1_32:
1220                                h->pAcquireParam->CommonAcquireParam.GuardInterval  = THD_GuardInterval_1_32;
1221                                break;
1222                        case BTHD_GuardInterval_e1_16:
1223                                h->pAcquireParam->CommonAcquireParam.GuardInterval  = THD_GuardInterval_1_16;
1224                                break;
1225                        case BTHD_GuardInterval_e1_8:
1226                                h->pAcquireParam->CommonAcquireParam.GuardInterval  = THD_GuardInterval_1_8;
1227                                break;
1228                        default:
1229                                BDBG_WRN(("Unrecognized GuardInterval setting - defaulting to THD_GuardInterval_1_4"));
1230                                /* fall through */
1231                        case BTHD_GuardInterval_e1_4:
1232                                h->pAcquireParam->CommonAcquireParam.GuardInterval  = THD_GuardInterval_1_4;
1233                                break;
1234                }
1235                break;
1236        case BTHD_ModeGuard_eAutoDvbt:
1237                h->pAcquireParam->CommonAcquireParam.TransGuardMode  = THD_TransGuardMode_Auto_DVBT;
1238                break;
1239        case BTHD_ModeGuard_eAutoIsdbt:
1240                h->pAcquireParam->CommonAcquireParam.TransGuardMode  = THD_TransGuardMode_Auto_ISDBT;
1241                break;
1242        default:
1243                BDBG_WRN(("Unrecognized TransGuardMode setting - defaulting to THD_TransGuardMode_Auto"));
1244                /* fall through */
1245        case BTHD_ModeGuard_eAuto:
1246                h->pAcquireParam->CommonAcquireParam.TransGuardMode  = THD_TransGuardMode_Auto;
1247                break;
1248  }
1249
1250
1251  if (h->pAcquireParam->CommonAcquireParam.Standard  == THD_Standard_DVBT)
1252  {
1253    BDBG_MSG(("BTHD_P_TuneAcquire = THD_Standard_DVBT"));
1254    BTHD_P_AppDVBTSettings(h, pParams);
1255  }
1256  else
1257  {
1258    BDBG_MSG(("BTHD_P_TuneAcquire = THD_Standard_ISDBT"));
1259#ifdef BTHD_ISDBT_SUPPORT
1260    BTHD_P_AppISDBTSettings(h, pParams);
1261#endif
1262  }
1263
1264  /*     Inetrnal Settings    */
1265
1266  h->pInternalAcquireParam->FrontEndMode         = THD_FrontEndMode_Baseband;
1267  h->pInternalAcquireParam->ChannelEstimatorMode = THD_ChannelEstimatorMode_Auto;
1268  h->pInternalAcquireParam->FFTWindowMode        = THD_FFTWindowMode_Auto;
1269  h->pInternalAcquireParam->ImpulseMode          = THD_ImpulseMode_None; 
1270  h->pInternalAcquireParam->TSMode               = THD_TSMode_Serial;
1271  h->pInternalAcquireParam->TransGuardMaxThreshold            = 0x00050000;
1272  h->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[0] = 296;
1273  h->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[1] = 210;
1274  h->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[2] = 150;
1275  h->pInternalAcquireParam->TransGuardMaxMinRatioThreshold[3] = 104;
1276  h->pInternalAcquireParam->SampleFreq                                          = 54000000;
1277
1278
1279
1280  return ( eResult );   
1281}
1282
1283
1284/***************************************************************************
1285 * BTHD_Acquire()
1286 ***************************************************************************/
1287BERR_Code BTHD_3x7x_Acquire(BTHD_Handle h, const BTHD_InbandParams *pParams)
1288{
1289  BERR_Code retCode;
1290  BTHD_3x7x_P_Handle *p3x7x;
1291  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1292 
1293  if (p3x7x->pStatus->PowerStatus != THD_ePower_On) {
1294                BDBG_ERR(("BTHD_3x7x_Acquire: power is still off  "));
1295                return BERR_NOT_INITIALIZED;
1296  }
1297
1298#if 0
1299  BTHD_3x7x_InitializeParams(h);
1300#else
1301  BTHD_P_SetAcqSettings(p3x7x, pParams);
1302#endif
1303  if (p3x7x->pAcquireParam->CommonAcquireParam.AcquireMode & (THD_AcquireMode_Manual)) {
1304    BTHD_P_ResetEvent(p3x7x);
1305    p3x7x->pStatus->ReacquireCount = 0;
1306  }
1307  BTMR_StopTimer(p3x7x->hTimer);
1308  BTMR_StartTimer(p3x7x->hBBSTimer, 1000000);   /* the timer is in Micro second */
1309  p3x7x->LockStatusTracking = 0xFFFFFFFF;
1310
1311#ifdef BTHD_ISDBT_SUPPORT
1312  p3x7x->pAcquireParam->IsdbtLocaleParam.EwsFlag |= (THD_IsdbtEwsFlag_eLockUpdate | THD_IsdbtEwsFlag_eUnlockStopEWS | THD_IsdbtEwsFlag_eLockStartEWS);
1313#endif
1314
1315  p3x7x->ThdLockStatus = 0;
1316  BKNI_SetEvent(p3x7x->hLockEvent);
1317  retCode = BTHD_P_Acquire(p3x7x);
1318  if (retCode != THD_AcquireResult_Lock) {
1319    BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_INTR, 1 );
1320    BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_INTR, 0 );       
1321  } 
1322  p3x7x->AutoAcquireMasked = false;
1323  BTMR_StartTimer(p3x7x->hTimer, 500000);   /* the timer is in Micro second */
1324
1325  return BERR_SUCCESS;
1326}
1327
1328
1329
1330/***************************************************************************
1331 * BTHD_P_GetDvbtStatus()
1332 ***************************************************************************/
1333void BTHD_P_GetDvbtStatus (BTHD_3x7x_Handle p3x7x, BTHD_THDStatus *pStatus)
1334{
1335  /* Decode Priority */
1336  switch (p3x7x->pStatus->DvbtStatus.Priority)
1337  {
1338  case THD_DvbtPriorityMode_High:
1339    pStatus->eDecodeMode  = BTHD_Decode_Hp; break;
1340  default:
1341    BDBG_WRN(("Unrecognized Priority - defaulting to BTHD_Decode_Lp"));
1342    /* fall through */
1343  case THD_DvbtPriorityMode_Low:
1344    pStatus->eDecodeMode  = BTHD_Decode_Lp; break;
1345  }
1346
1347  /*QAM Mode*/
1348  switch (p3x7x->pStatus->DvbtStatus.Qam)
1349  {
1350  case THD_Qam_Qpsk:
1351    pStatus->eModulation  = BTHD_Modulation_eQpsk; break;
1352  case THD_Qam_16Qam:
1353    pStatus->eModulation  = BTHD_Modulation_e16Qam; break;
1354 default:
1355    BDBG_WRN(("Unrecognized Modulation setting - defaulting to THD_Qam_64Qam"));
1356    /* fall through */
1357  case THD_Qam_64Qam:
1358    pStatus->eModulation  = BTHD_Modulation_e64Qam; break;
1359 
1360  case THD_Qam_Dqpsk:
1361    pStatus->eModulation  = BTHD_Modulation_eDqpsk; break;
1362  } 
1363
1364  /* Code Rate */
1365  switch (p3x7x->pStatus->DvbtStatus.CodeRateHP)
1366  {
1367  case THD_CodeRate_1_2:
1368    pStatus->eCodeRate  = BTHD_CodeRate_e1_2; break;
1369  case THD_CodeRate_2_3:
1370    pStatus->eCodeRate  = BTHD_CodeRate_e2_3; break;
1371  default:
1372    BDBG_WRN(("Unrecognized CodeRateHP - defaulting to BTHD_CodeRate_e3_4"));
1373    /* fall through */
1374  case THD_CodeRate_3_4:
1375    pStatus->eCodeRate  = BTHD_CodeRate_e3_4; break;
1376  case THD_CodeRate_5_6:
1377    pStatus->eCodeRate  = BTHD_CodeRate_e5_6; break;
1378  case THD_CodeRate_7_8:
1379    pStatus->eCodeRate  = BTHD_CodeRate_e7_8; break;
1380  }
1381
1382  /* Hierarchy */
1383  switch (p3x7x->pStatus->DvbtStatus.Hierarchy)
1384  {
1385  case THD_DvbtHierarchy_None:
1386    pStatus->eHierarchy  = BTHD_Hierarchy_0; break;
1387  case THD_DvbtHierarchy_1:
1388    pStatus->eHierarchy  = BTHD_Hierarchy_1; break;
1389  default:
1390    BDBG_WRN(("Unrecognized Hierarchy - defaulting to THD_Hierarchy_2"));
1391    /* fall through */
1392  case THD_DvbtHierarchy_2:
1393    pStatus->eHierarchy  = BTHD_Hierarchy_2; break;
1394  case THD_DvbtHierarchy_4:
1395    pStatus->eHierarchy  = BTHD_Hierarchy_4; break;;
1396  }
1397
1398  /*pStatus->nCellId*/
1399  pStatus->ulRsCorrectedBlocks       = p3x7x->pStatus->DvbtStatus.TS_CBERC;                 /* accumulated corrected blocks by FEC */
1400  pStatus->ulRsUncorrectedBlocks     = p3x7x->pStatus->DvbtStatus.TS_UBERC;                 /* accumlated uncorrected blocks */
1401  pStatus->ulRsCleanBlocks           = p3x7x->pStatus->DvbtStatus.TS_NBERC;                 /* accumlated clean RS blocks */
1402  pStatus->ulRsTotalBlocks                           = p3x7x->pStatus->DvbtStatus.TS_TBERC;
1403  pStatus->ulViterbiUncorrectedBits  = p3x7x->pStatus->DvbtStatus.TS_CERC;                  /* accumlated error bits after Viterbi kk*/
1404  pStatus->ulViterbiTotalbits        = (p3x7x->pStatus->DvbtStatus.TS_TBERC)*8*188;                  /* accumlated number of bits after Viterbi kk*/
1405  pStatus->ulViterbiBer              = p3x7x->pStatus->DvbtStatus.VitBER;                   /* This indicates the viterbi error rate in 1/2147483648 th unit. To calculate the actual rate, take the value and divide by 2147483648 */
1406  pStatus->ulPreViterbiBer           = p3x7x->pStatus->DvbtStatus.PreVitBER;                /* Indicates the pre-viterbi error rate in 1/2147483648 th unit. To calculate the actual rate, take the value and divide by 2147483648 */
1407}
1408
1409
1410
1411/***************************************************************************
1412 * BTHD_P_GetIsdbtStatus()
1413 ***************************************************************************/
1414void BTHD_P_GetIsdbtStatus (BTHD_3x7x_Handle p3x7x, BTHD_THDStatus *pStatus)
1415{
1416#ifdef BTHD_ISDBT_SUPPORT
1417  pStatus->bIsdbtEWS                                    = p3x7x->pStatus->IsdbtStatus.Ews;                /* This return the EWS status bit */
1418  pStatus->bIsdbtPartialReception               = p3x7x->pStatus->IsdbtStatus.Pr;
1419
1420  /*Layer A Modulation*/
1421 
1422  switch (p3x7x->pStatus->IsdbtStatus.Qam[0])
1423  {
1424  case THD_Qam_Qpsk:
1425    pStatus->eIsdbtAModulation  = BTHD_Modulation_eQpsk; break;
1426  case THD_Qam_16Qam:
1427    pStatus->eIsdbtAModulation  = BTHD_Modulation_e16Qam; break;
1428  default:
1429    BDBG_WRN(("Unrecognized Modulation setting 0 - defaulting to THD_Qam_64Qam"));
1430    /* fall through */
1431  case THD_Qam_64Qam:
1432    pStatus->eIsdbtAModulation  = BTHD_Modulation_e64Qam; break;
1433  case THD_Qam_Dqpsk:
1434    pStatus->eIsdbtAModulation  = BTHD_Modulation_eDqpsk; break;
1435  }
1436
1437  /*Layer A CodeRate*/
1438  switch (p3x7x->pStatus->IsdbtStatus.CodeRate[0])
1439  {
1440  case THD_CodeRate_1_2:
1441    pStatus->eIsdbtACodeRate  = BTHD_CodeRate_e1_2; break;
1442  case THD_CodeRate_2_3:
1443    pStatus->eIsdbtACodeRate  = BTHD_CodeRate_e2_3; break;
1444  default:
1445    BDBG_WRN(("Unrecognized CodeRateHP - defaulting to BTHD_CodeRate_e3_4"));
1446    /* fall through */
1447  case THD_CodeRate_3_4:
1448    pStatus->eIsdbtACodeRate  = BTHD_CodeRate_e3_4; break;
1449  case THD_CodeRate_5_6:
1450    pStatus->eIsdbtACodeRate  = BTHD_CodeRate_e5_6; break;
1451  case THD_CodeRate_7_8:
1452    pStatus->eIsdbtACodeRate  = BTHD_CodeRate_e7_8; break;
1453  }
1454
1455  /*Layer A TimeInterleaving*/       
1456  switch (p3x7x->pStatus->IsdbtStatus.TimeInt[0])
1457  {
1458  case THD_IsdbtTimeInt_0X:
1459    pStatus->eIsdbtATimeInterleaving  = BTHD_IsdbtTimeInterleaving_0X; break;
1460  case THD_IsdbtTimeInt_1X:
1461    pStatus->eIsdbtATimeInterleaving  = BTHD_IsdbtTimeInterleaving_1X; break;
1462  case THD_IsdbtTimeInt_2X:
1463    pStatus->eIsdbtATimeInterleaving  = BTHD_IsdbtTimeInterleaving_2X; break;
1464  default:
1465    BDBG_WRN(("Unrecognized Time Interleaving - defaulting to THD_TimeInt_4X"));
1466    /* fall through */
1467  case THD_IsdbtTimeInt_4X:
1468    pStatus->eIsdbtATimeInterleaving  = BTHD_IsdbtTimeInterleaving_3X; break;
1469  }
1470
1471  pStatus->eIsdbtASegments                                      = p3x7x->pStatus->IsdbtStatus.Segments[0];
1472  pStatus->ulIsdbtARsCorrectedBlocks            = p3x7x->pStatus->IsdbtStatus.TS_CBERC[0]; 
1473  pStatus->ulIsdbtARsUncorrectedBlocks          = p3x7x->pStatus->IsdbtStatus.TS_UBERC[0];
1474  pStatus->ulIsdbtARsCleanBlocks                        = p3x7x->pStatus->IsdbtStatus.TS_NBERC[0];
1475  pStatus->ulIsdbtARsTotalBlocks                        = p3x7x->pStatus->IsdbtStatus.TS_TBERC[0];         
1476  pStatus->ulIsdbtAViterbiUncorrectedBits       = p3x7x->pStatus->IsdbtStatus.VitBER[0];
1477  pStatus->ulIsdbtAViterbiTotalbits                     = (p3x7x->pStatus->IsdbtStatus.TS_TBERC[0])*8*188;
1478
1479  /*Layer B Modulation*/     
1480  switch (p3x7x->pStatus->IsdbtStatus.Qam[1])
1481  {
1482  case THD_Qam_Qpsk:
1483    pStatus->eIsdbtBModulation  = BTHD_Modulation_eQpsk; break;
1484  case THD_Qam_16Qam:
1485    pStatus->eIsdbtBModulation  = BTHD_Modulation_e16Qam; break;
1486 default:
1487    BDBG_WRN(("Unrecognized Modulation setting 1 - defaulting to THD_Qam_64Qam"));
1488    /* fall through */
1489  case THD_Qam_64Qam:
1490    pStatus->eIsdbtBModulation  = BTHD_Modulation_e64Qam; break;
1491  case THD_Qam_Dqpsk:
1492    pStatus->eIsdbtBModulation  = BTHD_Modulation_eDqpsk; break;
1493  }
1494
1495  /*Layer B CodeRate*/
1496  switch (p3x7x->pStatus->IsdbtStatus.CodeRate[1])
1497  {
1498  case THD_CodeRate_1_2:
1499    pStatus->eIsdbtBCodeRate  = BTHD_CodeRate_e1_2; break;
1500  case THD_CodeRate_2_3:
1501    pStatus->eIsdbtBCodeRate  = BTHD_CodeRate_e2_3; break;
1502  default:
1503    BDBG_WRN(("Unrecognized CodeRateHP - defaulting to BTHD_CodeRate_e3_4"));
1504    /* fall through */
1505  case THD_CodeRate_3_4:
1506    pStatus->eIsdbtBCodeRate  = BTHD_CodeRate_e3_4; break;
1507  case THD_CodeRate_5_6:
1508    pStatus->eIsdbtBCodeRate  = BTHD_CodeRate_e5_6; break;
1509  case THD_CodeRate_7_8:
1510    pStatus->eIsdbtBCodeRate  = BTHD_CodeRate_e7_8; break;
1511  }
1512
1513  /*Layer B TimeInterleaving*/       
1514  switch (p3x7x->pStatus->IsdbtStatus.TimeInt[1])
1515  {
1516  case THD_IsdbtTimeInt_0X:
1517    pStatus->eIsdbtBTimeInterleaving  = BTHD_IsdbtTimeInterleaving_0X; break;
1518  case THD_IsdbtTimeInt_1X:
1519    pStatus->eIsdbtBTimeInterleaving  = BTHD_IsdbtTimeInterleaving_1X; break;
1520  case THD_IsdbtTimeInt_2X:
1521    pStatus->eIsdbtBTimeInterleaving  = BTHD_IsdbtTimeInterleaving_2X; break;
1522  default:
1523    BDBG_WRN(("Unrecognized Time Interleaving - defaulting to THD_TimeInt_4X"));
1524    /* fall through */
1525  case THD_IsdbtTimeInt_4X:
1526    pStatus->eIsdbtBTimeInterleaving  = BTHD_IsdbtTimeInterleaving_3X; break;
1527  }
1528
1529  pStatus->eIsdbtBSegments                                      = p3x7x->pStatus->IsdbtStatus.Segments[1];
1530  pStatus->ulIsdbtBRsCorrectedBlocks            = p3x7x->pStatus->IsdbtStatus.TS_CBERC[1]; 
1531  pStatus->ulIsdbtBRsUncorrectedBlocks          = p3x7x->pStatus->IsdbtStatus.TS_UBERC[1];
1532  pStatus->ulIsdbtBRsCleanBlocks                        = p3x7x->pStatus->IsdbtStatus.TS_NBERC[1];
1533  pStatus->ulIsdbtBRsTotalBlocks                        = p3x7x->pStatus->IsdbtStatus.TS_TBERC[1];         
1534  pStatus->ulIsdbtBViterbiUncorrectedBits       = p3x7x->pStatus->IsdbtStatus.VitBER[1];
1535  pStatus->ulIsdbtBViterbiTotalbits                     = (p3x7x->pStatus->IsdbtStatus.TS_TBERC[1])*8*188;
1536
1537  /*Layer C Modulation*/     
1538  switch (p3x7x->pStatus->IsdbtStatus.Qam[2])
1539  {
1540  case THD_Qam_Qpsk:
1541    pStatus->eIsdbtCModulation  = BTHD_Modulation_eQpsk; break;
1542  case THD_Qam_16Qam:
1543    pStatus->eIsdbtCModulation  = BTHD_Modulation_e16Qam; break;
1544  default:
1545    BDBG_WRN(("Unrecognized Modulation setting 2 - defaulting to THD_Qam_64Qam"));
1546    /* fall through */
1547  case THD_Qam_64Qam:
1548    pStatus->eIsdbtCModulation  = BTHD_Modulation_e64Qam; break;
1549  case THD_Qam_Dqpsk:
1550    pStatus->eIsdbtCModulation  = BTHD_Modulation_eDqpsk; break;
1551  }
1552
1553  /*Layer C CodeRate*/
1554  switch (p3x7x->pStatus->IsdbtStatus.CodeRate[2])
1555  {
1556  case THD_CodeRate_1_2:
1557    pStatus->eIsdbtCCodeRate  = BTHD_CodeRate_e1_2; break;
1558  case THD_CodeRate_2_3:
1559    pStatus->eIsdbtCCodeRate  = BTHD_CodeRate_e2_3; break;
1560  default:
1561    BDBG_WRN(("Unrecognized CodeRateHP - defaulting to BTHD_CodeRate_e3_4"));
1562    /* fall through */
1563  case THD_CodeRate_3_4:
1564    pStatus->eIsdbtCCodeRate  = BTHD_CodeRate_e3_4; break;
1565  case THD_CodeRate_5_6:
1566    pStatus->eIsdbtCCodeRate  = BTHD_CodeRate_e5_6; break;
1567  case THD_CodeRate_7_8:
1568    pStatus->eIsdbtCCodeRate  = BTHD_CodeRate_e7_8; break;
1569  }
1570
1571  /*Layer C TimeInterleaving*/       
1572  switch (p3x7x->pStatus->IsdbtStatus.TimeInt[2])
1573  {
1574  case THD_IsdbtTimeInt_0X:
1575    pStatus->eIsdbtCTimeInterleaving  = BTHD_IsdbtTimeInterleaving_0X; break;
1576  case THD_IsdbtTimeInt_1X:
1577    pStatus->eIsdbtCTimeInterleaving  = BTHD_IsdbtTimeInterleaving_1X; break;
1578  case THD_IsdbtTimeInt_2X:
1579    pStatus->eIsdbtCTimeInterleaving  = BTHD_IsdbtTimeInterleaving_2X; break;
1580  default:
1581    BDBG_WRN(("Unrecognized Time Interleaving - defaulting to THD_TimeInt_4X"));
1582    /* fall through */
1583  case THD_IsdbtTimeInt_4X:
1584    pStatus->eIsdbtCTimeInterleaving  = BTHD_IsdbtTimeInterleaving_3X; break;
1585  }
1586
1587  pStatus->eIsdbtCSegments                                      = p3x7x->pStatus->IsdbtStatus.Segments[2];
1588  pStatus->ulIsdbtCRsCorrectedBlocks            = p3x7x->pStatus->IsdbtStatus.TS_CBERC[2]; 
1589  pStatus->ulIsdbtCRsUncorrectedBlocks          = p3x7x->pStatus->IsdbtStatus.TS_UBERC[2];
1590  pStatus->ulIsdbtCRsCleanBlocks                        = p3x7x->pStatus->IsdbtStatus.TS_NBERC[2];
1591  pStatus->ulIsdbtCRsTotalBlocks                        = p3x7x->pStatus->IsdbtStatus.TS_TBERC[2];         
1592  pStatus->ulIsdbtCViterbiUncorrectedBits       = p3x7x->pStatus->IsdbtStatus.VitBER[2];
1593  pStatus->ulIsdbtCViterbiTotalbits                     = (p3x7x->pStatus->IsdbtStatus.TS_TBERC[2])*8*188;
1594#else
1595        BSTD_UNUSED(p3x7x);
1596        BSTD_UNUSED(pStatus);
1597#endif
1598}
1599
1600/***************************************************************************
1601 * BTHD_3x7x_GetStatus()
1602 ***************************************************************************/
1603BERR_Code BTHD_3x7x_GetStatus (BTHD_Handle h, BTHD_THDStatus *pStatus)
1604{
1605  BTHD_3x7x_P_Handle *p3x7x;
1606  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1607  BDBG_MSG(("BTHD_3x7x_GetStatus"));
1608  BTHD_P_Status(p3x7x);
1609
1610  BDBG_ASSERT( NULL != pStatus );
1611
1612  if (p3x7x->pStatus->PowerStatus != THD_ePower_On)
1613      return BERR_NOT_INITIALIZED;
1614 
1615  /* ---------------  Mapping Common Fields ---------------- */
1616
1617  pStatus->bReceiverLock             = ((p3x7x->ThdLockStatus >> THD_LockStatusBit_SystemLock) & 1);    /* Indicates whether the receiver is locked */
1618  pStatus->bFecLock                  = ((p3x7x->ThdLockStatus >> THD_LockStatusBit_SystemLock) & 1);       /* Indicates whether FEC is locked */
1619  pStatus->bNoSignalDetected         = ((p3x7x->ThdLockStatus >> THD_LockStatusBit_NoDVBTSignal) & 1);  /* Indicates whether signal is detected. Only should be used by channel scan as a flag to move on to the next channel */                                       
1620
1621
1622  /* Transmission Mode */
1623  switch (p3x7x->pStatus->TransmissionMode)
1624  {
1625
1626  case THD_TransmissionMode_2k:
1627    pStatus->eTransmissionMode  = BTHD_TransmissionMode_e2K; break;
1628  case THD_TransmissionMode_4k:
1629    pStatus->eTransmissionMode  = BTHD_TransmissionMode_e4K; break;
1630  default:
1631    BDBG_WRN(("Unrecognized TransmissionMode - defaulting to THD_TransmissionMode_8k"));
1632    /* fall through */
1633  case THD_TransmissionMode_8k:
1634    pStatus->eTransmissionMode  = BTHD_TransmissionMode_e8K; break;
1635  }
1636
1637  /* Guard Interval */
1638  switch (p3x7x->pStatus->GuardInterval)
1639  {
1640  case THD_GuardInterval_1_32:
1641    pStatus->eGuardInterval  = BTHD_GuardInterval_e1_32; break;
1642  case THD_GuardInterval_1_16:
1643    pStatus->eGuardInterval  = BTHD_GuardInterval_e1_16; break;
1644  default:
1645    BDBG_WRN(("Unrecognized GuardInterval - defaulting to BTHD_GuardInterval_e1_8"));
1646    /* fall through */
1647  case THD_GuardInterval_1_8:
1648    pStatus->eGuardInterval  = BTHD_GuardInterval_e1_8; break;
1649  case THD_GuardInterval_1_4:
1650    pStatus->eGuardInterval  = BTHD_GuardInterval_e1_4; break;
1651  }
1652
1653  pStatus->ulRFAgc                   = p3x7x->pStatus->RagcGain;                 /* RF Agc value in 1/10 percent */
1654  pStatus->ulIFAgc                   = p3x7x->pStatus->IagcGain;                 /* IF Agc value in 1/10 percent */
1655  /*pStatus->nSignalStrength */
1656  pStatus->lCarrierOffset            = p3x7x->pStatus->CarrierOffset;            /* Offset of carrier loop in Hz */
1657  pStatus->lTimingOffset             = p3x7x->pStatus->TimingOffset;             /* Offset of timing loop in Hz */
1658  pStatus->nSnr                      = p3x7x->pStatus->SNR;                      /* SNR value of reciever in 1/256th dB */   
1659  pStatus->bSpectrumInverted         = p3x7x->pStatus->Spectrum;                  /* Indicates the signal is inverted */
1660  pStatus->ulReacqCount              = p3x7x->pStatus->ReacquireCount;           /* number of reacquisitions performed */
1661  /*pStatus->bValid*/
1662  pStatus->nSignalStrength                       = p3x7x->pStatus->SignalStrength*100/256 + 4875;
1663
1664  /* ---------------  Mapping DVB-T Specific Fields ---------------- */
1665 if (p3x7x->pAcquireParam->CommonAcquireParam.Standard == THD_Standard_DVBT) 
1666        BTHD_P_GetDvbtStatus (p3x7x, pStatus);
1667  /* ---------------  Mapping ISDB-T Specific Fields ---------------- */
1668#ifdef BTHD_ISDBT_SUPPORT
1669 if (p3x7x->pAcquireParam->CommonAcquireParam.Standard == THD_Standard_ISDBT) 
1670        BTHD_P_GetIsdbtStatus (p3x7x, pStatus);
1671#endif
1672  return BERR_SUCCESS;
1673
1674}
1675
1676/******************************************************************************
1677 * BTHD_LockStatus()
1678 ******************************************************************************/
1679BERR_Code BTHD_3x7x_GetLockStatus(BTHD_Handle h, BTHD_LockStatus *pLockStatus)
1680{
1681  BTHD_3x7x_P_Handle *p3x7x;
1682  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1683
1684  if (p3x7x->pStatus->PowerStatus != THD_ePower_On) {
1685                BDBG_ERR(("BTHD_3x7x_LockStatus: power is still off  "));
1686                return BERR_NOT_INITIALIZED;
1687  }
1688       
1689  *pLockStatus = (bool) ((p3x7x->ThdLockStatus >> THD_LockStatusBit_SystemLock) & 1);   
1690  return BERR_SUCCESS; 
1691}
1692
1693/******************************************************************************
1694 * BTHD_ResetStatus()
1695 ******************************************************************************/
1696BERR_Code BTHD_3x7x_ResetStatus(BTHD_Handle h)
1697{
1698  BTHD_3x7x_P_Handle *p3x7x;
1699  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1700
1701  if (p3x7x->pStatus->PowerStatus != THD_ePower_On) {
1702                BDBG_ERR(("BTHD_3x7x_ResetStatus: power is still off  "));
1703                return BERR_NOT_INITIALIZED;
1704  }
1705       
1706  BTHD_P_ResetStatusHW(p3x7x);
1707  BTHD_P_ResetStatus(p3x7x);
1708  p3x7x->pStatus->ReacquireCount = 0;   
1709  return BERR_SUCCESS;
1710}
1711
1712/***************************************************************************
1713 * BTHD_3x7x_GetConstellation()
1714 ***************************************************************************/
1715BERR_Code BTHD_3x7x_GetConstellation(BTHD_Handle h, int16_t *pI, int16_t *pQ) 
1716{
1717
1718  int16_t nbrGotten ; 
1719  BTHD_3x7x_P_Handle *p3x7x;
1720  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1721
1722    if (p3x7x->pStatus->PowerStatus != THD_ePower_On) {
1723                BDBG_ERR(("BTHD_3x7x_GetConstellation: power is still off  "));
1724                return BERR_NOT_INITIALIZED;
1725  }
1726#ifdef BTHD_ISDBT_SUPPORT
1727  if (p3x7x->pAcquireParam->CommonAcquireParam.Standard == THD_Standard_ISDBT)
1728        BTHD_P_GetIsdbtSoftDecisionBuf(p3x7x, THD_IQ_CONSTELLATION_VECTORS, pI, pQ, &nbrGotten);
1729  else
1730#endif
1731  BTHD_P_GetDvbtSoftDecisionBuf(p3x7x, THD_IQ_CONSTELLATION_VECTORS, pI, pQ, &nbrGotten);
1732     
1733
1734  return BERR_SUCCESS;
1735}
1736/******************************************************************************
1737 * BTHD_3x7x_ProcessBBSInterruptEvent()
1738 ******************************************************************************/
1739BERR_Code BTHD_3x7x_ProcessBBSInterruptEvent(BTHD_Handle h)
1740{
1741  BTHD_3x7x_P_Handle *p3x7x;
1742  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1743
1744  if (p3x7x->pStatus->PowerStatus != THD_ePower_On) {
1745                BDBG_MSG(("BTHD_3x7x_ProcessBBSInterruptEvent: power is still off  "));
1746                return BERR_NOT_INITIALIZED;
1747  }
1748
1749  /*BDBG_WRN(("BTHD_3x7x_ProcessBBSInterruptEvent "));*/
1750  if (p3x7x->pAcquireParam->CommonAcquireParam.NexusStatusMode & THD_NexusStatusMode_EnableStatusForNexus)
1751  {
1752    BTHD_P_Status(p3x7x);
1753    p3x7x->pAcquireParam->CommonAcquireParam.NexusStatusMode &= (~THD_NexusStatusMode_EnableStatusForNexus);
1754  }
1755
1756  if (p3x7x->pAcquireParam->CommonAcquireParam.AcquireMode & THD_AcquireMode_ResetStatus) {
1757    p3x7x->pAcquireParam->CommonAcquireParam.AcquireMode &= ~THD_AcquireMode_ResetStatus;
1758    BTHD_3x7x_ResetStatus(h);
1759  }
1760
1761  if (p3x7x->pAcquireParam->CommonAcquireParam.AcquireMode & THD_AcquireMode_Manual)
1762  {
1763    p3x7x->pAcquireParam->CommonAcquireParam.AcquireMode &= ~THD_AcquireMode_Manual;
1764        BTHD_P_ResetEvent(p3x7x);
1765    p3x7x->pStatus->ReacquireCount = 0;
1766        p3x7x->LockStatusTracking = 0xFFFFFFFF;
1767        BTHD_P_Acquire(p3x7x);
1768        p3x7x->AutoAcquireMasked = false;
1769  }
1770
1771  BTMR_StopTimer(p3x7x->hBBSTimer); /* just tobe safe */
1772  BTMR_StartTimer(p3x7x->hBBSTimer, 1000000);   /* the timer is in Micro second */
1773
1774  return BERR_SUCCESS;
1775}
1776
1777
1778/******************************************************************************
1779 * BTHD_ProcessInterruptEvent()
1780 ******************************************************************************/
1781BERR_Code BTHD_3x7x_ProcessInterruptEvent(BTHD_Handle h)
1782{
1783  BTHD_3x7x_P_Handle *p3x7x;
1784  BERR_Code retCode;
1785#ifdef BTHD_ISDBT_SUPPORT
1786  static uint8_t EWS_Setting=0;
1787  static uint32_t TMCC_Err=0;
1788  uint32_t TMCC_SYNC_value, TMCC_Alert_value, TMCC_Err_update;
1789#endif
1790  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1791
1792
1793  BDBG_MSG(("BTHD_ProcessInterruptEvent "));
1794
1795  if (p3x7x->pStatus->PowerStatus != THD_ePower_On) {
1796                BDBG_ERR(("BTHD_3x7x_ProcessInterruptEvent: power is still off  "));
1797                return BERR_NOT_INITIALIZED;
1798  }
1799
1800#ifdef BTHD_ISDBT_SUPPORT
1801  if ((p3x7x->pAcquireParam->CommonAcquireParam.Standard == THD_Standard_ISDBT) && ((p3x7x->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1)) {
1802    /* EWS bit flips when the cable is not connected, so we need to read the error count to make sure the cable is connected before */
1803    /* reporting the EWS status event change */
1804    TMCC_SYNC_value = BREG_ReadField(p3x7x->hRegister, THD_CORE_STATUS, TMCC_SYNC);
1805    if (TMCC_SYNC_value)
1806    {
1807                TMCC_Err_update = BREG_Read32(p3x7x->hRegister, BCHP_THD_CORE_TMCC_UBERC);
1808      if (TMCC_Err == TMCC_Err_update)
1809      {
1810                  TMCC_Alert_value = BREG_ReadField(p3x7x->hRegister, THD_CORE_TMCC_MISC, ALERT);
1811        /* If the channel is lock after tuning, set EWS event when EWS is on */
1812        if(p3x7x->pAcquireParam->IsdbtLocaleParam.EwsFlag & THD_IsdbtEwsFlag_eLockStartEWS)
1813        {
1814                        if (1 == TMCC_Alert_value)
1815          {
1816            p3x7x->pAcquireParam->IsdbtLocaleParam.EwsFlag &= ~THD_IsdbtEwsFlag_eLockStartEWS;
1817            p3x7x->pAcquireParam->IsdbtLocaleParam.EwsFlag &= ~THD_IsdbtEwsFlag_eUnlockStopEWS;
1818            BKNI_SetEvent(p3x7x->hEWSEvent);
1819            EWS_Setting = TMCC_Alert_value;
1820            TMCC_Err = TMCC_Err_update;
1821          }
1822        }
1823        /* In other cases, set EWS event when EWS changes */
1824        else if (EWS_Setting != TMCC_Alert_value)
1825        {
1826          p3x7x->pAcquireParam->IsdbtLocaleParam.EwsFlag &= ~THD_IsdbtEwsFlag_eUnlockStopEWS;
1827          BKNI_SetEvent(p3x7x->hEWSEvent);
1828          EWS_Setting = TMCC_Alert_value;
1829          TMCC_Err = TMCC_Err_update;
1830        }
1831      }
1832    }
1833  }
1834#endif
1835
1836  if ((p3x7x->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1) {
1837    BDBG_MSG(("Still locked"));
1838  } else {         
1839    BDBG_MSG(("Not locked %0x  %0x",  ((p3x7x->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1), p3x7x->LockStatusTracking));
1840        if (p3x7x->LockStatusTracking != ((p3x7x->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1)) 
1841        {
1842                p3x7x->LockStatusTracking = ((p3x7x->ThdLockStatus>> THD_LockStatusBit_SystemLock) & 1); 
1843                BKNI_SetEvent(p3x7x->hLockEvent);
1844#ifdef BTHD_ISDBT_SUPPORT
1845                if (p3x7x->pAcquireParam->CommonAcquireParam.Standard == THD_Standard_ISDBT) {
1846        /* If the channel is unlock, set EWS event if EWS has been started before. For the unlock channel after tuning , don't set EWS event */
1847          if (!(p3x7x->pAcquireParam->IsdbtLocaleParam.EwsFlag & THD_IsdbtEwsFlag_eUnlockStopEWS) && EWS_Setting == 1)
1848          {
1849                          BKNI_SetEvent(p3x7x->hEWSEvent);
1850          }
1851          EWS_Setting = 0;
1852                }
1853#endif
1854        }
1855    if (p3x7x->pAcquireParam->CommonAcquireParam.AcquireMode & (THD_AcquireMode_Auto | THD_AcquireMode_Scan) && ( ! p3x7x->AutoAcquireMasked) ) {
1856   /* if (p3x7x->pAcquireParam->CommonAcquireParam.AcquireMode & THD_AcquireMode_Auto) { */
1857      BTHD_P_ResetEvent(p3x7x);
1858      BTMR_StopTimer(p3x7x->hTimer);
1859      retCode = BTHD_P_Acquire(p3x7x);
1860      if (retCode != THD_AcquireResult_Lock) {
1861        BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_INTR, 1 );
1862        BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_INTR, 0 );       
1863#ifdef BTHD_ISDBT_SUPPORT
1864                if (p3x7x->pAcquireParam->CommonAcquireParam.Standard == THD_Standard_ISDBT) {
1865                  BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_B_INTR, 1 );
1866                  BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_C_INTR, 1 );
1867                  BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_B_INTR, 0 );   
1868                  BREG_WriteField(p3x7x->hRegister, THD_INTR2B_CPU_SET, RS_SYNC_LOSS_C_INTR, 0 );   
1869                }
1870#endif
1871      }
1872
1873   }
1874    /* In case of single acquire: if we lose lock, as long as the app is informed the AP is done */
1875  }
1876  BTMR_StartTimer(p3x7x->hTimer, 500000);   /* the timer is in Micro second */
1877
1878
1879  return BERR_SUCCESS;
1880}
1881
1882/******************************************************************************
1883BTHD_3x7x_GetLockStateChangeEvent()
1884******************************************************************************/
1885BERR_Code BTHD_3x7x_GetLockStateChangeEvent(BTHD_Handle h, BKNI_EventHandle* hEvent)
1886{
1887  BTHD_3x7x_P_Handle *p3x7x;
1888  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1889
1890  *hEvent = p3x7x->hLockEvent; 
1891  return BERR_SUCCESS;
1892}
1893
1894/******************************************************************************
1895BTHD_3x7x_GetInterruptEventHandle()
1896******************************************************************************/
1897BERR_Code BTHD_3x7x_GetInterruptEventHandle(BTHD_Handle h, BKNI_EventHandle* hEvent)
1898{
1899  BTHD_3x7x_P_Handle *p3x7x;
1900  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1901       
1902  *hEvent = p3x7x->hInterruptEvent;
1903  return BERR_SUCCESS;
1904
1905}
1906
1907/******************************************************************************
1908BTHD_3x7x_GetInterruptEventHandle()
1909******************************************************************************/
1910BERR_Code BTHD_3x7x_GetBBSInterruptEventHandle(BTHD_Handle h, BKNI_EventHandle* hEvent)
1911{
1912  BTHD_3x7x_P_Handle *p3x7x;
1913  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1914       
1915  *hEvent = p3x7x->hBBSInterruptEvent;
1916  return BERR_SUCCESS;
1917
1918}
1919
1920/******************************************************************************
1921BTHD_3x7x_GetEWSEventHandle()
1922******************************************************************************/
1923BERR_Code BTHD_3x7x_GetEWSEventHandle(BTHD_Handle h, BKNI_EventHandle* hEvent)
1924{
1925  BTHD_3x7x_P_Handle *p3x7x;
1926  p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1927
1928  *hEvent = p3x7x->hEWSEvent;
1929  return BERR_SUCCESS;
1930}
1931
1932/******************************************************************************
1933BTHD_3x7x_PowerDown()
1934******************************************************************************/
1935BERR_Code BTHD_3x7x_PowerDown(BTHD_Handle h)
1936{
1937        BTHD_3x7x_P_Handle *p3x7x;
1938        p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1939
1940        p3x7x->pStatus->PowerStatus = THD_ePower_Off;
1941        BREG_Write32(p3x7x->hRegister, BCHP_THD_CORE_CLK, 0xFFFFFFFF);
1942
1943        return BERR_SUCCESS;
1944}
1945
1946/******************************************************************************
1947BTHD_3x7x_PowerUp()
1948******************************************************************************/
1949BERR_Code BTHD_3x7x_PowerUp(BTHD_Handle h)
1950{
1951        BTHD_3x7x_P_Handle *p3x7x;
1952        p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1953
1954        BREG_Write32(p3x7x->hRegister, BCHP_THD_CORE_CLK, 0);
1955        p3x7x->pStatus->PowerStatus = THD_ePower_On;
1956        return BERR_SUCCESS;
1957}
1958
1959/***************************************************************************
1960BTHD_3x7x_InstallCallback
1961****************************************************************************/
1962BERR_Code BTHD_3x7x_InstallCallback(BTHD_Handle         h,  /* [in] Device channel handle */
1963                                                           BTHD_Callback                callbackType, /* [in] Type of callback */
1964                                                           BTHD_CallbackFunc    pCallback,     /* [in] Function Ptr to callback */
1965                                                           void                                 *pParam        /* [in] Generic parameter send on callback */
1966                                                           )
1967{
1968   BERR_Code retCode = BERR_SUCCESS;
1969     BTHD_3x7x_P_Handle *p3x7x;
1970   p3x7x = (BTHD_3x7x_P_Handle *)(h->pImpl);
1971   BDBG_ENTER(BTHD_InstallCallback);
1972
1973    switch( callbackType )
1974    {
1975        case BTHD_Callback_eLockChange:
1976            p3x7x->pCallback[callbackType] = pCallback;
1977            p3x7x->pCallbackParam[callbackType] = pParam;
1978            break;
1979                case BTHD_Callback_eUpdateGain:
1980            p3x7x->pCallback[callbackType] = pCallback;
1981            p3x7x->pCallbackParam[callbackType] = pParam;
1982            break;
1983                case BTHD_Callback_eNoSignal:
1984            p3x7x->pCallback[callbackType] = pCallback;
1985            p3x7x->pCallbackParam[callbackType] = pParam;
1986            break;
1987                case BTHD_Callback_eTuner:
1988            p3x7x->pCallback[callbackType] = pCallback;
1989            p3x7x->pCallbackParam[callbackType] = pParam;
1990            break;
1991
1992        default:
1993            retCode = BERR_TRACE(BERR_INVALID_PARAMETER);
1994            break;
1995    }
1996
1997    BDBG_LEAVE(BTHD_InstallCallback);
1998    return( retCode );
1999       
2000}
2001/******************************************************************************
2002BTHD_3x7x_P_TNR_callback()
2003******************************************************************************/ 
2004BERR_Code BTHD_3x7x_P_TNR_callback(
2005BTHD_3x7x_Handle        h,
2006uint16_t                        Mode,
2007int16_t                         *Gain,
2008uint16_t                        *SmartTune,
2009uint32_t                        *RF_Freq       
2010)
2011{
2012         BTHD_P_ThdCallbackData_t TunerCallback;
2013#if ((BCHP_CHIP==7552) || (BCHP_CHIP==3461))
2014        TunerCallback.hTunerChn = (h->pCallbackParam[BTHD_Callback_eTuner]);
2015        switch (Mode)
2016        {
2017                case BTHD_CallbackMode_eDisablePower:
2018                          TunerCallback.Mode = BTHD_CallbackMode_eDisablePower;
2019                          break;
2020                case BTHD_CallbackMode_eEnablePower:
2021                          TunerCallback.Mode = BTHD_CallbackMode_eEnablePower;
2022                          break;
2023                case BTHD_CallbackMode_eSetMode:
2024                          TunerCallback.Mode = BTHD_CallbackMode_eSetMode;
2025                          TunerCallback.Freq_Offset = 0;
2026                          TunerCallback.Symbol_Rate = 0;
2027                          break;
2028                case BTHD_CallbackMode_eRequestMode:
2029                          TunerCallback.Mode = BTHD_CallbackMode_eRequestMode;
2030                          break;
2031                case BTHD_CallbackMode_eSmartTune:
2032                          TunerCallback.Mode = BTHD_CallbackMode_eSmartTune;
2033                          break;                         
2034        }
2035        BKNI_EnterCriticalSection();
2036        (h->pCallback[BTHD_Callback_eTuner])(&TunerCallback);   
2037        BKNI_LeaveCriticalSection();
2038
2039        *SmartTune = TunerCallback.SmartTune;
2040       
2041  /* Compute total tuner gain */
2042        *Gain = TunerCallback.External_Gain_x256db;
2043        if (!((TunerCallback.PreADC_Gain_x256db == -32768) || (TunerCallback.PostADC_Gain_x256db == -32768)))
2044          *Gain += (TunerCallback.PreADC_Gain_x256db + TunerCallback.PostADC_Gain_x256db);
2045        *RF_Freq = TunerCallback.RF_Freq;
2046
2047#else
2048        TunerCallback.RF_Freq = 0;
2049        TunerCallback.Total_Mix_After_ADC = 0;         
2050        TunerCallback.PreADC_Gain_x256db  = 0;           
2051        TunerCallback.PostADC_Gain_x256db = 0;           
2052        TunerCallback.External_Gain_x256db = 0;
2053        TunerCallback.SmartTune = 0;       
2054#endif
2055
2056  return BERR_SUCCESS;
2057} 
2058
2059
2060
Note: See TracBrowser for help on using the repository browser.