📄 lnb21.c
字号:
/* ----------------------------------------------------------------------------
File Name: lnb21.c
Description:
LNB21 driver (should setup I/O passthrough to a stv0299 demod driver)
Copyright (C) 1999-2001 STMicroelectronics
History:
date: 04-November-2003
version:
author: SD,AS
comment:
date: 02-June-2006
version:
author: HS,SD
comment:
Reference:
ST API Definition "LNB Driver API" DVD-API-06
---------------------------------------------------------------------------- */
/* Includes ---------------------------------------------------------------- */
/* C libs */
#include <string.h>
/* Standard includes */
#include "stlite.h"
/* STAPI */
#include "stcommon.h" /* for ST_GetClocksPerSecond() */
#include "sttbx.h"
#include "stevt.h"
#include "sttuner.h"
/* local to stlnb */
#include "util.h" /* generic utility functions for stlnb */
#include "dbtypes.h" /* data types for databases */
#include "sysdbase.h" /* functions to accesss system data */
#ifndef STTUNER_MINIDRIVER
#include "ioarch.h" /* I/O for this driver */
#include "ioreg.h" /* I/O register mapping */
#include "sdrv.h" /* utilities */
#endif
#ifdef STTUNER_MINIDRIVER
#include "iodirect.h"
#endif
#include "lnb21.h" /* header for this file */
#include "sioctl.h" /* data structure typedefs for all the the sat ioctl functions */
/* macros ------------------------------------------------------------------ */
/* Delay calling task for a period of microseconds */
#ifdef ST_OS21
#define LNB21_Delay_uS(micro_sec) task_delay((signed int) \
(((micro_sec) + 999) / 1000) * \
ST_GetClocksPerSecond() / 1000)
#else
#define LNB21_Delay_uS(micro_sec) task_delay((unsigned int) \
(((micro_sec) + 999) / 1000) * \
ST_GetClocksPerSecond() / 1000)
#endif
/* private variables ------------------------------------------------------- */
#ifdef ST_OS21
static semaphore_t *Lock_InitTermOpenClose; /* guard calls to the functions */
#else
static semaphore_t Lock_InitTermOpenClose; /* guard calls to the functions */
#endif
/* ---------- per instance of driver ---------- */
#ifndef STTUNER_MINIDRIVER
static BOOL Installed = FALSE;
typedef struct
{
ST_DeviceName_t *DeviceName; /* unique name for opening under */
STTUNER_Handle_t TopLevelHandle; /* access tuner, demod etc. using this */
IOARCH_Handle_t IOHandle; /* instance access to I/O driver */
STTUNER_IOREG_DeviceMap_t DeviceMap; /* register map & data table */
LNB_Config_t Config; /* LNB config for each instance */
ST_Partition_t *MemoryPartition; /* which partition this data block belongs to */
void *InstanceChainPrev; /* previous data block in chain or NULL if not */
void *InstanceChainNext; /* next data block in chain or NULL if last */
U8 RegVal;
} LNB21_InstanceData_t;
#endif
#ifdef STTUNER_MINIDRIVER
typedef struct
{
LNB_Config_t Config; /* LNB config for each instance */
STTUNER_Handle_t TopLevelHandle;
ST_Partition_t *MemoryPartition; /* which partition this data block belongs to */
} LNB21_InstanceData_t;
#endif
#ifndef STTUNER_MINIDRIVER
/* instance chain, the default boot value is invalid, to catch errors */
static LNB21_InstanceData_t *InstanceChainTop = (LNB21_InstanceData_t *)0x7fffffff;
#endif
#ifdef STTUNER_MINIDRIVER
LNB21_InstanceData_t *LNB21Instance;
#endif
U8 DefLNB21Val = 0xc8;
/* functions --------------------------------------------------------------- */
#ifndef STTUNER_MINIDRIVER
/* API */
ST_ErrorCode_t lnb_lnb21_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams);
ST_ErrorCode_t lnb_lnb21_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams);
ST_ErrorCode_t lnb_lnb21_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle);
ST_ErrorCode_t lnb_lnb21_Close(LNB_Handle_t Handle, LNB_CloseParams_t *CloseParams);
ST_ErrorCode_t lnb_lnb21_GetConfig(LNB_Handle_t Handle, LNB_Config_t *Config);
ST_ErrorCode_t LNB21_GetPower(LNB_Handle_t Handle, STTUNER_IOREG_DeviceMap_t *DeviceMap, LNB_Status_t *Status);
ST_ErrorCode_t LNB21_GetStatus(LNB_Handle_t Handle, STTUNER_IOREG_DeviceMap_t *DeviceMap, LNB_Status_t *Status);
ST_ErrorCode_t lnb_lnb21_GetProtection(LNB_Handle_t *Handle, LNB_Config_t *Config);
ST_ErrorCode_t lnb_lnb21_GetCurrent(LNB_Handle_t *Handle, LNB_Config_t *Config);
ST_ErrorCode_t lnb_lnb21_GetLossCompensation(LNB_Handle_t *Handle, LNB_Config_t *Config);
/* I/O API */
ST_ErrorCode_t lnb_lnb21_ioaccess(LNB_Handle_t Handle, IOARCH_Handle_t IOHandle,
STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout);
/* access device specific low-level functions */
ST_ErrorCode_t lnb_lnb21_ioctl(LNB_Handle_t Handle, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status);
ST_ErrorCode_t lnb_lnb21_overloadcheck(LNB_Handle_t Handle, BOOL *IsOverTemp, BOOL *IsCurrentOvrLoad);
#if defined(STTUNER_DRV_SAT_LNB21) /*Added for for GNBvd40148-->Error
if sttuner compiled with LNB21 option but use another one: This will only come when more than 1 lnb is
in use & atleast one of them is LNB21*/
ST_ErrorCode_t lnb_lnb21_setttxmode(LNB_Handle_t Handle, STTUNER_LnbTTxMode_t Ttxmode);
#endif
/* local functions */
void LNB21_SetLnb (LNB21_InstanceData_t *Instance , int Lnb);
void LNB21_SetPolarization(LNB21_InstanceData_t *Instance ,LNB_Polarization_t Polarization);
void LNB21_SetCurrentThreshold(LNB21_InstanceData_t *Instance , LNB_CurrentThresholdSelection_t CurrentThresholdSelection);
void LNB21_SetProtectionMode(LNB21_InstanceData_t *Instance , LNB_ShortCircuitProtectionMode_t ShortCircuitProtectionMode);
void LNB21_SetLossCompensation(LNB21_InstanceData_t *Instance ,BOOL CoaxCableLossCompensation);
ST_ErrorCode_t LNB21_SetPower (LNB21_InstanceData_t *Instance , LNB_Status_t Status);
ST_ErrorCode_t lnb_lnb21_SetConfig(LNB_Handle_t Handle, LNB_Config_t *Config);
ST_ErrorCode_t LNB21_UpdateLNB (LNB21_InstanceData_t *Instance );
ST_ErrorCode_t LNB21_Reg_Install (STTUNER_IOREG_DeviceMap_t *DeviceMap);
#endif
/* functions --------------------------------------------------------------- */
#ifdef STTUNER_MINIDRIVER
U8 LNB21_Default_Reg[] = {0x3C};
#endif
#ifndef STTUNER_MINIDRIVER
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_LNB21_Install()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_LNB21_Install(STTUNER_lnb_dbase_t *Lnb)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
const char *identity = "STTUNER lnb21.c STTUNER_DRV_LNB_LNB21_Install()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == TRUE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail driver already installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s installing sat:lnb:LNB21...", identity));
#endif
/* mark ID in database */
Lnb->ID = STTUNER_LNB_LNB21;
/* map API */
Lnb->lnb_Init = lnb_lnb21_Init;
Lnb->lnb_Term = lnb_lnb21_Term;
Lnb->lnb_Open = lnb_lnb21_Open;
Lnb->lnb_Close = lnb_lnb21_Close;
Lnb->lnb_GetConfig = lnb_lnb21_GetConfig;
Lnb->lnb_SetConfig = lnb_lnb21_SetConfig;
Lnb->lnb_ioaccess = lnb_lnb21_ioaccess;
Lnb->lnb_ioctl = lnb_lnb21_ioctl;
Lnb->lnb_overloadcheck = lnb_lnb21_overloadcheck;
#if defined(STTUNER_DRV_SAT_LNB21) /*Added for for GNBvd40148-->Error
if sttuner compiled with LNB21 option but use another one: This will only come when more than 1 lnb is
in use & atleast one of them is LNB21*/
Lnb->lnb_setttxmode = lnb_lnb21_setttxmode;
#endif
InstanceChainTop = NULL;
#ifdef ST_OS21
Lock_InitTermOpenClose = semaphore_create_fifo(1);
#else
semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
#endif
Installed = TRUE;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("ok\n"));
#endif
return(Error);
}
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_LNB21_UnInstall()
Description:
install a satellite device driver.
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_LNB21_UnInstall(STTUNER_lnb_dbase_t *Lnb)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
const char *identity = "STTUNER lnb21.c STTUNER_DRV_LNB_LNB21_UnInstall()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
if(Installed == FALSE)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail driver not installed\n", identity));
#endif
return(STTUNER_ERROR_INITSTATE);
}
if(Lnb->ID != STTUNER_LNB_LNB21)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail incorrect driver type\n", identity));
#endif
return(STTUNER_ERROR_ID);
}
/* has all memory been freed, by Term() */
if(InstanceChainTop != NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail at least one instance not terminated\n", identity));
#endif
return(ST_ERROR_OPEN_HANDLE);
}
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s uninstalling sat:lnb:LNB21...", identity));
#endif
/* mark ID in database */
Lnb->ID = STTUNER_NO_DRIVER;
/* unmap API */
Lnb->lnb_Init = NULL;
Lnb->lnb_Term = NULL;
Lnb->lnb_Open = NULL;
Lnb->lnb_Close = NULL;
Lnb->lnb_GetConfig = NULL;
Lnb->lnb_SetConfig = NULL;
Lnb->lnb_ioaccess = NULL;
Lnb->lnb_ioctl = NULL;
Lnb->lnb_overloadcheck = NULL;
#if defined(STTUNER_DRV_SAT_LNB21)
Lnb->lnb_setttxmode = NULL;
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("<"));
#endif
#ifdef ST_OS21
semaphore_delete(Lock_InitTermOpenClose);
#else
semaphore_delete(&Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print((">"));
#endif
InstanceChainTop = (LNB21_InstanceData_t *)0x7ffffffe;
Installed = FALSE;
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("ok\n"));
#endif
return(Error);
}
#endif
/* ------------------------------------------------------------------------- */
/* /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ API /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ */
/* ------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------
Name: lnb_lnb21_Init()
Description:
Parameters:
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnb21_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
const char *identity = "STTUNER lnb21.c lnb_lnb21_Init()";
#endif
ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
LNB21_InstanceData_t *InstanceNew, *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 partition ---------- */
Error = STTUNER_Util_CheckPtrNull(InitParams->MemoryPartition);
if( Error != ST_NO_ERROR)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail MemoryPartition not valid\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(Error);
}
InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LNB21_InstanceData_t ));
if (InstanceNew == NULL)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNB21
STTBX_Print(("%s fail memory allocation InstanceNew\n", identity));
#endif
SEM_UNLOCK(Lock_InitTermOpenClose);
return(ST_ERROR_NO_MEMORY);
}
/* slot into chain */
if (InstanceChainTop == NULL)
{
InstanceNew->InstanceChainPrev = NULL; /* no previous instance */
InstanceChainTop = InstanceNew;
}
else /* tag onto last data block in chain */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -