📄 lnb21.c
字号:
{
Instance = InstanceChainTop;
while(Instance->InstanceChainNext != NULL)
{
Instance = Instance->InstanceChainNext; /* next block */
}
Instance->InstanceChainNext = (void *)InstanceNew;
InstanceNew->InstanceChainPrev = (void *)Instance;
}
InstanceNew->DeviceName = DeviceName;
InstanceNew->TopLevelHandle = STTUNER_MAX_HANDLES; /* mark as not used */
InstanceNew->IOHandle = InitParams->IOHandle;
InstanceNew->MemoryPartition = InitParams->MemoryPartition;
InstanceNew->DeviceMap.Timeout = IOREG_DEFAULT_TIMEOUT;
InstanceNew->DeviceMap.Registers = DEF_LNB_LNB21_NBREG;
InstanceNew->DeviceMap.Fields = DEF_LNB_LNB21_NBFIELD;
InstanceNew->DeviceMap.Mode = IOREG_MODE_SUBADR_8;
InstanceNew->DeviceMap.MemoryPartition = InitParams->MemoryPartition;
InstanceNew->InstanceChainNext = NULL; /* always last in the chain */
InstanceNew->RegVal = DefLNB21Val;
/* allocate memory for regmap */
Error = STTUNER_IOREG_Open(&InstanceNew->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail allocate register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
/* install a register map */
Error = LNB21_Reg_Install(&InstanceNew->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail install a register database\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( LNB21_InstanceData_t ) ));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
LNB21Instance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LNB21_InstanceData_t ));
if (LNB21Instance == NULL)
{
return(ST_ERROR_NO_MEMORY);
}
LNB21Instance->MemoryPartition = InitParams->MemoryPartition;
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_lnb21_Term()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb21_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
const char *identity = "STTUNER lnb21.c lnb_lnb21_Term()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
LNB21_InstanceData_t *Instance, *InstancePrev, *InstanceNext;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
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_LNB21
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_LNB21
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_LNB21
STTBX_Print(("%s looking for first free handle[\n", identity));
#endif
Instance = InstanceChainTop;
while(1)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
if ( strcmp((char *)Instance->DeviceName, (char *)DeviceName) == 0)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("]\n"));
#endif
Error = STTUNER_IOREG_Close(&Instance->DeviceMap);
if (Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail close register database\n", identity));
#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_LNB21
STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
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_LNB21
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_LNB21
STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
memory_deallocate(LNB21Instance->MemoryPartition, LNB21Instance);
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_lnb21_Open()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb21_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
const char *identity = "STTUNER lnb21.c lnb_lnb21_Open()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
LNB21_InstanceData_t *Instance;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
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_LNB21
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_LNB21
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_LNB21
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_LNB21
STTBX_Print(("(%s)", Instance->DeviceName));
#endif
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print((" found ok\n"));
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s using block at 0x%08x\n", identity, (U32)Instance));
#endif
if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
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 */
Instance->TopLevelHandle = OpenParams->TopLevelHandle; /* mark as valid */
*Handle = (U32)Instance;
/* Set LNB capabilties */
Capability->ShortCircuitDetect = TRUE; /* lie (rewrite to get pwr status using stv0299 i/o pin etc.) */
Capability->PowerAvailable = TRUE;
Capability->PolarizationSelect = STTUNER_PLR_ALL;
/* Set latest configuration */
Instance->Config.Status = LNB_STATUS_OFF;
Instance->Config.Polarization = STTUNER_LNB_OFF;
Instance->Config.ToneState = STTUNER_LNB_TONE_OFF;
Instance->Config.CurrentThresholdSelection = STTUNER_LNB_CURRENT_THRESHOLD_LOW;
Instance->Config.ShortCircuitProtectionMode = STTUNER_LNB_PROTECTION_STATIC;
Instance->Config.CableLossCompensation = FALSE;
/* LNB tone off */
LNB21_SetLnb(Instance,Instance->Config.ToneState);
/* LNB power on */
LNB21_SetPower(Instance, Instance->Config.Status);
/* LNB polarization horizontal*/
LNB21_SetPolarization(Instance,Instance->Config.Polarization);
/* LNB low current threshold*/
LNB21_SetCurrentThreshold(Instance,Instance->Config.CurrentThresholdSelection);
/*LNB circuit protection mode*/
LNB21_SetProtectionMode(Instance,Instance->Config.ShortCircuitProtectionMode);
/* LNB cable loss compenation off */
LNB21_SetLossCompensation(Instance,Instance->Config.CableLossCompensation);
Error = LNB21_UpdateLNB(Instance);
LNB21_Delay_uS(500);
/*Checking whether shortcircuit has ocurred i.e. whether OLF bit is high */
Error |= LNB21_GetStatus(*Handle, &Instance->DeviceMap, &Instance->Config.Status);
/* Check to ensure there is no problem with the LNB circuit */
if (Error == ST_NO_ERROR) /* last i/o (above) operation was good */
{
if (Instance->Config.Status == LNB_STATUS_SHORT_CIRCUIT || Instance->Config.Status == LNB_STATUS_OVER_TEMPERATURE || Instance->Config.Status == LNB_STATUS_SHORTCIRCUIT_OVERTEMPERATURE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail LNB_STATUS_SHORT_CIRCUIT or LNB_STATUS_OVER_TEMPERATURE\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(STTUNER_ERROR_HWFAIL);
}
}
else
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail Error=%u\n", identity, Error)); /* LNB21_GetPower failed */
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s opened ok\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
*Handle = (U32)LNB21Instance;
/* Set LNB capabilties */
Capability->ShortCircuitDetect = TRUE; /* lie (rewrite to get pwr status using stv0299 i/o pin etc.) */
Capability->PowerAvailable = TRUE;
Capability->PolarizationSelect = STTUNER_PLR_ALL;
/* Set latest configuration */
LNB21Instance->Config.Status = LNB_STATUS_ON;
LNB21Instance->Config.ToneState = STTUNER_LNB_TONE_OFF;
LNB21Instance->Config.CurrentThresholdSelection = STTUNER_LNB_CURRENT_THRESHOLD_LOW;
LNB21Instance->Config.ShortCircuitProtectionMode = STTUNER_LNB_PROTECTION_STATIC;
LNB21Instance->Config.CableLossCompensation = FALSE;
LNB21Instance->Config.Polarization = STTUNER_PLR_HORIZONTAL;
/* LNB tone off */
LNB21_SetLnb(LNB21Instance->Config.ToneState);
/* LNB power on */
LNB21_SetPower(LNB21Instance->Config.Status);
/* LNB polarization horizontal*/
LNB21_SetPolarization(LNB21Instance->Config.Polarization);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -