source: svn/trunk/newcon3bcm2_21bu/dta/src/settop_api/bsettop_tuner_isdb.c

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

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 22.8 KB
Line 
1 /***************************************************************************
2 *     Copyright (c) 2013, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile:  $
11 * $brcm_Revision:  $
12 * $brcm_Date: $
13 *
14 * Module Description:
15 *              ACB615 ISDB-T driver
16 *
17 * Revision History:
18 *              Modified by Liqun Ruan for the box with IDSB-T frontend
19 *
20 * $brcm_Log:  $
21 *
22 ***************************************************************************/
23#include "bsettop_tuner.h"
24#include "bthd.h"
25#include "bthd_priv.h"
26#include "bthd_3x7x.h"
27#include "btnr_3x7x.h"
28#include "gist.h"
29#include "breg_i2c_priv.h"
30#include "bchp_hif_cpu_intr1.h"
31#include "bos_task_priorities.h"
32#include "bsettop_tuner_isdb_p.h"
33
34#include "bchp_hif_cpu_intr1.h"
35#include "int1.h"
36
37BDBG_MODULE(bsettop_tuner_isdb);
38
39static btuner_t s_tuner = NULL;
40
41/***************************************************************************
42Summary:
43Acquisition processing thread
44 ***************************************************************************/
45static void btuner_task(void *arg)
46{
47    btuner_t p_tuner = (btuner_t)arg;
48    BDBG_ASSERT(p_tuner);
49    BDBG_MSG(("btuner_task"));
50    BERR_Code rc;
51
52#if 1
53    /* DO we need to enable THD interrupts explicitly? */
54    {
55        uint32_t reg;
56
57        reg = BREG_Read32(GetREG(),BCHP_HIF_CPU_INTR1_INTR_W2_MASK_CLEAR);
58        reg |= BCHP_HIF_CPU_INTR1_INTR_W2_STATUS_THD_A_CPU_INTR_MASK | BCHP_HIF_CPU_INTR1_INTR_W2_STATUS_THD_B_CPU_INTR_MASK;
59                BDBG_WRN(("===BCHP_HIF_CPU_INTR1_INTR_W2_MASK_CLEAR=0x%08x ", reg));
60        BREG_Write32(GetREG(),BCHP_HIF_CPU_INTR1_INTR_W2_MASK_CLEAR, reg);
61    }
62#endif
63
64    while (1)
65    {
66#if 0
67                uint32_t flags;
68
69                flags = bos_enter_critical();
70                //if (p_tuner->intEnable)
71                {
72                        /* Active Low */
73                        if (BREG_Read32(GetREG(),BCHP_HIF_CPU_INTR1_INTR_W2_STATUS) & BCHP_HIF_CPU_INTR1_INTR_W2_STATUS_THD_A_CPU_INTR_MASK)
74                        {
75                                p_tuner->in_critical = true;
76                                BDBG_WRN(("%s thdInterrupt", __func__));
77                                BTHD_HandleInterrupt_isr(p_tuner->thdHandle);
78                                p_tuner->in_critical = false;
79                        }
80                }
81                bos_exit_critical(flags);
82#endif
83
84                if (p_tuner->thdIsrEvent)
85                {
86                        rc = BKNI_WaitForEvent(p_tuner->thdIsrEvent,THD_EVT_TIMEOUT_MS);
87                        if (rc == BERR_SUCCESS)
88                        {
89                                BDBG_WRN(("%s thdIsrEvent", __func__));
90                                BTHD_ProcessInterruptEvent(p_tuner->thdHandle);
91                        }
92                }
93
94        if (p_tuner->thdBbsEvent)
95        {
96            rc = BKNI_WaitForEvent(p_tuner->thdBbsEvent,THD_EVT_TIMEOUT_MS);
97            if (rc == BERR_SUCCESS)
98            {
99                                BDBG_WRN(("%s thdBbsEvent", __func__));
100                BTHD_ProcessBBSInterruptEvent(p_tuner->thdHandle);
101            }
102        }
103                if (p_tuner->thdLockEvent)
104                {
105                        rc = BKNI_WaitForEvent(p_tuner->thdLockEvent,THD_EVT_TIMEOUT_MS);
106                        if (rc == BERR_SUCCESS)
107                        {
108                                BDBG_WRN(("%s thdLockEvent", __func__));
109                                p_tuner->lockEventReceived = true;
110                        }
111                }
112                if (p_tuner->tnrIsrEvent) {
113                        rc = BKNI_WaitForEvent(p_tuner->tnrIsrEvent,THD_EVT_TIMEOUT_MS);
114                        if (rc == BERR_SUCCESS)
115                        {
116                                BDBG_WRN(("%s tnrIsrEvent", __func__));
117                                BTNR_3x7x_ProcessInterruptEvent(p_tuner->tnrHandle);
118                        }
119                }
120                if (p_tuner->thdEwsEvent)
121                {
122                        rc = BKNI_WaitForEvent(p_tuner->thdEwsEvent,THD_EVT_TIMEOUT_MS);
123                        if (rc == BERR_SUCCESS)
124                        {
125                                BDBG_WRN(("%s thdEwsEvent", __func__));
126                        }
127                }
128                bos_sleep(THD_TASK_TIMEOUT_MS + p_tuner->long_yield * THD_TASK_TIMEOUT_MS);
129        }
130}
131
132/***************************************************************************
133Summary:
134 ***************************************************************************/
135static void btuner_thd_isr_ctrl(void *pParam)
136{
137    /* NOTE: Even though the pDevice is passed in as the pParam, NEXUS_Frontend_P_7552_Tuner_isr gets
138           called with BTHD_P_ThdCallbackData_t  as its pParam. */
139    BTHD_P_ThdCallbackData_t *pCallback = (BTHD_P_ThdCallbackData_t *)pParam;
140        btuner_t p_tuner = s_tuner;
141    BTNR_3x7x_RfStatus_t RfStatus;
142
143        BDBG_WRN(("%s", __func__));
144
145    if (NULL == p_tuner || !pCallback) {
146                BDBG_WRN(("%s: null pointer", __func__));
147                return;
148        }
149    if (BTHD_CallbackMode_eSetMode == pCallback->Mode) {
150        /* TODO: call the tuner with pCallback->Freq_Offset */
151        BTNR_3x7x_Set_RF_Offset( p_tuner->tnrHandle, pCallback->Freq_Offset, pCallback->Symbol_Rate);
152
153    } else {
154        /* magic numbers from hardware team */
155
156        BTNR_3x7x_Get_RF_Status(p_tuner->tnrHandle, &RfStatus);
157        pCallback->RF_Freq = RfStatus.RF_Freq;
158        pCallback->Total_Mix_After_ADC = RfStatus.Total_Mix_After_ADC;
159        pCallback->PreADC_Gain_x256db  = RfStatus.PreADC_Gain_x256db;
160        pCallback->PostADC_Gain_x256db = RfStatus.PostADC_Gain_x256db;
161        pCallback->External_Gain_x256db = RfStatus.External_Gain_x256db;
162    }
163}
164
165static void btuner_thd_async_status(void *pParam)
166{
167    btuner_t p_tuner = s_tuner;
168
169    BDBG_WRN(("%s", __func__));
170
171    if (NULL == p_tuner) {
172        BDBG_WRN(("%s: null pointer", __func__));
173        return;
174    }
175        /* status data is ready, set the event */
176        BKNI_SetEvent(p_tuner->thdAsyncStatusEvent);
177}
178
179/*
180Summary:
181Open a ISDB-T tuner.
182
183Description:
184On most platforms, the tuner_id is simply an index of the tuners.
185
186On platforms with more frontend options (e.g. 97038), please see bsettop_ids.txt
187for documentation on special numbers.
188
189*/
190btuner_t btuner_open(
191                bobject_t tuner_id     /* - handle used to identify a particular tuner */
192                )
193{
194        btuner_t p_tuner = NULL;
195        BERR_Code errCode;
196        BI2C_ChannelSettings defChnSettings;
197
198        p_tuner = BKNI_Malloc(sizeof(struct btuner));
199        BDBG_ASSERT(p_tuner);
200        BKNI_Memset(p_tuner,0,sizeof(struct btuner));
201
202        BI2C_GetChannelDefaultSettings( GetI2C(), BTHD_I2C_BUS, &defChnSettings );
203        defChnSettings.intMode = false;  //RLQ, TEMP   true; 
204        defChnSettings.clkRate = BI2C_Clk_eClk400Khz;
205        BI2C_OpenChannel( GetI2C(), &(p_tuner->i2cChannelHandle), BTHD_I2C_BUS, &defChnSettings );
206        BDBG_ASSERT(p_tuner->i2cChannelHandle);
207
208        BI2C_CreateI2cRegHandle (p_tuner->i2cChannelHandle, &(p_tuner->i2cRegHandle));
209        BDBG_ASSERT(p_tuner->i2cRegHandle);
210
211        p_tuner->tnrSettings.i2cAddr = 0;
212        p_tuner->tnrSettings.hTmr = GetTMR();
213        p_tuner->tnrSettings.hHeap = GetHEAP();
214
215        errCode = BTNR_3x7x_Open(&p_tuner->tnrHandle, &p_tuner->tnrSettings, GetREG());
216        BDBG_ASSERT(errCode == BERR_SUCCESS);
217
218        errCode = BTNR_3x7x_GetInterruptEventHandle(p_tuner->tnrHandle, &p_tuner->tnrIsrEvent);
219        BDBG_ASSERT(errCode == BERR_SUCCESS);
220
221        BTHD_3x7x_GetDefaultSettings(&p_tuner->thdSettings);
222        p_tuner->thdSettings.hTmr = GetTMR();
223        p_tuner->thdSettings.hHeap = GetHEAP();
224        p_tuner->thdSettings.supportIsdbt = true;
225
226        /* Open THD device */
227        errCode = BTHD_Open(&p_tuner->thdHandle, GetCHP(), (void*)p_tuner->i2cRegHandle,
228                        GetINT(), &p_tuner->thdSettings);
229
230        BDBG_ASSERT(errCode == BERR_SUCCESS);
231        BDBG_ASSERT(p_tuner->thdHandle);
232
233        /* Initialize Acquisition Processor */
234        BDBG_WRN(("Initializating OFDM core..."));
235        errCode = BTHD_Init(p_tuner->thdHandle, NULL, 0);
236        BDBG_ASSERT(errCode == BERR_SUCCESS);
237
238        /* Get events and register callbacks */
239        errCode = BTHD_GetInterruptEventHandle(p_tuner->thdHandle, &p_tuner->thdIsrEvent);
240        BDBG_ASSERT(errCode == BERR_SUCCESS);
241
242        errCode = BTHD_GetLockStateChangeEventHandle(p_tuner->thdHandle, &p_tuner->thdLockEvent);
243        BDBG_ASSERT(errCode == BERR_SUCCESS);
244
245        errCode = BTHD_GetEWSEventHandle(p_tuner->thdHandle, &p_tuner->thdEwsEvent);
246        BDBG_ASSERT(errCode == BERR_SUCCESS);
247
248        errCode = BTHD_GetEWSEventHandle(p_tuner->thdHandle, &p_tuner->thdEwsEvent);
249        BDBG_ASSERT(errCode == BERR_SUCCESS);
250
251        errCode = BTHD_GetBBSInterruptEventHandle(p_tuner->thdHandle, &p_tuner->thdBbsEvent);
252        BDBG_ASSERT(errCode == BERR_SUCCESS);
253
254        errCode = BTHD_InstallCallback(p_tuner->thdHandle, BTHD_Callback_eTuner, (BTHD_CallbackFunc)btuner_thd_isr_ctrl, (void *)p_tuner);
255        BDBG_ASSERT(errCode == BERR_SUCCESS);
256
257        /* track async status event */
258        BKNI_CreateEvent(&p_tuner->thdAsyncStatusEvent);
259        //errCode = BTHD_InstallCallback(p_tuner->thdHandle, BTHD_Callback_eAsyncStatusReady, (BTHD_CallbackFunc)btuner_thd_async_status, (void *)p_tuner);
260        //BDBG_ASSERT(errCode == BERR_SUCCESS);
261
262        p_tuner->task_params.name="THD";
263        p_tuner->task_params.priority = VSB_ACQ_PRIORITY;
264        p_tuner->task_params.stack_size = THD_TASK_STACK;
265        p_tuner->task_params.stack = p_tuner->task_stack;
266        bos_start_task(&(p_tuner->task_h),&(p_tuner->task_params),btuner_task,p_tuner);
267
268        p_tuner->long_yield = true;
269
270        s_tuner = p_tuner;
271        /* what is the IF frequency for internal tuner? */
272        p_tuner->IF_frequency_HZ = 36000000;
273
274#ifdef BCM_DEBUG
275        BDBG_SetModuleLevel("bthd_api",BDBG_eMsg);
276        BDBG_SetModuleLevel("bthd_acq",BDBG_eMsg);
277        BDBG_SetModuleLevel("btnr_3x7x_priv",BDBG_eMsg);
278        BDBG_SetModuleLevel("bthd_3x7x",BDBG_eMsg);
279        BDBG_SetModuleLevel("bthd_acq_isdbt",BDBG_eMsg);
280#endif
281
282        return p_tuner;
283}
284
285/*
286Summary:
287Close the ISDB-T tuner.
288*/
289void btuner_close(
290                btuner_t p_tuner  /* - handle returned by btuner_open */
291                )
292{
293        BDBG_ASSERT(p_tuner);
294
295        if (p_tuner->i2cRegHandle)
296                BI2C_CloseI2cRegHandle(p_tuner->i2cRegHandle);
297
298        if (p_tuner->i2cChannelHandle)
299                BI2C_CloseChannel(p_tuner->i2cChannelHandle);
300
301        BTHD_InstallCallback(p_tuner->thdHandle, BTHD_Callback_eTuner, (BTHD_CallbackFunc)NULL, (void *)NULL);
302
303        if (p_tuner->thdHandle)
304                BTHD_Close(p_tuner->thdHandle);
305
306        BKNI_Free(p_tuner);
307}
308
309/*
310Summary:
311Required to initialize THD parameters to defaults
312*/
313void btuner_params_init(
314                btuner_params *ds,      /* - [out] */
315                btuner_t tuner              /* - required for possible resource-dependent defaults */
316                )
317{
318        memset(ds,0,sizeof(btuner_params));
319        ds->wait_for_lock = true;
320        ds->timeout = THD_TUNE_TIMEOUT_MS;
321}
322
323/*
324Summary:
325Tune and acquire an ISDB-T downstream band
326*/
327bband_t btuner_tune(
328                btuner_t p_tuner,
329                unsigned freq,  /* - RF center frequency in Hz */
330                btuner_params *params    /* - parameters needed to tune and acquire */
331                )
332{
333        bool locked = false;
334        BERR_Code errCode;
335        BTHD_InbandParams in_params;
336        BTHD_LockStatus lockStatus;
337
338        BDBG_MSG(("%s: enter, freq=%d, if_freq=%d", __func__, freq, p_tuner->IF_frequency_HZ));
339        p_tuner->frequency_HZ = freq;
340
341        /* if tuning */
342        p_tuner->long_yield = false;
343
344        if (p_tuner->tnrHandle) {
345                BTNR_Settings tnrSettings;
346                BTNR_PowerSaverSettings pwrSettings;
347
348                errCode = BTNR_GetSettings(p_tuner->tnrHandle, &tnrSettings);
349                if (errCode) {
350                        BDBG_WRN(("BTRN_GetSettigns failed (err=0x%x)", errCode));
351                        return -1;
352                }       
353                pwrSettings.enable = false;
354                errCode = BTNR_SetPowerSaver(p_tuner->tnrHandle, &pwrSettings);
355                if (errCode) {
356                        BDBG_WRN(("BTRN_SetPowerSaver failed (err=0x%x)", errCode));
357                        return -1;
358                }       
359               
360                BTHD_PowerUp(p_tuner->thdHandle);
361
362                tnrSettings.std = BTNR_Standard_eIsdbt;
363                tnrSettings.bandwidth = 6000000;
364                tnrSettings.tnrApplication = BTNR_TunerApplication_eTerrestrial;
365                /*RLQ, for ISDB-T, it is internal LNA */
366                tnrSettings.rfInputMode = BTNR_RfInputMode_eInternalLna;
367                //tnrSettings.rfInputMode = BTNR_RfInputMode_eExternalLna;
368                errCode = BTNR_SetSettings(p_tuner->tnrHandle, &tnrSettings);
369                if (errCode) {
370                        BDBG_WRN(("BTNR_SetSettings failed (err=0x%x)", errCode));
371                        return -1;
372                }       
373                //errCode = BTNR_3x7x_SetTnrApplication(p_tuner->tnrHandle, true);
374
375                errCode = BTNR_SetTunerRfFreq(p_tuner->tnrHandle, freq, BTNR_TunerMode_eDigital);
376                if (errCode) {
377                        BDBG_WRN(("BTNR_SetTunerRfFreq failed (err=0x%x)", errCode));
378                        return -1;
379                }       
380        }
381
382    BTHD_GetDefaultInbandParams(p_tuner->thdHandle, &in_params);
383    in_params.mode = BTHD_InbandMode_eIsdbt;
384    in_params.decodeMode = BTHD_Decode_Hp; //params->priority;
385    in_params.cciMode = BTHD_CCI_Auto; // params->cci_mode;
386    in_params.tunerFreq = freq;
387    in_params.bandwidth = BTHD_Bandwidth_6Mhz;
388    in_params.bTpsAcquire = true;
389    /* TODO if in_params.bTpsAcquire is not auto, then we need to set many parameters */
390    in_params.eModeGuardAcquire = BTHD_ModeGuard_eAutoIsdbt;
391    in_params.eAcquisitionMode = BTHD_ThdAcquisitionMode_eScan; //BTHD_ThdAcquisitionMode_eAuto;
392
393    in_params.bTuneAcquire = true;
394    /* match the settings from Caminbo_das_indias_160209_Blcoco.ts */
395    //in_params.eGuardInterval = BTHD_GuardInterval_e1_8;
396    //in_params.eIsdbtATimeInterleaving = BTHD_IsdbtTimeInterleaving_2X;
397        BDBG_WRN(("if_Freq=%d", in_params.ifFreq));
398    //in_params.ifFreq = p_tuner->IF_frequency_HZ;
399    in_params.ePullinRange = BTHD_PullInRange_eWide;
400    /*RLQ*/
401    //in_params.bTmccAcquire = true;
402
403        /* for debug purpose, set it here and will move to open function once ISDB-T tuner driver works */
404        //BTHD_GetSettings(p_tuner->thdHandle, &p_tuner->thdSettings);
405        //p_tuner->thdSettings.bRfDeltaSigmaInvert; /* Inverts RF delta sigma pin */
406        //p_tuner->thdSettings.bIfDeltaSigmaInvert; /* Inverts IF delta sigma pin */
407        //p_tuner->thdSettings.IfAgcPinMode; /* specifis the voltage swing of RF delta sigma pin */
408        //p_tuner->thdSettings.bool                  bIfAgcZero;   /* Turns off IF AGC in the chip */
409        p_tuner->thdSettings.supportIsdbt = true;
410#if 0
411        errCode = BTHD_SetSettings(p_tuner->thdHandle, &p_tuner->thdSettings);
412        if ( errCode )
413        {
414                BDBG_WRN(("BTHD_SetSettings failed 0x%08x\n",errCode));
415                return -1;
416        }
417#endif
418
419        BKNI_ResetEvent(p_tuner->thdLockEvent);
420        p_tuner->lockEventReceived = false;
421        errCode = BTHD_TuneAcquire(p_tuner->thdHandle, &in_params);
422        if ( errCode )
423        {
424                BDBG_WRN(("BTHD_AcquireInband failed 0x%08x\n",errCode));
425                return -1;
426        }
427
428        if (params->wait_for_lock)
429        {
430                uint32_t to_ticks = bos_getticks() + MS_TO_TICKS(params->timeout);
431
432                while (bos_getticks() < to_ticks && !p_tuner->lockEventReceived)
433                {
434                        errCode = BTHD_GetThdLockStatus(p_tuner->thdHandle,&lockStatus);
435                        if ((errCode == BERR_SUCCESS) && (BTHD_LockStatus_eLocked == lockStatus))
436                        {
437                                BDBG_WRN(("%s: freq %d locked\n",__func__, p_tuner->frequency_HZ));
438                                locked = true;
439                                break;
440                        }
441                        bos_sleep(THD_EVT_TIMEOUT_MS);
442                }
443        }
444        errCode = BTHD_GetThdLockStatus(p_tuner->thdHandle,&lockStatus);
445
446        BDBG_MSG(("freq %d %s", freq, BTHD_LockStatus_eLocked == lockStatus ? "locked" : 
447                                BTHD_LockStatus_eUnlocked == lockStatus ? "unlocked" : "no signal"));
448
449        {
450                btuner_status status;
451
452                btuner_get_status(p_tuner, &status);
453        }
454
455        /* reset BER */
456        BTHD_ResetInbandStatus(p_tuner->thdHandle);
457
458        p_tuner->long_yield = true;
459        p_tuner->elapedTime_in_ms = bos_getticks();
460
461        return (locked) ? BXPT_EXT_INPUT_BAND : -1;
462}
463
464#include "ber_quality_lookup_table.c"
465
466#define CRS             398
467
468/*
469Summary:
470Get the status of DS receiver
471*/
472bresult btuner_get_status(
473                btuner_t tuner,
474                btuner_status *status   /* - [out] Current status of the SDS demod */
475                )
476{
477        BERR_Code err; 
478        BTHD_THDStatus thdStatus;
479        unsigned int elapSymbol, totalBits;
480        unsigned int db, ber_quality;
481
482        memset(&thdStatus, 0, sizeof(thdStatus));
483        err = BTHD_GetThdStatus(tuner->thdHandle,&thdStatus);
484        if (err == BERR_SUCCESS && thdStatus.bValid)
485        {
486                status->freq = tuner->frequency_HZ;     
487                status->snr = thdStatus.nSnr;   /* Signal to noise ratio */
488                status->lock = (thdStatus.bFecLock && thdStatus.bReceiverLock);
489                status->fecLock = thdStatus.bFecLock;
490                status->qamLock = thdStatus.bReceiverLock;
491
492                status->mode = thdStatus.acqParams.mode;
493
494                /* signal_strength */
495
496                status->power = thdStatus.nSignalStrength;
497
498#if 0
499                status->correctedCount = thdStatus.corrErrCount;
500                status->uncorrectedCount = thdStatus.ucorrBlockCount;
501                status->resyncCount = thdStatus.cleanBlockCount;
502
503                status->elapsedTimeSec = (bos_getticks() - tuner->elapedTime_in_ms);           /* postRsBER over this time */
504                tuner->elapedTime_in_ms = bos_getticks();
505
506                elapSymbol = (status->elapsedTimeSec * thdStatus.symbolRate) / 1000;
507                /* reset timer and also to clear the count */
508
509                /* now compute the signal quality */
510                db = (status->snr / 256);
511                if (db < 15 || !status->lock) {
512                        status->PreRS = 0;
513                }
514                else if (db > 19) {
515                        status->PreRS = 100;
516                }
517                else {
518                        if (0 == status->correctedCount) {
519                                if (db < 16)
520                                        status->PreRS = 0;
521                                else
522                                        status->PreRS = 100;
523                        }
524                        else {
525                                int i;
526
527                                /* experimental shows that the bit correction happened around the range of 15 - 18 db */
528                                totalBits = (elapSymbol * 398) / 100;           /* CRS = 3.98 */
529                                ber_quality = (totalBits / status->correctedCount);
530
531                                status->PreRS = 100;
532                                for (i = 0; i < ber_quality_lookup_table_size; i++) {
533                                        if (ber_quality < ber_quality_lookup_table[i]) {
534                                                status->PreRS = i;
535                                                break;
536                                        }
537                                }
538                        }
539                }
540                /* reset BER since the correctedErrCount is accumuated */
541                BTHD_ResetInbandStatus(tuner->thdHandle);
542#endif
543        }
544        return err;
545}
546
547/*
548 * Summary:
549 *      Clear the tuner's channel status
550 */
551bresult btuner_reset_status(btuner_t tuner)
552{
553        return b_ok;
554}
555
556bresult btuner_get_softdecisions(
557                btuner_t tuner, 
558                btuner_softdecision_t *pdec,    /* - [out] array of soft decisions */
559                size_t length                   /* number of soft decisions to get */
560                )
561{
562        return b_ok;
563}
564
565#ifdef CONFIG_TUNER_TEST
566
567extern unsigned get_opt(void);
568
569static const char *s_BTHD_InbandMode_Name[] =
570{
571        "BTHD_InbandMode_e8THD",
572        "BTHD_InbandMode_e16THD",
573        "BTHD_InbandMode_e1024QAM_B",
574        "BTHD_InbandMode_e512QAM_B",
575        "BTHD_InbandMode_e256QAM_B",
576        "BTHD_InbandMode_e128QAM_B",
577        "BTHD_InbandMode_e64QAM_B",
578        "BTHD_InbandMode_e64_256QAM_B",
579        "BTHD_InbandMode_e256QAM_A",
580        "BTHD_InbandMode_e128QAM_A",
581        "BTHD_InbandMode_e64QAM_A",
582        "BTHD_InbandMode_e32QAM_A",
583        "BTHD_InbandMode_e16QAM_A",
584        "BTHD_InbandMode_eAnalog",
585        "BTHD_InbandMode_eAnalog_SIF",
586        "BTHD_InbandMode_eUnknown"
587};
588
589void TunerTest()
590{
591        btuner_t p_tuner = btuner_open(0);
592        unsigned int cmd;
593        btuner_params params;
594        params.timeout = 20000;
595        params.wait_for_lock = 1;
596        p_tuner->frequency_HZ = 545142000;      /* 545.142 MHz as default */
597        BERR_Code err;
598
599        if (p_tuner)
600        {
601                while (1)
602                {
603                        printf("Freq: %dHz, IF Freq: %dHz, Acq Timeout: %dms\n", p_tuner->frequency_HZ, p_tuner->IF_frequency_HZ, params.timeout);
604                        printf("Tuner Test Menu:\n");
605                        printf("1)  Enable verbose debug...\n");
606                        printf("2)  Signal status...\n");
607                        printf("3)  Tune...\n");
608                        printf("4)  Acquire...\n");
609                        printf("5)  THD Parameters...\n");
610                        /* for debug purpose */
611                        printf("6)  Dump INT bin...\n");
612
613                        printf("Enter option:  ");
614
615                        cmd = get_opt();
616                        printf("\n");
617                        switch (cmd)
618                        {
619                                case 1:
620                                        BDBG_SetModuleLevel("bthd_api",BDBG_eMsg);
621                                        BDBG_SetModuleLevel("bthd_acq",BDBG_eMsg);
622                                        BDBG_SetModuleLevel("bthd_3x7x",BDBG_eMsg);
623                                        BDBG_SetModuleLevel("bthd_acq_isdbt",BDBG_eMsg);
624                                        BDBG_SetModuleLevel("bTHD",BDBG_eMsg);
625                                        BDBG_SetModuleLevel("btnr",BDBG_eMsg);
626                                        BDBG_SetModuleLevel("btnr_3x7x",BDBG_eMsg);
627                                        BDBG_SetModuleLevel("btnr_3x7x_priv",BDBG_eMsg);
628                                        BDBG_SetModuleLevel("btnr_callback",BDBG_eMsg);
629                                        BDBG_SetModuleLevel("btnr_tune",BDBG_eMsg);
630                                        break;
631
632                                case 2:
633                                        {
634                                                BTHD_THDStatus thdStatus;
635                                                memset(&thdStatus, 0, sizeof(thdStatus));
636
637                                                err = BTHD_RequestThdAsyncStatus(p_tuner->thdHandle);
638                                                BDBG_WRN(("Waiting for async status ready..."));
639                                                err = BKNI_WaitForEvent(p_tuner->thdAsyncStatusEvent, 2000);
640                                                if (err == BERR_SUCCESS)
641                                                {
642                                                        err = BTHD_GetThdAsyncStatus(p_tuner->thdHandle, &thdStatus);
643                                                        if (err == BERR_SUCCESS) {
644                                                                BDBG_WRN(("RecevierLock=%d, FecLock=%d, no_signal=%d, valid=%d",thdStatus.bReceiverLock, thdStatus.bFecLock, thdStatus.bNoSignalDetected, thdStatus.bValid));
645                                                                BDBG_WRN(("eIsdbtAModulation = %d", thdStatus.eIsdbtAModulation));
646                                                                BDBG_WRN(("eIsdbtACodeRate = %d", thdStatus.eIsdbtACodeRate));
647                                                                BDBG_WRN(("eIsdbtATimeInterleaving = %d", thdStatus.eIsdbtATimeInterleaving));
648                                                                BDBG_WRN(("eIsdbtASegments = %d", thdStatus.eIsdbtASegments));
649                                                                BDBG_WRN(("ulIsdbtARsCorrectedBlocks = %d", thdStatus.eIsdbtASegments));
650                                                                BDBG_WRN(("ulIsdbtARsUncorrectedBlocks = %d", thdStatus.ulIsdbtARsUncorrectedBlocks));
651                                                                BDBG_WRN(("ulIsdbtARsCleanBlocks = %d", thdStatus.ulIsdbtARsCleanBlocks));
652                                                                BDBG_WRN(("ulIsdbtARsTotalBlocks = %d", thdStatus.ulIsdbtARsTotalBlocks));
653                                                                BDBG_WRN(("ulIsdbtAViterbiUncorrectedBits = %d", thdStatus.ulIsdbtAViterbiUncorrectedBits));
654                                                                BDBG_WRN(("ulIsdbtAViterbiTotalbits = %d", thdStatus.ulIsdbtAViterbiTotalbits));
655
656                                                                BDBG_WRN(("eIsdbtBModulation = %d", thdStatus.eIsdbtBModulation));
657                                                        }
658                                                        else {
659                                                                printf("BTHD_GetThdAsyncStatus failed (err=0x%x)\n", err);
660                                                        }
661                                                }
662                                                else {
663                                                        printf("BTHD_GetVsbStatus timeout\n");
664                                                }
665                                        }
666                                        break;
667
668                                case 3:
669                                        {
670                                                btuner_params params;
671
672                                                printf("Enter IDSB-T frequency in Hz (545142 for 545.142 MHz):  ");
673                                                p_tuner->frequency_HZ = get_opt();
674                                                printf("\n");
675
676                                                btuner_params_init(&params, p_tuner);
677                                                p_tuner->frequency_HZ *= 1000;  /* convert to MHz */
678                                                if (-1 == btuner_tune(p_tuner, p_tuner->frequency_HZ, &params))
679                                                        printf("btuner_tune failed\n");
680                                                else
681                                                        printf("btuner_tune is successful\n");
682                                        }
683                                        break;
684                                case 4:
685                                        {
686                                                BERR_Code errCode;
687                                                BTHD_InbandParams in_params;
688                                                BTHD_THDStatus thdStatus;
689                                                bool lock = false;
690                                                uint32_t to_ticks;
691
692                                                BKNI_Memset(&in_params, 0, sizeof(in_params));
693                                                errCode = BTHD_GetDefaultInbandParams(p_tuner->thdHandle, &in_params);
694                                                in_params.mode = BTHD_InbandMode_eIsdbt;
695                                                errCode = BTHD_TuneAcquire(p_tuner->thdHandle, &in_params);
696                                                if ( errCode )
697                                                {
698                                                        BDBG_WRN(("BTHD_AcquireInband failed 0x%08x\n",errCode));
699                                                        break;
700                                                }
701                                                to_ticks = bos_getticks() + MS_TO_TICKS(params.timeout);
702
703                                                BTHD_ResetIfdStatus(p_tuner->thdHandle);
704
705                                                BTHD_RequestThdAsyncStatus(p_tuner->thdHandle);
706                                                err = BKNI_WaitForEvent(p_tuner->thdAsyncStatusEvent, 2000);
707                                                if (err == BERR_SUCCESS) {
708                                                        errCode = BTHD_GetThdAsyncStatus(p_tuner->thdHandle, &thdStatus);
709                                                        if (0 == errCode) {
710                                                                BDBG_WRN(("RecevierLock=%d, FecLock=%d, no_signal=%d, valid=%d",thdStatus.bReceiverLock, thdStatus.bFecLock, thdStatus.bNoSignalDetected, thdStatus.bValid));
711                                                                lock = thdStatus.bReceiverLock && thdStatus.bFecLock;
712                                                        }
713                                                        else 
714                                                                lock = false;
715                                                        if (!lock)
716                                                        {
717                                                                BDBG_WRN(("%s:%d, BTHD_AcquireInband not locked\n",__func__,__LINE__));
718                                                        }
719                                                }
720                                        }
721                                        break;
722                                case 5:
723                                        {
724                                                BERR_Code errCode;
725                                                BTHD_Settings thdSettings;
726                                                BTHD_GetSettings(p_tuner->thdHandle, &thdSettings);
727
728                                                printf("bRfDeltaSigmaInvert(%d):  ", thdSettings.bRfDeltaSigmaInvert);
729                                                thdSettings.bRfDeltaSigmaInvert = (get_opt() == 0) ? false : true;
730                                                printf("\n");
731                                                printf("bIfDeltaSigmaInvert(%d):  ",thdSettings.bIfDeltaSigmaInvert);
732                                                thdSettings.bIfDeltaSigmaInvert = (get_opt() == 0) ? false : true;
733                                                printf("\n");
734                                                printf("IfAgcPinMode (%d) (0 - 3.3V, 1 - 2.5V) ",thdSettings.IfAgcPinMode);
735                                                thdSettings.IfAgcPinMode = (get_opt() == 0) ? BTHD_AgcPinMode_e33V : BTHD_AgcPinMode_e25V;
736                                                printf("\n");
737                                                printf("bIfAgcZero (%d):  ",thdSettings.bIfAgcZero);
738                                                thdSettings.bIfAgcZero = get_opt() ? true : false;
739                                                printf("\n");
740                                                errCode = BTHD_SetSettings(p_tuner->thdHandle, &thdSettings);
741                                        }
742                                        break;
743                                case 6:
744                                        BINT_DumpInfo(GetINT());
745                                        break;
746
747                                default:
748                                        break;
749                        }
750                }
751        }
752}
753#endif
Note: See TracBrowser for help on using the repository browser.