📄 lstem.c
字号:
}
/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
const char *identity = "STTUNER lstem.c lnb_lstem_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
LSTEM_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
/* now safe to lock semaphore */
SEM_LOCK(Lock_InitTermOpenClose);
/* ---------- check params ---------- */
Error = STTUNER_Util_CheckPtrNull(TermParams);
if( Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
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_LSTEM
STTBX_Print(("%s looking for first free handle[\n", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp((char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
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_LSTEM
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_Open()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
const char *identity = "STTUNER lstem.c lnb_lstem_Open()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
LSTEM_InstanceData_t *Instance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
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_LSTEM
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_LSTEM
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_LSTEM
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print((" found ok\n"));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s using block at 0x%08x\n", identity, (U32)Instance));
#endif
if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s fail driver instance already open\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_OPEN_HANDLE);
}
/* now got pointer to free (and valid) data block */
/* Moved here for Dual Stem */
Instance->TopLevelHandle = OpenParams->TopLevelHandle; /* mark as valid */
*Handle = (U32)Instance;
LSTEM_UpdateLNB(Instance->IOHandle);
/* Moved till here for Dual Stem */
/* Set LNB capabilties */
Capability->ShortCircuitDetect = FALSE;
Capability->PowerAvailable = TRUE;
Capability->PolarizationSelect = STTUNER_PLR_ALL;
/* Set latest configuration */
Instance->Config.Status = LNB_STATUS_OFF;
Instance->Config.ToneState = STTUNER_LNB_TONE_OFF;
Instance->Config.Polarization = STTUNER_LNB_OFF;
/* LNB tone off */
LSTEM_SetLnb(Instance->IOHandle,0);
/* LNB polarization mode set to Horizontal*/
LSTEM_SetPower(Instance->IOHandle, LNB_STATUS_OFF);
LSTEM_UpdateLNB(Instance->IOHandle);
LSTEM_Delay_uS(500);
/* Check to ensure there is no problem with the LNB circuit */
LSTEM_UpdateLNB(Instance->IOHandle);
Error = LSTEM_GetPower(Instance->IOHandle, &Instance->Config.Status);
if (Error == ST_NO_ERROR) /* last i/o (above) operation was good */
{
if (Instance->Config.Status == LNB_STATUS_SHORT_CIRCUIT)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
STTBX_Print(("%s fail Error=%u\n", identity, Error)); /* LSTEM_GetPower failed */
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/*
Instance->TopLevelHandle = OpenParams->TopLevelHandle; *//* mark as valid */
/* *Handle = (U32)Instance;
*/
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s opened ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_Close()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_Close(LNB_Handle_t Handle, LNB_CloseParams_t *CloseParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
const char *identity = "STTUNER lstem.c lnb_lstem_Close()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
LSTEM_InstanceData_t *Instance;
Instance = (LSTEM_InstanceData_t *)Handle;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
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_LSTEM
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_LSTEM
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_LSTEM
STTBX_Print(("%s closed\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
#if defined(STTUNER_DRV_SAT_LNB21) || defined(STTUNER_DRV_SAT_LNBH21)
/* ----------------------------------------------------------------------------
Name: lnb_lstem_overloadcheck()
Description:
Dummy Function
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lstem_overloadcheck(LNB_Handle_t Handle, BOOL *IsOverTemp, BOOL *IsCurrentOvrLoad)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
return(Error);
}
#if defined(STTUNER_DRV_SAT_LNBH21)
/* ----------------------------------------------------------------------------
Name: lnb_lstem_setttxmode()
Description:
Dummy Function
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lstem_setttxmode(LNB_Handle_t Handle, STTUNER_LnbTTxMode_t Ttxmode)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
return(Error);
}
#endif
#endif
/* ----------------------------------------------------------------------------
Name: lnb_lSTEM_GetConfig()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lSTEM_GetConfig(LNB_Handle_t Handle, LNB_Config_t *Config)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
const char *identity = "STTUNER lstem.c lnb_lSTEM_GetConfig()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
LSTEM_InstanceData_t *Instance;
Instance = (LSTEM_InstanceData_t *)Handle;
Config->Status = Instance->Config.Status;
Config->Polarization = Instance->Config.Polarization;
Config->ToneState = Instance->Config.ToneState;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LSTEM
STTBX_Print(("%s called\n", identity));
#endif
return(Error);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -