demod_hamaro.c

来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 1,447 行 · 第 1/5 页

C
1,447
字号
/*                                                                           */
/*  PARAMETERS:  demod_handle - handle of demod for read request (San Diego  */
/*                   code handle, not multi-instance demod handle).          */
/*               reg_addr - the register offset to be read.                  */
/*               status - pointer to status value filled in at completion    */
/*                   (0 for success, non-0 for failure).                     */
/*                                                                           */
/*  DESCRIPTION: This function reads from the specified register offset of   */
/*               the specified demod unit and returns the value read.        */
/*                                                                           */
/*  RETURNS:     The value read from the device.                             */
/*                                                                           */
/*  CONTEXT:     Must be called from non-interrupt context.                  */
/*                                                                           */
/*****************************************************************************/
unsigned long TunerSBRead( unsigned long demod_handle, unsigned char reg_addr, unsigned long *status )
{
    unsigned char serial_bus_addr;
    unsigned long reg_value = 0;
    //unsigned long sts_reg_addr = 0;
    volatile unsigned short *sts_reg_addr=0;
    unsigned char page_addr;

    if ( 0 == status )
    {
        trace_new( TL_ERROR, "Bad status parameter to Hamaro SBRead!\n" );
        error_log( ERROR_WARNING | RC_SDM_BADVAL );
        return 0;
    }

    if( demod_handle & STS_APPLY_BASE_ADDRESS )
    {
        /* It's a Scan The Sky handle */
        
        /* extract page address from demod handle */
        page_addr    = (demod_handle>>11) & 0x3;
        
        /* 0x304e1000 is the base address for the 32-bit STS memory access          */
        /* copy page address to bit position [9:8] of the 32-bit memory address     */
        /* address bit 0 on the Hamaro side can be wired to bit 10 on the ARM side. */
        /* address bit 1 on the Hamaro side can be wired to bit 11 on the ARM side. */
        sts_reg_addr = (unsigned short *)(STS_BASE_ADDRESS |(page_addr << 8)|(reg_addr & 0xfc)|((reg_addr & 0x3)<<10));
        reg_value    = *sts_reg_addr;
        //reg_value = CNXT_GET(sts_reg_addr, 0xFFFF);
        *status      = 0;
        return reg_value;   
    }
    else if ( demod_handle & 0xfffeff00 )
    {
        trace_new( TL_ERROR, "Bad demod_handle parameter to Hamaro SBRead!\n" );
        error_log( ERROR_WARNING | RC_SDM_BADVAL );
        *status = 1;
        return 0;
    }
    
#if (HAMARO_INCLUDE_RATTLER || HAMARO_INCLUDE_VIPER)        
        
    if (((demod_handle & 0x000000FF) == HAMARO_CX24128_I2C_ADD1) || ((demod_handle & 0x000000FF) == HAMARO_CX24128_I2C_ADD2))
    {
        /* get serial bus address from demod handle */
        serial_bus_addr = (unsigned char)(demod_handle & 0x000000FF);

        #if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
        if ((demod_access_method == DEMOD_HYBRID) || (demod_access_method == DEMOD_REGISTER))
        {
            CNXT_SET( PLL_PAD_FAST_CTRL_REG, PLL_FAST_CTRL_DEMOD_CONNECT_SEL_MASK,
                      PLL_FAST_CTRL_DEMOD_CONNECT_I2C );
        }
        #endif
        
        /* if reading the tuner register, always use the I2C mode. */
        *status = !iicReadIndexedReg( serial_bus_addr, reg_addr, (unsigned char*)&reg_value, demod_iic_bus -1 );
        
        #if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
        if ((demod_access_method == DEMOD_HYBRID) || (demod_access_method == DEMOD_REGISTER))
        {
            CNXT_SET( PLL_PAD_FAST_CTRL_REG, PLL_FAST_CTRL_DEMOD_CONNECT_SEL_MASK,
                      PLL_FAST_CTRL_DEMOD_CONNECT_ASX );
        }
        #endif
    }
#endif
    return reg_value;
}
#endif
/*****************************************************************************/
/*  FUNCTION:    SBWrite                                                     */
/*                                                                           */
/*  PARAMETERS:  demod_handle - handle of demod for write request (San Diego */
/*                   code handle, not multi-instance demod handle).          */
/*               reg_addr - the register offset to be written.               */
/*               data - the data value to be written.                        */
/*               status - pointer to status value filled in at completion    */
/*                   (0 for success, non-0 for failure).                     */
/*                                                                           */
/*  DESCRIPTION: This function writes the specified value to the specified   */
/*               register offset of the specified demod unit.                */
/*                                                                           */
/*  RETURNS:     Nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     Must be called from non-interrupt context.                  */
/*                                                                           */
/*****************************************************************************/
static void SBWrite( unsigned long demod_handle, unsigned char reg_addr, unsigned long data, unsigned long *status )
{
    unsigned char serial_bus_addr;
    unsigned char page_addr;
    volatile unsigned short *sts_reg_addr;
    //unsigned long sts_reg_addr;
    unsigned long reg_value = 0;

    if ( 0 == status )
    {
        trace_new( TL_ERROR, "Bad status parameter to Hamaro SBWrite!\n" );
        error_log( ERROR_WARNING | RC_SDM_BADVAL );
        return;
    }

    if( demod_handle & STS_APPLY_BASE_ADDRESS )
    {
        /* It's a Scan The Sky handle */
        
        reg_value = data;
        /* extract page address from demod handle */
        page_addr    = (demod_handle>>11) & 0x3;
        
        /* 0x304e1000 is the base address for the 32-bit STS memory access          */
        /* copy page address to bit position [9:8] of the 32-bit memory address     */
        /* address bit 0 on the Hamaro side can be wired to bit 10 on the ARM side. */
        /* address bit 1 on the Hamaro side can be wired to bit 11 on the ARM side. */
        sts_reg_addr = (unsigned short *)(STS_BASE_ADDRESS|(page_addr << 8)|(reg_addr & 0xfc)|((reg_addr & 0x3)<<10));
        *sts_reg_addr = reg_value;
        *status      = 0;
       
        return;    
    }
    else if ( demod_handle & 0xfffeff00 )
    {
        trace_new( TL_ERROR, "Bad demod_handle parameter to Hamaro SBWrite!\n" );
        error_log( ERROR_WARNING | RC_SDM_BADVAL );
        *status = 1;
        return;
    }
	
#if (HAMARO_REGISGER_SEM == YES)
    if (RC_OK != sem_get(hamaro_sbrw_semaphore, KAL_WAIT_FOREVER))
    {
        *status = 1; /* indicate failure */
        return;
    }
#endif


#if (HAMARO_INCLUDE_RATTLER || HAMARO_INCLUDE_VIPER)
    
    if (((demod_handle & 0x000000FF) == HAMARO_CX24128_I2C_ADD1) || ((demod_handle & 0x000000FF) == HAMARO_CX24128_I2C_ADD2))
    {
        /* get serial bus address from demod handle */
        serial_bus_addr = (unsigned char)(demod_handle & 0x000000FF);

        #if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
        if ((demod_access_method == DEMOD_HYBRID) || (demod_access_method == DEMOD_REGISTER))
        {
            CNXT_SET( PLL_PAD_FAST_CTRL_REG, PLL_FAST_CTRL_DEMOD_CONNECT_SEL_MASK,
                      PLL_FAST_CTRL_DEMOD_CONNECT_I2C );
        }
        #endif
        /* if writing the tuner register, always use the I2C mode. */
        *status = !iicWriteIndexedReg( serial_bus_addr, reg_addr, data, demod_iic_bus -1);
        
        #if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
        if ((demod_access_method == DEMOD_HYBRID) || (demod_access_method == DEMOD_REGISTER))
        {
            CNXT_SET( PLL_PAD_FAST_CTRL_REG, PLL_FAST_CTRL_DEMOD_CONNECT_SEL_MASK,
                      PLL_FAST_CTRL_DEMOD_CONNECT_ASX );
        }
        #endif
    }
    else
    {
    
#endif

    /* perform the write */
    if ( (demod_access_method == DEMOD_IIC)
#if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
            || ((demod_access_method == DEMOD_HYBRID) &&
                (reg_addr == 0 ||  reg_addr == 0x23 || reg_addr == 0x33 || reg_addr == 0x34 ||
                reg_addr == 0x39 || reg_addr == 0x3a || reg_addr == 0x3b || reg_addr == 0x3c ||
                reg_addr == 0x43 || reg_addr == 0x44))
#endif
        )
    {
        /* get serial bus address from demod handle */
        serial_bus_addr = (unsigned char)(demod_handle & 0x000000FF);

        /* determine DEMOD_A or DEMOD_B register address offset. */
        if ( (demod_handle >> 16) != 0 )
            reg_addr |= 0x80;   /* add 128 to register address. */

#if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
        if ( demod_access_method == DEMOD_HYBRID )
        {
            CNXT_SET( PLL_PAD_FAST_CTRL_REG, PLL_FAST_CTRL_DEMOD_CONNECT_SEL_MASK,
                    PLL_FAST_CTRL_DEMOD_CONNECT_I2C );
        }
#endif

        *status = !iicWriteIndexedReg( serial_bus_addr, reg_addr, data, demod_iic_bus -1 );

#if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
        if ( demod_access_method == DEMOD_HYBRID )
        {
            CNXT_SET( PLL_PAD_FAST_CTRL_REG, PLL_FAST_CTRL_DEMOD_CONNECT_SEL_MASK,
                    PLL_FAST_CTRL_DEMOD_CONNECT_ASX );
        }
#endif
    }
#if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
    else if ( demod_access_method == DEMOD_REGISTER || demod_access_method == DEMOD_HYBRID )
    {
        *(LPREG)INTERNAL_DEMOD_REG_TO_ASX_ADDR(reg_addr) = data;
        *status = 0; /* indicate success */
    }
#endif
    else
    {
        trace_new( TL_ERROR, "Bad demod access method in Hamaro SBWrite!\n" );
        *status = 1; /* indicate failure */
    }
#if (HAMARO_INCLUDE_RATTLER || HAMARO_INCLUDE_VIPER)  
    }      
#endif
#if (HAMARO_REGISGER_SEM == YES)
	 sem_put(hamaro_sbrw_semaphore);
#endif

}

/*****************************************************************************/
/*  FUNCTION:    SBRead                                                      */
/*                                                                           */
/*  PARAMETERS:  demod_handle - handle of demod for read request (San Diego  */
/*                   code handle, not multi-instance demod handle).          */
/*               reg_addr - the register offset to be read.                  */
/*               status - pointer to status value filled in at completion    */
/*                   (0 for success, non-0 for failure).                     */
/*                                                                           */
/*  DESCRIPTION: This function reads from the specified register offset of   */
/*               the specified demod unit and returns the value read.        */
/*                                                                           */
/*  RETURNS:     The value read from the device.                             */
/*                                                                           */
/*  CONTEXT:     Must be called from non-interrupt context.                  */
/*                                                                           */
/*****************************************************************************/
static unsigned long SBRead( unsigned long demod_handle, unsigned char reg_addr, unsigned long *status )
{
    unsigned char serial_bus_addr;
    unsigned long reg_value = 0;
    //unsigned long sts_reg_addr = 0;
    volatile unsigned short *sts_reg_addr=0;
    unsigned char page_addr;

    if ( 0 == status )
    {
        trace_new( TL_ERROR, "Bad status parameter to Hamaro SBRead!\n" );
        error_log( ERROR_WARNING | RC_SDM_BADVAL );
        return 0;
    }

    if( demod_handle & STS_APPLY_BASE_ADDRESS )
    {
        /* It's a Scan The Sky handle */
        
        /* extract page address from demod handle */
        page_addr    = (demod_handle>>11) & 0x3;
        
        /* 0x304e1000 is the base address for the 32-bit STS memory access          */
        /* copy page address to bit position [9:8] of the 32-bit memory address     */
        /* address bit 0 on the Hamaro side can be wired to bit 10 on the ARM side. */
        /* address bit 1 on the Hamaro side can be wired to bit 11 on the ARM side. */
        sts_reg_addr = (unsigned short *)(STS_BASE_ADDRESS |(page_addr << 8)|(reg_addr & 0xfc)|((reg_addr & 0x3)<<10));
        reg_value    = *sts_reg_addr;
        //reg_value = CNXT_GET(sts_reg_addr, 0xFFFF);
        *status      = 0;
        return reg_value;   
    }
    else if ( demod_handle & 0xfffeff00 )
    {

⌨️ 快捷键说明

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