mt2063.c

来自「microtune 公司 硅高频头 源码」· C语言 代码 · 共 1,674 行 · 第 1/5 页

C
1,674
字号
    SData_t i;    MT2063_Info_t* pInfo = NULL;    /*  Check the argument before using  */    if (hMT2063 == NULL)        return MT_ARG_NULL;    /*  Default tuner handle to NULL.  If successful, it will be reassigned  */    *hMT2063 = NULL;    /*    **  If this is our first tuner, initialize the address fields and    **  the list of available control blocks.    */    if (nOpenTuners == 0)    {        for (i=MT2063_CNT-1; i>=0; i--)        {            MT2063_Info[i].handle = NULL;            MT2063_Info[i].address = MAX_UDATA;            MT2063_Info[i].rcvr_mode = MT2063_CABLE_QAM;            MT2063_Info[i].hUserData = NULL;            Avail[i] = &MT2063_Info[i];        }    }    /*    **  Look for an existing MT2063_State_t entry with this address.    */    for (i=MT2063_CNT-1; i>=0; i--)    {        /*        **  If an open'ed handle provided, we'll re-initialize that structure.        **        **  We recognize an open tuner because the address and hUserData are        **  the same as one that has already been opened        */        if ((MT2063_Info[i].address == MT2063_Addr) &&            (MT2063_Info[i].hUserData == hUserData))        {            pInfo = &MT2063_Info[i];            break;        }    }    /*  If not found, choose an empty spot.  */    if (pInfo == NULL)    {        /*  Check to see that we're not over-allocating  */        if (nOpenTuners == MT2063_CNT)            return MT_TUNER_CNT_ERR;        /* Use the next available block from the list */        pInfo = Avail[nOpenTuners];        nOpenTuners++;    }    if (MT_NO_ERROR(status))        status |= MT_RegisterTuner(&pInfo->AS_Data);    if (MT_NO_ERROR(status))    {        pInfo->handle    = (Handle_t) pInfo;        pInfo->hUserData = hUserData;        pInfo->address   = MT2063_Addr;        pInfo->rcvr_mode = MT2063_CABLE_QAM;        status |= MT2063_ReInit((Handle_t) pInfo);    }    if (MT_IS_ERROR(status))        /*  MT2063_Close handles the un-registration of the tuner  */        MT2063_Close((Handle_t) pInfo);    else        *hMT2063 = pInfo->handle;    return (status);}static UData_t IsValidHandle(MT2063_Info_t* handle){    return ((handle != NULL) && (handle->handle == handle)) ? 1 : 0;}/**********************************************************************************  Name: MT2063_Close****  Description:    Release the handle to the tuner.****  Parameters:     hMT2063      - Handle to the MT2063 tuner****  Returns:        status:**                      MT_OK         - No errors**                      MT_INV_HANDLE - Invalid tuner handle****  Dependencies:   mt_errordef.h - definition of error codes****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.********************************************************************************/UData_t MT2063_Close(Handle_t hMT2063){    MT2063_Info_t* pInfo = (MT2063_Info_t*) hMT2063;    if (!IsValidHandle(pInfo))        return MT_INV_HANDLE;    /* Unregister tuner with SpurAvoidance routines (if needed) */    MT_UnRegisterTuner(&pInfo->AS_Data);    /* Now remove the tuner from our own list of tuners */    pInfo->handle    = NULL;    pInfo->address   = MAX_UDATA;    pInfo->hUserData = NULL;    nOpenTuners--;    Avail[nOpenTuners] = pInfo; /* Return control block to available list */    return MT_OK;}/**********************************************************************************  Name: MT2063_GetGPIO****  Description:    Get the current MT2063 GPIO value.****  Parameters:     h            - Open handle to the tuner (from MT2063_Open).**                  gpio_id      - Selects GPIO0, GPIO1 or GPIO2**                  attr         - Selects input readback, I/O direction or**                                 output value**                  *value       - current setting of GPIO pin****  Usage:          status = MT2063_GetGPIO(hMT2063, MT2063_GPIO_OUT, &value);****  Returns:        status:**                      MT_OK            - No errors**                      MT_COMM_ERR      - Serial bus communications error**                      MT_INV_HANDLE    - Invalid tuner handle**                      MT_ARG_NULL      - Null pointer argument passed****  Dependencies:   MT_ReadSub  - Read byte(s) of data from the serial bus****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.********************************************************************************/UData_t MT2063_GetGPIO(Handle_t h, MT2063_GPIO_ID gpio_id,                                   MT2063_GPIO_Attr attr,                                   UData_t* value){    UData_t status = MT_OK;                  /* Status to be returned        */    U8Data  regno;    SData_t shift;    static U8Data GPIOreg[3] = {RF_STATUS, FIF_OV, RF_OV};    MT2063_Info_t* pInfo = (MT2063_Info_t*) h;    if (IsValidHandle(pInfo) == 0)        return MT_INV_HANDLE;    if (value == NULL)        return MT_ARG_NULL;    regno = GPIOreg[attr];    /*  We'll read the register just in case the write didn't work last time */    status = MT_ReadSub(pInfo->hUserData, pInfo->address, regno, &pInfo->reg[regno], 1);    shift = (gpio_id - MT2063_GPIO0 + 5);    *value = (pInfo->reg[regno] >> shift) & 1;    return (status);}/********************************************************************************  Name: MT2063_GetLocked****  Description:    Checks to see if LO1 and LO2 are locked.****  Parameters:     h            - Open handle to the tuner (from MT2063_Open).****  Returns:        status:**                      MT_OK            - No errors**                      MT_UPC_UNLOCK    - Upconverter PLL unlocked**                      MT_DNC_UNLOCK    - Downconverter PLL unlocked**                      MT_COMM_ERR      - Serial bus communications error**                      MT_INV_HANDLE    - Invalid tuner handle****  Dependencies:   MT_ReadSub    - Read byte(s) of data from the serial bus**                  MT_Sleep      - Delay execution for x milliseconds****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.******************************************************************************/UData_t MT2063_GetLocked(Handle_t h){    const UData_t nMaxWait = 100;            /*  wait a maximum of 100 msec   */    const UData_t nPollRate = 2;             /*  poll status bits every 2 ms */    const UData_t nMaxLoops = nMaxWait / nPollRate;    const U8Data LO1LK = 0x80;    U8Data LO2LK = 0x08;    UData_t status = MT_OK;                  /* Status to be returned        */    UData_t nDelays = 0;    MT2063_Info_t* pInfo = (MT2063_Info_t*) h;    if (IsValidHandle(pInfo) == 0)        return MT_INV_HANDLE;    /*  LO2 Lock bit was in a different place for B0 version  */    if (pInfo->tuner_id == MT2063_B0)        LO2LK = 0x40;    do    {        status |= MT_ReadSub(pInfo->hUserData, pInfo->address, LO_STATUS, &pInfo->reg[LO_STATUS], 1);        if (MT_IS_ERROR(status))            return (status);        if ((pInfo->reg[LO_STATUS] & (LO1LK | LO2LK)) == (LO1LK | LO2LK))            return (status);        MT_Sleep(pInfo->hUserData, nPollRate);       /*  Wait between retries  */    }    while (++nDelays < nMaxLoops);    if ((pInfo->reg[LO_STATUS] & LO1LK) == 0x00)        status |= MT_UPC_UNLOCK;    if ((pInfo->reg[LO_STATUS] & LO2LK) == 0x00)        status |= MT_DNC_UNLOCK;    return (status);}/********************************************************************************  Name: MT2063_GetParam****  Description:    Gets a tuning algorithm parameter.****                  This function provides access to the internals of the**                  tuning algorithm - mostly for testing purposes.****  Parameters:     h           - Tuner handle (returned by MT2063_Open)**                  param       - Tuning algorithm parameter**                                (see enum MT2063_Param)**                  pValue      - ptr to returned value****                  param                     Description**                  ----------------------    --------------------------------**                  MT2063_IC_ADDR            Serial Bus address of this tuner**                  MT2063_MAX_OPEN           Max # of MT2063's allowed open**                  MT2063_NUM_OPEN           # of MT2063's open**                  MT2063_SRO_FREQ           crystal frequency**                  MT2063_STEPSIZE           minimum tuning step size**                  MT2063_INPUT_FREQ         input center frequency**                  MT2063_LO1_FREQ           LO1 Frequency**                  MT2063_LO1_STEPSIZE       LO1 minimum step size**                  MT2063_LO1_FRACN_AVOID    LO1 FracN keep-out region**                  MT2063_IF1_ACTUAL         Current 1st IF in use**                  MT2063_IF1_REQUEST        Requested 1st IF**                  MT2063_IF1_CENTER         Center of 1st IF SAW filter**                  MT2063_IF1_BW             Bandwidth of 1st IF SAW filter**                  MT2063_ZIF_BW             zero-IF bandwidth**                  MT2063_LO2_FREQ           LO2 Frequency**                  MT2063_LO2_STEPSIZE       LO2 minimum step size**                  MT2063_LO2_FRACN_AVOID    LO2 FracN keep-out region**                  MT2063_OUTPUT_FREQ        output center frequency**                  MT2063_OUTPUT_BW          output bandwidth**                  MT2063_LO_SEPARATION      min inter-tuner LO separation**                  MT2063_AS_ALG             ID of avoid-spurs algorithm in use**                  MT2063_MAX_HARM1          max # of intra-tuner harmonics**                  MT2063_MAX_HARM2          max # of inter-tuner harmonics**                  MT2063_EXCL_ZONES         # of 1st IF exclusion zones**                  MT2063_NUM_SPURS          # of spurs found/avoided**                  MT2063_SPUR_AVOIDED       >0 spurs avoided**                  MT2063_SPUR_PRESENT       >0 spurs in output (mathematically)**                  MT2063_RCVR_MODE          Predefined modes.  **                  MT2063_DNC_OUTPUT_ENABLE  DNC output selection **                  MT2063_VGAGC              VGA gain code**                  MT2063_VGAOI              VGA output current**                  MT2063_TAGC               TAGC setting**                  MT2063_AMPGC              AMP gain code****  Usage:          status |= MT2063_GetParam(hMT2063,**                                            MT2063_IF1_ACTUAL,**                                            &f_IF1_Actual);****  Returns:        status:**                      MT_OK            - No errors**                      MT_INV_HANDLE    - Invalid tuner handle**                      MT_ARG_NULL      - Null pointer argument passed**                      MT_ARG_RANGE     - Invalid parameter requested****  Dependencies:   USERS MUST CALL MT2063_Open() FIRST!****  See Also:       MT2063_SetParam, MT2063_Open****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.**   154   09-13-2007    RSK    Ver 1.05: Get/SetParam changes for LOx_FREQ**         10-31-2007    PINZ   Ver 1.08: Get/SetParam add VGAGC, VGAOI, AMPGC, TAGC******************************************************************************/UData_t MT2063_GetParam(Handle_t     h,                        MT2063_Param param,                        UData_t*     pValue){    UData_t status = MT_OK;                  /* Status to be returned        */    MT2063_Info_t* pInfo = (MT2063_Info_t*) h;    if (pValue == NULL)        status |= MT_ARG_NULL;    /*  Verify that the handle passed points to a valid tuner         */    if (IsValidHandle(pInfo) == 0)

⌨️ 快捷键说明

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