📄 demod_dcf.c
字号:
/****************************************************************************/
/* CONEXANT PROPRIETARY AND CONFIDENTIAL */
/* Conexant Systems Inc. (c) 2007 - 2012 */
/* Shanghai, CHINA */
/* All Rights Reserved */
/****************************************************************************/
/*
* Filename: DEMOD_DCF.C
*
* Description: This file contains the module-level driver for the cable
* front-end interface for use with multi-instance demod.
*
* Author: Gavin Zhang
*
****************************************************************************/
/* $Header: demod_dcf.c, 1, 2007-10-8 13:36:53, Yong Huang$
* $Id: demod_dcf.c,v 1.0, 2007-10-08 05:36:53Z, Yong Huang$
****************************************************************************/
/***************************/
/* Header Files */
/***************************/
#include "stbcfg.h"
#include "hwlib.h"
#include "kal.h"
#include "retcodes.h"
#include "demod_module_api.h"
#include "basetype.h"
#include "iic.h"
/* header file of the cable dcf8722 can tuner driver */
#include "dcf.h"
/***************************/
/* Local Label Definitions */
/***************************/
/* Define the maximum number of cable front-end units in the system */
#define MAXIMUM_NUMBER_UNITS (2)
/* Define the states of cable front-end units in the system */
sem_id_t gsemDCFRegRW = 0;
sem_id_t gsemDCFTask = 0;
static task_id_t gDCFTask = 0;
static u_int32 gu32LocalModule = -1;
static u_int32 gu32Initialized = 0;
static u_int32 gu32LocalUnitCount = 0; /* ONLY ONE UNIT IS SUPPORTED */
static u_int8 gu8DemodAddr[MAXIMUM_NUMBER_UNITS] = {I2C_ADDR_DCF8722, 0xFF};
static MODULE_STATUS_FUNCTION *gpfnCallbacks[MAXIMUM_NUMBER_UNITS];
static TUNING_SPEC gLocalTuning[MAXIMUM_NUMBER_UNITS];
static DCF_NIM NIMs[MAXIMUM_NUMBER_UNITS];
static DCF_TS_OUT gTsOutFormat;
#define DCF_TASK_WAIT_TIME 25
#define DCF_RETRY_NUMBER 6
long n32sweep_rate;
long n32freq_offset;
#if(DCF_INCLUDE_UART_DEBUG)
#include "dcf_parser_cmd.h"
#include "dcf_test.h"
#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* =================================================== */
/* = TIMER, MAIN TASK OF CABLE FRONT-END DRIVER = */
/* =================================================== */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void dcf_task(void *parm);
static DEMOD_STATUS cnxt_dcf_get_unit_type(u_int32 u32Unit, DEMOD_NIM_TYPE *pUnitType);
static DEMOD_STATUS cnxt_dcf_ioctl(u_int32 u32Unit, DEMOD_IOCTL_TYPE eType, void *pData);
static DEMOD_STATUS cnxt_dcf_connect(u_int32 uUnit, TUNING_SPEC *pTuning, u_int32 *pTimeLimit);
static DEMOD_STATUS cnxt_dcf_disconnect(u_int32 u32Unit);
static DEMOD_STATUS cnxt_dcf_get_signal_stats(u_int32 u32Unit, SIGNAL_STATS *pSignalStats);
static DEMOD_STATUS cnxt_dcf_get_lock_status(u_int32 u32Unit, bool *pLocked);
static DEMOD_STATUS cnxt_dcf_get_tuning(u_int32 u32Unit, TUNING_SPEC *pTuning);
static DEMOD_STATUS cnxt_dcf_set_callback(u_int32 u32Unit, MODULE_STATUS_FUNCTION *pfnCallback);
static DEMOD_STATUS cnxt_dcf_clear_callback(u_int32 u32Unit);
/*****************************************************************************/
/* FUNCTION: dcf_wait */
/* */
/* PARAMETERS: n32waitms - millisecond to be delayed. */
/* */
/* DESCRIPTION: Unconditionally wait 'waitms' */
/* */
/* RETURNS: True - successful, False - unsuccessful. */
/* */
/* CONTEXT: Must be called from non-interrupt context. */
/* */
/*****************************************************************************/
static bool dcf_wait(int n32waitms)
{
task_time_sleep(n32waitms);
return(True);
}
/*****************************************************************************/
/* FUNCTION: dcf_pull_high_reset */
/* */
/* PARAMETERS: bFlag - if true, reset DCF8722, or DCF8722 is working in. */
/* normal mode */
/* */
/* DESCRIPTION: Reset DCF8722 */
/* */
/* RETURNS: Nothing. */
/* */
/* CONTEXT: When initializing DCF8722, CPU must pull high this pin */
/* */
/*****************************************************************************/
static void dcf_pull_high_reset(bool bFlag)
{
/* Reset DCF8722 */
if(bFlag == True)
{
set_gpio_output_high(PIO_FE_RESET);
}
/* DCF8722 works in normal mode */
else
{
set_gpio_output_low(PIO_FE_RESET);
}
return;
}
/*****************************************************************************/
/* FUNCTION: BusWrite */
/* */
/* PARAMETERS: u32Handle - device address, not multi-instance demod */
/* handle). */
/* u16RegAddr - the register offset to be written. */
/* u8RegCount - number of register to be written. */
/* pu8Data - the data value to be written. */
/* */
/* DESCRIPTION: This function writes the specified value to the specified */
/* register offset of the specified demod unit. */
/* */
/* RETURNS: True - successful, False - unsuccessful. */
/* */
/* CONTEXT: Must be called from non-interrupt context. */
/* */
/*****************************************************************************/
static bool BusWrite(u_int32 u32Handle, u_int16 u16RegAddr, u_int8 u8RegCount, u_int8 *pu8Data)
{
u_int8 u8IICSlaveAddr ;
IICTRANS iicTransBuf;
u_int8 u8Data[DCF_I2CBF_LEN+2];
u_int8 u8Cmd[DCF_I2CBF_LEN+3];
int i;
DCF_BUS_ACCESS_METHOD BusAccessMethod;
/* sanity check */
if((pu8Data == NULL) || (u8RegCount > DCF_I2CBF_LEN))
return(False);
/* determine what kind of access method: for CNXT internal demod extension
if(u32Handle == demod_handle)
{
if( u16RegAddr == 0x?? )
BusAccessMethod = I2C_BUS_ACCESS;
else
BusAccessMethod = ASX_BUS_ACCESS;
}
else
BusAccessMethod = ASX_BUS_ACCESS; */
BusAccessMethod = I2C_BUS_ACCESS;
switch(BusAccessMethod)
{
case I2C_BUS_ACCESS:
{
/* slave device address */
u8IICSlaveAddr = (unsigned char)(u32Handle & 0xFF);
/* TUA6020 register access deffers from that of other device */
if(u8IICSlaveAddr == DCF_TUNER_I2C_ADDR)
{
/* Slave Address --- IIC_START
register 0 data --- IIC_DATA
register 1 data --- IIC_DATA
register 2 data --- IIC_DATA
register 3 data --- IIC_DATA
--- IIC_STOP */
/* cmd sent to slave device */
u8Data[0] = u8IICSlaveAddr; /* i2c slave address - WR */
for(i = 0; i < u8RegCount; i++)
{
u8Data[i+1] = pu8Data[i];
}
/* cmd type */
u8Cmd[0] = IIC_START;
for(i = 0; i < u8RegCount; i++)
{
u8Cmd[i+1] = IIC_DATA;
}
u8Cmd[u8RegCount+1] = IIC_STOP;
iicTransBuf.dwCount = u8RegCount + 2;
}
else
{
/* Slave Address --- IIC_START
base address/index --- IIC_DATA
base address + 0 data --- IIC_DATA
base address + 1 data --- IIC_DATA
base address + n data --- IIC_DATA
--- IIC_STOP */
/* cmd sent to slave device */
u8Data[0] = u8IICSlaveAddr; /* i2c slave address - WR */
u8Data[1] = (unsigned char)u16RegAddr & 0xFF; /* the register address */
for(i = 0; i < u8RegCount; i++)
{
u8Data[i+2] = pu8Data[i];
}
/* cmd type */
u8Cmd[0] = IIC_START;
for(i = 0; i < u8RegCount+1; i++)
{
u8Cmd[i+1] = IIC_DATA;
}
u8Cmd[u8RegCount+2] = IIC_STOP;
iicTransBuf.dwCount = u8RegCount + 3;
}
iicTransBuf.pData = u8Data;
iicTransBuf.pCmd = u8Cmd;
/* send out CMD */
if(iicTransaction(&iicTransBuf, (unsigned char)I2C_BUS_DCF) != TRUE)
return(False);
break;
}
case ASX_BUS_ACCESS:
break;
default:
debug_out(TL_ERROR, "DCF does not support this type of access method.\n");
break;
}/* end of switch(BusAccessMethod)*/
/* sanity check */
if(pu8Data == NULL)
return(False);
return(True);
}
/*****************************************************************************/
/* FUNCTION: SBRead */
/* */
/* PARAMETERS: u32Handle - device address, not multi-instance demod handle.*/
/* u16RegAddr - the register offset to be read. */
/* u8RegCount - number of register to be written. */
/* pu8Data - pointer to register value. */
/* */
/* DESCRIPTION: This function reads from the specified register offset of */
/* the specified demod unit and returns the value read. */
/* */
/* RETURNS: True - successful, False - unsuccessful. */
/* */
/* CONTEXT: Must be called from non-interrupt context. */
/* */
/*****************************************************************************/
static bool BusRead(u_int32 u32Handle, u_int16 u16RegAddr, u_int8 u8RegCount, u_int8 *pu8Data)
{
u_int8 u8IICSlaveAddr ;
IICTRANS iicTransBuf;
u_int8 u8Data[DCF_I2CBF_LEN+2];
u_int8 u8Cmd[DCF_I2CBF_LEN+3];
int i;
DCF_BUS_ACCESS_METHOD BusAccessMethod;
/* sanity check */
if((pu8Data == NULL) || (u8RegCount > DCF_I2CBF_LEN))
return(False);
/* determine what kind of access method: for CNXT internal demod extension
if(u32Handle == demod_handle)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -