| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2012, 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 "bvsb.h" |
|---|
| 23 | #include "bvsb_3520.h" |
|---|
| 24 | #include "gist.h" |
|---|
| 25 | #include "breg_i2c_priv.h" |
|---|
| 26 | #include "bvsb.h" |
|---|
| 27 | #include "bvsb_3520.h" |
|---|
| 28 | #include "bchp_3520.h" |
|---|
| 29 | #include "bcm3520ap.h" |
|---|
| 30 | #include "bchp_hif_cpu_intr1.h" |
|---|
| 31 | #include "bos_task_priorities.h" |
|---|
| 32 | #include "bsettop_tuner_vsb_p.h" |
|---|
| 33 | |
|---|
| 34 | #include "bchp_hif_cpu_intr1.h" |
|---|
| 35 | |
|---|
| 36 | BDBG_MODULE(bsettop_tuner_vsb); |
|---|
| 37 | |
|---|
| 38 | static btuner_t s_tuner = NULL; |
|---|
| 39 | |
|---|
| 40 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 41 | static bool isInitTunerTDA182I4 = false; |
|---|
| 42 | tmErrorCode_t btuner_TDA182I4_init(); |
|---|
| 43 | #endif |
|---|
| 44 | |
|---|
| 45 | uint8_t origin_power_level = 0; |
|---|
| 46 | /*************************************************************************** |
|---|
| 47 | Summary: |
|---|
| 48 | Acquisition processing thread |
|---|
| 49 | ***************************************************************************/ |
|---|
| 50 | static void btuner_task(void *arg) |
|---|
| 51 | { |
|---|
| 52 | btuner_t p_tuner = (btuner_t)arg; |
|---|
| 53 | BDBG_ASSERT(p_tuner); |
|---|
| 54 | BDBG_MSG(("btuner_task")); |
|---|
| 55 | BERR_Code rc; |
|---|
| 56 | |
|---|
| 57 | while (1) |
|---|
| 58 | { |
|---|
| 59 | uint32_t flags; |
|---|
| 60 | |
|---|
| 61 | #if 1 |
|---|
| 62 | flags = bos_enter_critical(); |
|---|
| 63 | if (p_tuner->intEnable) |
|---|
| 64 | { |
|---|
| 65 | /* Active Low */ |
|---|
| 66 | if (BREG_Read32(GetREG(),BCHP_HIF_CPU_INTR1_INTR_W0_STATUS) & BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_EXT_IRQ_00_CPU_INTR_MASK) |
|---|
| 67 | { |
|---|
| 68 | /* the BVSB_HandleInterrupt_isr will call btuner_3520_isr_ctrl function */ |
|---|
| 69 | p_tuner->in_critical = true; |
|---|
| 70 | BVSB_HandleInterrupt_isr(p_tuner->vsbHandle); |
|---|
| 71 | p_tuner->in_critical = false; |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | bos_exit_critical(flags); |
|---|
| 75 | #endif |
|---|
| 76 | |
|---|
| 77 | #if 0 |
|---|
| 78 | if (p_tuner->intEnable && BREG_Read32(GetREG(),BCHP_HIF_CPU_INTR1_INTR_W0_STATUS) & BCHP_HIF_CPU_INTR1_INTR_W0_STATUS_EXT_IRQ_00_CPU_INTR_MASK) { |
|---|
| 79 | flags = bos_enter_critical(); |
|---|
| 80 | p_tuner->in_critical = true; |
|---|
| 81 | BVSB_HandleInterrupt_isr(p_tuner->vsbHandle); |
|---|
| 82 | p_tuner->in_critical = false; |
|---|
| 83 | bos_exit_critical(flags); |
|---|
| 84 | } |
|---|
| 85 | #endif |
|---|
| 86 | if (p_tuner->isrEvent) |
|---|
| 87 | { |
|---|
| 88 | rc = BKNI_WaitForEvent(p_tuner->isrEvent,VSB_EVT_TIMEOUT_MS); |
|---|
| 89 | if (rc == BERR_SUCCESS) |
|---|
| 90 | { |
|---|
| 91 | BDBG_MSG(("btuner_task isrEvent")); |
|---|
| 92 | BVSB_ProcessInterruptEvent(p_tuner->vsbHandle); |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | bos_sleep(VSB_TASK_TIMEOUT_MS + p_tuner->long_yield * VSB_TASK_TIMEOUT_MS); |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | /*************************************************************************** |
|---|
| 100 | Summary: |
|---|
| 101 | Enable/Disable interrupts for a 3520 device |
|---|
| 102 | ***************************************************************************/ |
|---|
| 103 | static void btuner_3520_isr_ctrl(bool enable, void *pParam) |
|---|
| 104 | { |
|---|
| 105 | btuner_t p_tuner = (btuner_t)pParam; |
|---|
| 106 | uint32_t flags; |
|---|
| 107 | if (!p_tuner->in_critical) |
|---|
| 108 | flags = bos_enter_critical(); |
|---|
| 109 | p_tuner->intEnable = enable; |
|---|
| 110 | if (!p_tuner->in_critical) |
|---|
| 111 | bos_exit_critical(flags); |
|---|
| 112 | BDBG_MSG(("\btuner_3520_isr_ctrl enable = %d\n",enable)); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | /* need to find a way to modify them if needed */ |
|---|
| 116 | int TCL_TI_TOP = 9; |
|---|
| 117 | int TCL_TI_CP = 1; |
|---|
| 118 | |
|---|
| 119 | /* for TCL DAQ63WT-6-E tuner */ |
|---|
| 120 | static BERR_Code TCLTISetRfFreq(btuner_t p_tuner) |
|---|
| 121 | { |
|---|
| 122 | uint8_t tnr[8]; |
|---|
| 123 | unsigned long n_cnt; |
|---|
| 124 | |
|---|
| 125 | n_cnt = (((p_tuner->frequency_HZ + p_tuner->IF_frequency_HZ) / 10000) * 16)/100; |
|---|
| 126 | |
|---|
| 127 | tnr[0] = 0x7F & (n_cnt >> 8); |
|---|
| 128 | tnr[1] = 0xFF & n_cnt; |
|---|
| 129 | tnr[2] = 0x83 | ((TCL_TI_TOP & 0x7) << 3); // 1000 0011 (bit 5~bit3) |
|---|
| 130 | |
|---|
| 131 | if(p_tuner->frequency_HZ >= 426000000) |
|---|
| 132 | { |
|---|
| 133 | tnr[3] = 0x08 | ((TCL_TI_CP & 0x3) << 6); //UHF 426MHZ ~864MHz |
|---|
| 134 | } |
|---|
| 135 | else if( p_tuner->frequency_HZ <= 160990000 ) |
|---|
| 136 | { |
|---|
| 137 | tnr[3] = 0x01 | ((TCL_TI_CP & 0x3) << 6); //VHF-L 54MHz~160.99MHz |
|---|
| 138 | } |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | tnr[3] = 0x06 | ((TCL_TI_CP & 0x3) << 6); //VHF-H 161MHz~425.99MHz |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | /* Configure AGC, ATC = 1 (bit 5), STBY = 0 (bit 4), test Bits/XTALOUT control = 00x1 (bits 3-0)*/ |
|---|
| 145 | if(TCL_TI_TOP >= 0x08) |
|---|
| 146 | tnr[4] = 0xC0 | (1 << 5) | (0 << 4) | 0x3; |
|---|
| 147 | else |
|---|
| 148 | tnr[4] = 0xC0 | (1 << 5) | (0 << 4) | 0x1; |
|---|
| 149 | |
|---|
| 150 | return BVSB_Mi2cWrite(p_tuner->vsbHandle, p_tuner->tuner_i2c_addr<<1, tnr, 5); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | #if 0 |
|---|
| 154 | /* not useful */ |
|---|
| 155 | static BERR_Code TCLTIGetStatus(btuner_t p_tuner) |
|---|
| 156 | { |
|---|
| 157 | uint8_t tnr[8]; |
|---|
| 158 | BERR_Code err; |
|---|
| 159 | |
|---|
| 160 | tnr[0] = tnr[1] = 0; |
|---|
| 161 | err = BVSB_Mi2cRead(p_tuner->vsbHandle, p_tuner->tuner_i2c_addr<<1, NULL, 0, tnr, 2); |
|---|
| 162 | if (err != 0) { |
|---|
| 163 | BDBG_WRN(("BVSB_Mi2cRead failed %d(0x%08x)\n",err,err)); |
|---|
| 164 | } |
|---|
| 165 | else { |
|---|
| 166 | BDBG_WRN(("tnr[0]=0x%02x, tnr[1]=0x%02x\n", tnr[0], tnr[1])); |
|---|
| 167 | BDBG_WRN(("TCL %s in frequency %d\n", tnr[0] & 0x40 ? "locked" : "not locked", p_tuner->frequency_HZ)); |
|---|
| 168 | } |
|---|
| 169 | return err; |
|---|
| 170 | } |
|---|
| 171 | #endif |
|---|
| 172 | |
|---|
| 173 | static void btuner_isr(void *param1, int param2) |
|---|
| 174 | { |
|---|
| 175 | btuner_t p_tuner= (btuner_t)param1; |
|---|
| 176 | |
|---|
| 177 | if (p_tuner->intEnable) { |
|---|
| 178 | BVSB_HandleInterrupt_isr(p_tuner->vsbHandle); |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | /* |
|---|
| 183 | Summary: |
|---|
| 184 | Open a tuner. |
|---|
| 185 | |
|---|
| 186 | Description: |
|---|
| 187 | On most platforms, the tuner_id is simply an index of the tuners. |
|---|
| 188 | |
|---|
| 189 | On platforms with more frontend options (e.g. 97038), please see bsettop_ids.txt |
|---|
| 190 | for documentation on special numbers. |
|---|
| 191 | |
|---|
| 192 | */ |
|---|
| 193 | btuner_t btuner_open( |
|---|
| 194 | bobject_t tuner_id /* - handle used to identify a particular tuner */ |
|---|
| 195 | ) |
|---|
| 196 | { |
|---|
| 197 | btuner_t p_tuner = NULL; |
|---|
| 198 | BERR_Code errCode; |
|---|
| 199 | uint8_t revision; |
|---|
| 200 | uint16_t chipId, chipVer; |
|---|
| 201 | uint8_t apVer, scrVer, cfgVer; |
|---|
| 202 | BI2C_ChannelSettings defChnSettings; |
|---|
| 203 | |
|---|
| 204 | p_tuner = BKNI_Malloc(sizeof(struct btuner)); |
|---|
| 205 | BDBG_ASSERT(p_tuner); |
|---|
| 206 | BKNI_Memset(p_tuner,0,sizeof(struct btuner)); |
|---|
| 207 | |
|---|
| 208 | //p_tuner->agcPolarityInversion = MXL_ENABLE; |
|---|
| 209 | //p_tuner->agcSingleSupply = MXL_ENABLE; |
|---|
| 210 | //p_tuner->agcExternal = MXL603_AGC_EXTERNAL; |
|---|
| 211 | //p_tuner->ifInversion = MXL_ENABLE; //MXL_DISABLE; |
|---|
| 212 | |
|---|
| 213 | BI2C_GetChannelDefaultSettings( GetI2C(), BVSB_I2C_BUS, &defChnSettings ); |
|---|
| 214 | defChnSettings.intMode = true; |
|---|
| 215 | defChnSettings.clkRate = BI2C_Clk_eClk400Khz; |
|---|
| 216 | BI2C_OpenChannel( GetI2C(), &(p_tuner->i2cChannelHandle), BVSB_I2C_BUS, &defChnSettings ); |
|---|
| 217 | BDBG_ASSERT(p_tuner->i2cChannelHandle); |
|---|
| 218 | |
|---|
| 219 | BI2C_CreateI2cRegHandle (p_tuner->i2cChannelHandle, &(p_tuner->i2cRegHandle)); |
|---|
| 220 | BDBG_ASSERT(p_tuner->i2cRegHandle); |
|---|
| 221 | |
|---|
| 222 | BVSB_3520_GetDefaultSettings(&p_tuner->vsbSettings); |
|---|
| 223 | p_tuner->vsbSettings.i2c.interruptEnableFunc = btuner_3520_isr_ctrl; |
|---|
| 224 | p_tuner->vsbSettings.i2c.interruptEnableFuncParam = (void *)p_tuner; |
|---|
| 225 | |
|---|
| 226 | /* Open VSB device */ |
|---|
| 227 | errCode = BVSB_Open(&p_tuner->vsbHandle, |
|---|
| 228 | GetCHP(), |
|---|
| 229 | (void*)p_tuner->i2cRegHandle, |
|---|
| 230 | NULL, /* only required for 356x platforms */ |
|---|
| 231 | &p_tuner->vsbSettings); |
|---|
| 232 | |
|---|
| 233 | BDBG_ASSERT(errCode == BERR_SUCCESS); |
|---|
| 234 | BDBG_ASSERT(p_tuner->vsbHandle); |
|---|
| 235 | |
|---|
| 236 | p_tuner->task_params.name="VSB"; |
|---|
| 237 | p_tuner->task_params.priority = VSB_ACQ_PRIORITY; |
|---|
| 238 | p_tuner->task_params.stack_size = VSB_TASK_STACK; |
|---|
| 239 | p_tuner->task_params.stack = p_tuner->task_stack; |
|---|
| 240 | bos_start_task(&(p_tuner->task_h),&(p_tuner->task_params),btuner_task,p_tuner); |
|---|
| 241 | |
|---|
| 242 | /* Initialize Acquisition Processor */ |
|---|
| 243 | BDBG_WRN(("Initializating 3520 VSB core...")); |
|---|
| 244 | BVSB_GetChipRevision(p_tuner->vsbHandle, &revision ); |
|---|
| 245 | if ( revision == REV_A1 ) |
|---|
| 246 | { |
|---|
| 247 | BDBG_WRN(("Attempt to load A1 AP image\n")); |
|---|
| 248 | BDBG_WRN(("Forcing fast acq for REV A1")); |
|---|
| 249 | p_tuner->vsbSettings.vsb.bFastAcq = true; |
|---|
| 250 | p_tuner->vsbSettings.qam.bFastAcq = true; |
|---|
| 251 | errCode = BVSB_InitAp(p_tuner->vsbHandle, bcm3520_ap_a1_image); |
|---|
| 252 | } else |
|---|
| 253 | { |
|---|
| 254 | BDBG_WRN(("Attempt to load B0 AP image\n")); |
|---|
| 255 | errCode = BVSB_InitAp(p_tuner->vsbHandle, bcm3520_ap_b0_image); |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | BDBG_ASSERT(errCode == BERR_SUCCESS); |
|---|
| 259 | BDBG_WRN(("Initializating 3520 VSB core... Done")); |
|---|
| 260 | |
|---|
| 261 | /* Get events and register callbacks */ |
|---|
| 262 | errCode = BVSB_GetInterruptEventHandle(p_tuner->vsbHandle, &p_tuner->isrEvent); |
|---|
| 263 | BDBG_ASSERT(errCode == BERR_SUCCESS); |
|---|
| 264 | BDBG_ASSERT(p_tuner->isrEvent); |
|---|
| 265 | errCode = BVSB_GetLockStateChangeEventHandle(p_tuner->vsbHandle, &p_tuner->lockEvent); |
|---|
| 266 | BDBG_ASSERT(errCode == BERR_SUCCESS); |
|---|
| 267 | BDBG_ASSERT(p_tuner->lockEvent); |
|---|
| 268 | |
|---|
| 269 | errCode = BVSB_GetApVersion(p_tuner->vsbHandle, &chipId, &chipVer, &apVer, &scrVer, &cfgVer); |
|---|
| 270 | BDBG_ASSERT(errCode == BERR_SUCCESS); |
|---|
| 271 | BDBG_ERR(("Chip ID 0x%x, ver 0x%x, ap 0x%x, script 0x%x, cfg 0x%x", chipId, chipVer, apVer, scrVer, cfgVer)); |
|---|
| 272 | |
|---|
| 273 | p_tuner->long_yield = true; |
|---|
| 274 | |
|---|
| 275 | s_tuner = p_tuner; |
|---|
| 276 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 277 | s_tuner->tuner_type = eTUNER_ID_NXP_TDA182I4; |
|---|
| 278 | s_tuner->tuner_i2c_addr = NXP_TDA182I4_I2C_ADDR; |
|---|
| 279 | p_tuner->IF_frequency_HZ = 4250000;/*5Mhz*/ |
|---|
| 280 | #else |
|---|
| 281 | s_tuner->tuner_type = eTUNER_ID_TCLTI; |
|---|
| 282 | s_tuner->tuner_i2c_addr = TCL_I2C_ADDR; |
|---|
| 283 | p_tuner->IF_frequency_HZ = 44000000;/*44Mhz*/ |
|---|
| 284 | #endif |
|---|
| 285 | |
|---|
| 286 | errCode = BVSB_SetInbandIfFreq(p_tuner->vsbHandle,p_tuner->IF_frequency_HZ); |
|---|
| 287 | if (BERR_SUCCESS != errCode) { |
|---|
| 288 | BDBG_ERR(("%s BVSB_SetInbandIfFreq failed (err=%d)", __func__, errCode)); |
|---|
| 289 | } |
|---|
| 290 | |
|---|
| 291 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 292 | if(!isInitTunerTDA182I4) |
|---|
| 293 | { |
|---|
| 294 | if (btuner_TDA182I4_init() == TM_OK) |
|---|
| 295 | isInitTunerTDA182I4 = true; |
|---|
| 296 | else { |
|---|
| 297 | BDBG_ERR(("%s btuner_TDA182I4_init", __func__)); |
|---|
| 298 | return NULL; |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | #endif |
|---|
| 302 | |
|---|
| 303 | return p_tuner; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | /* |
|---|
| 307 | Summary: |
|---|
| 308 | Close a tuner. |
|---|
| 309 | */ |
|---|
| 310 | void btuner_close( |
|---|
| 311 | btuner_t p_tuner /* - handle returned by btuner_open */ |
|---|
| 312 | ) |
|---|
| 313 | { |
|---|
| 314 | BDBG_ASSERT(p_tuner); |
|---|
| 315 | |
|---|
| 316 | if (p_tuner->i2cRegHandle) |
|---|
| 317 | BI2C_CloseI2cRegHandle(p_tuner->i2cRegHandle); |
|---|
| 318 | |
|---|
| 319 | if (p_tuner->i2cChannelHandle) |
|---|
| 320 | BI2C_CloseChannel(p_tuner->i2cChannelHandle); |
|---|
| 321 | |
|---|
| 322 | if (p_tuner->vsbHandle) |
|---|
| 323 | BVSB_Close(p_tuner->vsbHandle); |
|---|
| 324 | |
|---|
| 325 | BKNI_Free(p_tuner); |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | /* |
|---|
| 329 | Summary: |
|---|
| 330 | Required to initialize VSB parameters to defaults |
|---|
| 331 | */ |
|---|
| 332 | void btuner_params_init( |
|---|
| 333 | btuner_params *ds, /* - [out] */ |
|---|
| 334 | btuner_t tuner /* - required for possible resource-dependent defaults */ |
|---|
| 335 | ) |
|---|
| 336 | { |
|---|
| 337 | memset(ds,0,sizeof(btuner_params)); |
|---|
| 338 | ds->wait_for_lock = true; |
|---|
| 339 | ds->timeout = VSB_TUNE_TIMEOUT_MS; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 343 | static tmbslFrontEndDependency_t sSrvTunerFunc; |
|---|
| 344 | tmErrorCode_t btuner_TDA182I4_init() |
|---|
| 345 | { |
|---|
| 346 | tmErrorCode_t err = TM_OK; |
|---|
| 347 | TDA182I4StandardMode_t stdMode = TDA182I4_ATSC_6MHz; |
|---|
| 348 | |
|---|
| 349 | /* Driver layer struct set-up to link with user written functions */ |
|---|
| 350 | sSrvTunerFunc.sIo.Write = UserWrittenI2CWrite; |
|---|
| 351 | sSrvTunerFunc.sIo.Read = UserWrittenI2CRead; |
|---|
| 352 | sSrvTunerFunc.sTime.Get = Null; |
|---|
| 353 | sSrvTunerFunc.sTime.Wait = UserWrittenWait; |
|---|
| 354 | sSrvTunerFunc.sDebug.Print = UserWrittenPrint; |
|---|
| 355 | #if 0 |
|---|
| 356 | sSrvTunerFunc.sMutex.Init = UserWrittenMutexInit; |
|---|
| 357 | sSrvTunerFunc.sMutex.DeInit = UserWrittenMutexDeInit; |
|---|
| 358 | sSrvTunerFunc.sMutex.Acquire = UserWrittenMutexAcquire; |
|---|
| 359 | sSrvTunerFunc.sMutex.Release = UserWrittenMutexRelease; |
|---|
| 360 | #else |
|---|
| 361 | sSrvTunerFunc.sMutex.Init = NULL; |
|---|
| 362 | sSrvTunerFunc.sMutex.DeInit = NULL; |
|---|
| 363 | sSrvTunerFunc.sMutex.Acquire = NULL; |
|---|
| 364 | sSrvTunerFunc.sMutex.Release = NULL; |
|---|
| 365 | #endif |
|---|
| 366 | sSrvTunerFunc.dwAdditionalDataSize = 0; |
|---|
| 367 | sSrvTunerFunc.pAdditionalData = Null; |
|---|
| 368 | |
|---|
| 369 | /* TDA182I4 Driver initialization: 1st path */ |
|---|
| 370 | err = tmbslTDA182I4_Open(0, &sSrvTunerFunc); |
|---|
| 371 | |
|---|
| 372 | if(err == TM_OK) |
|---|
| 373 | { |
|---|
| 374 | /* TDA182I4 Hardware initialization: 1st path */ |
|---|
| 375 | err = tmbslTDA182I4_HwInit(0); |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | if(err == TM_OK) |
|---|
| 379 | { |
|---|
| 380 | /* TDA182I4 standard mode selection: 1st path */ |
|---|
| 381 | err = tmbslTDA182I4_SetStandardMode(0, stdMode); |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | if(err != TM_OK) |
|---|
| 385 | { |
|---|
| 386 | BDBG_ERR(("tmbslTDA182I4_SetStandardMode Fail!!!")); |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | return err; |
|---|
| 390 | } |
|---|
| 391 | |
|---|
| 392 | unsigned int nG_freq_test = 0; |
|---|
| 393 | void NXP_TDA182I4_SetScanfreqForTest(unsigned int freq) |
|---|
| 394 | { |
|---|
| 395 | nG_freq_test = freq*1000*1000; |
|---|
| 396 | //aov_dbg_print(("nG_freq_test=%3dMhz",nG_freq_test/(1000*1000))); |
|---|
| 397 | return; |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | #endif |
|---|
| 401 | |
|---|
| 402 | /* |
|---|
| 403 | Summary: |
|---|
| 404 | Tune and acquire a VSB downstream band |
|---|
| 405 | */ |
|---|
| 406 | bband_t btuner_tune( |
|---|
| 407 | btuner_t p_tuner, |
|---|
| 408 | unsigned freq, /* - RF center frequency in Hz */ |
|---|
| 409 | btuner_params *params /* - parameters needed to tune and acquire */ |
|---|
| 410 | ) |
|---|
| 411 | { |
|---|
| 412 | bresult result = b_ok; |
|---|
| 413 | bool locked = false; |
|---|
| 414 | BERR_Code errCode; |
|---|
| 415 | BVSB_Settings vsbSettings; |
|---|
| 416 | BVSB_InbandParams in_params; |
|---|
| 417 | BVSB_VsbStatus vsb_status; |
|---|
| 418 | int power_level, power_level_threshold; |
|---|
| 419 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 420 | tmErrorCode_t err; |
|---|
| 421 | #define POWER_LEVEL_THRESHOLD 28 /* around -94 dB */ |
|---|
| 422 | #define POWER_LEVEL_THRESHOLD_VHF 37 /* around -90 dB */ |
|---|
| 423 | #endif |
|---|
| 424 | |
|---|
| 425 | BKNI_Memset(&in_params, 0, sizeof(in_params)); |
|---|
| 426 | if(params->qamMode == eQAM_64) |
|---|
| 427 | in_params.mode = BVSB_InbandMode_e64QAM_B; |
|---|
| 428 | else if(params->qamMode == eQAM_256) |
|---|
| 429 | in_params.mode = BVSB_InbandMode_e256QAM_B; |
|---|
| 430 | else |
|---|
| 431 | in_params.mode = BVSB_InbandMode_e8VSB; |
|---|
| 432 | //in_params.symbolRateOffset = 0; |
|---|
| 433 | //in_params.ifFreqOffset = 0; |
|---|
| 434 | //in_params.eAcquisitionMode = BVSB_IfdAcquisitionMode_eFast; |
|---|
| 435 | //in_params.ifdAgcControl = true; |
|---|
| 436 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 437 | if(!isInitTunerTDA182I4) |
|---|
| 438 | { |
|---|
| 439 | if(btuner_TDA182I4_init() == TM_OK) |
|---|
| 440 | isInitTunerTDA182I4 = true; |
|---|
| 441 | else |
|---|
| 442 | { |
|---|
| 443 | BDBG_ERR(("btuner_TDA182I4_init failed\n")); |
|---|
| 444 | return -1; |
|---|
| 445 | } |
|---|
| 446 | } |
|---|
| 447 | #endif |
|---|
| 448 | |
|---|
| 449 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 450 | if(nG_freq_test != 0) |
|---|
| 451 | freq = nG_freq_test; |
|---|
| 452 | // aov_dbg_print(("freq=%3dMhz",freq/(1000*1000))); |
|---|
| 453 | #endif |
|---|
| 454 | |
|---|
| 455 | BDBG_MSG(("%s: enter, freq=%d, if_freq=%d", __func__, freq, p_tuner->IF_frequency_HZ)); |
|---|
| 456 | p_tuner->frequency_HZ = freq; |
|---|
| 457 | |
|---|
| 458 | /* if tuning */ |
|---|
| 459 | p_tuner->long_yield = false; |
|---|
| 460 | |
|---|
| 461 | if (eTUNER_ID_TCLTI == p_tuner->tuner_type) { |
|---|
| 462 | result = TCLTISetRfFreq(p_tuner); |
|---|
| 463 | if (b_ok != result) { |
|---|
| 464 | BDBG_WRN(("TCLTISetRfFreq failed (%d)\n", result)); |
|---|
| 465 | return -1; |
|---|
| 466 | } |
|---|
| 467 | /*TCLTIGetStatus(p_tuner);*/ |
|---|
| 468 | } |
|---|
| 469 | else { |
|---|
| 470 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 471 | if (eTUNER_ID_NXP_TDA182I4 == p_tuner->tuner_type) |
|---|
| 472 | { |
|---|
| 473 | /* TDA182I4 RF frequency selection: 1st path */ |
|---|
| 474 | err = tmbslTDA182I4_SetRF(0, (UInt32)freq); |
|---|
| 475 | |
|---|
| 476 | if(err != TM_OK) |
|---|
| 477 | { |
|---|
| 478 | BDBG_ERR(("tmbslTDA182I4_SetRF failed (%d)\n", err)); |
|---|
| 479 | return -1; |
|---|
| 480 | } |
|---|
| 481 | #if 0 //megakiss 2014.04.18 ³·Àº ·¹º§ÀÇ ½ÅÈ£ ·¹º§¿¡¼ óÀ½¿¡ Æ©´× ¾È µÇ´Â ¹®Á¦ ¼öÁ¤ |
|---|
| 482 | /* dwell per Tom's suggestion */ |
|---|
| 483 | bos_sleep(20); |
|---|
| 484 | |
|---|
| 485 | /* check the power level so that we can drop the frequency that without signal to improve the scan performance */ |
|---|
| 486 | power_level = NXP_TDA182I4_GetPowerLevel() >> 1; /* divide 2 for real power level */ |
|---|
| 487 | if (freq < 85000000) |
|---|
| 488 | power_level_threshold = POWER_LEVEL_THRESHOLD_VHF; |
|---|
| 489 | else |
|---|
| 490 | power_level_threshold = POWER_LEVEL_THRESHOLD; |
|---|
| 491 | /* for debug power level */ |
|---|
| 492 | BDBG_WRN(("freq=%d Mhz, PowerLevel=%3d, threshold=%d",freq,power_level,power_level_threshold)); |
|---|
| 493 | if (power_level <= power_level_threshold) { |
|---|
| 494 | /* early drop to improve scan efficiency */ |
|---|
| 495 | printf("%s|%d\n", __func__, __LINE__); |
|---|
| 496 | return -1; |
|---|
| 497 | } |
|---|
| 498 | #endif |
|---|
| 499 | } |
|---|
| 500 | else |
|---|
| 501 | { |
|---|
| 502 | BDBG_WRN(("Not supported tuner type %d)\n", p_tuner->tuner_type)); |
|---|
| 503 | return -1; |
|---|
| 504 | } |
|---|
| 505 | #else |
|---|
| 506 | BDBG_WRN(("Not supported tuner type %d)\n", p_tuner->tuner_type)); |
|---|
| 507 | return -1; |
|---|
| 508 | #endif |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | BVSB_GetSettings(p_tuner->vsbHandle, &vsbSettings); |
|---|
| 512 | vsbSettings.vsb.bFastAcq = false; |
|---|
| 513 | vsbSettings.vsb.bNtscSweep = false; /* should be set to false */ |
|---|
| 514 | //vsbSettings.vsb.bFastAcq = true; |
|---|
| 515 | vsbSettings.vsb.bTerr = true; |
|---|
| 516 | vsbSettings.vsb.bAutoAcq = true; |
|---|
| 517 | errCode = BVSB_SetSettings(p_tuner->vsbHandle, &vsbSettings); |
|---|
| 518 | if ( errCode ) |
|---|
| 519 | { |
|---|
| 520 | BDBG_WRN(("BVSB_SetSettings failed 0x%08x\n",errCode)); |
|---|
| 521 | return -1; |
|---|
| 522 | } |
|---|
| 523 | |
|---|
| 524 | BKNI_ResetEvent(p_tuner->lockEvent); |
|---|
| 525 | errCode = BVSB_AcquireInband(p_tuner->vsbHandle, &in_params); |
|---|
| 526 | if ( errCode ) |
|---|
| 527 | { |
|---|
| 528 | BDBG_WRN(("BVSB_AcquireInband failed 0x%08x\n",errCode)); |
|---|
| 529 | return -1; |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | if (params->wait_for_lock) |
|---|
| 533 | { |
|---|
| 534 | uint32_t to_ticks = bos_getticks() + MS_TO_TICKS(params->timeout); |
|---|
| 535 | int diff; |
|---|
| 536 | |
|---|
| 537 | diff = (int)to_ticks; |
|---|
| 538 | params->cancel = false; |
|---|
| 539 | do { |
|---|
| 540 | errCode = BKNI_WaitForEvent(p_tuner->lockEvent, TICKS_TO_MS(500)); |
|---|
| 541 | if (BERR_SUCCESS == errCode) { |
|---|
| 542 | /* NOTE that the lockEvent indicates it is locked, so no need to check VSB status */ |
|---|
| 543 | BDBG_WRN(("%s: freq %d locked\n",__func__, p_tuner->frequency_HZ)); |
|---|
| 544 | printf("%s: freq %d locked\n",__func__, p_tuner->frequency_HZ); |
|---|
| 545 | locked = true; |
|---|
| 546 | break; |
|---|
| 547 | } |
|---|
| 548 | /* if the user cancel the operation, simply quit */ |
|---|
| 549 | if (params->cancel_callback) |
|---|
| 550 | { |
|---|
| 551 | params->cancel_callback(params->cancel_callback_context); |
|---|
| 552 | if (params->cancel) |
|---|
| 553 | break; |
|---|
| 554 | } |
|---|
| 555 | diff = (int)(to_ticks - bos_getticks()); |
|---|
| 556 | } while (!locked && (diff > 0)); |
|---|
| 557 | } |
|---|
| 558 | else { |
|---|
| 559 | memset(&vsb_status, 0, sizeof(vsb_status)); |
|---|
| 560 | errCode = BVSB_GetVsbStatus(p_tuner->vsbHandle,&vsb_status); |
|---|
| 561 | BDBG_MSG(("%s: fec=%d, pll=%d, errCode= 0x%08x\n",__func__,vsb_status.bFecLocked, vsb_status.bPllLocked,errCode)); |
|---|
| 562 | locked = (vsb_status.bFecLocked && vsb_status.bPllLocked); |
|---|
| 563 | } |
|---|
| 564 | |
|---|
| 565 | #if 0 |
|---|
| 566 | /* for debug */ |
|---|
| 567 | if (!locked) |
|---|
| 568 | { |
|---|
| 569 | btuner_status status; |
|---|
| 570 | btuner_get_status(p_tuner, &status); |
|---|
| 571 | } |
|---|
| 572 | #endif |
|---|
| 573 | |
|---|
| 574 | /* reset BER */ |
|---|
| 575 | BVSB_ResetInbandStatus(p_tuner->vsbHandle); |
|---|
| 576 | |
|---|
| 577 | p_tuner->long_yield = true; |
|---|
| 578 | p_tuner->elapedTime_in_ms = bos_getticks(); |
|---|
| 579 | return (locked) ? BXPT_EXT_INPUT_BAND : -1; |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | #include "ber_quality_lookup_table.c" |
|---|
| 583 | |
|---|
| 584 | #define CRS 398 |
|---|
| 585 | |
|---|
| 586 | /* |
|---|
| 587 | Summary: |
|---|
| 588 | Get the status of DS receiver |
|---|
| 589 | */ |
|---|
| 590 | bresult btuner_get_status( |
|---|
| 591 | btuner_t tuner, |
|---|
| 592 | btuner_status *status /* - [out] Current status of the SDS demod */ |
|---|
| 593 | ) |
|---|
| 594 | { |
|---|
| 595 | BERR_Code err; |
|---|
| 596 | BVSB_VsbStatus vsbStatus; |
|---|
| 597 | unsigned int elapSymbol, totalBits; |
|---|
| 598 | unsigned int db, ber_quality; |
|---|
| 599 | |
|---|
| 600 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 601 | #define DEV_NUM 1 |
|---|
| 602 | #define SAMPL 12 |
|---|
| 603 | unsigned char powerlevel; |
|---|
| 604 | int npowerSum; |
|---|
| 605 | int i,j; |
|---|
| 606 | int a1,x,a3,b1,b2,b3; |
|---|
| 607 | /*janzy@20121015,get channel power level*/ |
|---|
| 608 | unsigned int frequency_Mhz; |
|---|
| 609 | |
|---|
| 610 | /*economize size,66 to 16*/ |
|---|
| 611 | #define COUNT 16 |
|---|
| 612 | unsigned int coux[COUNT][SAMPL] ={ |
|---|
| 613 | { 85,32,41,51,61,71,81,92,101,113,122,132, }, |
|---|
| 614 | { 195,30,40,50,60,71,81,91,101,111,121,131, }, |
|---|
| 615 | { 473,30,40,51,61,71,81,91,102,113,122,132, }, |
|---|
| 616 | { 497,30,40,50,60,70,80,91,101,112,122,132, }, |
|---|
| 617 | { 521,33,42,52,62,72,83,93,103,113,123,134, }, |
|---|
| 618 | { 545,33,43,53,63,73,83,93,103,114,124,134, }, |
|---|
| 619 | { 569,33,42,52,62,72,83,92,103,114,124,134, }, |
|---|
| 620 | { 593,34,43,53,63,73,83,93,104,115,125,136, }, |
|---|
| 621 | { 617,33,42,52,62,72,83,92,103,115,130,142, }, |
|---|
| 622 | { 641,34,43,53,63,73,83,94,107,116,131,142, }, |
|---|
| 623 | { 665,34,43,53,63,73,83,94,104,115,130,141, }, |
|---|
| 624 | { 689,32,41,51,61,71,82,92,102,114,129,140, }, |
|---|
| 625 | { 713,35,44,54,64,74,85,95,105,116,131,143, }, |
|---|
| 626 | { 737,34,44,54,64,74,84,94,104,116,125,136, }, |
|---|
| 627 | { 761,35,45,55,65,75,85,96,106,116,126,136, }, |
|---|
| 628 | { 785,36,46,56,66,76,86,96,106,117,127,138, } |
|---|
| 629 | }; |
|---|
| 630 | #endif |
|---|
| 631 | |
|---|
| 632 | memset(&vsbStatus, 0, sizeof(vsbStatus)); |
|---|
| 633 | err = BVSB_GetVsbStatus(tuner->vsbHandle,&vsbStatus); |
|---|
| 634 | |
|---|
| 635 | if (err == BERR_SUCCESS) |
|---|
| 636 | { |
|---|
| 637 | status->freq = tuner->frequency_HZ; |
|---|
| 638 | status->snr = vsbStatus.snr; /* Signal to noise ratio */ |
|---|
| 639 | status->lock = (vsbStatus.bFecLocked && vsbStatus.bPllLocked); |
|---|
| 640 | status->fecLock = vsbStatus.bFecLocked; |
|---|
| 641 | status->qamLock = vsbStatus.bPllLocked; |
|---|
| 642 | |
|---|
| 643 | status->mode = vsbStatus.acqParams.mode; |
|---|
| 644 | //status->fecMode; /* QAM FEC mode the input signal is */ |
|---|
| 645 | |
|---|
| 646 | //status->goodRsBlockCount; /* reset on every read */ |
|---|
| 647 | //status->berRawCount = vsbStatus.BER; /* reset on every read */ |
|---|
| 648 | status->berRawCount = vsbStatus.berCount; /* reset on every read */ |
|---|
| 649 | status->agcIntLevel = vsbStatus.if_agc; /* in 1/10 percent */ |
|---|
| 650 | status->agcExtLevel = vsbStatus.rf_agc; /* in 1/10 percent */ |
|---|
| 651 | status->carrierFreqOffset = vsbStatus.acqParams.ifFreqOffset; /* in 1/1000 Hz */ |
|---|
| 652 | status->carrierPhaseOffset = vsbStatus.acqParams.symbolRateOffset; /* in 1/1000 Hz */ |
|---|
| 653 | //status->rxSymbolRate = vsbStatus.acqParams.symbolRate; |
|---|
| 654 | status->rxSymbolRate = vsbStatus.symbolRate; |
|---|
| 655 | //status->equalizerGain; /* Channel equalizer gain value in dBm */ |
|---|
| 656 | status->postRsBER = vsbStatus.PostRS; /* Converted floating point fpostRsBER --> uint32_t postRsBER for rMagnum transport: */ |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | /* signal_strength */ |
|---|
| 660 | |
|---|
| 661 | //khw140417 |
|---|
| 662 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 663 | frequency_Mhz = status->freq/(1000*1000); |
|---|
| 664 | npowerSum = 0; |
|---|
| 665 | for(i=0;i<DEV_NUM;i++) |
|---|
| 666 | { |
|---|
| 667 | powerlevel = NXP_TDA182I4_GetPowerLevel() ; |
|---|
| 668 | npowerSum += powerlevel; |
|---|
| 669 | //bos_sleep(100); |
|---|
| 670 | } |
|---|
| 671 | status->power = (int32_t)npowerSum/DEV_NUM; |
|---|
| 672 | origin_power_level = status->power; |
|---|
| 673 | /*janzy@20121015,get channel power level*/ |
|---|
| 674 | for(i=0;i<COUNT;i++) |
|---|
| 675 | { |
|---|
| 676 | if(frequency_Mhz <= coux[i][0]) |
|---|
| 677 | { |
|---|
| 678 | if(status->power >= coux[i][SAMPL-1]) |
|---|
| 679 | status->power = 100; |
|---|
| 680 | else if(status->power <= coux[i][1]) |
|---|
| 681 | status->power = 0; |
|---|
| 682 | else |
|---|
| 683 | { |
|---|
| 684 | for(j=(SAMPL - 2);j>0;j--) |
|---|
| 685 | { |
|---|
| 686 | if(status->power > coux[i][j]) |
|---|
| 687 | { |
|---|
| 688 | a1 = j*(100/(SAMPL - 2)); |
|---|
| 689 | a3 = (j+1)*(100/(SAMPL - 2)); |
|---|
| 690 | b1 = coux[i][j]; |
|---|
| 691 | b2 = status->power; |
|---|
| 692 | b3 = coux[i][j+1]; |
|---|
| 693 | x = (b2*a3 - a3*b1+a1*b3-a1*b2)/(b3 - b1); |
|---|
| 694 | if(x > 100) x = 100; |
|---|
| 695 | else if(x < 0) x = 0; |
|---|
| 696 | status->power = x; |
|---|
| 697 | break; |
|---|
| 698 | } |
|---|
| 699 | } |
|---|
| 700 | } |
|---|
| 701 | break; |
|---|
| 702 | } |
|---|
| 703 | } |
|---|
| 704 | // aov_dbg_print(("status->power = %d",status->power)); |
|---|
| 705 | #else |
|---|
| 706 | #define SIGNAL_STRENGTH_MAX 460 /* (26624 * 1000) / 65535 */ |
|---|
| 707 | #define SIGNAL_STRENGTH_MIN 531 /* (34816 * 1000) / 65535 */ |
|---|
| 708 | |
|---|
| 709 | if (status->agcIntLevel < SIGNAL_STRENGTH_MAX) |
|---|
| 710 | status->power = 100; |
|---|
| 711 | else if (status->agcIntLevel > SIGNAL_STRENGTH_MIN) |
|---|
| 712 | status->power = 0; |
|---|
| 713 | else status->power = (SIGNAL_STRENGTH_MIN - status->agcIntLevel)/(SIGNAL_STRENGTH_MIN - SIGNAL_STRENGTH_MAX); |
|---|
| 714 | #endif |
|---|
| 715 | |
|---|
| 716 | status->correctedCount = vsbStatus.corrErrCount; |
|---|
| 717 | status->uncorrectedCount = vsbStatus.ucorrBlockCount; |
|---|
| 718 | status->resyncCount = vsbStatus.cleanBlockCount; |
|---|
| 719 | |
|---|
| 720 | status->elapsedTimeSec = (bos_getticks() - tuner->elapedTime_in_ms); /* postRsBER over this time */ |
|---|
| 721 | tuner->elapedTime_in_ms = bos_getticks(); |
|---|
| 722 | |
|---|
| 723 | elapSymbol = (status->elapsedTimeSec * vsbStatus.symbolRate) / 1000; |
|---|
| 724 | /* reset timer and also to clear the count */ |
|---|
| 725 | |
|---|
| 726 | /* now compute the signal quality */ |
|---|
| 727 | db = (status->snr / 256); |
|---|
| 728 | if (db < 15 || !status->lock) { |
|---|
| 729 | status->PreRS = 0; |
|---|
| 730 | } |
|---|
| 731 | else if (db > 19) { |
|---|
| 732 | status->PreRS = 100; |
|---|
| 733 | } |
|---|
| 734 | else { |
|---|
| 735 | if (0 == status->correctedCount) { |
|---|
| 736 | if (db < 16) |
|---|
| 737 | status->PreRS = 0; |
|---|
| 738 | else |
|---|
| 739 | status->PreRS = 100; |
|---|
| 740 | } |
|---|
| 741 | else { |
|---|
| 742 | int i; |
|---|
| 743 | |
|---|
| 744 | /* experimental shows that the bit correction happened around the range of 15 - 18 db */ |
|---|
| 745 | totalBits = (elapSymbol * 398) / 100; /* CRS = 3.98 */ |
|---|
| 746 | ber_quality = (totalBits / status->correctedCount); |
|---|
| 747 | |
|---|
| 748 | status->PreRS = 100; |
|---|
| 749 | for (i = 0; i < ber_quality_lookup_table_size; i++) { |
|---|
| 750 | if (ber_quality < ber_quality_lookup_table[i]) { |
|---|
| 751 | status->PreRS = i; |
|---|
| 752 | break; |
|---|
| 753 | } |
|---|
| 754 | } |
|---|
| 755 | } |
|---|
| 756 | } |
|---|
| 757 | /* reset BER since the correctedErrCount is accumuated */ |
|---|
| 758 | BVSB_ResetInbandStatus(tuner->vsbHandle); |
|---|
| 759 | #if 0 |
|---|
| 760 | BDBG_WRN(("snr=%d", status->snr)); |
|---|
| 761 | BDBG_WRN(("agc=%d", status->agcIntLevel)); |
|---|
| 762 | BDBG_WRN(("if_agc=%d", vsbStatus.if_agc)); |
|---|
| 763 | #endif |
|---|
| 764 | } |
|---|
| 765 | return err; |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | /* |
|---|
| 769 | * Summary: |
|---|
| 770 | * Clear the tuner's channel status |
|---|
| 771 | */ |
|---|
| 772 | bresult btuner_reset_status(btuner_t tuner) |
|---|
| 773 | { |
|---|
| 774 | return b_ok; |
|---|
| 775 | } |
|---|
| 776 | |
|---|
| 777 | bresult btuner_get_softdecisions( |
|---|
| 778 | btuner_t tuner, |
|---|
| 779 | btuner_softdecision_t *pdec, /* - [out] array of soft decisions */ |
|---|
| 780 | size_t length /* number of soft decisions to get */ |
|---|
| 781 | ) |
|---|
| 782 | { |
|---|
| 783 | return b_ok; |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | #ifdef CONFIG_TUNER_TEST |
|---|
| 787 | |
|---|
| 788 | /* avoid compile error in standalong build for unit_test */ |
|---|
| 789 | static unsigned get_opt(void) |
|---|
| 790 | { |
|---|
| 791 | unsigned opt = 0; |
|---|
| 792 | char entry[16]={0}; |
|---|
| 793 | |
|---|
| 794 | gets(entry); |
|---|
| 795 | sscanf(entry, "%d", &opt); |
|---|
| 796 | printf("\n"); |
|---|
| 797 | return opt; |
|---|
| 798 | } |
|---|
| 799 | |
|---|
| 800 | static const char *s_BVSB_InbandMode_Name[] = |
|---|
| 801 | { |
|---|
| 802 | "BVSB_InbandMode_e8VSB", |
|---|
| 803 | "BVSB_InbandMode_e16VSB", |
|---|
| 804 | "BVSB_InbandMode_e1024QAM_B", |
|---|
| 805 | "BVSB_InbandMode_e512QAM_B", |
|---|
| 806 | "BVSB_InbandMode_e256QAM_B", |
|---|
| 807 | "BVSB_InbandMode_e128QAM_B", |
|---|
| 808 | "BVSB_InbandMode_e64QAM_B", |
|---|
| 809 | "BVSB_InbandMode_e64_256QAM_B", |
|---|
| 810 | "BVSB_InbandMode_e256QAM_A", |
|---|
| 811 | "BVSB_InbandMode_e128QAM_A", |
|---|
| 812 | "BVSB_InbandMode_e64QAM_A", |
|---|
| 813 | "BVSB_InbandMode_e32QAM_A", |
|---|
| 814 | "BVSB_InbandMode_e16QAM_A", |
|---|
| 815 | "BVSB_InbandMode_eAnalog", |
|---|
| 816 | "BVSB_InbandMode_eAnalog_SIF", |
|---|
| 817 | "BVSB_InbandMode_eUnknown" |
|---|
| 818 | }; |
|---|
| 819 | |
|---|
| 820 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 821 | static bool block_i2c = false; |
|---|
| 822 | |
|---|
| 823 | void NXP_tuner_test(void) |
|---|
| 824 | { |
|---|
| 825 | /* test NXP tuner only */ |
|---|
| 826 | BERR_Code errCode; |
|---|
| 827 | btuner_t p_tuner = NULL; |
|---|
| 828 | BI2C_ChannelSettings defChnSettings; |
|---|
| 829 | uint32_t freq; /* freq in KHz */ |
|---|
| 830 | tmErrorCode_t err = TM_OK; |
|---|
| 831 | Bool agcLock, agcMax; |
|---|
| 832 | tmSWVersion_t swVer; |
|---|
| 833 | TDA182I4PowerState_t pwState; |
|---|
| 834 | unsigned int cmd; |
|---|
| 835 | |
|---|
| 836 | /* if hacked test from the bapp.c, so we need to initialize NXP tuner first */ |
|---|
| 837 | if (!isInitTunerTDA182I4) { |
|---|
| 838 | p_tuner = BKNI_Malloc(sizeof(struct btuner)); |
|---|
| 839 | BDBG_ASSERT(p_tuner); |
|---|
| 840 | BKNI_Memset(p_tuner,0,sizeof(struct btuner)); |
|---|
| 841 | |
|---|
| 842 | /* I2C for NXP tuner */ |
|---|
| 843 | BI2C_GetChannelDefaultSettings( GetI2C(), BVSB_I2C_BUS, &defChnSettings ); |
|---|
| 844 | defChnSettings.intMode = true; |
|---|
| 845 | defChnSettings.clkRate = BI2C_Clk_eClk400Khz; |
|---|
| 846 | BI2C_OpenChannel( GetI2C(), &(p_tuner->i2cChannelHandle), BVSB_I2C_BUS, &defChnSettings ); |
|---|
| 847 | BDBG_ASSERT(p_tuner->i2cChannelHandle); |
|---|
| 848 | |
|---|
| 849 | BI2C_CreateI2cRegHandle (p_tuner->i2cChannelHandle, &(p_tuner->i2cRegHandle)); |
|---|
| 850 | BDBG_ASSERT(p_tuner->i2cRegHandle); |
|---|
| 851 | |
|---|
| 852 | p_tuner->tuner_type = eTUNER_ID_NXP_TDA182I4; |
|---|
| 853 | p_tuner->tuner_i2c_addr = NXP_TDA182I4_I2C_ADDR; |
|---|
| 854 | p_tuner->IF_frequency_HZ = 4250000;/*5Mhz*/ |
|---|
| 855 | |
|---|
| 856 | /* currently we need the vsbHandle to access NXP tuner, for 7543 there will be via BSC instead of I2C */ |
|---|
| 857 | BVSB_3520_GetDefaultSettings(&p_tuner->vsbSettings); |
|---|
| 858 | p_tuner->vsbSettings.i2c.interruptEnableFunc = btuner_3520_isr_ctrl; |
|---|
| 859 | p_tuner->vsbSettings.i2c.interruptEnableFuncParam = (void *)p_tuner; |
|---|
| 860 | |
|---|
| 861 | /* Open VSB device */ |
|---|
| 862 | errCode = BVSB_Open(&p_tuner->vsbHandle, |
|---|
| 863 | GetCHP(), |
|---|
| 864 | (void*)p_tuner->i2cRegHandle, |
|---|
| 865 | NULL, /* only required for 356x platforms */ |
|---|
| 866 | &p_tuner->vsbSettings); |
|---|
| 867 | |
|---|
| 868 | BDBG_ASSERT(errCode == BERR_SUCCESS); |
|---|
| 869 | BDBG_ASSERT(p_tuner->vsbHandle); |
|---|
| 870 | |
|---|
| 871 | s_tuner = p_tuner; |
|---|
| 872 | |
|---|
| 873 | if(!isInitTunerTDA182I4) |
|---|
| 874 | { |
|---|
| 875 | if(btuner_TDA182I4_init() == TM_OK) |
|---|
| 876 | isInitTunerTDA182I4 = true; |
|---|
| 877 | } |
|---|
| 878 | } |
|---|
| 879 | else { |
|---|
| 880 | BDBG_ASSERT(s_tuner); |
|---|
| 881 | /* it has been initialized, so just reuse it */ |
|---|
| 882 | p_tuner = s_tuner; |
|---|
| 883 | } |
|---|
| 884 | |
|---|
| 885 | /* initialize the NXP tuner successfully */ |
|---|
| 886 | while (1) |
|---|
| 887 | { |
|---|
| 888 | printf("NXP Tuner Test Menu:\n"); |
|---|
| 889 | printf("1) Tune...\n"); |
|---|
| 890 | printf("2) Tuner status...\n"); |
|---|
| 891 | printf("3) Block I2C access...\n"); |
|---|
| 892 | printf("Enter option: "); |
|---|
| 893 | |
|---|
| 894 | cmd = get_opt(); |
|---|
| 895 | printf("\n"); |
|---|
| 896 | switch (cmd) |
|---|
| 897 | { |
|---|
| 898 | case 1: |
|---|
| 899 | printf("Please input frequency in KHz to tune (e.g. 57000 for 57 MHz)?\n"); |
|---|
| 900 | freq = get_opt(); |
|---|
| 901 | |
|---|
| 902 | if (block_i2c) { |
|---|
| 903 | printf("Need to unblock I2C for NXP tuner first\n"); |
|---|
| 904 | break; |
|---|
| 905 | } |
|---|
| 906 | |
|---|
| 907 | err = tmbslTDA182I4_SetRF(0, freq * 1000); |
|---|
| 908 | if(err != TM_OK) |
|---|
| 909 | { |
|---|
| 910 | p_tuner->frequency_HZ = 0; |
|---|
| 911 | BDBG_ERR(("tmbslTDA182I4_SetRF failed on frequency %d err=%d\n", p_tuner->frequency_HZ, err)); |
|---|
| 912 | break; |
|---|
| 913 | } |
|---|
| 914 | p_tuner->frequency_HZ = freq * 1000; |
|---|
| 915 | printf("tune to frequency %d successful\n", p_tuner->frequency_HZ); |
|---|
| 916 | break; |
|---|
| 917 | |
|---|
| 918 | case 2: |
|---|
| 919 | if (block_i2c) { |
|---|
| 920 | printf("Need to unblock I2C for NXP tuner first\n"); |
|---|
| 921 | break; |
|---|
| 922 | } |
|---|
| 923 | if (0 == p_tuner->frequency_HZ) { |
|---|
| 924 | printf("You need to tune a frequency first\n"); |
|---|
| 925 | break; |
|---|
| 926 | } |
|---|
| 927 | /* check the power level */ |
|---|
| 928 | tmbslTDA182I4_GetSWVersion(&swVer); |
|---|
| 929 | printf("SW version: Compatibility=%d, Major=%d, Minor=%d\n", swVer.compatibilityNr, |
|---|
| 930 | swVer.majorVersionNr, swVer.minorVersionNr); |
|---|
| 931 | printf("tune in frequency = %d\n", p_tuner->frequency_HZ); |
|---|
| 932 | printf("power level = %d dB\n", NXP_TDA182I4_GetPowerLevel() >> 1); /* divide 2 for real power level */ |
|---|
| 933 | err = tmbslTDA182I4_GetAgcStatus(0, &agcLock, &agcMax); |
|---|
| 934 | printf("AGC status: agcLock= %s, acgMax=%s\n", agcLock ? "yes" : "no", agcMax ? "yes" : "no"); |
|---|
| 935 | err = tmbslTDA182I4_GetLLPowerState(0, &pwState); |
|---|
| 936 | printf("Power state=%s\n", (0 == pwState) ? "normal" : |
|---|
| 937 | (1 == pwState) ? "standby with Xtal" : |
|---|
| 938 | (2 == pwState) ? "standy with LT" : |
|---|
| 939 | (3 == pwState) ? "standy with PLL" : "standy LT/PLL"); |
|---|
| 940 | break; |
|---|
| 941 | case 3: |
|---|
| 942 | break; |
|---|
| 943 | } |
|---|
| 944 | } |
|---|
| 945 | } |
|---|
| 946 | #endif |
|---|
| 947 | |
|---|
| 948 | void TunerTest() |
|---|
| 949 | { |
|---|
| 950 | btuner_t tuner = btuner_open(0); |
|---|
| 951 | unsigned int cmd; |
|---|
| 952 | btuner_params params; |
|---|
| 953 | params.timeout = 5000; |
|---|
| 954 | params.wait_for_lock = 1; |
|---|
| 955 | tuner->frequency_HZ = 641000000; |
|---|
| 956 | if (tuner) |
|---|
| 957 | { |
|---|
| 958 | while (1) |
|---|
| 959 | { |
|---|
| 960 | printf("Freq: %dHz, IF Freq: %dHz, Acq Timeout: %dms\n", tuner->frequency_HZ, tuner->IF_frequency_HZ, params.timeout); |
|---|
| 961 | printf("Tuner Test Menu:\n"); |
|---|
| 962 | printf("1) Enable verbose debug...\n"); |
|---|
| 963 | printf("2) Signal status...\n"); |
|---|
| 964 | printf("3) Tune...\n"); |
|---|
| 965 | printf("4) Acquire...\n"); |
|---|
| 966 | printf("5) VSB Parameters...\n"); |
|---|
| 967 | printf("6) Set IF...\n"); |
|---|
| 968 | printf("7) Tuner submenu...\n"); |
|---|
| 969 | |
|---|
| 970 | printf("Enter option: "); |
|---|
| 971 | |
|---|
| 972 | cmd = get_opt(); |
|---|
| 973 | printf("\n"); |
|---|
| 974 | switch (cmd) |
|---|
| 975 | { |
|---|
| 976 | case 1: |
|---|
| 977 | BDBG_SetModuleLevel("bvsb",BDBG_eMsg); |
|---|
| 978 | BDBG_SetModuleLevel("bvsb_3520",BDBG_eMsg); |
|---|
| 979 | BDBG_SetModuleLevel("bvsb_3520_priv",BDBG_eMsg); |
|---|
| 980 | break; |
|---|
| 981 | |
|---|
| 982 | case 2: |
|---|
| 983 | { |
|---|
| 984 | BVSB_VsbStatus vsbStatus; |
|---|
| 985 | memset(&vsbStatus, 0, sizeof(vsbStatus)); |
|---|
| 986 | BERR_Code err = BVSB_GetVsbStatus(tuner->vsbHandle,&vsbStatus); |
|---|
| 987 | if (err == BERR_SUCCESS) |
|---|
| 988 | { |
|---|
| 989 | printf("vsbStatus.acqParams.eAcquisitionMode = %s\n",s_BVSB_InbandMode_Name[vsbStatus.acqParams.mode]); |
|---|
| 990 | printf("vsbStatus.acqParams.symbolRate = %d\n",vsbStatus.acqParams.symbolRate); |
|---|
| 991 | printf("vsbStatus.acqParams.symbolRateOffset = %d\n",vsbStatus.acqParams.symbolRateOffset); |
|---|
| 992 | printf("vsbStatus.acqParams.ifFreqOffset = %d\n",vsbStatus.acqParams.ifFreqOffset); |
|---|
| 993 | printf("vsbStatus.acqSettings.bAutoAcq = %d\n",vsbStatus.acqSettings.bAutoAcq); |
|---|
| 994 | printf("vsbStatus.acqSettings.bFastAcq = %d\n",vsbStatus.acqSettings.bFastAcq); |
|---|
| 995 | printf("vsbStatus.acqSettings.bTei = %d\n",vsbStatus.acqSettings.bTei); |
|---|
| 996 | printf("vsbStatus.acqSettings.bRfiSweep = %d\n",vsbStatus.acqSettings.bRfiSweep); |
|---|
| 997 | printf("vsbStatus.acqSettings.bTerr = %d\n",vsbStatus.acqSettings.bTerr); |
|---|
| 998 | printf("vsbStatus.acqSettings.bw = %d\n",vsbStatus.acqSettings.bw); |
|---|
| 999 | printf("bFecLocked = %d\n",vsbStatus.bFecLocked); |
|---|
| 1000 | printf("bPllLocked = %d\n",vsbStatus.bPllLocked); |
|---|
| 1001 | printf("bNtscEngaged = %d\n",vsbStatus.bNtscEngaged); |
|---|
| 1002 | printf("bRfiEngaged = %d\n",vsbStatus.bRfiEngaged); |
|---|
| 1003 | printf("ifFreq = %d\n",vsbStatus.ifFreq); |
|---|
| 1004 | printf("ifFreqError = %d\n",vsbStatus.ifFreqError); |
|---|
| 1005 | printf("symbolRate = %d\n",vsbStatus.symbolRate); |
|---|
| 1006 | printf("symbolRateError = %d\n",vsbStatus.symbolRateError); |
|---|
| 1007 | printf("corrErrCount = %d\n",vsbStatus.corrErrCount); |
|---|
| 1008 | printf("symbolRateError = %d\n",vsbStatus.symbolRateError); |
|---|
| 1009 | printf("corrErrCount = %d\n",vsbStatus.corrErrCount); |
|---|
| 1010 | printf("corrBlockCount = %d\n",vsbStatus.corrBlockCount); |
|---|
| 1011 | printf("ucorrBlockCount = %d\n",vsbStatus.ucorrBlockCount); |
|---|
| 1012 | printf("cleanBlockCount = %d\n",vsbStatus.cleanBlockCount); |
|---|
| 1013 | printf("berCount = %d\n",vsbStatus.berCount); |
|---|
| 1014 | printf("rf_agc = %d\n",vsbStatus.rf_agc); |
|---|
| 1015 | printf("if_agc = %d\n",vsbStatus.if_agc); |
|---|
| 1016 | printf("snr = %d\n",vsbStatus.snr); |
|---|
| 1017 | printf("agf = %d\n",vsbStatus.agf); |
|---|
| 1018 | printf("PreRS = %d\n",vsbStatus.PreRS); |
|---|
| 1019 | printf("PostRS = %d\n",vsbStatus.PostRS); |
|---|
| 1020 | printf("BER = %d\n",vsbStatus.BER); |
|---|
| 1021 | if (eTUNER_ID_TCLTI == tuner->tuner_type) { |
|---|
| 1022 | /*TCLTIGetStatus(tuner);*/ |
|---|
| 1023 | } |
|---|
| 1024 | } |
|---|
| 1025 | else |
|---|
| 1026 | { |
|---|
| 1027 | printf("BVSB_GetVsbStatus failed err = 0x%08x\n",err); |
|---|
| 1028 | } |
|---|
| 1029 | |
|---|
| 1030 | } |
|---|
| 1031 | break; |
|---|
| 1032 | case 3: |
|---|
| 1033 | { |
|---|
| 1034 | printf("Enter frequency in Hz: "); |
|---|
| 1035 | tuner->frequency_HZ = get_opt(); |
|---|
| 1036 | printf("\n"); |
|---|
| 1037 | |
|---|
| 1038 | if (eTUNER_ID_TCLTI == tuner->tuner_type) { |
|---|
| 1039 | btuner_params params; |
|---|
| 1040 | |
|---|
| 1041 | btuner_params_init(¶ms, tuner); |
|---|
| 1042 | if (-1 == btuner_tune(tuner, tuner->frequency_HZ, ¶ms)) |
|---|
| 1043 | printf("btuner_tune failed\n"); |
|---|
| 1044 | else |
|---|
| 1045 | printf("btuner_tune is successful\n"); |
|---|
| 1046 | } |
|---|
| 1047 | } |
|---|
| 1048 | break; |
|---|
| 1049 | case 4: |
|---|
| 1050 | { |
|---|
| 1051 | BERR_Code errCode; |
|---|
| 1052 | BVSB_InbandParams in_params; |
|---|
| 1053 | BVSB_VsbStatus vsb_status; |
|---|
| 1054 | bool lock = false; |
|---|
| 1055 | uint32_t to_ticks; |
|---|
| 1056 | BKNI_Memset(&in_params, 0, sizeof(in_params)); |
|---|
| 1057 | in_params.mode = BVSB_InbandMode_e8VSB; |
|---|
| 1058 | errCode = BVSB_AcquireInband(tuner->vsbHandle, &in_params); |
|---|
| 1059 | if ( errCode ) |
|---|
| 1060 | { |
|---|
| 1061 | BDBG_WRN(("BVSB_AcquireInband failed 0x%08x\n",errCode)); |
|---|
| 1062 | break; |
|---|
| 1063 | } |
|---|
| 1064 | to_ticks = bos_getticks() + MS_TO_TICKS(params.timeout); |
|---|
| 1065 | |
|---|
| 1066 | memset(&vsb_status, 0, sizeof(vsb_status)); |
|---|
| 1067 | |
|---|
| 1068 | while (bos_getticks() < to_ticks) |
|---|
| 1069 | { |
|---|
| 1070 | errCode = BVSB_GetVsbStatus(tuner->vsbHandle,&vsb_status); |
|---|
| 1071 | if (errCode == BERR_SUCCESS) |
|---|
| 1072 | { |
|---|
| 1073 | if (vsb_status.bFecLocked && vsb_status.bPllLocked) |
|---|
| 1074 | { |
|---|
| 1075 | BDBG_WRN(("%s:%d, locked\n",__func__,__LINE__)); |
|---|
| 1076 | lock = true; |
|---|
| 1077 | break; |
|---|
| 1078 | } |
|---|
| 1079 | } |
|---|
| 1080 | else |
|---|
| 1081 | { |
|---|
| 1082 | BDBG_WRN(("%s:%d, BVSB_GetVsbStatus failed %d\n",__func__,__LINE__,errCode)); |
|---|
| 1083 | } |
|---|
| 1084 | bos_sleep(VSB_EVT_TIMEOUT_MS); |
|---|
| 1085 | } |
|---|
| 1086 | if (!lock) |
|---|
| 1087 | { |
|---|
| 1088 | BDBG_WRN(("%s:%d, BVSB_AcquireInband failed\n",__func__,__LINE__)); |
|---|
| 1089 | } |
|---|
| 1090 | } |
|---|
| 1091 | break; |
|---|
| 1092 | case 5: |
|---|
| 1093 | { |
|---|
| 1094 | BERR_Code errCode; |
|---|
| 1095 | BVSB_Settings vsbSettings; |
|---|
| 1096 | BVSB_GetSettings(tuner->vsbHandle, &vsbSettings); |
|---|
| 1097 | printf("bAutoAcq(%d): ",vsbSettings.vsb.bAutoAcq); |
|---|
| 1098 | vsbSettings.vsb.bAutoAcq = (get_opt() == 0) ? false : true; |
|---|
| 1099 | printf("\n"); |
|---|
| 1100 | printf("bFastAcq(%d): ",vsbSettings.vsb.bFastAcq); |
|---|
| 1101 | vsbSettings.vsb.bFastAcq = (get_opt() == 0) ? false : true; |
|---|
| 1102 | printf("\n"); |
|---|
| 1103 | printf("bNtscSweep(%d): ",vsbSettings.vsb.bNtscSweep); |
|---|
| 1104 | vsbSettings.vsb.bNtscSweep = (get_opt() == 0) ? false : true; |
|---|
| 1105 | printf("\n"); |
|---|
| 1106 | printf("bRfiSweep(%d): ",vsbSettings.vsb.bRfiSweep); |
|---|
| 1107 | vsbSettings.vsb.bRfiSweep = (get_opt() == 0) ? false : true; |
|---|
| 1108 | printf("\n"); |
|---|
| 1109 | printf("bTei(%d): ",vsbSettings.vsb.bTei); |
|---|
| 1110 | vsbSettings.vsb.bTei = (get_opt() == 0) ? false : true; |
|---|
| 1111 | printf("\n"); |
|---|
| 1112 | printf("bTerr(%d): ",vsbSettings.vsb.bTerr); |
|---|
| 1113 | vsbSettings.vsb.bTerr = (get_opt() == 0) ? false : true; |
|---|
| 1114 | printf("\n"); |
|---|
| 1115 | printf("bw(%d): ",vsbSettings.vsb.bw); |
|---|
| 1116 | vsbSettings.vsb.bw = get_opt(); |
|---|
| 1117 | printf("\n"); |
|---|
| 1118 | printf("pgaGain(%d): ",vsbSettings.vsb.pgaGain); |
|---|
| 1119 | vsbSettings.vsb.pgaGain = get_opt(); |
|---|
| 1120 | printf("\n"); |
|---|
| 1121 | errCode = BVSB_SetSettings(tuner->vsbHandle, &vsbSettings); |
|---|
| 1122 | } |
|---|
| 1123 | break; |
|---|
| 1124 | case 6: |
|---|
| 1125 | printf("Enter IF frequency in Hz: "); |
|---|
| 1126 | tuner->IF_frequency_HZ = get_opt(); |
|---|
| 1127 | printf("\n"); |
|---|
| 1128 | BVSB_SetInbandIfFreq(tuner->vsbHandle,tuner->IF_frequency_HZ); |
|---|
| 1129 | break; |
|---|
| 1130 | case 7: |
|---|
| 1131 | printf("Submenu test is not implemented yet\n"); |
|---|
| 1132 | break; |
|---|
| 1133 | default: |
|---|
| 1134 | break; |
|---|
| 1135 | } |
|---|
| 1136 | } |
|---|
| 1137 | } |
|---|
| 1138 | } |
|---|
| 1139 | #endif |
|---|
| 1140 | |
|---|
| 1141 | #ifdef CONFIG_NXP_TDA182I4 |
|---|
| 1142 | unsigned char NXP_TDA182I4_GetPowerLevel() |
|---|
| 1143 | { |
|---|
| 1144 | unsigned char pPowerLevel; |
|---|
| 1145 | tmbslTDA182I4_GetPowerLevel(0,&pPowerLevel); |
|---|
| 1146 | return pPowerLevel; |
|---|
| 1147 | } |
|---|
| 1148 | |
|---|
| 1149 | |
|---|
| 1150 | void NXP_TDA182I4_SetPowerState(bool onoff) |
|---|
| 1151 | { |
|---|
| 1152 | if(onoff) |
|---|
| 1153 | { |
|---|
| 1154 | aov_tmbslTDA182I4_LTOEnable(0); |
|---|
| 1155 | tmbslTDA182I4_SetPowerState(0,tmPowerOn); |
|---|
| 1156 | } |
|---|
| 1157 | else |
|---|
| 1158 | { |
|---|
| 1159 | aov_tmbslTDA182I4_LTODisable(0); |
|---|
| 1160 | tmbslTDA182I4_SetPowerState(0,tmPowerOn); |
|---|
| 1161 | } |
|---|
| 1162 | return; |
|---|
| 1163 | } |
|---|
| 1164 | |
|---|
| 1165 | void NXP_TDA182I4_DupReg(unsigned int max) |
|---|
| 1166 | { |
|---|
| 1167 | aov_tmbslTDA182I4_dbg_test(max); |
|---|
| 1168 | return; |
|---|
| 1169 | } |
|---|
| 1170 | |
|---|
| 1171 | tmErrorCode_t UserWrittenI2CRead(tmUnitSelect_t tUnit,UInt32 AddrSize, UInt8* pAddr,UInt32 ReadLen, UInt8* pData) |
|---|
| 1172 | { |
|---|
| 1173 | btuner_t p_tuner = (btuner_t) s_tuner; |
|---|
| 1174 | BERR_Code errCode; |
|---|
| 1175 | uint8_t slave_addr; |
|---|
| 1176 | #ifdef TDA182I4_I2C |
|---|
| 1177 | int i,j; |
|---|
| 1178 | #endif |
|---|
| 1179 | BDBG_ASSERT(p_tuner); |
|---|
| 1180 | slave_addr = p_tuner->tuner_i2c_addr; |
|---|
| 1181 | |
|---|
| 1182 | errCode = BVSB_Mi2cRead(p_tuner->vsbHandle, slave_addr<<1, pAddr, AddrSize, pData, ReadLen); |
|---|
| 1183 | |
|---|
| 1184 | #ifdef TDA182I4_I2C |
|---|
| 1185 | if(ReadLen > 1) |
|---|
| 1186 | { |
|---|
| 1187 | printf("%15s@%5d:%25s ", strrchr(__FILE__,'/')? strrchr(__FILE__,'/')+1 : __FILE__,__LINE__,__func__); |
|---|
| 1188 | printf("%5s(0x%02x, 0x%02x) ReadLen = %d\n",((errCode == BERR_SUCCESS)?"OK":"Faill"),slave_addr,pAddr[0],ReadLen); |
|---|
| 1189 | j = 0; |
|---|
| 1190 | for(i=0;i<ReadLen;i++) |
|---|
| 1191 | { |
|---|
| 1192 | j++; |
|---|
| 1193 | printf(" 0x%02x,",pData[i]); |
|---|
| 1194 | if(j % 8 == 0) |
|---|
| 1195 | { |
|---|
| 1196 | j = 0; |
|---|
| 1197 | printf("\n"); |
|---|
| 1198 | } |
|---|
| 1199 | } |
|---|
| 1200 | printf("\n"); |
|---|
| 1201 | } |
|---|
| 1202 | else |
|---|
| 1203 | { |
|---|
| 1204 | AOV_DBG_PRINT(("%5s(0x%02x, 0x%02x, 0x%02x,%d)",((errCode == BERR_SUCCESS)?"OK":"Faill"),slave_addr,pAddr[0],pData[0],ReadLen)); |
|---|
| 1205 | } |
|---|
| 1206 | |
|---|
| 1207 | #else |
|---|
| 1208 | if(errCode != BERR_SUCCESS) |
|---|
| 1209 | { |
|---|
| 1210 | BDBG_ERR(("%s(0x%02x, 0x%02x,%d, 0x%02x,0x%02x,%d)\n",__func__,slave_addr,pAddr[0],AddrSize,pData[0],pData[1],ReadLen)); |
|---|
| 1211 | } |
|---|
| 1212 | #endif |
|---|
| 1213 | return (errCode == BERR_SUCCESS) ? TM_OK : TM_ERR_BAD_PARAMETER; |
|---|
| 1214 | } |
|---|
| 1215 | |
|---|
| 1216 | #define MAX_3520_I2C_WRITE 31 |
|---|
| 1217 | tmErrorCode_t UserWrittenI2CWrite (tmUnitSelect_t tUnit, UInt32 AddrSize, UInt8* pAddr,UInt32 WriteLen, UInt8* pData) |
|---|
| 1218 | { |
|---|
| 1219 | btuner_t p_tuner = (btuner_t) s_tuner; |
|---|
| 1220 | BERR_Code errCode; |
|---|
| 1221 | uint8_t slave_addr; |
|---|
| 1222 | uint8_t buffer[MAX_3520_I2C_WRITE]; |
|---|
| 1223 | #ifdef TDA182I4_I2C |
|---|
| 1224 | int i,j; |
|---|
| 1225 | #endif |
|---|
| 1226 | BDBG_ASSERT(p_tuner); |
|---|
| 1227 | BDBG_ASSERT((WriteLen + AddrSize) <= MAX_3520_I2C_WRITE); |
|---|
| 1228 | slave_addr = p_tuner->tuner_i2c_addr; |
|---|
| 1229 | |
|---|
| 1230 | BKNI_Memcpy(buffer,pAddr,AddrSize); |
|---|
| 1231 | BKNI_Memcpy(&buffer[AddrSize],pData,WriteLen); |
|---|
| 1232 | errCode = BVSB_Mi2cWrite(p_tuner->vsbHandle, slave_addr<<1, buffer, WriteLen + AddrSize); |
|---|
| 1233 | #ifdef TDA182I4_I2C |
|---|
| 1234 | if(WriteLen > 1) |
|---|
| 1235 | { |
|---|
| 1236 | printf("%15s@%5d:%25s ", strrchr(__FILE__,'/')? strrchr(__FILE__,'/')+1 : __FILE__,__LINE__,__func__); |
|---|
| 1237 | printf("%5s(0x%02x, 0x%02x),WriteLen = %d\n",((errCode == BERR_SUCCESS)?"OK":"Faill"),slave_addr,buffer[0],WriteLen); |
|---|
| 1238 | j = 0; |
|---|
| 1239 | for(i=0;i<WriteLen;i++) |
|---|
| 1240 | { |
|---|
| 1241 | j++; |
|---|
| 1242 | printf(" 0x%02x,",buffer[i]); |
|---|
| 1243 | if(j % 8 == 0) |
|---|
| 1244 | { |
|---|
| 1245 | j = 0; |
|---|
| 1246 | printf("\n"); |
|---|
| 1247 | } |
|---|
| 1248 | } |
|---|
| 1249 | printf("\n"); |
|---|
| 1250 | } |
|---|
| 1251 | else |
|---|
| 1252 | { |
|---|
| 1253 | AOV_DBG_PRINT(("%5s(0x%02x, 0x%02x, 0x%02x,%d)",((errCode == BERR_SUCCESS)?"OK":"Faill"),slave_addr,pAddr[0],buffer[1],WriteLen)); |
|---|
| 1254 | } |
|---|
| 1255 | #else |
|---|
| 1256 | if(errCode != BERR_SUCCESS) |
|---|
| 1257 | { |
|---|
| 1258 | BDBG_ERR(("%s(0x%02x, 0x%02x,%d, 0x%02x,%d)\n",__func__,slave_addr,pAddr[0],AddrSize,pData[0],WriteLen)); |
|---|
| 1259 | } |
|---|
| 1260 | #endif |
|---|
| 1261 | return (errCode == BERR_SUCCESS) ? TM_OK : TM_ERR_BAD_PARAMETER; |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | tmErrorCode_t UserWrittenWait(tmUnitSelect_t tUnit, UInt32 tms) |
|---|
| 1265 | { |
|---|
| 1266 | bos_sleep(tms); |
|---|
| 1267 | return TM_OK; |
|---|
| 1268 | } |
|---|
| 1269 | |
|---|
| 1270 | /* defined in ministd.c */ |
|---|
| 1271 | tmErrorCode_t UserWrittenPrint(UInt32 level, const char* format, ...) |
|---|
| 1272 | { |
|---|
| 1273 | printf("L = %d ",level); |
|---|
| 1274 | printf(format); |
|---|
| 1275 | printf("\n"); |
|---|
| 1276 | return TM_OK; |
|---|
| 1277 | } |
|---|
| 1278 | tmErrorCode_t UserWrittenMutexInit(ptmbslFrontEndMutexHandle *ppMutexHandle) |
|---|
| 1279 | { |
|---|
| 1280 | BKNI_MutexHandle hMutexHandle; |
|---|
| 1281 | if(BKNI_CreateMutex(&hMutexHandle) == BERR_SUCCESS) |
|---|
| 1282 | { |
|---|
| 1283 | *ppMutexHandle = (ptmbslFrontEndMutexHandle)hMutexHandle; |
|---|
| 1284 | return TM_OK; |
|---|
| 1285 | } |
|---|
| 1286 | else |
|---|
| 1287 | return -1; |
|---|
| 1288 | } |
|---|
| 1289 | tmErrorCode_t UserWrittenMutexDeInit( ptmbslFrontEndMutexHandle pMutex) |
|---|
| 1290 | { |
|---|
| 1291 | BKNI_MutexHandle hMutexHandle = (BKNI_MutexHandle)pMutex; |
|---|
| 1292 | |
|---|
| 1293 | BKNI_DestroyMutex(hMutexHandle) ; |
|---|
| 1294 | |
|---|
| 1295 | return TM_OK; |
|---|
| 1296 | } |
|---|
| 1297 | tmErrorCode_t UserWrittenMutexAcquire(ptmbslFrontEndMutexHandle pMutex, UInt32 timeOut) |
|---|
| 1298 | { |
|---|
| 1299 | BKNI_MutexHandle hMutexHandle = (BKNI_MutexHandle)pMutex; |
|---|
| 1300 | |
|---|
| 1301 | if(BKNI_TryAcquireMutex(hMutexHandle) == BERR_SUCCESS) |
|---|
| 1302 | { |
|---|
| 1303 | if(BKNI_AcquireMutex(hMutexHandle) == BERR_SUCCESS) |
|---|
| 1304 | return TM_OK; |
|---|
| 1305 | else |
|---|
| 1306 | return -1; |
|---|
| 1307 | } |
|---|
| 1308 | else |
|---|
| 1309 | return -1; |
|---|
| 1310 | } |
|---|
| 1311 | tmErrorCode_t UserWrittenMutexRelease(ptmbslFrontEndMutexHandle pMutex) |
|---|
| 1312 | { |
|---|
| 1313 | BKNI_MutexHandle hMutexHandle = (BKNI_MutexHandle)pMutex; |
|---|
| 1314 | |
|---|
| 1315 | BKNI_ReleaseMutex(hMutexHandle) ; |
|---|
| 1316 | |
|---|
| 1317 | return TM_OK; |
|---|
| 1318 | } |
|---|
| 1319 | #endif |
|---|
| 1320 | |
|---|