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

📄 scrdrv.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
    InstanceNew->MemoryPartition     = InitParams->MemoryPartition;
    InstanceNew->InstanceChainNext   = NULL; /* always last in the chain */
    
    InstanceNew->LNBIndex            = InitParams->LNBIndex;
    InstanceNew->SCRBPF              = InitParams->SCRBPF;
    InstanceNew->SCR_Mode            = InitParams->SCR_Mode;
    if(InitParams->Scr_App_Type != STTUNER_SCR_NULL)	
    {
        InstanceNew->SCREnable=TRUE;
    }
    else	
    {
	InstanceNew->SCREnable=FALSE;
    }

    if(InstanceNew->SCR_Mode == STTUNER_SCR_MANUAL || InstanceNew->SCR_Mode == STTUNER_UBCHANGE)
    {
    	InstanceNew->Scr_App_Type  = InitParams->Scr_App_Type;
   	InstanceNew->NbScr = InitParams->Number_of_SCR;
   	InstanceNew->NbLnb = InitParams->Number_of_LNB;
	for(i=0; i<InstanceNew->NbScr; ++i)
   	 {
   		InstanceNew->SCRBPFFrequencies[i] = InitParams->SCRBPFFrequencies[i];
   	 }
   	 for(i=0; i<InstanceNew->NbLnb; ++i)
   	 {
   		InstanceNew->SCRLNB_LO_Frequencies[i] = InitParams->SCRLNB_LO_Frequencies[i];
   		
   	 }
     }
   	

#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
    STTBX_Print(("%s allocated & initalized block named '%s' at 0x%08x (%d bytes)\n", identity, InstanceNew->DeviceName, (U32)InstanceNew, sizeof( SCR_InstanceData_t ) ));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
    
#endif
/****************************MINIDRIVER**********************
**************************************************************
***************************************************************/
#ifdef STTUNER_MINIDRIVER
	
	#if defined(ST_OS21) || defined(ST_OSLINUX)      
	    Lock_InitTermOpenClose = semaphore_create_fifo(1);
	    DiSEqC_Semaphore  = semaphore_create_fifo(1);
	#else
	    semaphore_init_fifo(&Lock_InitTermOpenClose, 1);
	    semaphore_init_fifo(&DiSEqC_Semaphore, 1);
	#endif
    
        /* now safe to lock semaphore */
    SEM_LOCK(Lock_InitTermOpenClose);

    SCRInstance = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( SCR_InstanceData_t ));
    if (SCRInstance == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
        STTBX_Print(("%s fail memory allocation InstanceNew\n", identity));
#endif    
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_NO_MEMORY);           
    }
    
    SCRInstance->TopLevelHandle      = STTUNER_MAX_HANDLES;
    SCRInstance->IOHandle            = InitParams->IOHandle;
    SCRInstance->MemoryPartition     = InitParams->MemoryPartition;
    
    SCRInstance->SCRBPF              = InitParams->SCRBPF;
    SCRInstance->SCR_Mode            = InitParams->SCR_Mode;
    if(SCRInstance->SCR_Mode == STTUNER_SCR_MANUAL)
    {
    	SCRInstance->Scr_App_Type  = InitParams->Scr_App_Type;
   	SCRInstance->NbScr = InitParams->Number_of_SCR;
   	SCRInstance->NbLnb  = InitParams->Number_of_LNB;
	for(i=0; i<SCRInstance->NbScr; ++i)
   	 {
   		SCRInstance->SCRBPFFrequencies[i] = InitParams->SCRBPFFrequencies[i];
   	 }
   	 for(i=0; i<SCRInstance->NbLnb; ++i)
   	 {
   		SCRInstance->SCRLNB_LO_Frequencies[i] = InitParams->SCRLNB_LO_Frequencies[i];
   		
   	 }
     }
     else 
     Error = ST_ERROR_FEATURE_NOT_SUPPORTED;
	/**************************************************/
    SEM_UNLOCK(Lock_InitTermOpenClose);
    
#endif
    return(Error);
}   



/*----------------------------------------------------------------------------
Name: scr_scrdrv_Term()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t scr_scrdrv_Term(ST_DeviceName_t *DeviceName, SCR_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
   const char *identity = "STTUNER scr scr_scrdrv_Term()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
    SCR_InstanceData_t *Instance, *InstancePrev, *InstanceNext;

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

    Instance = InstanceChainTop;
    while(1)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
        STTBX_Print(("(%s)", Instance->DeviceName));
#endif
        if ( strcmp( (char *)Instance->DeviceName, (char *)DeviceName) == 0)
        {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
            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_SCR
            STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif

#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
            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_SCR
                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_SCR
    STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
#endif
/*********************************MINIDRIVER*****************************
**************************************************************************
***************************************************************************/
#ifdef STTUNER_MINIDRIVER
   
    /* now safe to lock semaphore */
    SEM_LOCK(Lock_InitTermOpenClose);
	memory_deallocate(SCRInstance->MemoryPartition, SCRInstance);
    SEM_UNLOCK(Lock_InitTermOpenClose);
   #if defined(ST_OS21)|| defined(ST_OSLINUX)
      semaphore_delete(Lock_InitTermOpenClose);
       semaphore_delete(DiSEqC_Semaphore);
    #else
      semaphore_delete(&Lock_InitTermOpenClose);
       semaphore_delete(&DiSEqC_Semaphore);
    #endif 
#endif    
    return(Error);
}   

/* ----------------------------------------------------------------------------
Name: scr_scrdrv_Open()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t scr_scrdrv_Open(ST_DeviceName_t *DeviceName, SCR_OpenParams_t  *OpenParams, SCR_Handle_t  *Handle, DEMOD_Handle_t DemodHandle, SCR_Capability_t *Capability)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
   const char *identity = "STTUNER scr scr_scrdrv_Open()";
#endif
    U8 i;
    ST_ErrorCode_t Error = ST_NO_ERROR;
#ifndef STTUNER_MINIDRIVER
   SCR_InstanceData_t     *Instance;
    STTUNER_InstanceDbase_t  *Inst;
    U32 ToneList[8] = {0};
    U32 ToneFreq[8] = {0};
    U32 ToneFound;
    U8  NbScr=0;
    U32 StartFreq, StopFreq;
    U32 index=0;
    U8  NbTones=0,j; 
    int  power_detection_level=0;
    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
        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_SCR
        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_SCR
    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_SCR
            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_SCR
        STTBX_Print(("(%s)", Instance->DeviceName));
#endif
    }
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
        STTBX_Print((" found ok\n"));
#endif

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

    /* check handle IS actually free */
    if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_SCR
        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 */

    Inst = STTUNER_GetDrvInst();    /* pointer to instance database */

     Capability->SCREnable=Instance->SCREnable; 
     if(Instance->SCREnable==TRUE)
     {
      	if(Instance->SCR_Mode == STTUNER_SCR_AUTO)
   	{ 
   		 Capability->SCRBPF  = STTUNER_SCRBPF0;
   		 StartFreq = (U32)950000000l;
	   	 StopFreq  = (U32)2150000000ul;
	   	 Error = scr_auto_detect(OpenParams, DemodHandle, StartFreq, StopFreq, &NbScr, ToneFreq,&power_detection_level);
	   	 index=0;
                for(i=0;i<NbScr;i++) 
                {
                 scr_tone_enable_x(OpenParams,DemodHandle,i,NbScr);
                 for(j=index;j<NbScr;j++)
                 {
                  StartFreq=ToneFreq[j]-10000000;
                  StopFreq=ToneFreq[j]+10000000;
                  ToneFound=0;
                  Error |= Inst[OpenParams->TopLevelHandle].Sat.Demod.Driver->demod_tonedetection(DemodHandle, StartFreq, StopFreq, &NbTones, &ToneFound,0,&power_detection_level);
                  if(ToneFound>StartFreq & ToneFound<StopFreq)
                  {
                   ToneList[index]=ToneFreq[j];
                   index++;
                   break;
                  }
                 }
                }
                Instance->NbScr=index;
                
	   	 Capability->Number_of_SCR = Instance->NbScr;
	   	 Capability->SCR_Mode=STTUNER_SCR_AUTO;
	   	 if(Instance->NbScr)
	   	 {
		   	 for(i=0; i<Instance->NbScr; ++i)
		   	 {
		   		scr_scrdrv_Off (OpenParams, DemodHandle, i);
		   		Instance->SCRBPFFrequencies[i] = (U16)(ToneList[i]/1000000l);
		   		Capability->SCRBPFFrequencies[i] = (U16)(ToneList[i]/1000000l);
		   		
		   	 }
		   		   	
		   	Instance->SCRBPF = STTUNER_SCRBPF0; /* Use SCR Index 0 to extract installation parameters*/
		   		   	
		     	Instance->NbLnb = scr_get_LO_frequency(OpenParams, DemodHandle, Instance->SCRBPF, Instance->SCRBPFFrequencies[Instance->SCRBPF], Instance->SCRLNB_LO_Frequencies,&power_detection_level);
		     	Capability->Number_of_LNB = Instance->NbLnb;
		     	for(i=0; i<Instance->NbLnb; ++i)
		   	 {
		   		Capability->SCRLNB_LO_Frequencies[i] = (U16)(Instance->SCRLNB_LO_Frequencies[i]);
		   		
		   	 }
		     	
		     	Instance->Scr_App_Type = scr_get_application_number(OpenParams, DemodHandle, Instance->SCRBPF, Instance->SCRBPFFrequencies[Instance->SCRBPF],&power_detection_level);
		     	if(Instance->Scr_App_Type == STTUNER_SCR_APPLICATION_NOT_SUPPORTED)
		     	{
		     		SEM_UNLOCK(Lock_InitTermOpenClose);
		   		return ST_ERROR_FEATURE_NOT_SUPPORTED;
		   	}
		   	else
		   	Capability->Scr_App_Type = Instance->Scr_App_Type;
		   	
		   	scr_scrdrv_Off (OpenParams, DemodHandle, Instance->SCRBPF);
		}
		else
		{
			SEM_UNLOCK(Lock_InitTermOpenClose);
	   		return ST_ERROR_FEATURE_NOT_SUPPORTED;
	   	}
   	}
   	else if(Instance->SCR_Mode == STTUNER_SCR_MANUAL)
   	{
   		/* make scr off*/
   		scr_scrdrv_Off (OpenParams, DemodHandle, Instance->SCRBPF);
   		Capability->SCR_Mode      = STTUNER_SCR_MANUAL;
   		Capability->SCRBPF        = Instance->SCRBPF;
   		Capability->Scr_App_Type  = Instance->Scr_App_Type;
   		Capability->Number_of_SCR = Instance->NbScr;
   		Capability->Number_of_LNB = Instance->NbLnb;
   		Capability->LNBIndex      = Instance->LNBIndex;
   		for(i=0; i<Instance->NbScr; ++i)
	   	 {
	   		Capability->SCRBPFFrequencies[i] = Instance->SCRBPFFrequencies[i];

⌨️ 快捷键说明

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