mt2063.c

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

C
1,674
字号
        status |= MT_INV_HANDLE;    if (MT_NO_ERROR(status))    {        switch (param)        {        /*  Serial Bus address of this tuner      */        case MT2063_IC_ADDR:            *pValue = pInfo->address;            break;        /*  Max # of MT2063's allowed to be open  */        case MT2063_MAX_OPEN:            *pValue = nMaxTuners;            break;        /*  # of MT2063's open                    */        case MT2063_NUM_OPEN:            *pValue = nOpenTuners;            break;        /*  crystal frequency                     */        case MT2063_SRO_FREQ:            *pValue = pInfo->AS_Data.f_ref;            break;        /*  minimum tuning step size              */        case MT2063_STEPSIZE:            *pValue = pInfo->AS_Data.f_LO2_Step;            break;        /*  input center frequency                */        case MT2063_INPUT_FREQ:            *pValue = pInfo->AS_Data.f_in;            break;        /*  LO1 Frequency                         */        case MT2063_LO1_FREQ:            {                const UData_t Div = pInfo->reg[LO1C_1];                const UData_t Num = pInfo->reg[LO1C_2] & 0x3F;                pInfo->AS_Data.f_LO1 = (pInfo->AS_Data.f_ref * Div) + fLO_FractionalTerm(pInfo->AS_Data.f_ref, Num, 64);            }            *pValue = pInfo->AS_Data.f_LO1;            break;        /*  LO1 minimum step size                 */        case MT2063_LO1_STEPSIZE:            *pValue = pInfo->AS_Data.f_LO1_Step;            break;        /*  LO1 FracN keep-out region             */        case MT2063_LO1_FRACN_AVOID:            *pValue = pInfo->AS_Data.f_LO1_FracN_Avoid;            break;        /*  Current 1st IF in use                 */        case MT2063_IF1_ACTUAL:            *pValue = pInfo->f_IF1_actual;            break;        /*  Requested 1st IF                      */        case MT2063_IF1_REQUEST:            *pValue = pInfo->AS_Data.f_if1_Request;            break;        /*  Center of 1st IF SAW filter           */        case MT2063_IF1_CENTER:            *pValue = pInfo->AS_Data.f_if1_Center;            break;        /*  Bandwidth of 1st IF SAW filter        */        case MT2063_IF1_BW:            *pValue = pInfo->AS_Data.f_if1_bw;            break;        /*  zero-IF bandwidth                     */        case MT2063_ZIF_BW:            *pValue = pInfo->AS_Data.f_zif_bw;            break;        /*  LO2 Frequency                         */        case MT2063_LO2_FREQ:            {                const UData_t Div =  (pInfo->reg[LO2C_1] & 0xFE ) >> 1;                const UData_t Num = ((pInfo->reg[LO2C_1] & 0x01 ) << 12) | (pInfo->reg[LO2C_2] << 4) | (pInfo->reg[LO2C_3] & 0x00F);                pInfo->AS_Data.f_LO2 = (pInfo->AS_Data.f_ref * Div) + fLO_FractionalTerm(pInfo->AS_Data.f_ref, Num, 8191);            }            *pValue = pInfo->AS_Data.f_LO2;            break;        /*  LO2 minimum step size                 */        case MT2063_LO2_STEPSIZE:            *pValue = pInfo->AS_Data.f_LO2_Step;            break;        /*  LO2 FracN keep-out region             */        case MT2063_LO2_FRACN_AVOID:            *pValue = pInfo->AS_Data.f_LO2_FracN_Avoid;            break;        /*  output center frequency               */        case MT2063_OUTPUT_FREQ:            *pValue = pInfo->AS_Data.f_out;            break;        /*  output bandwidth                      */        case MT2063_OUTPUT_BW:            *pValue = pInfo->AS_Data.f_out_bw - 750000;            break;        /*  min inter-tuner LO separation         */        case MT2063_LO_SEPARATION:            *pValue = pInfo->AS_Data.f_min_LO_Separation;            break;        /*  ID of avoid-spurs algorithm in use    */        case MT2063_AS_ALG:            *pValue = pInfo->AS_Data.nAS_Algorithm;            break;        /*  max # of intra-tuner harmonics        */        case MT2063_MAX_HARM1:            *pValue = pInfo->AS_Data.maxH1;            break;        /*  max # of inter-tuner harmonics        */        case MT2063_MAX_HARM2:            *pValue = pInfo->AS_Data.maxH2;            break;        /*  # of 1st IF exclusion zones           */        case MT2063_EXCL_ZONES:            *pValue = pInfo->AS_Data.nZones;            break;        /*  # of spurs found/avoided              */        case MT2063_NUM_SPURS:            *pValue = pInfo->AS_Data.nSpursFound;            break;        /*  >0 spurs avoided                      */        case MT2063_SPUR_AVOIDED:            *pValue = pInfo->AS_Data.bSpurAvoided;            break;        /*  >0 spurs in output (mathematically)   */        case MT2063_SPUR_PRESENT:            *pValue = pInfo->AS_Data.bSpurPresent;            break;        /*  Predefined receiver setup combination */        case MT2063_RCVR_MODE:            *pValue = pInfo->rcvr_mode;            break;        case MT2063_PD1:        case MT2063_PD2:            {                U8Data mask = (param == MT2063_PD1 ? 0x01 : 0x03);  /* PD1 vs PD2 */                U8Data orig = (pInfo->reg[BYP_CTRL]);                U8Data reg  = (orig & 0xF1) | mask;  /* Only set 3 bits (not 5) */                int   i;                *pValue = 0;                /* Initiate ADC output to reg 0x0A */                if (reg != orig)                    status |= MT_WriteSub(pInfo->hUserData, pInfo->address, BYP_CTRL, &reg, 1);                if (MT_IS_ERROR(status))                    return (status);                for (i=0; i<8; i++) {                    status |= MT_ReadSub(pInfo->hUserData, pInfo->address, ADC_OUT, &pInfo->reg[ADC_OUT], 1);                    if (MT_NO_ERROR(status))                        *pValue += pInfo->reg[ADC_OUT];                    else                    {                        if( i ) *pValue /= i;                        return (status);                    }                }                *pValue /= 8;     /*  divide by number of reads  */                *pValue >>=2;     /*  only want 6 MSB's out of 8  */                /* Restore value of Register BYP_CTRL */                if (reg != orig)                    status |= MT_WriteSub(pInfo->hUserData, pInfo->address, BYP_CTRL, &orig, 1);            }            break;        /*  Get LNA attenuator code                */        case MT2063_ACLNA:            {                U8Data val;                status |= MT2063_GetReg(pInfo, XO_STATUS, &val);                *pValue = val & 0x1f;            }            break;        /*  Get RF attenuator code                */        case MT2063_ACRF:            {                U8Data val;                status |= MT2063_GetReg(pInfo, RF_STATUS, &val);                *pValue = val & 0x1f;            }            break;        /*  Get FIF attenuator code               */        case MT2063_ACFIF:            {                U8Data val;                status |= MT2063_GetReg(pInfo, FIF_STATUS, &val);                *pValue = val & 0x1f;            }            break;        /*  Get current used DNC output */        case MT2063_DNC_OUTPUT_ENABLE:            {                if ( (pInfo->reg[DNC_GAIN] & 0x03) == 0x03)   /* if DNC1 is off */                    {                    if ( (pInfo->reg[VGA_GAIN] & 0x03) == 0x03) /* if DNC2 is off */                        *pValue = (UData_t)MT2063_DNC_NONE;                    else                         *pValue = (UData_t)MT2063_DNC_2;                    }                else /* DNC1 is on */                    {                    if ( (pInfo->reg[VGA_GAIN] & 0x03) == 0x03) /* if DNC2 is off */                        *pValue = (UData_t)MT2063_DNC_1;                    else                         *pValue = (UData_t)MT2063_DNC_BOTH;                    }            }            break;       /*  Get VGA Gain Code */        case MT2063_VGAGC:           *pValue = ( (pInfo->reg[VGA_GAIN] & 0x0C) >> 2 );            break;       /*  Get VGA bias current */        case MT2063_VGAOI:            *pValue = (pInfo->reg[RSVD_31] & 0x07);            break;       /*  Get TAGC setting */        case MT2063_TAGC:            *pValue = (pInfo->reg[RSVD_1E] & 0x03);            break;       /*  Get AMP Gain Code */        case MT2063_AMPGC:           *pValue = (pInfo->reg[TEMP_SEL] & 0x03);            break;        case MT2063_EOP:        default:            status |= MT_ARG_RANGE;        }    }    return (status);}/********************************************************************************  Name: MT2063_GetReg****  Description:    Gets an MT2063 register.****  Parameters:     h           - Tuner handle (returned by MT2063_Open)**                  reg         - MT2063 register/subaddress location**                  *val        - MT2063 register/subaddress 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**                      MT_ARG_RANGE     - Argument out of range****  Dependencies:   USERS MUST CALL MT2063_Open() FIRST!****                  Use this function if you need to read a register from**                  the MT2063.****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.******************************************************************************/UData_t MT2063_GetReg(Handle_t h,                      U8Data   reg,                      U8Data*  val){    UData_t status = MT_OK;                  /* Status to be returned        */    MT2063_Info_t* pInfo = (MT2063_Info_t*) h;    /*  Verify that the handle passed points to a valid tuner         */    if (IsValidHandle(pInfo) == 0)        status |= MT_INV_HANDLE;    if (val == NULL)        status |= MT_ARG_NULL;    if (reg >= END_REGS)        status |= MT_ARG_RANGE;    if (MT_NO_ERROR(status))    {        status |= MT_ReadSub(pInfo->hUserData, pInfo->address, reg, &pInfo->reg[reg], 1);        if (MT_NO_ERROR(status))            *val = pInfo->reg[reg];    }    return (status);}/**********************************************************************************  Name: MT2063_GetTemp****  Description:    Get the MT2063 Temperature register.****  Parameters:     h            - Open handle to the tuner (from MT2063_Open).**                  *value       - value read from the register

⌨️ 快捷键说明

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