📄 scrdrv.c
字号:
SEM_LOCK(DiSEqC_Semaphore);
/* Invoke new configuration 13V*/
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
/*18V*/
LnbConfig.Polarization = STTUNER_PLR_HORIZONTAL;
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
task_delay(25 * (ST_GetClocksPerSecond() / 1000));
/* send DiSEqC Commands */
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Demod.Driver->demod_DiSEqC)(DemodHandle, &pDiSEqCSendPacket, &pDiSEqCResponsePacket );
task_delay(10 * (ST_GetClocksPerSecond() / 1000));
/* Come back to 13V */
LnbConfig.Polarization = STTUNER_PLR_VERTICAL;
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
SEM_UNLOCK(DiSEqC_Semaphore);
return Error;
}
#endif
/* ----------------------------------------------------------------------------
Name: scr_auto_detect()
Description:
This routine will find free scr with auto detection of tone sent by free scrs
Parameters:
Return Value:
---------------------------------------------------------------------------- */
#ifndef STTUNER_MINIDRIVER
ST_ErrorCode_t scr_auto_detect(SCR_OpenParams_t *OpenParams, DEMOD_Handle_t DemodHandle, U32 StartFreq, U32 StopFreq, U8 *NbTones, U32 *ToneList,int* power_detection_level)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
STTUNER_InstanceDbase_t *Inst;
Inst = STTUNER_GetDrvInst();
Error = scr_tone_enable(OpenParams, DemodHandle);
if(Error == ST_NO_ERROR)
{
Error |= Inst[OpenParams->TopLevelHandle].Sat.Demod.Driver->demod_tonedetection(DemodHandle, StartFreq, StopFreq, NbTones, ToneList, 1,power_detection_level);
}
return Error;
}
#endif
#ifndef STTUNER_MINIDRIVER
U8 scr_get_LO_frequency(SCR_OpenParams_t *OpenParams, DEMOD_Handle_t DemodHandle, U8 SCRBPF, U16 SCRCenterFrequency, U16 *SCRLNB_Frequency,int* power_detection_level)
{
STTUNER_DiSEqCSendPacket_t pDiSEqCSendPacket;
STTUNER_DiSEqCResponsePacket_t pDiSEqCResponsePacket;
LNB_Config_t LnbConfig;
ST_ErrorCode_t Error = ST_NO_ERROR;
U8 lo_num, NbTones, nbLnbs=0;
U32 StartFreq, StopFreq, CenterFreq, tonefreq;
unsigned char command_array [] = {0xE0, 0x10, 0x5B, 0x02, 0x00};/* E0(Framing) 10/11(address) 5B(command) data1(Sub_func = 2) data2 = Lo_num*/
STTUNER_InstanceDbase_t *Inst;
Inst = STTUNER_GetDrvInst();
pDiSEqCSendPacket.DiSEqCCommandType = STTUNER_DiSEqC_COMMAND;
pDiSEqCSendPacket.pFrmAddCmdData = &command_array[0];
pDiSEqCSendPacket.uc_TotalNoOfBytes = 5;
LnbConfig.TopLevelHandle = OpenParams->TopLevelHandle;
LnbConfig.Status = LNB_STATUS_ON; /* Set the Satellite Dish LNB power to ON */
LnbConfig.Polarization = STTUNER_PLR_VERTICAL; /* Setup the Satellite Dish LNB Polarization */
LnbConfig.ToneState = STTUNER_LNB_TONE_OFF; /* Setup the require tone state */
pDiSEqCSendPacket.uc_msecBeforeNextCommand = 50;
CenterFreq = (U32)(SCRCenterFrequency*1000000);
StartFreq = (U32)(CenterFreq - 10000000);
StopFreq = (U32)(CenterFreq + 10000000);
command_array[3] |= (SCRBPF<<5);
/* Invoke new configuration 13V*/
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
for(lo_num = 2; lo_num<=0x0c; lo_num++)
{
command_array[4] = lo_num;
SEM_LOCK(DiSEqC_Semaphore);
/*18V*/
LnbConfig.Polarization = STTUNER_PLR_HORIZONTAL;
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
task_delay(25 * (ST_GetClocksPerSecond() / 1000));
/* send DiSEqC Commands */
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Demod.Driver->demod_DiSEqC)(DemodHandle, &pDiSEqCSendPacket, &pDiSEqCResponsePacket );
task_delay(10 * (ST_GetClocksPerSecond() / 1000));
/* Come back to 13V */
LnbConfig.Polarization = STTUNER_PLR_VERTICAL;
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
SEM_UNLOCK(DiSEqC_Semaphore);
Error |= Inst[OpenParams->TopLevelHandle].Sat.Demod.Driver->demod_tonedetection(DemodHandle, StartFreq, StopFreq, &NbTones, &tonefreq,0,power_detection_level);
if(NbTones)
{
if((tonefreq>= StartFreq) && (tonefreq<= StopFreq))
{SCRLNB_Frequency[nbLnbs] = LO_LUT[lo_num]; ++nbLnbs;}
}
}
return (nbLnbs);
}
#endif
#ifndef STTUNER_MINIDRIVER
U8 scr_get_application_number(SCR_OpenParams_t *OpenParams, DEMOD_Handle_t DemodHandle, U8 SCRBPF, U16 SCRCenterFrequency,int* power_detection_level)
{
STTUNER_DiSEqCSendPacket_t pDiSEqCSendPacket;
STTUNER_DiSEqCResponsePacket_t pDiSEqCResponsePacket;
LNB_Config_t LnbConfig;
ST_ErrorCode_t Error = ST_NO_ERROR;
U8 app_num, NbTones;
U32 StartFreq, StopFreq, CenterFreq, tonefreq = 0;
unsigned char command_array [] = {0xE0, 0x10, 0x5B, 0x01, 0x00};
STTUNER_InstanceDbase_t *Inst;
Inst = STTUNER_GetDrvInst();
pDiSEqCSendPacket.DiSEqCCommandType = STTUNER_DiSEqC_COMMAND;
pDiSEqCSendPacket.pFrmAddCmdData = &command_array[0];
pDiSEqCSendPacket.uc_TotalNoOfBytes = 5;
LnbConfig.TopLevelHandle = OpenParams->TopLevelHandle;
LnbConfig.Status = LNB_STATUS_ON; /* Set the Satellite Dish LNB power to ON */
LnbConfig.Polarization = STTUNER_PLR_VERTICAL; /* Setup the Satellite Dish LNB Polarization */
LnbConfig.ToneState = STTUNER_LNB_TONE_OFF; /* Setup the require tone state */
pDiSEqCSendPacket.uc_msecBeforeNextCommand = 50;
CenterFreq = (U32)(SCRCenterFrequency*1000000);
StartFreq = (U32)(CenterFreq - 10000000);
StopFreq = (U32)(CenterFreq + 10000000);
command_array[3] |= (SCRBPF<<5);
/* Invoke new configuration 13V*/
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
for(app_num = 1; app_num<=7; app_num++)
{
command_array[4] = app_num;
SEM_LOCK(DiSEqC_Semaphore);
/*18V*/
LnbConfig.Polarization = STTUNER_PLR_HORIZONTAL;
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
task_delay(25 * (ST_GetClocksPerSecond() / 1000));
/* send DiSEqC Commands */
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Demod.Driver->demod_DiSEqC)(DemodHandle, &pDiSEqCSendPacket, &pDiSEqCResponsePacket );
task_delay(10 * (ST_GetClocksPerSecond() / 1000));
/* Come back to 13V */
LnbConfig.Polarization = STTUNER_PLR_VERTICAL;
Error |= (Inst[OpenParams->TopLevelHandle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[OpenParams->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
SEM_UNLOCK(DiSEqC_Semaphore);
Error |= Inst[OpenParams->TopLevelHandle].Sat.Demod.Driver->demod_tonedetection(DemodHandle, StartFreq, StopFreq, &NbTones, &tonefreq,0,power_detection_level);
if(NbTones)
{
if((tonefreq>= StartFreq) && (tonefreq<= StopFreq))
{
return(app_num);
}
}
}
return STTUNER_SCR_APPLICATION_NOT_SUPPORTED;
}
#endif
/* ----------------------------------------------------------------------------
Name: scr_scrdrv_SetFrequency()
Description:
This routine will attempt to scan and find a QPSK signal based on the
passed in parameters.
Parameters:
InitialFrequency, IF value to commence scan (in kHz).
SymbolRate, required symbol bit rate (in Hz).
MaxLNBOffset, maximum allowed LNB offset (in Hz).
TunerStep, Tuner's step value -- enables override of
TNR device's internal setting.
DerotatorStep, derotator step (usually 6).
ScanSuccess, boolean that indicates QPSK search success.
NewFrequency, pointer to area to store locked frequency.
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t scr_scrdrv_SetFrequency (STTUNER_Handle_t Handle, DEMOD_Handle_t DemodHandle, ST_DeviceName_t *DeviceName, U32 InitialFrequency, U8 LNBIndex, U8 SCRBPF)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_D0299
const char *identity = "STTUNER scr scr_scrdrv_SetFrequency()";
#endif
unsigned char command_array [5] = {0xE0, 0x10, 0x5A, 0x00, 0x00};
LNB_Config_t LnbConfig;
ST_ErrorCode_t Error = ST_NO_ERROR;
STTUNER_DiSEqCSendPacket_t pDiSEqCSendPacket;
STTUNER_DiSEqCResponsePacket_t pDiSEqCResponsePacket;
U32 tuning_word, temp;
#ifndef STTUNER_MINIDRIVER
STTUNER_InstanceDbase_t *Inst;
SCR_InstanceData_t *Instance;
/* top level public instance data */
Inst = STTUNER_GetDrvInst();
/* now safe to lock semaphore */
SEM_LOCK(Lock_InitTermOpenClose);
/* find handle from name */
/***************************************************/
Instance = InstanceChainTop;
while(strcmp((char *)Instance->DeviceName, (char *)DeviceName) != 0)
{
/* error, should have found matching DeviceName before end of list */
if(Instance->InstanceChainNext == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
STTBX_Print(("\n%s fail no block named '%s' before end of list\n", identity, DeviceName));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
Instance = Instance->InstanceChainNext; /* next block */
}
SEM_UNLOCK(Lock_InitTermOpenClose);
/*******************************************************/
/* For Auto Detect update scanlist for free SCR found */
/*if(Instance->SCR_Mode == STTUNER_SCR_AUTO)
{
Inst[Instance->TopLevelHandle].ScanList.ScanList->ScrParams.SCRBPF=Inst[Instance->TopLevelHandle].CurrentTunerInfo.ScanInfo.ScrParams.SCRBPF = Instance->SCRBPF;
SCRBPF = Instance->SCRBPF;
}*/
/******************************************************/
pDiSEqCSendPacket.DiSEqCCommandType = STTUNER_DiSEqC_COMMAND;
pDiSEqCSendPacket.uc_TotalNoOfBytes = 5;
pDiSEqCSendPacket.uc_msecBeforeNextCommand = 50;
/* do the frequency translation here*/
InitialFrequency += Instance->SCRBPFFrequencies[SCRBPF];
tuning_word = (InitialFrequency/4) - 350; /* Formula according to data sheet */
/*Inst[Instance->TopLevelHandle].ScanList.ScanList->ScrParams.SCRVCOFrequency = (tuning_word + 350)*4000;*/
command_array[4] = tuning_word & 0xFF;
temp = tuning_word & 0x300;
temp = temp>>8;
command_array[3] |= temp;
temp = SCRBPF<<5;
command_array[3] |= temp;
temp = LNBIndex<<2;
command_array[3] |= temp;
pDiSEqCSendPacket.pFrmAddCmdData = &command_array[0];
LnbConfig.TopLevelHandle = Handle;
LnbConfig.Status = LNB_STATUS_ON; /* Set the Satellite Dish LNB power to ON */
LnbConfig.Polarization = STTUNER_PLR_VERTICAL; /* Setup the Satellite Dish LNB Polarization */
LnbConfig.ToneState = STTUNER_LNB_TONE_OFF; /* Setup the require tone state */
/* Use semaphore not to distrub the SCR setting during DiSEqC- ST Commands */
SEM_LOCK(DiSEqC_Semaphore);
/* Invoke new configuration 13V*/
Error = (Inst[Handle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[Handle].Sat.Lnb.DrvHandle, &LnbConfig);
/*18V*/
LnbConfig.Polarization = STTUNER_PLR_HORIZONTAL;
Error = (Inst[Handle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[Handle].Sat.Lnb.DrvHandle, &LnbConfig);
task_delay(25 * (ST_GetClocksPerSecond() / 1000));
Error = (Inst[Handle].Sat.Demod.Driver->demod_DiSEqC)(DemodHandle, &pDiSEqCSendPacket, &pDiSEqCResponsePacket );
task_delay(10 * (ST_GetClocksPerSecond() / 1000));
/*come back on 13V*/
LnbConfig.Polarization = STTUNER_PLR_VERTICAL;
Error = (Inst[Handle].Sat.Lnb.Driver->lnb_SetConfig)(Inst[Handle].Sat.Lnb.DrvHandle, &LnbConfig);
SEM_UNLOCK(DiSEqC_Semaphore);
#endif
/************************MINIDRIVER************************
**************************************************************
****************************************************************/
#ifdef STTUNER_MINIDRIVER
STTUNER_InstanceDbase_t *Inst;
Inst = STTUNER_GetDrvInst();
/*******************************************************/
/* For Auto Detect update scanlist for free SCR found */
if(SCRInstance->SCR_Mode == STTUNER_SCR_AUTO)
{
Inst[SCRInstance->TopLevelHandle].ScanList.ScanList->ScrParams.SCRBPF=Inst[SCRInstance->TopLevelHandle].CurrentTunerInfo.ScanInfo.ScrParams.SCRBPF = SCRInstance->SCRBPF;
SCRBPF = SCRInstance->SCRBPF;
}
/******************************************************/
pDiSEqCSendPacket.DiSEqCCommandType = STTUNER_DiSEqC_COMMAND;
pDiSEqCSendPacket.uc_TotalNoOfBytes = 5;
pDiSEqCSendPacket.uc_msecBeforeNextCommand = 25;
/* do the frequency translation here*/
InitialFrequency += SCRInstance->SCRBPFFrequencies[SCRBPF];
tuning_word = (InitialFrequency/4) - 350; /* Formula according to data sheet */
/*Inst[SCRInstance->TopLevelHandle].ScanList.ScanList->ScrParams.SCRVCOFrequency = (tuning_word + 350)*4000;*/
command_array[4] = tuning_word & 0xFF;
temp = tuning_word & 0x300;
temp = temp>>8;
command_array[3] |= temp;
temp = SCRBPF<<5;
command_array[3] |= temp;
temp = LNBIndex<<2;
command_array[3] |= temp;
pDiSEqCSendPacket.pFrmAddCmdData = &command_array[0];
LnbConfig.TopLevelHandle = Handle;
LnbConfig.Status = LNB_STATUS_ON; /* Set the Satellite Dish LNB power to ON */
LnbConfig.Polarization = STTUNER_PLR_VERTICAL; /* Setup the Satellite Dish LNB Polarization */
LnbConfig.ToneState = STTUNER_LNB_TONE_OFF; /* Setup the require tone state */
#ifdef STTUNER_DRV_SAT_STV0299
/* Use semaphore not to distrub the SCR setting during DiSEqC- ST Commands */
SEM_LOCK(DiSEqC_Semaphore);
/* Invoke new configuration 13V*/
#ifdef STTUNER_DRV_SAT_LNB21
Error = lnb_lnb21_SetConfig(&LnbConfig);
#elif defined STTUNER_DRV_SAT_LNBH21
Error = lnb_lnbh21_SetConfig(&LnbConfig);
#else
Error = lnb_l0299_SetConfig(Inst[SCRInstance->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
#endif
/*18V*/
LnbConfig.Polarization = STTUNER_PLR_HORIZONTAL;
#ifdef STTUNER_DRV_SAT_LNB21
Error = lnb_lnb21_SetConfig(&LnbConfig);
#elif defined STTUNER_DRV_SAT_LNBH21
Error = lnb_lnbh21_SetConfig(&LnbConfig);
#else
Error = lnb_l0299_SetConfig(Inst[SCRInstance->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
#endif
task_delay(30 * (ST_GetClocksPerSecond() / 1000));
Error = demod_d0299_DiSEqC(DemodHandle, &pDiSEqCSendPacket, &pDiSEqCResponsePacket );
task_delay(10 * (ST_GetClocksPerSecond() / 1000));
/*come back on 13V*/
LnbConfig.Polarization = STTUNER_PLR_VERTICAL;
#ifdef STTUNER_DRV_SAT_LNB21
Error = lnb_lnb21_SetConfig(&LnbConfig);
#elif defined STTUNER_DRV_SAT_LNBH21
Error = lnb_lnbh21_SetConfig(&LnbConfig);
#else
Error = lnb_l0299_SetConfig(Inst[SCRInstance->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
#endif
SEM_UNLOCK(DiSEqC_Semaphore);
#endif
#ifdef STTUNER_DRV_SAT_STV0399
/* Use semaphore not to distrub the SCR setting during DiSEqC- ST Commands */
SEM_LOCK(DiSEqC_Semaphore);
/* Invoke new configuration 13V*/
#ifdef STTUNER_DRV_SAT_LNB21
Error = lnb_lnb21_SetConfig(&LnbConfig);
#elif defined STTUNER_DRV_SAT_LNBH21
Error = lnb_lnbh21_SetConfig(&LnbConfig);
#else
Error = lnb_l0399_SetConfig(Inst[SCRInstance->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
#endif
/*18V*/
LnbConfig.Polarization = STTUNER_PLR_HORIZONTAL;
#ifdef STTUNER_DRV_SAT_LNB21
Error = lnb_lnb21_SetConfig(&LnbConfig);
#elif defined STTUNER_DRV_SAT_LNBH21
Error = lnb_lnbh21_SetConfig(&LnbConfig);
#else
Error = lnb_l0399_SetConfig(Inst[SCRInstance->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
#endif
task_delay(10 * (ST_GetClocksPerSecond() / 1000));
Error = demod_d0399_DiSEqC(DemodHandle, &pDiSEqCSendPacket, &pDiSEqCResponsePacket );
task_delay(2 * (ST_GetClocksPerSecond() / 1000));
/*come back on 13V*/
LnbConfig.Polarization = STTUNER_PLR_VERTICAL;
#ifdef STTUNER_DRV_SAT_LNB21
Error = lnb_lnb21_SetConfig(&LnbConfig);
#elif defined STTUNER_DRV_SAT_LNBH21
Error = lnb_lnbh21_SetConfig(&LnbConfig);
#else
Error = lnb_l0399_SetConfig(Inst[SCRInstance->TopLevelHandle].Sat.Lnb.DrvHandle, &LnbConfig);
#endif
SEM_UNLOCK(DiSEqC_Semaphore);
#endif
#endif
return(Error);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -