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

📄 mt2063.c

📁 microtune 公司 硅高频头 源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    return (status);}/**********************************************************************************  Name: MT2063_ReInit****  Description:    Initialize the tuner's register values.****  Parameters:     h           - Tuner handle (returned by MT2063_Open)****  Returns:        status:**                      MT_OK            - No errors**                      MT_TUNER_ID_ERR   - Tuner Part/Rev code mismatch**                      MT_INV_HANDLE    - Invalid tuner handle**                      MT_COMM_ERR      - Serial bus communications error****  Dependencies:   MT_ReadSub  - Read byte(s) of data from the two-wire bus**                  MT_WriteSub - Write byte(s) of data to the two-wire bus****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.**   148   09-04-2007    RSK    Ver 1.02: Corrected logic of Reg 3B Reference**   153   09-07-2007    RSK    Ver 1.03: Lock Time improvements**   N/A   10-31-2007    PINZ   Ver 1.08: Changed values suitable to rcvr-mode 0 **   N/A   11-12-2007    PINZ   Ver 1.09: Changed values suitable to rcvr-mode 0 **   N/A   01-03-2007    PINZ   Ver 1.10: Added AFCsd = 1 into defaults**   N/A   01-04-2007    PINZ   Ver 1.10: Changed CAP1sel default**         01-14-2008    PINZ   Ver 1.11: Updated gain settings******************************************************************************/UData_t MT2063_ReInit(Handle_t h){    U8Data all_resets = 0xF0;                /* reset/load bits */    UData_t status = MT_OK;                  /* Status to be returned */    MT2063_Info_t* pInfo = (MT2063_Info_t*) h;    U8Data *def;    U8Data MT2063B0_defaults[] = { /* Reg,  Value */                                     0x19, 0x05,                                     0x1B, 0x1D,                                     0x1C, 0x1F,                                     0x1D, 0x0F,                                     0x1E, 0x3F,                                     0x1F, 0x0F,                                     0x20, 0x3F,                                     0x22, 0x21,                                     0x23, 0x3F,                                     0x24, 0x20,                                     0x25, 0x3F,                                     0x27, 0xEE,                                     0x2C, 0x27,  /*  bit at 0x20 is cleared below  */                                     0x30, 0x03,                                     0x2C, 0x07,  /*  bit at 0x20 is cleared here   */                                     0x2D, 0x87,                                     0x2E, 0xAA,                                     0x28, 0xE1,  /*  Set the FIFCrst bit here      */                                     0x28, 0xE0,  /*  Clear the FIFCrst bit here    */                                     0x00 };    /* writing 0x05 0xf0 sw-resets all registers, so we write only needed changes */    U8Data MT2063B1_defaults[] = { /* Reg,  Value */                                     0x05, 0xF0,                                     0x11, 0x10,  /* New Enable AFCsd */                                     0x19, 0x05,                                     0x1A, 0x6C,                                     0x1B, 0x24,                                     0x1C, 0x28,                                     0x1D, 0x8F,                                     0x1E, 0x14,                                     0x1F, 0x8F,                                     0x20, 0x57,                                     0x22, 0x21,  /* New - ver 1.03 */                                     0x23, 0x3C,  /* New - ver 1.10 */                                     0x24, 0x20,  /* New - ver 1.03 */                                     0x2C, 0x24,  /*  bit at 0x20 is cleared below  */                                     0x2D, 0x87,  /*  FIFFQ=0  */                                     0x2F, 0xF3,                                     0x30, 0x0C,  /* New - ver 1.11 */                                     0x31, 0x1B,  /* New - ver 1.11 */                                     0x2C, 0x04,  /*  bit at 0x20 is cleared here  */                                     0x28, 0xE1,  /*  Set the FIFCrst bit here      */                                     0x28, 0xE0,  /*  Clear the FIFCrst bit here    */                                     0x00 };    /*  Verify that the handle passed points to a valid tuner         */    if (IsValidHandle(pInfo) == 0)        status |= MT_INV_HANDLE;    /*  Read the Part/Rev code from the tuner */    if (MT_NO_ERROR(status))        status |= MT_ReadSub(pInfo->hUserData, pInfo->address, PART_REV, pInfo->reg, 1);    if (MT_NO_ERROR(status)  /* Check the part/rev code */        && (   (pInfo->reg[PART_REV] != MT2063_B0)    /*  MT2063 B0  */            && (pInfo->reg[PART_REV] != MT2063_B1)))  /*  MT2063 B1  */            status |= MT_TUNER_ID_ERR;      /*  Wrong tuner Part/Rev code */    /*  Read the Part/Rev code (2nd byte) from the tuner */    if (MT_NO_ERROR(status))        status |= MT_ReadSub(pInfo->hUserData, pInfo->address, RSVD_3B, &pInfo->reg[RSVD_3B], 1);    if (MT_NO_ERROR(status)  /* Check the 2nd part/rev code */        && ((pInfo->reg[RSVD_3B] & 0x80) != 0x00))    /* b7 != 0 ==> NOT MT2063 */            status |= MT_TUNER_ID_ERR;      /*  Wrong tuner Part/Rev code */    /*  Reset the tuner  */    if (MT_NO_ERROR(status))        status |= MT_WriteSub(pInfo->hUserData,                              pInfo->address,                              LO2CQ_3,                              &all_resets,                              1);    /* change all of the default values that vary from the HW reset values */    def = (pInfo->reg[PART_REV] == MT2063_B0) ? MT2063B0_defaults : MT2063B1_defaults;    while (MT_NO_ERROR(status) && *def)    {        U8Data reg = *def++;        U8Data val = *def++;        status |= MT_WriteSub(pInfo->hUserData, pInfo->address, reg, &val, 1);    }    /*  Wait for FIFF location to complete.  */    if (MT_NO_ERROR(status))    {        UData_t FCRUN = 1;        SData_t maxReads = 10;        while (MT_NO_ERROR(status) && (FCRUN != 0) && (maxReads-- > 0))        {            MT_Sleep(pInfo->hUserData, 2);            status |= MT_ReadSub(pInfo->hUserData,                                pInfo->address,                                XO_STATUS,                                &pInfo->reg[XO_STATUS],                                1);            FCRUN = (pInfo->reg[XO_STATUS] & 0x40) >> 6;        }        if (FCRUN != 0)            status |= MT_TUNER_INIT_ERR | MT_TUNER_TIMEOUT;        if (MT_NO_ERROR(status))  /* Re-read FIFFC value */            status |= MT_ReadSub(pInfo->hUserData, pInfo->address, FIFFC, &pInfo->reg[FIFFC], 1);    }    /* Read back all the registers from the tuner */    if (MT_NO_ERROR(status))        status |= MT_ReadSub(pInfo->hUserData,                             pInfo->address,                             PART_REV,                             pInfo->reg,                             END_REGS);    if (MT_NO_ERROR(status))    {        /*  Initialize the tuner state.  */        pInfo->version = VERSION;        pInfo->tuner_id = pInfo->reg[PART_REV];        pInfo->AS_Data.f_ref = REF_FREQ;        pInfo->AS_Data.f_if1_Center = (pInfo->AS_Data.f_ref / 8) * ((UData_t) pInfo->reg[FIFFC] + 640);        pInfo->AS_Data.f_if1_bw = IF1_BW;        pInfo->AS_Data.f_out = 43750000UL;        pInfo->AS_Data.f_out_bw = 6750000UL;        pInfo->AS_Data.f_zif_bw = ZIF_BW;        pInfo->AS_Data.f_LO1_Step = pInfo->AS_Data.f_ref / 64;        pInfo->AS_Data.f_LO2_Step = TUNE_STEP_SIZE;        pInfo->AS_Data.maxH1 = MAX_HARMONICS_1;        pInfo->AS_Data.maxH2 = MAX_HARMONICS_2;        pInfo->AS_Data.f_min_LO_Separation = MIN_LO_SEP;        pInfo->AS_Data.f_if1_Request = pInfo->AS_Data.f_if1_Center;        pInfo->AS_Data.f_LO1 = 2181000000UL;        pInfo->AS_Data.f_LO2 = 1486249786UL;        pInfo->f_IF1_actual = pInfo->AS_Data.f_if1_Center;        pInfo->AS_Data.f_in = pInfo->AS_Data.f_LO1 - pInfo->f_IF1_actual;        pInfo->AS_Data.f_LO1_FracN_Avoid = LO1_FRACN_AVOID;        pInfo->AS_Data.f_LO2_FracN_Avoid = LO2_FRACN_AVOID;        pInfo->num_regs = END_REGS;    }    return (status);}/**********************************************************************************  Name: MT2063_SetGPIO****  Description:    Modify the 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        - value to set GPIO pin 15, 14 or 19****  Usage:          status = MT2063_SetGPIO(hMT2063, MT2063_GPIO1, MT2063_GPIO_OUT, 1);****  Returns:        status:**                      MT_OK            - No errors**                      MT_COMM_ERR      - Serial bus communications error**                      MT_INV_HANDLE    - Invalid tuner handle****  Dependencies:   MT_WriteSub - Write byte(s) of data to the two-wire-bus****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.********************************************************************************/UData_t MT2063_SetGPIO(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] = {0x15, 0x19, 0x18};    MT2063_Info_t* pInfo = (MT2063_Info_t*) h;    if (IsValidHandle(pInfo) == 0)        return MT_INV_HANDLE;    regno = GPIOreg[attr];    shift = (gpio_id - MT2063_GPIO0 + 5);    if (value & 0x01)        pInfo->reg[regno] |= (0x01 << shift);    else        pInfo->reg[regno] &= ~(0x01 << shift);    status = MT_WriteSub(pInfo->hUserData, pInfo->address, regno, &pInfo->reg[regno], 1);    return (status);}/********************************************************************************  Name: MT2063_ControlAtten****  Description:    A local function to control various attenuation fields.**                  This function can SET, INCREMENT or DECREMENT an**                  attenuation field that is in the LSBs of a register.**                  A more complex solution would be required to manipulate**                  fields located at any position within a register.****  Parameters:     h            - Tuner handle (returned by MT2063_Open)**                  control_mode - The action { Set, Increment, Decrement }**                  regNum       - Register number being changed.**                  val          - value to be set**                  bitMask      - the bitMask of the field being set.****  Usage:          It is not intended for usage outside this module.****  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**                                         or register number out-of-range**                                         or control_mode out-of-range****  Dependencies:   USERS MUST CALL MT2063_Open() FIRST!****  See Also:       MT2063_SetReg, MT2063_SetParam****  Revision History:****   SCR      Date      Author  Description**  -------------------------------------------------------------------------**   138   06-19-2007    DAD    Ver 1.00: Initial, derived from mt2067_b.**         01-03-2008    PINZ             Added missing status readback******************************************************************************/static UData_t MT2063_ControlAtten( Handle_t               h,                                    MT2063_ATTEN_CNTL_MODE control_mode,                                    U8Data                 regNum,                                    U8Data                 val,                                    U8Data                 bitMask ){    U8Data limit;    U8Data reg_w=0;    UData_t status = MT_OK;                      /* Status to be returned  */    MT2063_Info_t* pInfo = (MT2063_Info_t*) h;    if (IsValidHandle(pInfo) == 0)        status = MT_INV_HANDLE;    else    {        if (regNum >= END_REGS)        {            status |= MT_ARG_RANGE;        }        else        {            switch( control_mode )            {            case MT2063_SET_ATTEN:                reg_w = ( pInfo->reg[regNum] & ~bitMask) | ( val & bitMask );                if( pInfo->reg[regNum] != reg_w )                {                    status |= MT2063_SetReg(pInfo, regNum, reg_w);                }                if (MT_NO_ERROR(status)) status |= MT2063_SetParam(h,MT2063_BYPATNUP,1);                break;            case MT2063_INCR_ATTEN:                /* Limit the max value to val or the field size to prevent overflow. */                limit = (bitMask > val) ? val : bitMask;                if ((pInfo->reg[regNum] & bitMask) < limit)                {                    pInfo->reg[regNum]++;                    status |= MT_WriteSub(pInfo->hUserData, pInfo->address, regNum, &pInfo->reg[regNum], 1);                    if (MT_NO_ERROR(status)) status |= MT2063_SetParam(h,MT2063_BYPATNUP,1);                }                break;            case MT2063_DECR_ATTEN:                /* Limit the minimum value to val or to 0  */                limit = (val > 0) ? val : 0;                if ((pInfo->reg[regNum] & bitMask) > limit)                {                    pInfo->reg[regNum]--;                    status |= MT_WriteSub(pInfo->hUserData, pInfo->address, regNum, &pInfo->reg[regNum], 1);       

⌨️ 快捷键说明

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