source: svn/trunk/newcon3bcm2_21bu/dta/src/settop_api/bsettop_tuner.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: 19.9 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2006, 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 *
16 * Revision History:
17 *
18 * $brcm_Log:  $
19 *
20 ***************************************************************************/
21#include "bsettop_tuner.h"
22#include "bads.h"
23#include "bads_3x7x.h"
24#include "bads_api.h"
25#include "btnr.h"
26#include "btnr_3x7x.h"
27#include "gist.h"
28#include "bkni_multi.h"
29#include "bos_task_priorities.h"
30#include "bapp_util.h"
31
32BDBG_MODULE(btuner);            /* Register software module with debug interface */
33
34#define DS_TASK_STACK   0x400
35#define TIMEOUT_INC_MS  50
36
37#define TUNE_TIMEOUT_MS (3*350)
38#define SCAN_TIMEOUT_MS (3*500)
39
40struct btuner
41{
42        b_task_params task_params;
43        b_task_t task_h;
44        unsigned int task_stack[DS_TASK_STACK];
45
46        BKNI_EventHandle isrEvent;
47        BKNI_EventHandle lockEvent;
48        BKNI_EventHandle bbsEvent;
49
50        btuner_params last_params;
51        BI2C_ChannelHandle i2cChannelHandle;
52        BREG_I2C_Handle i2cRegHandle;
53        BTNR_Handle tnrHandle;
54        BADS_Handle adsHandle;
55        BADS_ChannelHandle adsChannelHandle;
56        unsigned int freq_hz;
57        unsigned int timeout_ms;
58        b_mutex_t       mutex;
59};
60
61/*
62Summary:
63        btuner_ads_tuner_cb is called by ADS.
64 */
65
66
67void btuner_ads_tuner_cb(void *param)
68{
69        BTNR_3x7x_RfStatus_t RfCallbackStatus;
70        BADS_P_AdsCallbackData_t *pCallback = (BADS_P_AdsCallbackData_t *)param;
71        btuner_t tuner = (btuner_t)pCallback->hTunerChn;
72
73        BDBG_MSG(("%s: %d\n", __FUNCTION__,__LINE__));
74
75        if (BADS_CallbackMode_eSetMode == pCallback->Mode)
76        {
77                /* TODO: call the tuner with pCallback->Freq_Offset */
78                BTNR_3x7x_Set_RF_Offset( tuner->tnrHandle, pCallback->Freq_Offset, pCallback->Symbol_Rate);
79
80        } else
81        {
82                /* magic numbers from hardware team */
83
84                BTNR_3x7x_Get_RF_Status(tuner->tnrHandle, &RfCallbackStatus);
85                pCallback->RF_Freq = RfCallbackStatus.RF_Freq;
86                pCallback->Total_Mix_After_ADC = RfCallbackStatus.Total_Mix_After_ADC;
87                pCallback->PreADC_Gain_x256db  = RfCallbackStatus.PreADC_Gain_x256db;
88                pCallback->PostADC_Gain_x256db = RfCallbackStatus.PostADC_Gain_x256db;
89                pCallback->External_Gain_x256db = RfCallbackStatus.External_Gain_x256db; 
90                pCallback->Freq_Offset = RfCallbackStatus.RF_Offset;
91                pCallback->Symbol_Rate = RfCallbackStatus.Symbol_Rate;
92        }
93}
94
95/*
96Summary:
97        btuner_ads_lock_cb is called by ADS to provide notification of lock/unlock
98 */
99
100void btuner_ads_lock_cb(void *param)
101{
102        BADS_LockStatus lockStatus;
103        btuner_t tuner = (btuner_t)param;
104        BDBG_ASSERT(tuner);
105        BDBG_ASSERT(tuner->adsChannelHandle);
106
107        if (BADS_GetLockStatus(tuner->adsChannelHandle,&lockStatus) == BERR_SUCCESS)
108        {
109                BDBG_MSG(("%s: %s", __func__, (BADS_LockStatus_eLocked == lockStatus) ? "Locked" : 
110                        (BADS_LockStatus_eNoSignal == lockStatus) ? "No Signal" : "Not Locked"));
111                BKNI_SetEvent(tuner->lockEvent);
112        }
113}
114
115/*
116Summary:
117        Tune the actual tuner.
118 */
119
120static void btuner_tune_tuner(btuner_t tuner)
121{
122        BTNR_PowerSaverSettings pwrSettings;
123        BTNR_Settings tnrSettings;
124
125        /* TODO: we should be able to call BTNR_SetSettings after BTNR_SetPowerSaver. verify */
126        pwrSettings.enable = false;     
127        BTNR_SetPowerSaver(tuner->tnrHandle, &pwrSettings);
128
129        BTNR_GetSettings(tuner->tnrHandle, &tnrSettings);
130
131        tnrSettings.tnrApplication = BTNR_TunerApplication_eCable;
132        tnrSettings.bandwidth = 6000000;
133        tnrSettings.rfInputMode = BTNR_RfInputMode_eInternalLna;       
134        BTNR_SetSettings(tuner->tnrHandle, &tnrSettings);
135
136        BTNR_SetTunerRfFreq(tuner->tnrHandle, tuner->freq_hz, BTNR_TunerMode_eDigital);
137
138        BADS_DisablePowerSaver(tuner->adsChannelHandle);
139}
140
141/***************************************************************************
142Summary:
143Acquisition processing thread
144 ***************************************************************************/
145static void ds_task(void *arg)
146{
147        btuner_t p_tune = (btuner_t)arg;
148        BDBG_ASSERT(p_tune);
149        BDBG_MSG(("ds_task"));
150        BERR_Code rc;
151
152        while (1)
153        {
154                if (0 == p_tune->freq_hz)
155                {
156                        /* if no frequency is given, skip it */
157                        bos_sleep(100); 
158                        continue;
159                }
160                rc = BKNI_WaitForEvent(p_tune->bbsEvent,10);
161                if (BERR_SUCCESS == rc)
162                {
163                        BDBG_MSG(("%s BBS Event",__FUNCTION__));
164                        /* only return if user don't issue tune request */
165                        if (bos_acquire_mutex(&(p_tune->mutex), BOS_PEND_FOREVER) == b_ok)
166                        {
167                                BTNR_3x7x_ProcessInterruptEvent(p_tune->tnrHandle);
168                                bos_release_mutex(&(p_tune->mutex));
169                        }
170                }
171
172                rc = BKNI_WaitForEvent(p_tune->isrEvent,10);
173                if (BERR_TIMEOUT != rc)
174                {
175                        BDBG_WRN(("%s ISR Event",__FUNCTION__));
176                        if (bos_acquire_mutex(&(p_tune->mutex), BOS_PEND_FOREVER) == b_ok)
177                        {
178                                BADS_ProcessInterruptEvent(p_tune->adsHandle);
179                                bos_release_mutex(&(p_tune->mutex));
180                        }
181                }
182                bos_sleep(40);
183        }
184}
185
186/*
187Summary:
188        To achieve best performance the fastAcquire needs to be true for normal tune/acquire but
189        false for channel scanning.  Also disabling and re-enabling the channel prevents redundent acquires.
190
191 */
192void btuner_ads_open(
193                                        btuner_t p_tune,        /* - handle used to identify a particular tuner */
194                                        bool autoAcquire,       /* enable auto reacquisiton */
195                                        bool fastAcquire        /* enable "fast acquisition */
196                                        )
197{
198        BADS_ChannelSettings adsChannelSettings;
199        BDBG_ASSERT(p_tune);
200        BDBG_ASSERT(p_tune->adsHandle);
201        BADS_GetChannelDefaultSettings(p_tune->adsHandle, 0, &adsChannelSettings);
202        BADS_OpenChannel(p_tune->adsHandle, &p_tune->adsChannelHandle, 0, &adsChannelSettings);
203        BDBG_ASSERT(p_tune->adsChannelHandle);
204
205        BADS_InstallCallback(p_tune->adsChannelHandle, BADS_Callback_eLockChange, (BADS_CallbackFunc)btuner_ads_lock_cb, p_tune);
206        BADS_InstallCallback(p_tune->adsChannelHandle, BADS_Callback_eTuner, (BADS_CallbackFunc)btuner_ads_tuner_cb, p_tune);
207}
208
209/*
210Summary:
211        To achieve best performance the fastAcquire needs to be true for normal tune/acquire but
212        false for channel scanning.  Also disabling and re-enabling the channel prevents redundent acquires.
213
214 */
215void btuner_ads_close(
216                                         btuner_t p_tune         /* - handle used to identify a particular tuner */
217                                         )
218{
219        BDBG_ASSERT(p_tune);
220        if (p_tune->adsChannelHandle)
221        {
222                BADS_CloseChannel(p_tune->adsChannelHandle);
223                p_tune->adsChannelHandle = NULL;
224        }
225}
226/*
227Summary:
228Open a tuner.
229
230Description:
231On most platforms, the tuner_id is simply an index of the tuners.
232
233On platforms with more frontend options (e.g. 97038), please see bsettop_ids.txt
234for documentation on special numbers.
235
236 */
237btuner_t btuner_open(
238                                        bobject_t tuner_id      /* - handle used to identify a particular tuner */
239                                        )
240{
241        btuner_t p_tune = NULL;
242        p_tune = (btuner_t)BKNI_Malloc(sizeof(struct btuner));
243        bresult rc;
244
245        if (!p_tune)
246                return NULL;
247
248        BKNI_Memset(p_tune,0,sizeof(struct btuner));
249
250        p_tune->task_params.name="ds_task";
251        p_tune->task_params.priority = VSB_ACQ_PRIORITY;
252        p_tune->task_params.stack_size = DS_TASK_STACK;
253        p_tune->task_params.stack = p_tune->task_stack;
254
255#if 0
256        BDBG_SetModuleLevel("bads_acquire",BDBG_eMsg);
257        BDBG_SetModuleLevel("bads_3x7x",BDBG_eMsg);
258        BDBG_SetModuleLevel("bads_utils",BDBG_eMsg);
259        BDBG_SetModuleLevel("bads_api",BDBG_eMsg);
260        BDBG_SetModuleLevel("bads_status",BDBG_eMsg);
261        BDBG_SetModuleLevel("btnr_tune",BDBG_eMsg);
262        BDBG_SetModuleLevel("btnr_init",BDBG_eMsg);
263        BDBG_SetModuleLevel("btnr_3x7x_priv",BDBG_eMsg);
264#endif
265
266        BTNR_3x7x_Settings tnrSettings;
267        BADS_Settings adsSettings;
268
269        BKNI_CreateEvent(&(p_tune->lockEvent));
270        BDBG_ASSERT(p_tune->lockEvent);
271
272        tnrSettings.i2cAddr = 0;
273        tnrSettings.hTmr = GetTMR();
274        tnrSettings.hHeap = GetHEAP();
275        BTNR_3x7x_Open( &p_tune->tnrHandle, &tnrSettings, GetREG());   
276        BDBG_ASSERT(p_tune->tnrHandle);
277
278        BTNR_3x7x_Set_RF_LoopThrough(p_tune->tnrHandle, false); /* Disable loop through for DTA low power requirments */
279
280        BTNR_3x7x_GetInterruptEventHandle(p_tune->tnrHandle, &p_tune->bbsEvent);
281        BDBG_ASSERT(p_tune->bbsEvent);
282
283        BADS_3x7x_GetDefaultSettings(&adsSettings,GetCHP());
284
285        adsSettings.hTmr = GetTMR();
286        adsSettings.hHeap = GetHEAP();
287        BADS_Open( &p_tune->adsHandle, GetCHP(),  GetREG(), GetINT(),  &adsSettings );
288        BDBG_ASSERT(p_tune->adsHandle);
289
290        BADS_Init(p_tune->adsHandle);
291
292        /* RLQ, _Get_DPM function will call callback unconditionally without checking the pointer, so have to install a dummy callback */
293        /* per Tak's request to power down dsisy buffer */
294        BADS_SetDaisyChain(p_tune->adsHandle, false);
295
296        /* Get events and register callbacks */
297        BADS_GetInterruptEventHandle(p_tune->adsHandle, &p_tune->isrEvent);
298        BDBG_ASSERT(p_tune->isrEvent);
299
300        rc = bos_create_mutex(&p_tune->mutex);
301        BDBG_ASSERT(rc == b_ok);
302
303        btuner_ads_open(p_tune,false, false     /*(params->qamMode != eQAM_Scan)*/);
304
305        bos_start_task(&(p_tune->task_h),&(p_tune->task_params),ds_task,p_tune);
306
307        return p_tune;
308
309}
310
311/*
312Summary:
313Close a tuner.
314 */
315void btuner_close(
316                                 btuner_t tuner  /* - handle returned by btuner_open */
317                                 )
318{
319        BDBG_ASSERT(tuner);
320        BDBG_ASSERT(tuner->i2cChannelHandle);
321        BDBG_ASSERT(tuner->i2cRegHandle);
322        BDBG_ASSERT(tuner->tnrHandle);
323        BDBG_ASSERT(tuner->adsHandle);
324        BDBG_ASSERT(tuner->adsChannelHandle);
325
326        btuner_ads_close(tuner);
327
328        BADS_Close(tuner->adsHandle);
329        BTNR_Close(tuner->tnrHandle);
330        BI2C_CloseI2cRegHandle(tuner->i2cRegHandle);
331        BI2C_CloseChannel(tuner->i2cChannelHandle);
332
333        bos_delete_mutex(&tuner->mutex);
334        BKNI_DestroyEvent(tuner->lockEvent);
335        BKNI_Free(tuner);
336}
337
338
339/*
340Summary:
341Tune and acquire a VSB downstream band
342 */
343static const unsigned J83A_SYMBOLRATE_UPPER = 7200000;
344static const unsigned J83A_SYMBOLRATE_LOWER = 4000000;
345static const unsigned J83A_SYMBOLRATE_DEFAULT = 6952000;
346static const unsigned J83B_SYMBOLRATE_QAM64 = 5056941;
347static const unsigned J83B_SYMBOLRATE_QAM256 = 5360537;
348bband_t btuner_tune(
349                                   btuner_t tuner,
350                                   unsigned freq,  /* - RF center frequency in Hz */
351                                   btuner_params *params        /* - parameters needed to tune and acquire */
352                                   )
353{
354        BADS_InbandParam inbandParams;
355        BERR_Code err;
356        int timeout_cnt,lock_status;
357        BADS_Status status;
358        BADS_ModulationType modType;
359        BADS_InvertSpectrum invert_spectrum = BADS_InvertSpectrum_eNoInverted;
360        BADS_LockStatus lockStatus;
361        bband_t result = -1;
362
363        BDBG_MSG(("%s:%d Freq = %d\n",__FUNCTION__,__LINE__,freq));
364        if (bos_acquire_mutex(&(tuner->mutex),BKNI_INFINITE) != b_ok)
365        {
366                BDBG_ERR(("bos_acquire_mutex failed"));
367                return result;
368        }
369
370        tuner->last_params = *params;
371
372        tuner->freq_hz = freq;
373
374        btuner_tune_tuner(tuner);
375
376        BDBG_MSG(("%s:%d Freq = %d\n",__FUNCTION__,__LINE__,freq));
377
378        BKNI_Memset(&inbandParams,0,sizeof(inbandParams));
379
380        inbandParams.spectrum = BADS_SpectrumMode_eAuto;
381        inbandParams.autoAcquire = false;
382
383        timeout_cnt = TUNE_TIMEOUT_MS;
384        if (params->qamMode == eQAM_Scan)
385        {
386                timeout_cnt = SCAN_TIMEOUT_MS;
387        } else if (params->spectrum)
388        {
389                invert_spectrum = BADS_InvertSpectrum_eInverted;
390        }
391
392        /* start with QAM256 first if auto */
393        if (params->qamMode == eQAM_64)
394                modType = BADS_ModulationType_eAnnexBQam64;
395        else
396                modType = BADS_ModulationType_eAnnexBQam256; 
397
398        inbandParams.spectrum = BADS_SpectrumMode_eAuto;
399        inbandParams.enableDpm = BADS_DpmMode_Disabled;
400        inbandParams.invertSpectrum = invert_spectrum;
401        inbandParams.modType = modType;
402        inbandParams.acquisitionType = BADS_AcquireType_eAuto;
403        inbandParams.autoAcquire = true;
404
405        BDBG_MSG(("%s Freq = %d\n",__FUNCTION__,freq));
406        BDBG_MSG(("%s inbandParams.modType = %d\n",__FUNCTION__,inbandParams.modType));
407        BDBG_MSG(("%s inbandParams.symbolRate = %d\n",__FUNCTION__,inbandParams.symbolRate));
408        BDBG_MSG(("%s inbandParams.invertSpectrum = %d\n",__FUNCTION__,inbandParams.invertSpectrum));
409        BDBG_MSG(("%s inbandParams.spectrum = %d\n",__FUNCTION__,inbandParams.spectrum));
410        BDBG_MSG(("%s inbandParams.enableDpm = %d\n",__FUNCTION__,inbandParams.enableDpm));
411        BDBG_MSG(("%s inbandParams.autoAcquire = %d\n",__FUNCTION__,inbandParams.autoAcquire));
412
413        err = BADS_Acquire(tuner->adsChannelHandle,&inbandParams);
414        if (err != BERR_SUCCESS)
415        {
416                BDBG_ERR(("BADS_Acquire(%d,%d,%d) error %d\n",freq, inbandParams.modType,inbandParams.symbolRate, err));
417                bos_release_mutex(&(tuner->mutex));
418                return result;
419        }
420
421        lock_status = false;
422        bos_release_mutex(&(tuner->mutex));
423
424        if ((params->qamMode == eQAM_Scan) && (lock_status == 2 /* BADS_Timing_eUnLocked */))
425        {
426                BDBG_MSG(("BADS_Timing_eUnLocked - quick non-signal indication"));
427                return result;
428        }
429
430        if (BKNI_WaitForEvent(tuner->lockEvent,timeout_cnt) != BERR_SUCCESS)
431        {
432                BDBG_MSG(("BKNI_WaitForEvent failed in %s",__FUNCTION__));
433        }
434
435        if (bos_acquire_mutex(&(tuner->mutex),BKNI_INFINITE) != b_ok)
436        {
437                BDBG_ERR(("bos_acquire_mutex failed"));
438                return result;
439        }
440
441        if ((err = BADS_GetLockStatus(tuner->adsChannelHandle,&lockStatus)) == BERR_SUCCESS)
442        {
443                BDBG_MSG(("%s: %s\n", __func__, (BADS_LockStatus_eLocked == lockStatus) ? "Locked" : 
444                        (BADS_LockStatus_eNoSignal == lockStatus) ? "No Signal" : "Not Locked"));
445                if (BADS_LockStatus_eLocked == lockStatus)
446                {
447                        result = 0;
448                        params->qamMode = (status.modType == BADS_ModulationType_eAnnexBQam256) ? eQAM_256 : eQAM_64;
449                        params->spectrum = status.isSpectrumInverted;
450                }
451        }
452
453        bos_release_mutex(&(tuner->mutex));
454
455        return result;
456}
457
458bresult btuner_reset_status(btuner_t tuner)
459{
460        if (!tuner->freq_hz) return BERR_INVALID_PARAMETER;
461        return BADS_ResetStatus(tuner->adsChannelHandle);
462}
463
464/*
465Summary:
466Get the status of DS receiver
467 */
468bresult btuner_get_status(
469                                                 btuner_t tuner,
470                                                 btuner_status *status   /* - [out] Current status of the SDS demod */
471                                                 )
472{
473        BERR_Code err;
474        BADS_Status ads_status;
475
476        BKNI_Memset(status,0,sizeof(*status));
477
478        if (!tuner->freq_hz) 
479                return BERR_INVALID_PARAMETER;
480       
481        err = BADS_GetStatus(tuner->adsChannelHandle,&ads_status);
482        status->freq = tuner->freq_hz;
483        status->lock = (ads_status.isFecLock && ads_status.isQamLock);
484        status->fecLock = ads_status.isFecLock;
485        status->qamLock = ads_status.isQamLock; 
486        switch (ads_status.modType)
487        {
488        case BADS_ModulationType_eAnnexAQam16: status->mode = eQAM_16; status->fecMode = eFEC_ANNEX_A; break;
489        case BADS_ModulationType_eAnnexAQam32: status->mode = eQAM_32; status->fecMode = eFEC_ANNEX_A; break;
490        case BADS_ModulationType_eAnnexAQam64: status->mode = eQAM_64; status->fecMode = eFEC_ANNEX_A; break;
491        case BADS_ModulationType_eAnnexAQam128: status->mode = eQAM_128; status->fecMode = eFEC_ANNEX_A; break;
492        case BADS_ModulationType_eAnnexAQam256: status->mode = eQAM_256; status->fecMode = eFEC_ANNEX_A; break;
493        case BADS_ModulationType_eAnnexAQam512: status->mode = eQAM_512; status->fecMode = eFEC_ANNEX_A; break;
494        case BADS_ModulationType_eAnnexAQam1024: status->mode = eQAM_1024; status->fecMode = eFEC_ANNEX_A; break;
495        case BADS_ModulationType_eAnnexAQam2048: status->mode = eQAM_2048; status->fecMode = eFEC_ANNEX_A; break;
496        case BADS_ModulationType_eAnnexAQam4096: status->mode = eQAM_4096; status->fecMode = eFEC_ANNEX_A; break;
497        case BADS_ModulationType_eAnnexBQam16: status->mode = eQAM_16; status->fecMode = eFEC_ANNEX_B; break;
498        case BADS_ModulationType_eAnnexBQam32: status->mode = eQAM_32; status->fecMode = eFEC_ANNEX_B; break;
499        case BADS_ModulationType_eAnnexBQam64: status->mode = eQAM_64; status->fecMode = eFEC_ANNEX_B; break;
500        case BADS_ModulationType_eAnnexBQam128: status->mode = eQAM_128; status->fecMode = eFEC_ANNEX_B; break;
501        case BADS_ModulationType_eAnnexBQam256: status->mode = eQAM_256; status->fecMode = eFEC_ANNEX_B; break;
502        case BADS_ModulationType_eAnnexBQam512: status->mode = eQAM_512; status->fecMode = eFEC_ANNEX_B; break;
503        case BADS_ModulationType_eAnnexBQam1024: status->mode = eQAM_1024; status->fecMode = eFEC_ANNEX_B; break;
504        case BADS_ModulationType_eAnnexBQam2048: status->mode = eQAM_2048; status->fecMode = eFEC_ANNEX_B; break;
505        case BADS_ModulationType_eAnnexBQam4096: status->mode = eQAM_4096; status->fecMode = eFEC_ANNEX_B; break;
506        default:
507                return BERR_INVALID_PARAMETER;
508        }
509
510#ifndef ACB612
511        if (status->get_power)
512#endif
513        {
514#if (BCHP_CHIP==7550)
515                BTNR_7550_TunerStatus TStatus;
516
517                BTNR_7550_EnableDPM(tuner->tnrHandle);
518                err = BTNR_7550_GetTunerStatus(tuner->tnrHandle, &TStatus);
519                if (!err)
520                {
521                        status->power = TStatus.dpmLvel >> 8;   /* / 256 */
522                } else
523                        status->power = 0;
524#endif 
525        }
526
527        //status->power = ads_status.dsChannelPower;
528        status->snr = ads_status.snrEstimate;
529        /* divide 256 per Charlie's advice */
530        status->snr >>= 8;
531        status->goodRsBlockCount = ads_status.goodRsBlockCount;
532        status->berRawCount = ads_status.berRawCount;
533        status->agcIntLevel = ads_status.agcIntLevel;
534        status->agcExtLevel = ads_status.agcExtLevel;
535        status->carrierFreqOffset = ads_status.carrierFreqOffset;
536        status->carrierPhaseOffset = ads_status.carrierPhaseOffset;
537        status->rxSymbolRate = ads_status.rxSymbolRate;
538        status->equalizerGain = ads_status.equalizerGain;
539        status->postRsBER = ads_status.postRsBER;
540        status->elapsedTimeSec = ads_status.elapsedTimeSec;
541        status->isSpectrumInverted = ads_status.isSpectrumInverted;
542        status->correctedCount = ads_status.correctedCount;
543        status->uncorrectedCount = ads_status.uncorrectedCount;
544        //status->reacquireCount = ads_status.reacquireCount;
545        //status->resyncCount = ads_status.resyncCount;
546        return BERR_SUCCESS;
547}
548/*
549Summary:
550Required to initialize VSB parameters to defaults
551 */
552void btuner_params_init(
553                                           btuner_params *ds,      /* - [out] */
554                                           btuner_t tuner                          /* - required for possible resource-dependent defaults */
555                                           )
556{
557        BKNI_Memset(ds,0,sizeof(btuner_params));
558}
559
560#ifdef CONFIG_TUNER_TEST
561        #include "bsettop.h"
562        #include "ministd.h"
563static unsigned char ibuffer[0x100];
564static unsigned int input_number(void)
565{
566        unsigned number;
567        gets(ibuffer);
568        if ('0' ==ibuffer[0])
569        {
570                switch (ibuffer[1])
571                {
572                case 'x':
573                        sscanf(&ibuffer[2], "%x", &number);
574                        break;
575                case 'X':
576                        sscanf(&ibuffer[2], "%x", &number);
577                        break;
578                default:
579                        sscanf(ibuffer, "%d", &number);
580                        break;
581                }
582        } else
583        {
584                sscanf(ibuffer, "%d", &number);
585        }
586        printf(" %d %x", number, number);
587        return number;
588}
589void bapp_tune_test(void)
590{
591        btuner_t p_tune;
592        char input;
593        btuner_params params;
594        unsigned int freq,qam_mode,symbol_rate,fec_mode;
595        bool locked = false;
596        bsettop_init(0);
597        p_tune = btuner_open(B_ID(0));
598        BDBG_ASSERT(p_tune);
599
600        start:
601        printf("Enter frequency in Hz: ");
602        freq = input_number();
603        printf("\n");
604
605        printf("FEC Mode(1-Annex B, 2-Annex A): ");
606        fec_mode = input_number();
607        printf("\n");
608
609        if (fec_mode == 2)
610        {
611                printf("Enter symbol rate: ");
612                symbol_rate = input_number();
613                printf("\n");
614        }
615
616        printf("QAM Mode(1-QAM64, 2-QAM256): ");
617        qam_mode = input_number();
618        printf("\n");
619        {
620                btuner_params_init(&params,p_tune);
621                if (qam_mode == 1)
622                {
623                        params.qamMode = eQAM_64;
624                        printf("Tune QAM64\n");
625                } else if (qam_mode == 2)
626                {
627                        params.qamMode = eQAM_256;
628                        printf("Tune QAM256\n");
629                } else
630                {
631                        params.qamMode = eQAM_Scan;
632                        printf("Tune Scan\n");
633                }
634
635                if (fec_mode == 2)
636                {
637                        params.fecMode = eFEC_ANNEX_A;
638                        printf("Tune Annex A\n");
639                        params.symbol_rate = symbol_rate;
640                        printf("Tune symbol rate = %d\n",symbol_rate);
641                } else
642                {
643                        params.fecMode = eFEC_ANNEX_B;
644                        printf("Tune Annex B\n");
645                }
646                params.wait_for_lock = 1;
647                if (btuner_tune(p_tune,freq,&params) < 0)
648                {
649                        BDBG_ERR(("Tune to %dHz failed\n",freq));
650                } else
651                {
652                        BDBG_ERR(("Tune to %dHz success\n",freq));
653                }
654        }
655
656        printf("Tune again? [y/n]: ");
657        input = getchar();
658        printf("\n");
659        if (('y' == input)||('Y' == input))
660        {
661                locked = false;
662                goto start;
663        }
664}
665#endif
666
667/*
668 * Summary:
669 * Get an arry of soft decision for a constellation
670 * Description:
671 * I and Q range from 32767 to -32768
672 */
673#define TOTAL_ADS_SOFTDECISIONS 30
674bresult btuner_get_softdecisions(
675                                                                btuner_t tuner, 
676                                                                btuner_softdecision_t *pdec,    /* - [out] array of soft decisions */
677                                                                size_t length                                   /* number of soft decisions to get */
678                                                                )
679{
680        int i,j;
681        bresult rc;
682        int16_t nbr;
683        int16_t d_i[TOTAL_ADS_SOFTDECISIONS], d_q[TOTAL_ADS_SOFTDECISIONS];
684
685        BDBG_ASSERT(tuner);
686        BDBG_ASSERT(tuner->adsChannelHandle);
687
688        for (i=0; i<length; i+= TOTAL_ADS_SOFTDECISIONS )
689        {
690                rc = BADS_GetSoftDecision(tuner->adsChannelHandle,(int16_t)TOTAL_ADS_SOFTDECISIONS, d_i, d_q, &nbr);
691                if (rc) return BERR_INVALID_PARAMETER;
692
693                for (j=0; ((j<TOTAL_ADS_SOFTDECISIONS) && ((i+j)<length)); j++)
694                {
695                        pdec[i+j].i = d_i[j]*2;
696                        pdec[i+j].q = d_q[j]*2;
697                }
698        }   
699        return BERR_SUCCESS;
700}
701
Note: See TracBrowser for help on using the repository browser.