⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lnbbeio.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ----------------------------------------------------------------------------
File Name: lnbBEIO.c
Description:
This file is to control LNB IC through GPIOs of backend or CPU.
Copyright (C) 2005-2006 STMicroelectronics
History:
date: 30-March-2006
version: 0.1.0
author: SD
Reference:
---------------------------------------------------------------------------- */
#ifdef ST_OSLINUX
   #include "stos.h"
#else
/* C libs */
#include <string.h>
/* Standard includes */
#include "stlite.h"
#include "sttbx.h"
#endif
/* STAPI */
#include "stcommon.h"   /* for ST_GetClocksPerSecond() */
#include "stevt.h"
#include "lnbBEIO.h"      /* header for this file */
#include "sttuner.h"
#include "util.h"  
#ifndef STTUNER_MINIDRIVER
/* local to stlnb */
/* generic utility functions for stlnb */
#include "dbtypes.h"    /* data types for databases */
#include "sysdbase.h"   /* functions to accesss system data */
#include "ioarch.h"     /* I/O for this driver */
#include "ioreg.h"      /* I/O register mapping */
#include "sdrv.h"       /* utilities */
#include "sioctl.h"     /* data structure typedefs for all the the sat ioctl functions */
#endif
#ifdef STTUNER_MINIDRIVER
#include "dbtypes.h"    /* data types for databases */
#include "sysdbase.h"   /* functions to accesss system data */
#include "iodirect.h"
#ifdef STTUNER_DRV_SAT_STV0299
	#include "reg0299.h"
	#elif defined(STTUNER_DRV_SAT_STV0399E)
	#include "init399E.h"
	#endif
#endif

#ifndef STTUNER_MINIDRIVER
/* private variables ------------------------------------------------------- */
#if defined(ST_OS21) || defined(ST_OSLINUX) 
static semaphore_t *Lock_InitTermOpenClose; /* guard calls to the functions */
#else
static semaphore_t Lock_InitTermOpenClose; /* guard calls to the functions */
#endif
static BOOL        Installed = FALSE;
/* ---------- per instance of driver ---------- */
typedef struct
{
    ST_DeviceName_t           *DeviceName;  
    STTUNER_Handle_t          TopLevelHandle;   /* access tuner, backend etc. using this */
    LNB_Config_t              Config;           /* LNB config for each instance        */
    STPIO_Handle_t            LNBVSEL_PIOHandle,LNBVEN_PIOHandle,LNBTEN_PIOHandle;
    STTUNER_LNB_Via_PIO_t     *LnbIOPort;
    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 */
} 
LNB_BackEndIO_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 */
    STTUNER_LNB_Via_PIO_t     LnbIOPort;
} LNB_BackEndIO_InstanceData_t;

#endif
/* instance chain, the default boot value is invalid, to catch errors */

#ifdef STTUNER_BASIC
/************extern from open.c for SatCR loopthrough mode application ************/
#ifdef STTUNER_DRV_SAT_SCR
#ifdef STTUNER_DRV_SAT_SCR_LOOPTHROUGH
extern U32 LnbDrvHandleOne;
#endif
#endif

#endif
#ifndef STTUNER_MINIDRIVER
static LNB_BackEndIO_InstanceData_t *InstanceChainTop = (LNB_BackEndIO_InstanceData_t *)0x7fffffff;
#endif

#ifdef STTUNER_MINIDRIVER
LNB_BackEndIO_InstanceData_t *LNBInstance;
#endif

/* functions --------------------------------------------------------------- */


#ifndef STTUNER_MINIDRIVER
/* I/O API */
ST_ErrorCode_t lnb_backendIO_ioaccess(LNB_BackEndIO_InstanceData_t *Instance,
    STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout);

/* access device specific low-level functions */
ST_ErrorCode_t lnb_backendIO_ioctl(LNB_BackEndIO_InstanceData_t *Instance, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status);
ST_ErrorCode_t lnb_backendIO_overloadcheck(LNB_BackEndIO_InstanceData_t *Instance, BOOL  *IsOverTemp, BOOL *IsCurrentOvrLoad);

ST_ErrorCode_t lnb_backendIO_setttxmode(LNB_BackEndIO_InstanceData_t *Instance, STTUNER_LnbTTxMode_t Ttxmode);

#endif

/* local functions */
#ifndef STTUNER_MINIDRIVER
void           LNB_BackEndIO_SetLnb         (LNB_BackEndIO_InstanceData_t *Instance, int Lnb);
void           LNB_BackEndIO_SetPolarization(LNB_BackEndIO_InstanceData_t *Instance, LNB_Polarization_t Polarization);
ST_ErrorCode_t LNB_BackEndIO_SetPower       (LNB_BackEndIO_InstanceData_t *Instance, LNB_Status_t  Status);
ST_ErrorCode_t LNB_BackEndIO_GetPower       (LNB_BackEndIO_InstanceData_t *Instance, LNB_Status_t *Status);
#endif


#ifndef STTUNER_MINIDRIVER
/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STV0299_Install()

Description:
    install a satellite device driver.

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_BackEndIO_Install(STTUNER_lnb_dbase_t *Lnb)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;

    if(Installed == TRUE)
    {
        return(STTUNER_ERROR_INITSTATE);
    }
    /* mark ID in database */
    Lnb->ID = STTUNER_LNB_BACKENDGPIO;

    /* map API */
    Lnb->lnb_Init  = lnb_backendIO_Init;
    Lnb->lnb_Term  = lnb_backendIO_Term;
    Lnb->lnb_Open  = lnb_backendIO_Open;
    Lnb->lnb_Close = lnb_backendIO_Close;

    Lnb->lnb_GetConfig = lnb_backendIO_GetConfig;
    Lnb->lnb_SetConfig = lnb_backendIO_SetConfig;

    /*Lnb->lnb_ioaccess = lnb_backendIO_ioaccess;
    Lnb->lnb_ioctl    = lnb_backendIO_ioctl;
    Lnb->lnb_overloadcheck    = lnb_backendIO_overloadcheck;
    Lnb->lnb_setttxmode       = lnb_backendIO_setttxmode;*/
    InstanceChainTop = NULL;
#if defined(ST_OS21) || defined(ST_OSLINUX)  
    Lock_InitTermOpenClose = semaphore_create_fifo(1);
#else
    semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
#endif     

    Installed = TRUE;

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: STTUNER_DRV_LNB_STV0299_UnInstall()

Description:
    install a satellite device driver.

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_LNB_BackEndIO_UnInstall(STTUNER_lnb_dbase_t *Lnb)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;

    if(Installed == FALSE)
    {
	return(STTUNER_ERROR_INITSTATE);
    }
    if(Lnb->ID != STTUNER_LNB_BACKENDGPIO)
    {
	return(STTUNER_ERROR_ID);
    }
    /* has all memory been freed, by Term() */
    if(InstanceChainTop != NULL)
    {
    	return(ST_ERROR_OPEN_HANDLE);
    }
    /* 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;
    Lnb->lnb_setttxmode       = NULL;
    
#if defined(ST_OS21) || defined(ST_OSLINUX)    
        semaphore_delete(Lock_InitTermOpenClose);
#else
        semaphore_delete(&Lock_InitTermOpenClose);
#endif         
    InstanceChainTop = (LNB_BackEndIO_InstanceData_t *)0x7ffffffe;
    Installed        = FALSE;
    return(Error);
}

#endif
/* ----------------------------------------------------------------------------
Name: lnb_backendIO_Init()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_backendIO_Init(ST_DeviceName_t *DeviceName,LNB_InitParams_t *InitParams)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    #ifndef STTUNER_MINIDRIVER
    LNB_BackEndIO_InstanceData_t *InstanceNew, *Instance;
    if(Installed == FALSE)
    {
    	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)
    {
	SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LNB_BackEndIO_InstanceData_t ));
    if (InstanceNew == NULL)
    {
	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 */
    {
        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->MemoryPartition     = InitParams->MemoryPartition;
    InstanceNew->LnbIOPort = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( STTUNER_LNB_Via_PIO_t ));
    strcpy(InstanceNew->LnbIOPort->PIODeviceName,InitParams->LnbIOPort->PIODeviceName);
    InstanceNew->LnbIOPort->VSEL_PIOPort           = InitParams->LnbIOPort->VSEL_PIOPort;
    InstanceNew->LnbIOPort->VSEL_PIOPin           = InitParams->LnbIOPort->VSEL_PIOPin;
    InstanceNew->LnbIOPort->VSEL_PIOBit           = InitParams->LnbIOPort->VSEL_PIOBit;
    InstanceNew->LnbIOPort->VEN_PIOPort           = InitParams->LnbIOPort->VEN_PIOPort;
    InstanceNew->LnbIOPort->VEN_PIOPin           = InitParams->LnbIOPort->VEN_PIOPin;
    InstanceNew->LnbIOPort->VEN_PIOBit           = InitParams->LnbIOPort->VEN_PIOBit;
    InstanceNew->LnbIOPort->TEN_PIOPort           = InitParams->LnbIOPort->TEN_PIOPort;
    InstanceNew->LnbIOPort->TEN_PIOPin           = InitParams->LnbIOPort->TEN_PIOPin;
    InstanceNew->LnbIOPort->TEN_PIOBit           = InitParams->LnbIOPort->TEN_PIOBit;
    
    InstanceNew->InstanceChainNext   = NULL; /* always last in the chain */
    
    SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
#ifdef STTUNER_MINIDRIVER
    LNBInstance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LNB_BackEndIO_InstanceData_t ));
    LNBInstance->MemoryPartition = InitParams->MemoryPartition;
#endif
    return(Error);
}
/* ----------------------------------------------------------------------------
Name: lnb_backendIO_Term()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_backendIO_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams)
{
    ST_ErrorCode_t Error = ST_NO_ERROR;
    #ifndef STTUNER_MINIDRIVER
    LNB_BackEndIO_InstanceData_t *Instance, *InstancePrev, *InstanceNext;

    if(Installed == FALSE)
    {
	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)
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -