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

📄 d0297j.c

📁 st7710的tuner标准驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
                SEM_UNLOCK(Lock_InitTermOpenClose);
                return(STTUNER_ERROR_INITSTATE);
        }
        else
        {
            Instance = Instance->InstanceChainNext;   /* next block */
        }

    }


#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
    STTBX_Print(("%s FAIL! this point should NEVER be reached\n", identity));
#endif
    SEM_UNLOCK(Lock_InitTermOpenClose);
    return(Error);
}



/* ----------------------------------------------------------------------------
Name: demod_d0297J_Open()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0297J_Open(ST_DeviceName_t *DeviceName, DEMOD_OpenParams_t  *OpenParams, DEMOD_Capability_t *Capability, DEMOD_Handle_t *Handle)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
   const char *identity = "STTUNER d0297J.c demod_d0297J_Open()";
#endif
    ST_ErrorCode_t          Error = ST_NO_ERROR;
    U8                      Version;
    D0297J_InstanceData_t    *Instance;
    STTUNER_InstanceDbase_t *Inst;


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

#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
    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_CABDRV_D0297J
        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 */

    /*
    --- wake up chip if in standby, Reset
    */
    /*  soft reset of the whole chip */
    Error = STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle, R0297J_CTRL_0, 1);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
        STTBX_Print(("%s fail SOFT_RESET\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }
    Error = STTUNER_IOREG_SetRegister( &Instance->DeviceMap, Instance->IOHandle, R0297J_CTRL_0, 0);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
        STTBX_Print(("%s fail SOFT_RESET\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    /*
    --- Get chip ID
    */
    Version = Reg0297J_GetSTV0297JId(&Instance->DeviceMap, Instance->IOHandle);
    if ( Version !=  STV0297J_DEVICE_VERSION)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
        STTBX_Print(("%s fail device not found (0x%02x)\n", identity, Version));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(ST_ERROR_UNKNOWN_DEVICE);
    }
    else
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
        STTBX_Print(("%s device found, release/revision=%u\n", identity, Version));
#endif
    }

    /* reset all chip registers */
    Error = STTUNER_IOREG_Reset(&Instance->DeviceMap, Instance->IOHandle, defval, addressarray);
    if (Error != ST_NO_ERROR)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
        STTBX_Print(("%s fail reset device\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(Error);
    }

    /* Set capabilties */
    Capability->FECAvail        = 0;
    Capability->ModulationAvail = STTUNER_MOD_QAM    |
                                  STTUNER_MOD_16QAM  |
                                  STTUNER_MOD_32QAM  |
                                  STTUNER_MOD_64QAM  |
                                  STTUNER_MOD_128QAM |
                                  STTUNER_MOD_256QAM;   /* direct mapping to STTUNER_Modulation_t */

    Capability->J83Avail        = STTUNER_J83_A |
                                  STTUNER_J83_B |
                                  STTUNER_J83_C;

    Capability->AGCControl      = FALSE;
    Capability->SymbolMin       = STV0297J_SYMBOLMIN;        /*   1 MegaSymbols/sec (e.g) */
    Capability->SymbolMax       = STV0297J_SYMBOLMAX;        /*  11 MegaSymbols/sec (e.g) */

    Capability->BerMax           = 0;
    Capability->SignalQualityMax = STV0297J_MAX_SIGNAL_QUALITY;
    Capability->AgcMax           = STV0297J_MAX_AGC;

    /* Setup stateblock */
    Instance->StateBlock.ScanMode     = DEF0297J_CHANNEL;
    Instance->StateBlock.lastAGC2Coef = 1;
    Instance->StateBlock.Ber[0] = 0;
    Instance->StateBlock.Ber[1] = 50;                       /* Default Ratio for BER */
    Instance->StateBlock.Ber[2] = 0;
    Instance->StateBlock.CNdB = 0;
    Instance->StateBlock.SignalQuality = 0;

    /* TS output mode */
    switch (Instance->TSOutputMode)
    {
         case STTUNER_TS_MODE_SERIAL:
#ifdef STTUNER_DRV_CAB_J83B
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_0, 0x4f);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_1, 0x00);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_2, 0x24);
#ifdef STTUNER_BLOCK_SYNC_MODE_SELECT
            if (Instance->Sti5518 == STTUNER_STI5518_NONE)
                STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x01);
            else
                STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x05);
#else
            /* Default value for all chips except 5518 */
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x01);
#endif
#else
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_0, 0x4f);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_1, 0x00);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_2, 0x24);
#endif
            break;

        case STTUNER_TS_MODE_DVBCI:
#ifdef STTUNER_DRV_CAB_J83B
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_0, 0x43);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_1, 0x60);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_2, 0x24);
#ifdef STTUNER_BLOCK_SYNC_MODE_SELECT
            if (Instance->Sti5518 == STTUNER_STI5518_NONE)
                STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x00);
            else
                STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x04);
#else
            /* Default value for all chips except 5518 */
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x00);
#endif
#else
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_0, 0x43);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_1, 0x60);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_2, 0x24);
#endif
            break;

        case STTUNER_TS_MODE_PARALLEL:
        case STTUNER_TS_MODE_DEFAULT:
#ifdef STTUNER_DRV_CAB_J83B
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_0, 0x4b);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_1, 0x00);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_2, 0x24);
#ifdef STTUNER_BLOCK_SYNC_MODE_SELECT
            if (Instance->Sti5518 == STTUNER_STI5518_NONE)
                STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x00);
            else
                STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x04);
#else
            /* Default value for all chips except 5518 */
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_DATA_OUT_CTRL, 0x00);
#endif
#else
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_0, 0x4b);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_1, 0x00);
            STTUNER_IOREG_SetRegister(&Instance->DeviceMap, Instance->IOHandle, R0297J_OUTFORMAT_2, 0x24);
#endif
        default:
            break;
    }

    /* Set default error count mode, bit error rate */
    Reg0297J_StopBlkCounter(&Instance->DeviceMap, Instance->IOHandle);

    /* finally (as nor more errors to check for, allocate handle */
    Instance->TopLevelHandle = OpenParams->TopLevelHandle;
    *Handle = (U32)Instance;

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

    SEM_UNLOCK(Lock_InitTermOpenClose);
    Error |= Instance->DeviceMap.Error;

    Instance->DeviceMap.Error = ST_NO_ERROR;

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: demod_d0297J_Close()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0297J_Close(DEMOD_Handle_t Handle, DEMOD_CloseParams_t *CloseParams)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
   const char *identity = "STTUNER d0297J.c demod_d0297J_Close()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0297J_InstanceData_t     *Instance;

    /* private driver instance data */
    Instance = D0297J_GetInstFromHandle(Handle);

    if(Installed == FALSE)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
        STTBX_Print(("%s fail driver not installed\n", identity));
#endif
        return(STTUNER_ERROR_INITSTATE);
    }

    SEM_LOCK(Lock_InitTermOpenClose);

    /* ---------- check that at least one init has taken place ---------- */
    if(InstanceChainTop == NULL)
    {
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
        STTBX_Print(("%s fail nothing initalized\n", identity));
#endif
        SEM_UNLOCK(Lock_InitTermOpenClose);
        return(STTUNER_ERROR_INITSTATE);
    }

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

    Instance->TopLevelHandle = STTUNER_MAX_HANDLES;

#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
    STTBX_Print(("%s closed\n", identity));
#endif

    SEM_UNLOCK(Lock_InitTermOpenClose);
    return(Error);
}


/* ----------------------------------------------------------------------------
Name: demod_d0297J_IsAnalogCarrier()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0297J_IsAnalogCarrier(DEMOD_Handle_t Handle, BOOL *IsAnalog)
{
    ST_ErrorCode_t Error = ST_ERROR_FEATURE_NOT_SUPPORTED;
    return(Error);
}


/* ----------------------------------------------------------------------------
Name: demod_d0297J_GetSignalQuality()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0297J_GetSignalQuality(DEMOD_Handle_t Handle, U32  *SignalQuality_p, U32 *Ber_p)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
   const char *identity = "STTUNER d0297J.c demod_d0297J_GetSignalQuality()";
#endif
    ST_ErrorCode_t              Error = ST_NO_ERROR;
    STTUNER_tuner_instance_t    *TunerInstance;
    STTUNER_InstanceDbase_t     *Inst;
    D0297J_InstanceData_t        *Instance;
    int                         Mean, CNdB100;
    int                         ApplicationBERCount;
    BOOL                        IsLocked;

    /*
    --- Set parameters
    */
    *SignalQuality_p = 0;
    *Ber_p = 0;
    Mean = 0;
    CNdB100 = 0;
    ApplicationBERCount = 0;    /* Bit Error counter */


    /* private driver instance data */
    Instance = D0297J_GetInstFromHandle(Handle);
    /* top level public instance data */
    Inst = STTUNER_GetDrvInst();
    /* get the tuner instance for this driver from the top level handle */
    TunerInstance = &Inst[Instance->TopLevelHandle].Cable.Tuner;

    /*
    --- Get Carrier And Data (TS) status
    */
    Error = demod_d0297J_IsLocked(Handle, &IsLocked);
    if ( Error == ST_NO_ERROR && IsLocked )
    {
        /*
        --- Read Blk Counter
        */
        Reg0297J_StopBlkCounter(&Instance->DeviceMap, Instance->IOHandle);

        /*
        --- Read noise estimations and BER
        */
        Driv0297JBertCount(&Instance->DeviceMap, Instance->IOHandle, &Instance->StateBlock,
                            TunerInstance, &ApplicationBERCount, Instance->StateBlock.Ber);
        Driv0297JCNEstimator(&Instance->DeviceMap, Instance->IOHandle, &Instance->StateBlock,
                            TunerInstance, &Mean, &CNdB100, &Instance->StateBlock.SignalQuality);

        /*
        --- Restart Blk Counter
        */
        Reg0297J_StartBlkCounter(&Instance->DeviceMap, Instance->IOHandle);

        /*
        --- Set results
        */
        *SignalQuality_p = Instance->StateBlock.SignalQuality;
        if ( Instance->StateBlock.Ber[2] == 0 && ApplicationBERCount != 0 )
        {
            *Ber_p = ApplicationBERCount;           /* Set BER to counter (no time to count) */
        }
        else
        {
            *Ber_p = Instance->StateBlock.Ber[2];
        }
    }

#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
    STTBX_Print(("%s Mean=%d CN=%d dBx100 (%d %%)\n", identity, Mean, CNdB100, Instance->StateBlock.SignalQuality));
    STTBX_Print(("%s BERCount=%d BER[0..2] (cnt %d sat %d rate %d 10E-6)\n", identity,
                ApplicationBERCount,
                Instance->StateBlock.Ber[0],
                Instance->StateBlock.Ber[1],
                Instance->StateBlock.Ber[2]));
    STTBX_Print(("%s SignalQuality %u %% Ber %u 10E-6\n", identity, *SignalQuality_p, *Ber_p));
    STTBX_Print(("%s BlkCounter %9d CorrBlk %9d UncorrBlk %9d\n", identity,
                Instance->StateBlock.BlkCounter,
                Instance->StateBlock.CorrBlk,
                Instance->StateBlock.UncorrBlk
                ));
#endif

    Error |= Instance->DeviceMap.Error;
    Instance->DeviceMap.Error = ST_NO_ERROR;

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: demod_d0297J_GetModulation()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0297J_GetModulation(DEMOD_Handle_t Handle, STTUNER_Modulation_t *Modulation)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
   const char *identity = "STTUNER d0297J.c demod_d0297J_GetModulation()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0297J_InstanceData_t *Instance;

    /* private driver instance data */
    Instance = D0297J_GetInstFromHandle(Handle);

    /* This implementation of the DEMOD device only supports one type of modulation */
    *Modulation = Reg0297J_GetQAMSize(&Instance->DeviceMap, Instance->IOHandle);

#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
    STTBX_Print(("%s Modulation=%u\n", identity, *Modulation));
#endif

    Error |= Instance->DeviceMap.Error;
    Instance->DeviceMap.Error = ST_NO_ERROR;

    return(Error);
}



/* ----------------------------------------------------------------------------
Name: demod_d0297J_GetAGC()

Description:

Parameters:

Return Value:
---------------------------------------------------------------------------- */
ST_ErrorCode_t demod_d0297J_GetAGC(DEMOD_Handle_t Handle, S16  *Agc)
{
#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
   const char *identity = "STTUNER d0297J.c demod_d0297J_GetAGC()";
#endif
    ST_ErrorCode_t Error = ST_NO_ERROR;
    D0297J_InstanceData_t *Instance;

    /* private driver instance data */
    Instance = D0297J_GetInstFromHandle(Handle);

    *Agc   = (S16)(0xFFFF & Reg0297J_GetAGC(&Instance->DeviceMap, Instance->IOHandle));

#ifdef STTUNER_DEBUG_MODULE_CABDRV_D0297J
    STTBX_Print(("%s Agc=%u\n", identity, *Agc));
#endif

    Error |= Instance->DeviceMap.Error;
    Instance->DeviceMap.Error = ST_NO_ERROR;

    return(Error);
}


⌨️ 快捷键说明

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