📄 tuner.c
字号:
//============================================================================// File Name: newtuner.c//// (c) Copyright [2003] Cirrus Logic Inc. All rights reserved// // This source code is Cirrus Logic, Inc. proprietary and confidential // information// // Description:// Device driver for Xu-Guang JS-6B1/L111F2-F2 TV-Tuner// Initial Release May 14, 2004 Phan.// // Modification History:// $Id: tuner.c,v 1.2 2004/05/21 15:36:24 haluk Exp $// $Log: tuner.c,v $// Revision 1.2 2004/05/21 15:36:24 haluk// Merge into head 20040520//// Revision 1.1.2.4 2004/05/18 20:21:04 phan// Fixed PAL IF setup.////////============================================================================#define DEBUG_CPU 2#include "eromdbg.h"#include "apitypes.h"#include "osapi.h"#include "tuner.h"#include "apii2c.h"#include "video_decoder.h"#include "bsp_av.h"#include "formatdetection.h"#include "assert.h"#include "tuner.h"#include "apiconfig.h"#define I2C_TUNER_ADDR ( 0xC0)#define I2C_TUNER_IF_ADDR ( 0x86)#define TUNER_FREQ_STEP_VALUE ( 62500)#define LOWBAND_MIDBAND_LIMIT (160000000)#define MIDBAND_HIGHBAND_LIMIT (442000000)#define TUNER_DBG(fmt, args...) { ERomPrintFunc(3, fmt, ## args); }//----------------------------------------------------------------------------//LOCAL VARIABLES//----------------------------------------------------------------------------static TUNER_SYSTEM tuner_std = -1;#if (USE_SYS_M_TUNER != 0)static Uint32 tuner_if = 38000000;static Uint32 tuner_min = 51050000;static Uint32 tuner_max = 805250000;#elsestatic Uint32 tuner_if = 38900000;static Uint32 tuner_min = 44900000;static Uint32 tuner_max = 860900000;#endif//----------------------------------------------------------------------------// TUNER DRIVER INTERFACE//----------------------------------------------------------------------------//----------------------------------------------------------------------------// Function:TUNER_ERROR TunerInitIF (// // Description:// setup IF for new standard and resets PLL //// // Parameters: TUNER_SYSTEM std, //video std Uint32 freq //video carrier in HZ)//// Returns: TUNER_ERROR// TUNER_SUCCESS: If succesfull// //----------------------------------------------------------------------------{ Uint32 osc; Uint16 pll; Uint8 data[6]; data[0] = 0x00; // subaddress data[2] = 0x01; data[4] = 0x02; switch(std) {#if (USE_SYS_M_TUNER != 0) case TUNER_SYSTEM_NTSC_M_KOREA: case TUNER_SYSTEM_NTSC_M_BTSC: case TUNER_SYSTEM_NTSC_M_JAPAN: case TUNER_SYSTEM_PAL_M: case TUNER_SYSTEM_PAL_N_CMB: data[1] = 0x16; data[3] = 0x30; data[5] = 0x0C; tuner_std = std; tuner_if = 38000000; tuner_min = 51050000; tuner_max = 805250000; break;#if ((USE_SYS_M_TUNER != 0) && (USE_PROG_SEARCH != 0))//TEST CODE FOR GUI START case TUNER_SYSTEM_BG_PAL_A2: case TUNER_SYSTEM_BG_PAL_NICAM: case TUNER_SYSTEM_BG_SECAM_A2: case TUNER_SYSTEM_BG_SECAM_NICAM: case TUNER_SYSTEM_I_PAL_FM: case TUNER_SYSTEM_I_PAL_NICAM: case TUNER_SYSTEM_DK_PAL_A2: case TUNER_SYSTEM_DK_SECAM_A2: case TUNER_SYSTEM_DK_PAL_NICAM: case TUNER_SYSTEM_DK_SECAM_NICAM: case TUNER_SYSTEM_L_SECAM_AM: case TUNER_SYSTEM_L_SECAM_NICAM: data[1] = 0x16; data[3] = 0x30; data[5] = 0x0C; tuner_std = std; tuner_if = 38000000; tuner_min = 51050000; tuner_max = 805250000; break;//TEST CODE FOR GUI END#endif //((USE_SYS_M_TUNER != 0) && (USE_PROG_SEARCH != 0))#else //#if (USE_SYS_M_TUNER != 0) case TUNER_SYSTEM_BG_PAL_A2: case TUNER_SYSTEM_BG_PAL_NICAM: case TUNER_SYSTEM_BG_SECAM_A2: case TUNER_SYSTEM_BG_SECAM_NICAM: data[1] = 0xD6; data[3] = 0x70; data[5] = 0x1D; tuner_std = std; tuner_if = 38000000; tuner_min = 44900000; tuner_max = 860900000; break; case TUNER_SYSTEM_I_PAL_FM: case TUNER_SYSTEM_I_PAL_NICAM: data[1] = 0xD6; data[3] = 0x70; data[5] = 0x1E; tuner_std = std; tuner_if = 38000000; tuner_min = 44900000; tuner_max = 860900000; break; case TUNER_SYSTEM_DK_PAL_A2: case TUNER_SYSTEM_DK_SECAM_A2: case TUNER_SYSTEM_DK_PAL_NICAM: case TUNER_SYSTEM_DK_SECAM_NICAM: data[1] = 0xD6; data[3] = 0x70; data[5] = 0x1F; tuner_std = std; tuner_if = 38000000; tuner_min = 44900000; tuner_max = 860900000; break;#endif //#if (USE_SYS_M_TUNER != 0) default: TUNER_DBG("<TunerInitIF> STD err\n"); return TUNER_SYSTEM_ERROR; break; } if (API_SendSeqI2C((Byte)I2C_TUNER_IF_ADDR, 2, &data[0]) != SUCCESS) { TUNER_DBG("<TunerInitIF> IF comm err\n"); return TUNER_COMM_ERROR; } if (API_SendSeqI2C((Byte)I2C_TUNER_IF_ADDR, 2, &data[2]) != SUCCESS) { TUNER_DBG("<TunerInitIF> IF comm err\n"); return TUNER_COMM_ERROR; } if (API_SendSeqI2C((Byte)I2C_TUNER_IF_ADDR, 2, &data[4]) != SUCCESS) { TUNER_DBG("<TunerInitIF> IF comm err\n"); return TUNER_COMM_ERROR; } OS_TaskDelay(3);/* FOSC = FRF + FIF */ osc = freq + tuner_if;/* pll divider value*/ pll = osc / TUNER_FREQ_STEP_VALUE; data[0] = (Uint8) ((pll >> 8) & 0xff); data[1] = (Uint8) ((pll >> 0) & 0xff); data[2] = 0xce; if(freq < tuner_min) {//too low TUNER_DBG("<TunerInitIF> freq err\n"); return TUNER_FREQ_ERROR; } else if (freq < LOWBAND_MIDBAND_LIMIT) {//lowband data[3] = 0x1; } else if (freq < MIDBAND_HIGHBAND_LIMIT) {//midband data[3] = 0x2; } else if (freq < tuner_max) {//highband data[3] = 0x4; } else {//too high TUNER_DBG("<TunerInitIF> freq err\n"); return TUNER_FREQ_ERROR; } data[4] = 0xce; data[5] = 0x60; if(API_SendSeqI2C((Byte)I2C_TUNER_ADDR, 2, &data[0]) != SUCCESS) { TUNER_DBG("<TunerInitIF> RF comm err\n"); return TUNER_COMM_ERROR; } if(API_SendSeqI2C((Byte)I2C_TUNER_ADDR, 4, &data[2]) != SUCCESS) { TUNER_DBG("<TunerInitIF> RF comm err\n"); return TUNER_COMM_ERROR; } TUNER_DBG("<TunerInitIF> %2x %2x %2x %2x %2x OK\n", data[0], data[1], data[2], data[3], data[4]); return TUNER_SUCCESS;}//----------------------------------------------------------------------------// Function:TUNER_ERROR TunerSetPLL (// // Description:// setup PLL //// // Parameters: Uint32 freq //video carrier in HZ)//// Returns: TUNER_ERROR// TUNER_SUCCESS: If succesfull// //----------------------------------------------------------------------------{//set pll parameters Uint32 osc; Uint16 pll; Uint8 data[6];/* FOSC = FRF + FIF */ osc = freq + tuner_if;/* pll divider value*/ pll = osc / TUNER_FREQ_STEP_VALUE; data[0] = (Uint8) ((pll >> 8) & 0xff); data[1] = (Uint8) ((pll >> 0) & 0xff); data[2] = 0xce; if( (freq < tuner_min) || (freq > tuner_max)) {//too low TUNER_DBG("<TunerSetPLL> freq err\n"); return TUNER_FREQ_ERROR; } else if (freq < LOWBAND_MIDBAND_LIMIT) {//lowband data[3] = 0x1; } else if (freq < MIDBAND_HIGHBAND_LIMIT) {//midband data[3] = 0x2; } else if (freq < tuner_max) {//highband data[3] = 0x4; } else {//too high TUNER_DBG("<TunerSetPLL> freq err\n"); return TUNER_FREQ_ERROR; } data[4] = 0xde; data[5] = 0x60; TUNER_DBG("<TunerSetPLL> search %d -> %2x %2x %2x %2x\n", freq, data[0], data[1], data[2], data[3]); if(API_SendSeqI2C((Byte)I2C_TUNER_ADDR, 6, &data[0]) != SUCCESS) { TUNER_DBG("<TunerSetPLL> comm err\n"); return TUNER_COMM_ERROR; } return TUNER_SUCCESS;}//----------------------------------------------------------------------------// Function:TUNER_ERROR TunerGetAFC (// // Description:// retreives AFC level //// // Parameters: TUNER_AFC *afc //afc level)//// Returns: TUNER_ERROR// TUNER_SUCCESS: If succesfull// //----------------------------------------------------------------------------{//get afc level Uint8 afclevel; int status; TUNER_DBG("<TunerGetAFC>\n"); status = API_GetSeqI2C((Byte)I2C_TUNER_IF_ADDR, 1, &afclevel); if( (status != SUCCESS) || ((afclevel & 0x1) != 0) ) {//err status = API_GetSeqI2C((Byte)I2C_TUNER_IF_ADDR, 1, &afclevel); if( (status != SUCCESS) || ((afclevel & 0x1) != 0) ) {//retry TUNER_DBG("<TunerGetAFC> comm err\n"); *afc = TUNER_AFC_OPTIMAL; return TUNER_COMM_ERROR; } } afclevel = (afclevel >> 1) & 0xf; if(afclevel == 0) { *afc = TUNER_AFC_OPTIMAL; } else if(afclevel <= 7) {//4bit signed pos *afc = TUNER_AFC_HIGH; } else {//4bit signed neg *afc = TUNER_AFC_LOW; } return TUNER_SUCCESS;}//----------------------------------------------------------------------------// Function:TUNER_ERROR TunerGetHLock (// // Description:// retreives HLOCK status //// // Parameters: Boolean *lock //horizontal lock)//// Returns: TUNER_ERROR// TUNER_SUCCESS: If succesfull// //----------------------------------------------------------------------------{//get horizontal lock video_decoder_result_type status; video_decoder_signal_lock_type locklevel; TUNER_DBG("<TunerGetHLock>\n"); status = video_decoder_signal_lock_status_get(&locklevel); if(status != VIDEO_DECODER_RESULT_SUCCESS) { status = video_decoder_signal_lock_status_get(&locklevel); if(status != VIDEO_DECODER_RESULT_SUCCESS) { TUNER_DBG("<TunerGetHLock> comm err\n"); *lock = FALSE; return TUNER_COMM_ERROR; } } if(locklevel != VIDEO_DECODER_SIGNAL_LOCK_NONE) { *lock = TRUE; } else { *lock = FALSE; } return TUNER_SUCCESS;}//----------------------------------------------------------------------------// Function:TUNER_ERROR TunerDelay (// // Description:// delays between PLL settings and status checks//// // Parameters: Boolean jumped //jumped to different freq or iterating)//// Returns: TUNER_ERROR// TUNER_SUCCESS: If succesfull// //----------------------------------------------------------------------------{ if(jumped == TRUE) { OS_TaskDelay(10); } else { OS_TaskDelay(5); } return TUNER_SUCCESS;}//----------------------------------------------------------------------------// Function:TUNER_ERROR TunerInit(// // Description:// inits tuner// // Parameters: void)//// Returns: TUNER_ERROR// TUNER_SUCCESS: If succesfull// //----------------------------------------------------------------------------{#if (USE_SYS_M_TUNER != 0) return(TunerInitIF(TUNER_SYSTEM_NTSC_M_BTSC, 61250000));#else return(TunerInitIF(TUNER_SYSTEM_BG_PAL_A2, 55250000));#endif}//----------------------------------------------------------------------------// Function:TUNER_ERROR TunerGetProperties(// // Description:// retreives tuner limits// // Parameters: Uint32 *step_size, Uint32 *min_freq, Uint32 *max_freq, TUNER_SYSTEM *tuner_sys)//// Returns: TUNER_ERROR// TUNER_SUCCESS: If succesfull// //----------------------------------------------------------------------------{ *step_size = TUNER_FREQ_STEP_VALUE; *min_freq = tuner_min; *max_freq = tuner_max; *tuner_sys = tuner_std; return TUNER_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -