📄 l0399.c
字号:
if( Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail TermParams not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ---------- check that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
/* reap next matching DeviceName */
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s reap next matching DeviceName[ ", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp((char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("<-- ]\n"));
#endif
/* found so now xlink prev and next(if applicable) and deallocate memory */
InstancePrev = Instance->InstanceChainPrev;
InstanceNext = Instance->InstanceChainNext;
/* if instance to delete is first in chain */
if (Instance->InstanceChainPrev == NULL)
{
InstanceChainTop = InstanceNext; /* which would be NULL if last block to be term'd */
if (InstanceNext != NULL)
{
InstanceNext->InstanceChainPrev = NULL; /* now top of chain, no previous instance */
}
}
else
{ /* safe to set value for prev instaance (because there IS one) */
InstancePrev->InstanceChainNext = InstanceNext;
}
/* if there is a next block in the chain */
if (InstanceNext != NULL)
{
InstanceNext->InstanceChainPrev = InstancePrev;
}
memory_deallocate(Instance->MemoryPartition, Instance);
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s freed block at 0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s terminated ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
else if(Instance->InstanceChainNext == NULL)
{ /* error we should have found a matching name before the end of the list */
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("\n%s fail no free handle before end of list\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
else
{
Instance = Instance->InstanceChainNext; /* next block */
}
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
memory_deallocate(LNBInstance->MemoryPartition, LNBInstance);
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_l0399_Open()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_l0399_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
const char *identity = "STTUNER l0399.c lnb_l0399_Open()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
L0399_InstanceData_t *Instance;
STTUNER_InstanceDbase_t *Inst;
STTUNER_demod_instance_t *DemodInstance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
/* now safe to lock semaphore */
SEM_LOCK(Lock_InitTermOpenClose);
/* ---------- check that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
/* find handle from name */
Instance = InstanceChainTop;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s looking (%s)", identity, Instance->DeviceName));
#endif
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_L0399
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 */
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print((" found ok\n"));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s using block at 0x%08x\n", identity, (U32)Instance));
#endif
if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail driver instance already open\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_OPEN_HANDLE);
} /* now have pointer to free (and valid) L0399_InstanceData_t data block */
/* get pointer to **OPENED** demod for this instance */
Inst = STTUNER_GetDrvInst(); /* get instance database */
DemodInstance = &Inst[OpenParams->TopLevelHandle].Sat.Demod; /* recover specific instance */
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s DemodInstance at 0x%08x\n", identity, (U32)DemodInstance ));
#endif
/* this LNB driver is only for use with an STV0399 demod */
if(DemodInstance->Driver->ID != STTUNER_DEMOD_STV0399)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail STV0399 required\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_ID);
}
else
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s STV0399 demod found\n", identity));
#endif
}
/* make use of demod data for I/O */
Instance->FE_399_Handle = ( (D0399_InstanceData_t *)DemodInstance->DrvHandle)->FE_399_Handle;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s Instance->FE_399_Handle = 0x%08x\n", identity, Instance->FE_399_Handle));
#endif
/* Set LNB capabilties */
Capability->ShortCircuitDetect = TRUE;
Capability->PowerAvailable = TRUE;
Capability->PolarizationSelect = STTUNER_PLR_ALL;
/* Set latest configuration */
#ifdef STTUNER_LNB_POWER_OFF_BY_DEFAULT
Instance->Config.Status = LNB_STATUS_OFF;
Instance->Config.Polarization = STTUNER_LNB_OFF;
#else
Instance->Config.Status = LNB_STATUS_ON;
Instance->Config.Polarization = STTUNER_PLR_HORIZONTAL;
#endif
Instance->Config.ToneState = STTUNER_LNB_TONE_OFF;
/* set LNB tone off */
Error = FE_399_SetBand(Instance->FE_399_Handle, FE_BAND_LOW);
Error = FE_399_SetPol(Instance->FE_399_Handle, Instance->Config.Polarization);
Error = FE_399_SetPower(Instance->FE_399_Handle, Instance->Config.Status);
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s FE_399_SetBand(FE_BAND_LOW)\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* LNB power on, wait 500uS (0.5mS) then get power status */
/* Error = FE_399_SetPower(Instance->FE_399_Handle, LNB_STATUS_ON);
UTIL_Delay(500);
Error = FE_399_GetPower(Instance->FE_399_Handle, &Instance->Config.Status);
*/
/* Check to ensure there is no problem with the LNB circuit */
if (Error == ST_NO_ERROR)
{
if (Instance->Config.Status == LNB_STATUS_SHORT_CIRCUIT)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail SAT_LNB_SHORT_CIRCUIT\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_HWFAIL);
}
}
else
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail Error=%u\n", identity, Error)); /* L0399_GetPower failed */
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
Instance->TopLevelHandle = OpenParams->TopLevelHandle; /* mark as valid */
/* In loopthrough mode 13 to 18V transition for DiSEQC-ST command should be on first demod */
#ifdef STTUNER_DRV_SAT_SCR
#ifdef STTUNER_DRV_SAT_SCR_LOOPTHROUGH
if(OpenParams->TopLevelHandle == 0)
Instance->DISECQ_ST_ENABLE = TRUE;
if(OpenParams->TopLevelHandle == 1)
Instance->DISECQ_ST_ENABLE = FALSE;
#endif
#endif
*Handle = (U32)Instance;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s opened ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
/*********************MINIDRIVER***********************
*******************************************************
******************************************************/
#ifdef STTUNER_MINIDRIVER
LNBInstance->FE_399_Handle = 0x00;
/* Set LNB capabilties */
Capability->ShortCircuitDetect = TRUE;
Capability->PowerAvailable = TRUE;
Capability->PolarizationSelect = STTUNER_PLR_ALL;
/* Set latest configuration */
LNBInstance->Config.Status = LNB_STATUS_ON;
LNBInstance->Config.ToneState = STTUNER_LNB_TONE_OFF;
LNBInstance->Config.Polarization = STTUNER_PLR_HORIZONTAL;
/* set LNB tone off */
Error = FE_399_SetBand(LNBInstance->FE_399_Handle, FE_BAND_LOW);
Error = FE_399_SetPol(LNBInstance->FE_399_Handle, FE_POL_HORIZONTAL);
/* LNB power on, wait 500uS (0.5mS) then get power status */
/* Error = FE_399_SetPower(Instance->FE_399_Handle, LNB_STATUS_ON);
UTIL_Delay(500);
Error = FE_399_GetPower(Instance->FE_399_Handle, &Instance->Config.Status);
*/
/* Check to ensure there is no problem with the LNB circuit */
if (Error == ST_NO_ERROR)
{
if (LNBInstance->Config.Status == LNB_STATUS_SHORT_CIRCUIT)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail SAT_LNB_SHORT_CIRCUIT\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_HWFAIL);
}
}
else
return Error;
LNBInstance->TopLevelHandle = OpenParams->TopLevelHandle; /* mark as valid */
/* In loopthrough mode 13 to 18V transition for DiSEQC-ST command should be on first demod */
#ifdef STTUNER_DRV_SAT_SCR
#ifdef STTUNER_DRV_SAT_SCR_LOOPTHROUGH
if(OpenParams->TopLevelHandle == 0)
LNBInstance->DISECQ_ST_ENABLE = TRUE;
if(OpenParams->TopLevelHandle == 1)
LNBInstance->DISECQ_ST_ENABLE = FALSE;
#endif
#endif
*Handle = (U32)LNBInstance;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_l0399_Close()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_l0399_Close(LNB_Handle_t Handle, LNB_CloseParams_t *CloseParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
const char *identity = "STTUNER l0399.c lnb_l0399_Close()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
L0399_InstanceData_t *Instance;
Instance = (L0399_InstanceData_t *)Handle;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
SEM_LOCK(Lock_InitTermOpenClose);
/* ---------- check that at least one init has taken place ---------- */
if(InstanceChainTop == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_INITSTATE);
}
if(Instance->TopLevelHandle == STTUNER_MAX_HANDLES)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s fail driver instance not open\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_OPEN_HANDLE);
}
Instance->TopLevelHandle = STTUNER_MAX_HANDLES;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_L0399
STTBX_Print(("%s closed\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
LNBInstance->TopLevelHandle = STTUNER_MAX_HANDLES;
#endif
return(Error);
}
#if defined(STTUNER_DRV_SAT_LNB21) || defined(STTUNER_DRV_SAT_LNBH21)
/* ----------------------------------------------------------------------------
Name: lnb_l0399_overloadcheck()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -