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

📄 lnbh21.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* allocate memory for regmap */
    Error = STTUNER_IOREG_Open(&InstanceNew->DeviceMap);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
        STTBX_Print(("%s fail allocate register database\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    }

    /* install a register map */
    Error = LNBH21_Reg_Install(&InstanceNew->DeviceMap);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
        STTBX_Print(("%s fail install a register database\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    }
    
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
    STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( LNBH21_InstanceData_t ) ));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
    #endif
    
#ifdef STTUNER_MINIDRIVER
    
    LNBH21Instance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( LNB21_InstanceData_t ));
    if (LNBH21Instance == NULL)
    {
        return(ST_ERROR_NO_MEMORY);           
    }
    LNBH21Instance->MemoryPartition     = InitParams->MemoryPartition;
#endif
    
    
    return(Error);
}   



/* ----------------------------------------------------------------------------
Name: lnb_lnbh21_Term()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnbh21_Term(ST_DeviceName_t *DeviceName,LNB_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
   const char *identity = "STTUNER lnbh21.c lnb_lnbh21_Term()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
    LNBH21_InstanceData_t *Instance, *InstancePrev, *InstanceNext;

    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
        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_LNBH21
        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_LNBH21
        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_LNBH21
    STTBX_Print(("%s looking for first free handle[\n", identity));
#endif

    Instance = InstanceChainTop;
    while(1)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
        STTBX_Print(("(%s)", Instance->DeviceName));
#endif
        if ( strcmp((char *)Instance->DeviceName, (char *)DeviceName) == 0)
        {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
            STTBX_Print(("]\n"));
#endif
            Error = STTUNER_IOREG_Close(&Instance->DeviceMap);
            if (Error != ST_NO_ERROR)
            {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
                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_LNBH21
            STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif

#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
            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_LNBH21
                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_LNBH21
    STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
#endif

#ifdef STTUNER_MINIDRIVER
   
            memory_deallocate(LNBH21Instance->MemoryPartition, LNBH21Instance);   
#endif
    return(Error);
}   

/* ----------------------------------------------------------------------------
Name: lnb_lnbh21_Open()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t lnb_lnbh21_Open (ST_DeviceName_t *DeviceName, LNB_OpenParams_t *OpenParams, LNB_Capability_t *Capability, LNB_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
   const char *identity = "STTUNER lnbh21.c lnb_lnbh21_Open()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
    LNBH21_InstanceData_t     *Instance;
    

    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
        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_LNBH21
        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_LNBH21
    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_LNBH21
            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_LNBH21
        STTBX_Print(("(%s)", Instance->DeviceName));
#endif
    }
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
    STTBX_Print((" found ok\n"));
#endif

#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
    STTBX_Print(("%s using block at 0x%08x\n", identity, (U32)Instance));
#endif

    if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
        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.ShortCircuitProtectionMode = STTUNER_LNB_PROTECTION_STATIC;
    Instance->Config.CableLossCompensation = FALSE;
    
    /*STTUNER_IOREG_Reset(&Instance->DeviceMap, Instance->IOHandle);*/
    /* set LNB tone  */
   LNBH21_SetLnb(Instance, Instance->Config.ToneState);

    /* LNB power on */
    LNBH21_SetPower(Instance, Instance->Config.Status);
    
    /* LNB polarization horizontal*/
    LNBH21_SetPolarization(Instance, Instance->Config.Polarization);

    /* LNB low current threshold*/
 /*   LNBH21_SetCurrentThreshold(&Instance->DeviceMap, Instance->Config.CurrentThresholdSelection);*/

    /*LNB circuit protection mode*/
    LNBH21_SetProtectionMode(Instance, Instance->Config.ShortCircuitProtectionMode);
    
    /* LNB cable loss compenation off */
    LNBH21_SetLossCompensation(Instance, Instance->Config.CableLossCompensation);

    Error = LNBH21_UpdateLNB (Instance);

    LNBH21_Delay_uS(25000);

      /*Checking whether shortcircuit has ocurred i.e. whether OLF bit is high */
    Error |= LNBH21_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_LNBH21
            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_LNBH21
        STTBX_Print(("%s fail Error=%u\n", identity, Error));   /* LNBH21_GetPower failed */
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }


#ifdef STTUNER_DEBUG_MODULE_SATDRV_LNBH21
    STTBX_Print(("%s opened ok\n", identity));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
#endif

#ifdef STTUNER_MINIDRIVER
    
    *Handle = (U32)LNBH21Instance;
    
    /* 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 */
    LNBH21Instance->Config.Status    = LNB_STATUS_ON;
    LNBH21Instance->Config.ToneState = STTUNER_LNB_TONE_OFF;
    LNBH21Instance->Config.ShortCircuitProtectionMode = STTUNER_LNB_PROTECTION_STATIC;
    LNBH21Instance->Config.CableLossCompensation = FALSE;
    LNBH21Instance->Config.Polarization = STTUNER_PLR_HORIZONTAL;
    
    /* LNB tone off */
    LNBH21_SetLnb(LNBH21Instance->Config.ToneState);

    /* LNB power on */
    LNBH21_SetPower(LNBH21Instance->Config.Status);
    
    /* LNB polarization horizontal*/
    LNBH21_SetPolarization(LNBH21Instance->Config.Polarization);
    
    
    /*LNB circuit protection mode*/
    LNBH21_SetProtectionMode(LNBH21Instance->Config.ShortCircuitProtectionMode);
    
    /* LNB cable loss compenation off */
    LNBH21_SetLossCompensation(LNBH21Instance->Config.CableLossCompensation);

    Error = LNBH21_UpdateLNB();
    
    LNBH21_Delay_uS(500);
    
    /*Checking whether shortcircuit has ocurred i.e. whether OLF bit is high */
    Error |= LNBH21_GetStatus(&LNBH21Instance->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 (LNBH21Instance->Config.Status == LNB_STATUS_SHORT_CIRCUIT || LNBH21Instance->Config.Status == LNB_STATUS_OVER_TEMPERATURE  || LNBH21Instance->Config.Status == LNB_STATUS_SHORTCIRCUIT_OVERTEMPERATURE)
        {

            return(STTUNER_ERROR_HWFAIL);
        }
    }
    else
    {

    return(Error);
    }
  
#endif
    return(Error);
}   



/* ----------------------------------------------------------------------------
Name: lnb_lnbh21_Close()

Description:
    
Parameters:
    
Return Value:

⌨️ 快捷键说明

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