AVL_DVBSx_ErrorCode CPU_Halt(struct AVL_DVBSx_Chip * pAVLChip) { AVL_DVBSx_ErrorCode r; AVL_uint16 i= 0; r = AVL_DVBSx_IBase_SendRxOP(OP_RX_HALT, pAVLChip ); printf("%s r is %d",__FUNCTION__,r); if(AVL_DVBSx_EC_OK == r) { while(i++<20) { r = AVL_DVBSx_IBase_GetRxOPStatus(pAVLChip); if(AVL_DVBSx_EC_OK == r) { break; } else { AVL_DVBSx_IBSP_Delay(10); } } } printf("%s r is %d",__FUNCTION__,r); return (r); }
static int AVL6211_Diseqc_Send_Burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) { AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; struct AVL_DVBSx_Diseqc_TxStatus sTxStatus; AVL_uchar ucTone = 0; int i=100; #define TONE_COUNT 8 if(minicmd == SEC_MINI_A) ucTone = 1; else if(minicmd == SEC_MINI_B) ucTone = 0; else ; r = AVL_DVBSx_IDiseqc_SendTone(ucTone, TONE_COUNT, pAVLChip_all); if(AVL_DVBSx_EC_OK != r) { pr_dbg("\rSend tone %d --- Fail!\n",ucTone); } else { do { i--; AVL_DVBSx_IBSP_Delay(1); r =AVL_DVBSx_IDiseqc_GetTxStatus(&sTxStatus, pAVLChip_all); //Get current status of the Diseqc transmitter data FIFO. } while((1 != sTxStatus.m_TxDone)&&i); //Wait until operation finished. if(AVL_DVBSx_EC_OK != r) { pr_dbg("\rOutput tone %d --- Fail!\n",ucTone); } } return (r); }
int AVL_Get_Quality_Percent(struct AVL_DVBSx_Chip * pAVLChip) { AVL_DVBSx_ErrorCode r=AVL_DVBSx_EC_OK; AVL_uint32 uiSNR; AVL_uint16 uiLockStatus=0; AVL_uchar SNRrefer = 0;; AVL_uchar Quality=5; AVL_uchar i; struct AVL_DVBSx_SignalInfo SignalInfo; for(i=0;i<5;i++) { AVL_DVBSx_IBSP_Delay(10); r |= AVL_DVBSx_IRx_GetLockStatus(&uiLockStatus, pAVLChip); if(uiLockStatus!=1) break; } if(i==5) { r |= AVL_DVBSx_IRx_GetSNR(&uiSNR, pAVLChip); r |= AVL_DVBSx_IRx_GetSignalInfo(&SignalInfo, pAVLChip); } else return Quality; if (SignalInfo.m_coderate < RX_DVBS2_1_4) { SNRrefer = DVBS_SNR[SignalInfo.m_coderate]; } else { if (SignalInfo.m_modulation == AVL_DVBSx_MM_8PSK) SNRrefer = DVBS28psk_SNR[SignalInfo.m_coderate -RX_DVBS2_3_5]; else SNRrefer = DVBS2Qpsk_SNR[SignalInfo.m_coderate -RX_DVBS2_1_2]; } if ((uiSNR/10) > SNRrefer) { uiSNR = uiSNR/10 - SNRrefer; if(uiSNR>=100) Quality = 99; else if(uiSNR>=50) // >5.0dB Quality = 80+ (uiSNR-50)*20/50; else if(uiSNR>=25) // > 2.5dB Quality = 50+ (uiSNR-25)*30/25; else if(uiSNR>=10) // > 1dB Quality = 25+ (uiSNR-10)*25/15; else Quality = 5+ (uiSNR)*20/10; } else { Quality = 5; } return Quality; }
AVL_DVBSx_ErrorCode AVL_DVBSx_IBase_Initialize( const struct AVL_DVBSx_PllConf * pPLLConf, AVL_puchar pInitialData, struct AVL_DVBSx_Chip * pAVLChip ) { AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; r |= AVL_DVBSx_IBase_SetPLL(pPLLConf, pAVLChip ); r |= AVL_DVBSx_IBSP_Delay(1); // this delay is critical r |= AVL_DVBSx_IBase_DownloadFirmware(pInitialData, pAVLChip); return(r); }
AVL_DVBSx_ErrorCode AVL_DVBSx_IBlindScanAPI_Exit(struct AVL_DVBSx_Chip * pAVLChip, struct AVL_DVBSx_BlindScanAPI_Setting * pBSsetting) { AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; struct AVL_DVBSx_BlindScanInfo * pbsInfo = &pBSsetting->bsInfo; if(pBSsetting->m_uiScaning == 1) { do { AVL_DVBSx_IBSP_Delay(50); r |= AVL_DVBSx_IBlindScan_GetScanStatus(pbsInfo, pAVLChip); //Query the internal blind scan procedure information. if(AVL_DVBSx_EC_OK !=r) { return r; } }while(100 != pbsInfo->m_uiProgress); } r |= AVL_DVBSx_IBase_SetFunctionalMode(pAVLChip,AVL_DVBSx_FunctMode_Demod); AVL_DVBSx_IBSP_Delay(10); return r; }
AVL_DVBSx_ErrorCode AVL_DVBSx_IBlindScanAPI_Start(struct AVL_DVBSx_Chip * pAVLChip, struct AVL_Tuner * pTuner, struct AVL_DVBSx_BlindScanAPI_Setting * pBSsetting) { AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; struct AVL_DVBSx_BlindScanPara * pbsPara = &pBSsetting->bsPara; r |= AVL_DVBSx_IBase_SetFunctionalMode(pAVLChip, AVL_DVBSx_FunctMode_BlindScan); r |= AVL_DVBSx_IBase_SetSpectrumPolarity(pBSsetting->m_eSpectrumMode,pAVLChip); if(pBSsetting->BS_Mode) { pTuner->m_uiFrequency_100kHz = 10*pBSsetting->m_uiScan_Start_Freq_MHz + pBSsetting->m_uiTuner_MaxLPF_100kHz + (pBSsetting->m_uiScan_Bind_No) * pBSsetting->m_uiScan_Center_Freq_Step_100KHz; pbsPara->m_uiStartFreq_100kHz = pTuner->m_uiFrequency_100kHz - pBSsetting->m_uiTuner_MaxLPF_100kHz; pbsPara->m_uiStopFreq_100kHz = pTuner->m_uiFrequency_100kHz + pBSsetting->m_uiTuner_MaxLPF_100kHz; } else { pbsPara->m_uiStartFreq_100kHz = pBSsetting->m_uiScan_Next_Freq_100KHz; pbsPara->m_uiStopFreq_100kHz = pBSsetting->m_uiScan_Next_Freq_100KHz + pBSsetting->m_uiTuner_MaxLPF_100kHz*2; pTuner->m_uiFrequency_100kHz = (pbsPara->m_uiStartFreq_100kHz + pbsPara->m_uiStopFreq_100kHz)/2; } pTuner->m_uiLPF_100kHz = pBSsetting->m_uiTuner_MaxLPF_100kHz; r |= pTuner->m_pLockFunc(pTuner); //Lock the tuner. AVL_DVBSx_IBSP_Delay(50); //wait a while for tuner to lock in certain frequency. r |= pTuner->m_pGetLockStatusFunc(pTuner); //Check the lock status of the tuner. if (AVL_DVBSx_EC_OK != r) { return r; } pbsPara->m_uiMaxSymRate_kHz = 1000*pBSsetting->m_uiScan_Max_Symbolrate_MHz; pbsPara->m_uiMinSymRate_kHz = 1000*pBSsetting->m_uiScan_Min_Symbolrate_MHz; r |= AVL_DVBSx_IBlindScan_Reset(pAVLChip); r |= AVL_DVBSx_IBlindScan_Scan(pbsPara,pBSsetting->m_uiTuner_MaxLPF_100kHz, pAVLChip); pBSsetting->m_uiScaning = 1; return r; }
AVL_DVBSx_ErrorCode AVL_DVBSx_II2CRepeater_ReadData_Multi( AVL_uchar ucSlaveAddr, AVL_puchar pucBuff, AVL_uchar ucRegAddr, AVL_uint16 uiSize, struct AVL_DVBSx_Chip * pAVLChip ) { AVL_DVBSx_ErrorCode r; AVL_uchar pBuff[I2CM_RSP_LENGTH]; AVL_uint16 uiTimeOut; const AVL_uint16 uiTimeOutTh = 10; const AVL_uint32 uiTimeDelay = 100; //100 ms if ( uiSize > I2CM_RSP_LENGTH ) { return(AVL_DVBSx_EC_GeneralFail); } r = AVL_DVBSx_IBSP_WaitSemaphore(&(pAVLChip->m_semI2CRepeater_r)); ChunkAddr(i2cm_cmd_addr+I2CM_CMD_LENGTH-6, pBuff); pBuff[3] = 0; pBuff[4] = ucRegAddr; pBuff[5] = 0x1; pBuff[6] = (AVL_uchar)uiSize; pBuff[7] = ucSlaveAddr; pBuff[8] = OP_I2CM_READ; r |= AVL_DVBSx_II2CRepeater_SendOP(pBuff, 9, pAVLChip); if ( AVL_DVBSx_EC_OK == r ) { uiTimeOut = 0; while ( AVL_DVBSx_EC_OK != AVL_DVBSx_II2CRepeater_GetOPStatus(pAVLChip) ) { if((++uiTimeOut) >= uiTimeOutTh) { r |= AVL_DVBSx_EC_TimeOut; r |= AVL_DVBSx_IBSP_ReleaseSemaphore(&(pAVLChip->m_semI2CRepeater_r)); return(r); } r |= AVL_DVBSx_IBSP_Delay(uiTimeDelay); } r |= (AVL_DVBSx_II2C_Read(pAVLChip, i2cm_rsp_addr, pucBuff, uiSize)); } r |= AVL_DVBSx_IBSP_ReleaseSemaphore(&(pAVLChip->m_semI2CRepeater_r)); return(r); }
static int AVL6211_Diseqc_Send_Master_Cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) { AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; AVL_uchar ucData[8]; int j=100; struct AVL_DVBSx_Diseqc_TxStatus TxStatus; int i; pr_dbg("msg_len is %d,\n data is",cmd->msg_len); for(i=0;i<cmd->msg_len;i++){ ucData[i]=cmd->msg[i]; printk("%x ",cmd->msg[i]); } r=AVL_DVBSx_IDiseqc_SendModulationData(ucData, cmd->msg_len, pAVLChip_all); if(r != AVL_DVBSx_EC_OK) { pr_dbg("AVL_DVBSx_IDiseqc_SendModulationData failed !\n"); } else { do { j--; AVL_DVBSx_IBSP_Delay(1); r= AVL_DVBSx_IDiseqc_GetTxStatus(&TxStatus, pAVLChip_all); }while((TxStatus.m_TxDone != 1)&&j); if(r ==AVL_DVBSx_EC_OK ) { } else { pr_dbg("AVL_DVBSx_IDiseqc_SendModulationData Err. !\n"); } } return r; }
static int dvbs2_blindscan_task(struct dvbsx_blindscanpara *pbspara)//(struct dvb_frontend* fe, struct dvbsx_blindscanpara *pbspara) { struct dvbsx_blindscanevent bsevent; AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; AVL_uint16 index = 0; struct AVL_DVBSx_Channel * pChannel; // AVL_uchar HandIndex = 0; //struct AVL_DVBSx_Chip * pAVLChip = &g_stAvlDVBSxChip[HandIndex]; //struct AVL_Tuner * pTuner = &g_stTuner[HandIndex]; struct AVL_DVBSx_BlindScanAPI_Setting BSsetting; enum AVL_DVBSx_BlindScanAPI_Status BS_Status; struct AVL_DVBSx_BlindScanAPI_Setting * pBSsetting = &BSsetting; BS_Status = AVL_DVBSx_BS_Status_Init; //This function do all the initialization work.It should be called only once at the beginning.It needn't be recalled when we want to lock a new channel. /* r = Initialize(pAVLChip,pTuner); if(AVL_DVBSx_EC_OK != r) { printf("Initialization failed !\n"); return (r); } printf("Initialization success !\n");*/ memset(pBSsetting, 0, sizeof(struct AVL_DVBSx_BlindScanAPI_Setting)); pBSsetting->m_uiScan_Start_Freq_MHz=pbspara->minfrequency/1000; pBSsetting->m_uiScan_Stop_Freq_MHz=pbspara->maxfrequency/1000; pBSsetting->m_uiScan_Max_Symbolrate_MHz=pbspara->maxSymbolRate/(1000 * 1000); pBSsetting->m_uiScan_Min_Symbolrate_MHz=pbspara->minSymbolRate/(1000 * 1000); while(BS_Status != AVL_DVBSx_BS_Status_Exit) { if(!blindstart){ BS_Status = AVL_DVBSx_BS_Status_Cancel; printf("AVL_DVBSx_BS_Status_Cancel\n"); } printk(KERN_INFO "BS_Status %d blindstart %d\n", BS_Status, blindstart); switch(BS_Status) { case AVL_DVBSx_BS_Status_Init: { printk(KERN_INFO "AVL_DVBSx_BS_Status_Init\n"); AVL_DVBSx_IBlindScanAPI_Initialize(pBSsetting);//this function set the parameters blind scan process needed. AVL_DVBSx_IBlindScanAPI_SetFreqRange(pBSsetting, bs_start_freq, bs_stop_freq); //Default scan rang is from 950 to 2150. User may call this function to change scan frequency rang. AVL_DVBSx_IBlindScanAPI_SetScanMode(pBSsetting, Blindscan_Mode); AVL_DVBSx_IBlindScanAPI_SetSpectrumMode(pBSsetting, AVL_DVBSx_Spectrum_Invert); //Default set is AVL_DVBSx_Spectrum_Normal, it must be set correctly according Board HW configuration AVL_DVBSx_IBlindScanAPI_SetMaxLPF(pBSsetting, M_TUNERMAXLPF_100KHZ); //Set Tuner max LPF value, this value will difference according tuner type BS_Status = AVL_DVBSx_BS_Status_Start; AVL6211_DumpSetting(pBSsetting); break; } case AVL_DVBSx_BS_Status_Start: { r = AVL_DVBSx_IBlindScanAPI_Start(pAVLChip_all, avl6211pTuner, pBSsetting); printk(KERN_INFO "AVL_DVBSx_BS_Status_Start %d\n", r); if(AVL_DVBSx_EC_OK != r) { BS_Status = AVL_DVBSx_BS_Status_Exit; } else { bsevent.status = BLINDSCAN_UPDATESTARTFREQ; bsevent.u.m_uistartfreq_khz = avl6211pTuner->m_uiFrequency_100kHz * 100; fe_use->ops.blindscan_ops.info.blindscan_callback(fe_use, &bsevent); BS_Status = AVL_DVBSx_BS_Status_Wait; } break; } case AVL_DVBSx_BS_Status_Wait: { r = AVL_DVBSx_IBlindScanAPI_GetCurrentScanStatus(pAVLChip_all, pBSsetting); printk(KERN_INFO "AVL_DVBSx_BS_Status_Wait %d %d\n", r, pBSsetting->bsInfo.m_uiChannelCount); if(AVL_DVBSx_EC_GeneralFail == r) { BS_Status = AVL_DVBSx_BS_Status_Exit; } if(AVL_DVBSx_EC_OK == r) { BS_Status = AVL_DVBSx_BS_Status_Adjust; } if(AVL_DVBSx_EC_Running == r) { AVL_DVBSx_IBSP_Delay(100); } break; } case AVL_DVBSx_BS_Status_Adjust: { r = AVL_DVBSx_IBlindScanAPI_Adjust(pAVLChip_all, pBSsetting); printk(KERN_INFO "AVL_DVBSx_BS_Status_Adjust %d\n", r); if(AVL_DVBSx_EC_OK != r) { BS_Status = AVL_DVBSx_BS_Status_Exit; } BS_Status = AVL_DVBSx_BS_Status_User_Process; break; } case AVL_DVBSx_BS_Status_User_Process: { printk(KERN_INFO "AVL_DVBSx_BS_Status_User_Process\n"); //------------Custom code start------------------- //customer can add the callback function here such as adding TP information to TP list or lock the TP for parsing PSI //Add custom code here; Following code is an example /*----- example 1: print Blindscan progress ----*/ printf(" %2d%% \n", AVL_DVBSx_IBlindscanAPI_GetProgress(pBSsetting)); //display progress Percent of blindscan process /*----- example 2: print TP information if found valid TP ----*/ while(index < pBSsetting->m_uiChannelCount) //display new TP info found in current stage { pChannel = &pBSsetting->channels[index++]; printf(" Ch%2d: RF: %4d SR: %5d ",index, (pChannel->m_uiFrequency_kHz/1000),(pChannel->m_uiSymbolRate_Hz/1000)); bsevent.status = BLINDSCAN_UPDATERESULTFREQ; bsevent.u.parameters.frequency = pChannel->m_uiFrequency_kHz; bsevent.u.parameters.u.qpsk.symbol_rate = pChannel->m_uiSymbolRate_Hz; fe_use->ops.blindscan_ops.info.blindscan_callback(fe_use, &bsevent); } bsevent.status = BLINDSCAN_UPDATEPROCESS; bsevent.u.m_uiprogress = AVL_DVBSx_IBlindscanAPI_GetProgress(pBSsetting); fe_use->ops.blindscan_ops.info.blindscan_callback(fe_use, &bsevent); //------------Custom code end ------------------- if ( (AVL_DVBSx_IBlindscanAPI_GetProgress(pBSsetting) < 100)) BS_Status = AVL_DVBSx_BS_Status_Start; else BS_Status = AVL_DVBSx_BS_Status_WaitExit; break; } case AVL_DVBSx_BS_Status_WaitExit: { msleep(50); break; } case AVL_DVBSx_BS_Status_Cancel: { r = AVL_DVBSx_IBlindScanAPI_Exit(pAVLChip_all,pBSsetting); printk(KERN_INFO "AVL_DVBSx_BS_Status_Cancel %d\n", r); BS_Status = AVL_DVBSx_BS_Status_Exit; blindstart=2; break; } default: { BS_Status = AVL_DVBSx_BS_Status_Cancel; break; } } } return 0; }
AVL_DVBSx_ErrorCode AVL6211_Initialize(struct AVL_DVBSx_Chip * pAVLChip,struct AVL_Tuner * pTuner) { struct AVL_DVBSx_Diseqc_Para sDiseqcPara; struct AVL_DVBSx_MpegInfo sMpegMode; AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; struct AVL_Demod_Tuner_Configuration_t *pDemodTunerConfig = &g_DemodTuner_Config[g_nDemodTunerArrayIndex]; struct AVL_DVBSx_VerInfo VerInfo; //AVL_uint32 uiTemp; AVL_uint32 uiDeviceID=0; #if 0 //This function should be implemented by customer. //This function should be called before all other functions to prepare everything for a BSP operation. r = AVL_DVBSx_IBSP_Initialize(); if( AVL_DVBSx_EC_OK != r ) { printf("BSP Initialization failed !\n"); return (r); } #endif pAVLChip->m_uiBusId=pDemodTunerConfig->m_ChannelId; // This function should be called after bsp initialized to initialize the chip object. r = Init_AVL_DVBSx_ChipObject(pAVLChip, pDemodTunerConfig->m_uiDemodAddress); if( AVL_DVBSx_EC_OK != r ) { printf("Chip Object Initialization failed !\n"); return (r); } //Judge the chip ID of current chip. //r = AVL_DVBSx_II2C_Read32(pAVLChip, rom_ver_addr, &uiTemp); r= AVL_DVBSx_IRx_GetDeviceID( pAVLChip, &uiDeviceID); printk("r is %x,uiDeviceID is %x\n",r,uiDeviceID); if (AVL_DVBSx_EC_OK != r) { printf("Get Chip ID failed !\n"); return (r); } //if ( uiTemp != Chip_ID ) if(uiDeviceID != Chip_ID ) { printf("Chip ID isn't correct !\n"); return AVL_DVBSx_EC_GeneralFail; } //This function should be called after chip object initialized to initialize the IBase,using reference clock as 10M. Make sure you pickup the right pll_conf since it may be modified in BSP. r = AVL_DVBSx_IBase_Initialize(&(pll_conf[pDemodTunerConfig->m_DemodReferenceClk]), ucPatchData, pAVLChip); if( AVL_DVBSx_EC_OK != r ) { printf("IBase Initialization failed !\n"); return (r); } AVL_DVBSx_IBSP_Delay(100); //Wait 100 ms to assure that the AVL_DVBSx chip boots up.This function should be implemented by customer. //This function should be called to verify the AVL_DVBSx chip has completed its initialization procedure. r = AVL_DVBSx_IBase_GetStatus(pAVLChip); if( AVL_DVBSx_EC_OK != r ) { printf("Booted failed !\n"); return (r); } printf("Booted !\n"); //Get Chip ID, Patch version and SDK version. AVL_DVBSx_IBase_GetVersion( &VerInfo, pAVLChip); printf("Chip Ver:{%d}.{%d}.{%d} API Ver:{%d}.{%d}.{%d} Patch Ver:{%d}.{%d}.{%d} \n", VerInfo.m_Chip.m_Major, VerInfo.m_Chip.m_Minor, VerInfo.m_Chip.m_Build, VerInfo.m_API.m_Major, VerInfo.m_API.m_Minor, VerInfo.m_API.m_Build, VerInfo.m_Patch.m_Major, VerInfo.m_Patch.m_Minor, VerInfo.m_Patch.m_Build); //This function should be called after IBase initialized to initialize the demod. r = AVL_DVBSx_IRx_Initialize(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Demod Initialization failed !\n"); return (r); } //This function should be called after demod initialized to set RF AGC polar. //User does not need to setup this for Sharp tuner since it is the default value. But for other tuners, user may need to do it here. r |= AVL_DVBSx_IRx_SetRFAGCPola(pDemodTunerConfig->m_TunerRFAGC, pAVLChip); r |= AVL_DVBSx_IRx_DriveRFAGC(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set RF AGC Polar failed !\n"); return (r); } //This function should be called after demod initialized to set spectrum polar. r = AVL_DVBSx_IBase_SetSpectrumPolarity(pDemodTunerConfig->m_Tuner_IQ_SpectrumMode, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set Spectrum Polar failed !\n"); return (r); } //Setup MPEG mode parameters. sMpegMode.m_MpegFormat = pDemodTunerConfig->m_TSFormat; sMpegMode.m_MpegMode = pDemodTunerConfig->m_TSOutPutMode; sMpegMode.m_MpegClockPolarity = pDemodTunerConfig->m_TSClockPolarity; //This function should be called after demod initialized to set MPEG mode.(These parameters will be valid after call lock channel function) r = AVL_DVBSx_IRx_SetMpegMode(&sMpegMode,pAVLChip ); if(sMpegMode.m_MpegMode == AVL_DVBSx_MPM_Serial) { AVL_DVBSx_IRx_SetMpegSerialPin(pAVLChip,pDemodTunerConfig->m_SerDataPin); } if(AVL_DVBSx_EC_OK != r) { printf("Set MPEG output mode failed !\n"); return (r); } // Enable the MPEG output (this function call has no effect for the AVL_DVBSxLG and AVL_DVBSxLGa devices) r = AVL_DVBSx_IRx_DriveMpegOutput(pAVLChip); //Setup tuner parameters for tuner initialization. pTuner->m_uiSlaveAddress = pDemodTunerConfig->m_uiTunerAddress; pTuner->m_uiI2CBusClock_kHz = pDemodTunerConfig->m_uiTuner_I2Cbus_clock; pTuner->m_pParameters = 0; pTuner->m_pAVLChip = pAVLChip; pTuner->m_pInitializeFunc = pDemodTunerConfig->m_pInitializeFunc; pTuner->m_pLockFunc = pDemodTunerConfig->m_pLockFunc; pTuner->m_pGetLockStatusFunc = pDemodTunerConfig->m_pGetLockStatusFunc; //This function should be called after IBase initialized to initialize the tuner. r = pTuner->m_pInitializeFunc(pTuner); if(AVL_DVBSx_EC_OK != r) { printf("Tuner Initialization failed !\n"); return (r); } //Setup DiSEqC parameters for DiSEqC initialization. sDiseqcPara.m_RxTimeout = AVL_DVBSx_DRT_150ms; sDiseqcPara.m_RxWaveForm = AVL_DVBSx_DWM_Normal; sDiseqcPara.m_ToneFrequency_kHz = Diseqc_Tone_Frequency; sDiseqcPara.m_TXGap = AVL_DVBSx_DTXG_15ms; sDiseqcPara.m_TxWaveForm = AVL_DVBSx_DWM_Normal; //The DiSEqC should be initialized if AVL_DVBSx need to supply power to LNB. This function should be called after IBase initialized to initialize the DiSEqC. r = AVL_DVBSx_IDiseqc_Initialize(&sDiseqcPara, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("DiSEqC Initialization failed !\n"); } return (r); }
AVL_DVBSx_ErrorCode DiSEqC(void) { struct AVL_DVBSx_Diseqc_TxStatus sTxStatus; struct AVL_DVBSx_Diseqc_RxStatus sRxStatus; AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; AVL_uchar ucData[8]; AVL_uchar i,i1; struct AVL_DVBSx_Chip * pAVLChip = &AVL_DVBSxChip; //This function do all the initialization work. It should be called only once at the beginning. r = Initialize(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Initialization failed !\n"); return (r); } printf("Initialization success !\n"); /*PIN 59/60 I/O Control exmples*/ r=AVL6211_LNB_PIO_Control(LNB0_PIN_59,1); if(r== AVL_DVBSx_EC_OK) { printf("Set PIO 59 to 1,OK\n"); } AVL_DVBSx_IBSP_Delay(1000); r=AVL6211_LNB_PIO_Control(LNB0_PIN_59,0); if(r== AVL_DVBSx_EC_OK) { printf("Set PIO 59 to 0,OK\n"); } AVL_DVBSx_IBSP_Delay(1000); r=AVL6211_LNB_PIO_Control(LNB1_PIN_60,1); if(r== AVL_DVBSx_EC_OK) { printf("Set PIO 60 to 1,OK\n"); } AVL_DVBSx_IBSP_Delay(100); r=AVL6211_LNB_PIO_Control(LNB1_PIN_60,0); if(r== AVL_DVBSx_EC_OK) { printf("Set PIO 60 to 0,OK\n"); } AVL_DVBSx_IBSP_Delay(1000); //22K Control examples r=AVL6211_22K_Control(1); if(r== AVL_DVBSx_EC_OK) { printf("Set 22K On,OK\n"); } AVL_DVBSx_IBSP_Delay(1000); r=AVL6211_22K_Control(0); if(r== AVL_DVBSx_EC_OK) { printf("Set 22K Off,OK\n"); } AVL_DVBSx_IBSP_Delay(1000); //Send the tone burst command r=AVL6211_SetToneOut(1); if(r== AVL_DVBSx_EC_OK) { printf("Send ToneBurst 1,OK\n"); } AVL_DVBSx_IBSP_Delay(1000); r=AVL6211_SetToneOut(0); if(r== AVL_DVBSx_EC_OK) { printf("Send ToneBurst 0,OK\n"); } AVL_DVBSx_IBSP_Delay(1000); //LNB switch control ucData[0]=0xE0; ucData[1]=0x10; ucData[2]=0x38; ucData[3]=0xF0; AVL_uchar uPortBit=0; AVL_uchar uLNBPort = 1; switch(uLNBPort) { case 1: uPortBit=0; break; case 2: uPortBit=0x04; break; case 3: uPortBit=0x08; break; case 4: uPortBit=0x0C; break; default: uPortBit=0; break; } ucData[3] += uPortBit; //This function can be called after initialization to send out 4 modulation bytes to select the LNB port if used the 1/4 LNB switch. AVL6211_DiseqcSendCmd(ucData, 4); //Positioner control one degree. ucData[0]=0xE0; ucData[1]=0x31; ucData[2]=0x68; ucData[3]=0xFF; AVL_uchar uDirection = EAST; AVL_uchar uCommandByte; switch(uDirection) { case EAST: uCommandByte=0x68; //Turn east break; case WEST: uCommandByte=0x69; //Turn west break; default: uCommandByte=0x68; break; } ucData[2] = uCommandByte; AVL6211_DiseqcSendCmd(ucData, 4); //Before receiving modulation data, we should send some request data first. //Read input status. do { r = AVL_DVBSx_IDiseqc_GetRxStatus(&sRxStatus, pAVLChip); //Get current status of the DiSEqC receiver. } while(1 != sRxStatus.m_RxDone); //Wait until operation finished. if(AVL_DVBSx_EC_OK != r) { printf("Read modulation bytes --- Fail!\n"); } else { if(0 != sRxStatus.m_RxFifoCount) //Data received. { i = sRxStatus.m_RxFifoCount; //This function can be called to read data back from the DiSEqC input FIFO when there are data received. r = AVL_DVBSx_IDiseqc_ReadModulationData(ucData, &i, pAVLChip); if(AVL_DVBSx_EC_OK == r) { printf("Received %u modulation bytes:",i); for(i1=0; i1<i; i1++) { printf("0x%x,", ucData[i1]); } printf("\n"); } else { printf("Read modulation data --- Fail!\n"); } } else { printf("There is no data in input FIFO.\n"); } } return (r); }
AVL_DVBSx_ErrorCode Initialize(struct AVL_DVBSx_Chip * pAVLChip) { struct AVL_DVBSx_Diseqc_Para sDiseqcPara; AVL_DVBSx_ErrorCode r=AVL_DVBSx_EC_OK; struct AVL_DVBSx_VerInfo VerInfo; //AVL_uint32 uiTemp; AVL_uint32 uiDeviceID=0; /* //This function should be implemented by customer. //This function should be called before all other functions to prepare everything for a BSP operation. r = AVL_DVBSx_IBSP_Initialize(); if( AVL_DVBSx_EC_OK !=r ) { printf("BSP Initialization failed !\n"); return (r); } */ // This function should be called after bsp initialized to initialize the chip object. r = Init_AVL_DVBSx_ChipObject(pAVLChip, AVL_DVBSx_SA_0); if( AVL_DVBSx_EC_OK !=r ) { printf("Chip Object Initialization failed !\n"); return (r); } //Judge the chip ID of current chip. r= AVL_DVBSx_IRx_GetDeviceID( pAVLChip, &uiDeviceID); //r = AVL_DVBSx_II2C_Read32(pAVLChip, rom_ver_addr, &uiTemp); if (AVL_DVBSx_EC_OK != r) { printf("Get Chip ID failed !\n"); return (r); } //if ( uiTemp != Chip_ID ) if(uiDeviceID != Chip_ID ) { printf("uiDeviceID:0x%x,Chip ID isn't correct!\n",uiDeviceID); return AVL_DVBSx_EC_GeneralFail; } //This function should be called after chip object initialized to initialize the IBase,using reference clock as 10M. Make sure you pickup the right pll_conf since it may be modified in BSP. r = AVL_DVBSx_IBase_Initialize(const_cast<AVL_DVBSx_PllConf *>(pll_conf+2), ucPatchData, pAVLChip); if( AVL_DVBSx_EC_OK !=r ) { printf("IBase Initialization failed !\n"); return (r); } AVL_DVBSx_IBSP_Delay(100); //Wait 100 ms to assure that the AVLDVBSx chip boots up.This function should be implemented by customer. //This function should be called to verify the AVLDVBSx chip has completed its initialization procedure. r = AVL_DVBSx_IBase_GetStatus(pAVLChip); if( AVL_DVBSx_EC_OK != r ) { printf("Booted failed !\n"); return (r); } printf("Booted !\n"); //Get Chip ID, Patch version and SDK version. AVL_DVBSx_IBase_GetVersion( &VerInfo, pAVLChip); printf("Chip Ver:{%d}.{%d}.{%d} API Ver:{%d}.{%d}.{%d} Patch Ver:{%d}.{%d}.{%d} \n", VerInfo.m_Chip.m_Major, VerInfo.m_Chip.m_Minor, VerInfo.m_Chip.m_Build, VerInfo.m_API.m_Major, VerInfo.m_API.m_Minor, VerInfo.m_API.m_Build, VerInfo.m_Patch.m_Major, VerInfo.m_Patch.m_Minor, VerInfo.m_Patch.m_Build); //This function should be called after IBase initialized to initialize the demod. r = AVL_DVBSx_IRx_Initialize(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Demod Initialization failed !\n"); return (r); } //This function should be called after demod initialized to set RF AGC polar. //User does not need to setup this for Sharp tuner since it is the default value. But for other tuners, user may need to do it here. r |= AVL_DVBSx_IRx_SetRFAGCPola(AVL_DVBSx_RA_Invert, pAVLChip); r |= AVL_DVBSx_IRx_DriveRFAGC(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set RF AGC Polar failed !\n"); return (r); } //This function should be called after demod initialized to set spectrum polar. r = AVL_DVBSx_IBase_SetSpectrumPolarity(AVL_DVBSx_Spectrum_Normal, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set Spectrum Polar failed !\n"); return (r); } //Setup DiSEqC parameters for DiSEqC initialization. sDiseqcPara.m_RxTimeout = AVL_DVBSx_DRT_150ms; sDiseqcPara.m_RxWaveForm = AVL_DVBSx_DWM_Normal; sDiseqcPara.m_ToneFrequency_kHz = DiSEqC_Tone_Frequency; sDiseqcPara.m_TXGap = AVL_DVBSx_DTXG_15ms; sDiseqcPara.m_TxWaveForm = AVL_DVBSx_DWM_Normal; //This function should be called after IBase initialized to initialize the DiSEqC. r = AVL_DVBSx_IDiseqc_Initialize(&sDiseqcPara, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("DiSEqC Initialization failed !\n"); } return (r); }