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

📄 diseqcdrv.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
    /* unmap API */
    Diseqc->diseqc_Init = NULL;
    Diseqc->diseqc_Term = NULL;

    Diseqc->diseqc_Open  = NULL;
    Diseqc->diseqc_Close = NULL;
    Diseqc->diseqc_SendReceive = NULL;
    
	
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
    STTBX_Print(("<"));
#endif

    
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
    STTBX_Print((">"));
#endif

    InstanceChainTop = (DISEQC_InstanceData_t *)0x7ffffffe;
#ifdef ST_OS21     
    semaphore_delete(Lock_InitTermOpenClose);
#else
    semaphore_delete(&Lock_InitTermOpenClose);
#endif    
    Installed        = FALSE;

#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        STTBX_Print(("ok\n"));
#endif

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: diseqc_diseqcdrv_Init()

Description:
    
Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t diseqc_diseqcdrv_Init(ST_DeviceName_t *DeviceName, DISEQC_InitParams_t *InitParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
    const char *identity = "STTUNER diseqc diseqc_diseqcdrv_Init()";
#endif
    S32                  IntReturn;
    ST_ErrorCode_t Error = ST_NO_ERROR;
    DISEQC_InstanceData_t *InstanceNew, *Instance;

    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        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(InitParams->MemoryPartition);
    if( Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        STTBX_Print(("%s fail MemoryPartition not valid\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    Error = STTUNER_Util_CheckPtrNull(DeviceName);
    if( Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        STTBX_Print(("%s fail DeviceName not valid\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    InstanceNew = memory_allocate_clear(InitParams->MemoryPartition, 1, sizeof( DISEQC_InstanceData_t ));
    if (InstanceNew == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        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 */
    {
        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;
    InstanceNew->IOHandle            = InitParams->IOHandle;
    InstanceNew->MemoryPartition     = InitParams->MemoryPartition;
    InstanceNew->InstanceChainNext   = NULL; /* always last in the chain */
    InstanceNew->BaseAddress	     = InitParams->Init_Diseqc.BaseAddress;
    InstanceNew->InterruptNumber     = InitParams->Init_Diseqc.InterruptNumber;
    InstanceNew->InterruptLevel     = InitParams->Init_Diseqc.InterruptLevel;
   
   
  /**************************************************/

    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        STTBX_Print(("%s fail setup register database params\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);           
    }
  
     /* install and enable interrupt for Diseqc2.0 on 5100*/
    IntReturn = interrupt_install ( InstanceNew->InterruptNumber,
                                                InstanceNew->InterruptLevel,
                                                (void (*) (void *)) DiseqcHandler,(void*)NULL );
     if (IntReturn != 0)
      {
    	return ST_ERROR_INTERRUPT_INSTALL;    
      }
      else
      {
      	  interrupt_enable_number(InstanceNew->InterruptNumber);
      	/* code to be added here */
      }


 /*Create handler related semaphores*/
/* create semaphores */
  DISEQC_Tx_Ready = semaphore_create_fifo_timeout(0);
  DISEQC_Rx_last_byte_received = semaphore_create_fifo_timeout(0);
  
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
    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);
    return(Error);
}   



/*----------------------------------------------------------------------------
Name: diseqc_diseqcdrv_Term()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t diseqc_diseqcdrv_Term(ST_DeviceName_t *DeviceName, DISEQC_TermParams_t *TermParams)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
   const char *identity = "STTUNER diseqc diseqc_diseqcdrv_Term()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    DISEQC_InstanceData_t *Instance, *InstancePrev, *InstanceNext;

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

    Instance = InstanceChainTop;
    while(1)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        STTBX_Print(("(%s)", Instance->DeviceName));
#endif
        if ( strcmp( (char *)Instance->DeviceName, (char *)DeviceName) == 0)
        {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
            STTBX_Print(("]\n"));
#endif
            
            /*uninstall the inrrupt handler here, is it necessary to disable the interrput as well???*/
            if (interrupt_uninstall(Instance->InterruptNumber,Instance->InterruptLevel) != 0)
            {
            	return ST_ERROR_INTERRUPT_UNINSTALL;
            }
            
            interrupt_disable_number(Instance->InterruptNumber);
            
            /* 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_DISEQC
            STTBX_Print(("%s freed block at %0x%08x\n", identity, (U32)Instance ));
#endif

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



/* ----------------------------------------------------------------------------
Name: diseqc_diseqcdrv_Open()

Description:
    
Parameters:
    
Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t diseqc_diseqcdrv_Open(ST_DeviceName_t *DeviceName, DISEQC_OpenParams_t  *OpenParams, DISEQC_Handle_t  *Handle,DISEQC_Capability_t *Capability)
{
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
   const char *identity = "STTUNER diseqcdrv.c diseqc_diseqcdrv_Open()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    DISEQC_InstanceData_t *Instance;

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

    if(Instance->TopLevelHandle != STTUNER_MAX_HANDLES)
    {
#ifdef STTUNER_DEBUG_MODULE_SATDRV_DISEQC
        STTBX_Print(("%s fail driver instance already open\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_OPEN_HANDLE);
    }

    /* finally (as nor more errors to check for, allocate handle */
    Instance->TopLevelHandle = OpenParams->TopLevelHandle;
     /* now got pointer to free (and valid) data block */
    *Handle = (U32)Instance;

     /*Get the base pointer from Instance database*/
     RegPtr = Instance->BaseAddress;

⌨️ 快捷键说明

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