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

📄 demod_dcf.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
   }
   
   if(NIMs[u32Unit].cur_state == DCF_NIM_UNINITIALIZED)
   {
      return(DEMOD_BAD_UNIT);
   }
   
   if(NULL == pLocked)
   {
      return(DEMOD_BAD_PARAMETER);
   }
   
   /* return the current lock status of the unit. */
   if(NIMs[u32Unit].cur_state == DCF_NIM_LOCKED)
   {
      *pLocked = TRUE;
   }
   else
   {
      *pLocked = FALSE;
   }
   
   return(DEMOD_SUCCESS);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*               =========================================                   */
/*               = ENTRY POINT OF CABLE FRONT-END DRIVER =                   */
/*               =========================================                   */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*****************************************************************************/
/*  FUNCTION:    cnxt_dcf_demod_init                                         */
/*                                                                           */
/*  PARAMETERS:  u32Module  - the module designation to be used by this      */
/*                            driver in subsequent callbacks.                */
/*                                                                           */
/*               pu32NumberUnits - the pointer to an integer to be filled    */
/*                                 with the total number of units in this    */
/*                                 module.                                   */
/*                                                                           */
/*               pfnFTable    - the pointer to the DEMOD_FTABLE structure to */
/*                              be filled out with function pointers for the */
/*                              module.                                      */
/*                                                                           */
/*  DESCRIPTION: This function initializes the module and returns a count of */
/*               units in the module and the function table for module       */
/*               functions.                                                  */
/*                                                                           */
/*  RETURNS:     DEMOD_SUCCESS - the function completed successfully.        */
/*               DEMOD_INITIALIZED - this module has been initialized.       */
/*               DEMOD_BAD_PARAMETER - there is a bad parameter.             */
/*               DEMOD_NO_HARDWARE - there is no NIM hardware in the system. */
/*               DEMOD_ERROR - An error was received from a call             */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEMOD_STATUS cnxt_cable_demod_init (u_int32 u32Module, u_int32 *pu32NumberUnits, DEMOD_FTABLE *pfnFTable)
{
   int32   ii;
	  
   debug_out(TL_FUNC, "CABLE INIT: Entered initialization uModule 0x%02X\n", u32Module);
   
   if(gu32Initialized)
   {
      debug_out(TL_ERROR, "CABLE INIT: Already been initialized\n");
      return(DEMOD_INITIALIZED);
   }
   
   /*   check whether the input parameters are valid.*/
   if(NULL == pu32NumberUnits)
   {
      debug_out(TL_ERROR, "CABLE INIT: Bad parameter - pNumberUnits\n");
      return(DEMOD_BAD_PARAMETER);
   }
   
   if(NULL == pfnFTable)
   {
      debug_out(TL_ERROR, "CABLE INIT: Bad parameter - pfnFTable\n");
      return(DEMOD_BAD_PARAMETER);
   }
   
   /* set the RESET GPIO to high to pull NIM out of reset */
   dcf_pull_high_reset(True);

   /* create the semaphore to be used to protect the cable front-end */
   gsemDCFRegRW = sem_create(1, "DCF_REG");
   if(gsemDCFRegRW == (sem_id_t)(0))
   {
      debug_out (TL_ERROR, "CABLE INIT: Can't create REG R/W semaphore\n");
      return(DEMOD_ERROR);
   }
   
   /* create the semaphore to be used to implement mutex in control task */
   gsemDCFTask = sem_create(1, "DCF_TASK");
   if(gsemDCFTask == (sem_id_t)(0))
   {
      debug_out (TL_ERROR, "CABLE INIT: Can't create control task semaphore\n");
      return(DEMOD_ERROR);
   }
   
   /*  check whether the NIM hardwares to be initialized are valid. */
   gu32LocalUnitCount = 0;
   
   for(ii=0; ii<(MAXIMUM_NUMBER_UNITS); ii++)
   {
      if(FALSE == iicAddressTest(gu8DemodAddr[ii], I2C_BUS_DCF, 0))
      {
         debug_out(TL_INFO, "CABLE INIT: Unit %d is not found at i2c addr 0x%03X\n", ii, gu8DemodAddr[ii]);
         NIMs[ii].cur_state = DCF_NIM_NOHARDWARE;
      }
      else
      {
         debug_out(TL_INFO, "CABLE INIT: Unit %d is found at i2c addr 0x%03X\n", ii, gu8DemodAddr[ii]);
         NIMs[ii].cur_state = DCF_NIM_UNINITIALIZED;
         gu32LocalUnitCount++;
      }
   }
   
   /* detect no hardware */
   if(0 == gu32LocalUnitCount)
   {
      debug_out(TL_ERROR, "CABLE INIT: No hardware is detected\n");
      return(DEMOD_NO_HARDWARE);
   }
   
   /**************************************************************************/
   /*   initialize the found NIM interfaces.
    */
   for(ii=0; ii<gu32LocalUnitCount; ii++)
   {
      /* clear the callback function pointer */
      gpfnCallbacks[ii] = 0;
      gTsOutFormat.TsOutMode = DCF_PARALLEL_OUT;
      gTsOutFormat.TsClkPar = DCF_FALLING_EDGE;
      gTsOutFormat.TsClkGatting = DCF_CLK_GATTING_OFF;

      /* initialize the Cable NIM */
      if(dcf_init_environment(&NIMs[ii], gu8DemodAddr[ii], BusWrite, BusRead, DCF_TUNER_install_TUA6020, 28800, &gTsOutFormat, &dcf_wait) != True)
      {
         debug_out(TL_ERROR, "CABLE INIT: Low level driver initial fail!\n");
         return(DEMOD_ERROR);
      }
      
      /* update the state */
      NIMs[ii].cur_state = DCF_NIM_INITIALIZED;
      
   }

   /* initialize the functions table for this module type */
   pfnFTable->unit_type      = cnxt_dcf_get_unit_type;
   pfnFTable->ioctl          = cnxt_dcf_ioctl;
   pfnFTable->connect        = cnxt_dcf_connect;
   pfnFTable->disconnect     = cnxt_dcf_disconnect;
   pfnFTable->get_signal     = cnxt_dcf_get_signal_stats;
   pfnFTable->get_lock       = cnxt_dcf_get_lock_status;
   pfnFTable->get_tuning     = cnxt_dcf_get_tuning;
   pfnFTable->set_callback   = cnxt_dcf_set_callback;
   pfnFTable->clear_callback = cnxt_dcf_clear_callback;

   /* how many units are supported -- MUST BE ONLY ONE */
   *pu32NumberUnits = gu32LocalUnitCount;
   gu32LocalModule = u32Module;
   gu32Initialized = 1;

   /* create the task to be used to process the messages from the DEMOD ISR */
   gDCFTask = task_create(dcf_task, NULL, NULL, (NIM_TASK_STK_SIZE),
                           (NIM_TASK_PRIORITY), (NIM_TASK_NAME));
   if(gDCFTask == (task_id_t)(0))
   {
      debug_out(TL_ERROR, "CABLE INIT: Can't create task\n");
      return(DEMOD_ERROR);
   }
   
   debug_out(TL_FUNC, "CABLE INIT: Finished initialization uModule 0x%02X\n", u32Module);

#if DCF_INCLUDE_UART_DEBUG
   if(cnxt_drvtest_init() != DRVTEST_OK)
      debug_out(TL_ALWAYS, "DCF UART test Task initialize failed!\n");
#endif /*DCF_INCLUDE_UART_DEBUG*/
   return(DEMOD_SUCCESS);
}

#if DCF_INCLUDE_UART_DEBUG
/********************/
/* Global Variables */
/********************/
CNXT_DRVTEST_STATUS dcf_set_sweep_rate(u_int8* pszStr, u_int8* pszFmt)
{    
   long   n32SweepRate=0;
    
   debug_out(TL_ALWAYS, "\n\n Set sweep rate++++++++++\n");
   if(!cnxt_drvtest_get_cmd_para(1, pszStr, pszFmt, &n32SweepRate))
   {
      n32sweep_rate = n32SweepRate;
      return(DRVTEST_OK);
   }
   else
   {
      return(DRVTEST_ERROR);
   }
}

CNXT_DRVTEST_STATUS dcf_set_freq_offset(u_int8* pszStr, u_int8* pszFmt)
{   
   long   n32FreqOffset=0;
    
    debug_out(TL_ALWAYS, "\n\n Set freq offset++++++++++\n");
   if(!cnxt_drvtest_get_cmd_para(1, pszStr, pszFmt, &n32FreqOffset))
   {
      n32freq_offset = n32FreqOffset;
      debug_out(TL_ALWAYS, "Freq offset=%d\n", n32FreqOffset);
      return(DRVTEST_OK);
   }
   else
   {
      return(DRVTEST_ERROR);
   }
}

CNXT_DRVTEST_STATUS dcf_write_demod(u_int8* pszStr, u_int8* pszFmt)
{   
   unsigned char u8DemodRegAddr;
   unsigned char u8DemodRegVal;
    
    debug_out(TL_ALWAYS, "\n\n Write Demod REG++++++++++\n");
   if(!cnxt_drvtest_get_cmd_para(2, pszStr, pszFmt, &u8DemodRegAddr, &u8DemodRegVal))
   {

      if(DCF_RegWrite(&NIMs[0], u8DemodRegAddr, 1, &u8DemodRegVal, DCF_DEMOD_I2C) == True)
      {
         debug_out(TL_ALWAYS, "Write 0x%2X 0x%2X\n", u8DemodRegAddr, u8DemodRegVal);
         return(DRVTEST_OK);
      }
      else
	  return(DRVTEST_ERROR);
   }
   else
   {
      return(DRVTEST_ERROR);
   }
}

CNXT_DRVTEST_STATUS dcf_read_demod(u_int8* pszStr, u_int8* pszFmt)
{   
   unsigned u8DemodRegAddr;
   unsigned char u8DemodRegVal;
    
    debug_out(TL_ALWAYS, "\n\n Read REG++++++++++\n");
   if(!cnxt_drvtest_get_cmd_para(1, pszStr, pszFmt, &u8DemodRegAddr))
   {
      if(DCF_RegRead(&NIMs[0], u8DemodRegAddr, 1, &u8DemodRegVal, DCF_DEMOD_I2C) == True)
      {
         debug_out(TL_ALWAYS, "Read 0x%2X 0x%2X\n", u8DemodRegAddr, u8DemodRegVal);
         return(DRVTEST_OK);
      }
      else
      {
         return(DRVTEST_ERROR);
      }
   }
   else
   {
      return(DRVTEST_ERROR);
   }
}

CNXT_DRVTEST_CMD cmd_format_demod[DRVTEST_ITEM_NUM_DEMOD] =
{ 
    "sr %d",
    "fo %d",
    "wd %d %d",
    "rd %d"
};

drvtest_cmd_callback cmd_callback_demod[DRVTEST_ITEM_NUM_DEMOD] = 
{
    dcf_set_sweep_rate,
    dcf_set_freq_offset,
    dcf_write_demod,
    dcf_read_demod
};
#endif /* DCF_INCLUDE_UART_DEBUG*/

/****************************************************************************
 * Modifications:
 * $Log:
 *  1    Virgo      1.0         2007-10-8 13:36:53     Yong Huang
 *       Restructure DCF8722 driver
 * $
 *
 ****************************************************************************/

⌨️ 快捷键说明

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