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

TXT
1,683
字号
/****************************************************************************/
/*                   CONEXANT PROPRIETARY AND CONFIDENTIAL                  */
/*                     Conexant Systems Inc. (c) 2002                       */
/*                              Austin, TX                                  */
/*                         All Rights Reserved                              */
/****************************************************************************/
/*
 * Filename: multi_demod.c
 *
 * Description: This file contains the implementation of the user-level
 *              interface to multi-instance demod.
 *
 * Author: Billy Jackman
 *
 ****************************************************************************/
/* $Id: demod.c,v 1.24, 2004-03-15 16:33:03Z, Matt Korte$
 ****************************************************************************/

#include <stdlib.h>
#include <string.h>

#include "hwconfig.h"
#include "basetype.h"
#include "demod_user_api.h"
#include "demod_module_api.h"
#include "hwlib.h"
#include "kal.h"
#include "retcodes.h"
#include "CS_typedef.h"
#include "hamaro_sts.h"
#include "cs_qpsk.h"
#include "Apifix.h"
#include "h_skyscan_app.h"
/* Provide an upper limit on the number of modules handled in a
   system so we can allocate some data structures statically. */
#define MAX_MODULES  (8)

/* Provide an upper limit on the number of units handled in a
   system so we can allocate some data structures statically.
   This value is based upon MAX_MODULES, but it is not magic.
   Some modules will have a single unit, some may have two or
   more.  Set it to what is needed. */
#define MAX_UNITS (MAX_MODULES * 2)

/* Allow up to 4 opens and callbacks registered per unit. */
#define MAX_CALLBACKS   (4)

/* Just a magic number to appear in a handle. */
#define HANDLE_MAGIC       (0x00c00000)
#define HANDLE_MAGIC_MASK  (0x0ff00000)

/* Define the init pointers for all the demod drivers.  NULL is
   not present.  Adding a new kind of demod to the system will
   require adding a block here and a line in the definition of
   the demod_init array. */

/* The demod_baseband driver is the module that supports the
   baseband input. */
#ifdef DRIVER_INCL_DEMOD_BASEBAND
extern INIT_FUNC  cnxt_baseband_demod_init;
#define DVB_BASEBAND & cnxt_baseband_demod_init
#else
#define DVB_BASEBAND 0
#endif

/* The satellite_110 driver supports the CX24106 (HM1221) and
   CX24110 chips. */
#ifdef DRIVER_INCL_DEMOD_VALIANT
extern INIT_FUNC  cnxt_single_cx24110_demod_init;
#define SAT_110   & cnxt_single_cx24110_demod_init
#else
#define SAT_110   0
#endif

/* The demod_cobra driver supports the CX24121 and CX24130
   Cobra chips. */
#ifdef DRIVER_INCL_DEMOD_COBRA
extern INIT_FUNC  cnxt_cobra_demod_init;
#define SAT_COBRA & cnxt_cobra_demod_init
#else
#define SAT_COBRA 0
#endif

/* The demod_hamaro driver supports the CX24121 and CX24130
   hamaro chips. */
#if 1//def DRIVER_INCL_DEMOD_HAMARO
extern INIT_FUNC  cnxt_hamaro_demod_init;
#define SAT_HAMARO & cnxt_hamaro_demod_init
#else
#define SAT_HAMARO 0
#endif

/* The terrestrial driver supports the CX22702 chip. */
#ifdef DRIVER_INCL_DEMOD_TERRESTRIAL
extern INIT_FUNC  cnxt_terrestrial_demod_init;
#define TERRESTRIAL  & cnxt_terrestrial_demod_init
#else
#define TERRESTRIAL  0
#endif

/* The analogue terrestrial driver supports the MACO chip. */
#ifdef DRIVER_INCL_DEMOD_ANALOGUE_TERRESTRIAL
extern INIT_FUNC              cnxt_analogue_terrestrial_demod_init;
#define ANALOGUE_TERRESTRIAL  & cnxt_analogue_terrestrial_demod_init
#else
#define ANALOGUE_TERRESTRIAL  0
#endif

#ifdef DRIVER_INCL_DEMOD_CX24430
extern INIT_FUNC              cnxt_24430_demod_init;
#define CABLE_WABASH & cnxt_24430_demod_init
#else
#define CABLE_WABASH 0
#endif

/* The cable front-end driver supports the Thomson DCF8722 can tuner. */
#ifdef DRIVER_INCL_DEMOD_DCF8722
extern INIT_FUNC              cnxt_cable_demod_init;
#define CABLE_DCF8722 & cnxt_cable_demod_init
#else
#define CABLE_DCF8722 0
#endif

static INIT_FUNC              *demod_init[] =
{
   DVB_BASEBAND,
   SAT_110,
   SAT_COBRA,
   SAT_HAMARO,
   TERRESTRIAL,
   ANALOGUE_TERRESTRIAL,
   CABLE_DCF8722,
   CABLE_WABASH
};

static u_int32                total_number_units;
static u_int32                demod_initialized = 0;

static u_int32                module_base_unit[MAX_MODULES];
static DEMOD_FTABLE           function_table[MAX_MODULES];
static DEMOD_STATUS_FUNCTION   *callback_table[MAX_UNITS][MAX_CALLBACKS];
static u_int32                unit_xlat_table[MAX_UNITS];
static u_int32                is_controlled[MAX_UNITS];
static u_int32                open_flag[MAX_UNITS][MAX_CALLBACKS];
u_int32 dwNimCount;
u_int32 dwQpskHandle;

/* stuff for state machine */
typedef enum
{
   DISCONNECTED,
   ACQUIRING_SIGNAL,
   RE_ACQUIRE,
   CALL_CONNECT,
   CONNECTED,
   CALL_DISCONNECT,
   LOCK_LOST,
   LOCK_WANTED,
   INIT_SCAN,
   SCAN_NEXT
} STATE_LIST;

typedef enum
{
   JUST_LOST,
   BOUNCING,
   BOUNCED_OUT,
   LOCKED_OUT
} DEBOUNCE_STATUS;

static int debounce_status_array[MAX_UNITS];

typedef struct
{
   bool        scanning;
   STATE_LIST  state;
   TUNING_SPEC requested_tuning_spec;  /* This is a record of the original connect */
   TUNING_SPEC tuning_spec;
   SCAN_SPEC   scanning_spec;
} UNIT_STATE;

static UNIT_STATE unit_state_machine_info[MAX_UNITS];

/* functions with file scope */
static u_int32    change_demod_state(u_int32     unit,
                                                       u_int32     module,
                                                       STATE_LIST  state);
static bool       tuning_spec_equal(TUNING_SPEC ts1, TUNING_SPEC ts2);

typedef struct
{
   int   connection_timer;
   bool  flag;
} TIMER_STR;

static TIMER_STR  unit_timer[MAX_UNITS];

/* macro to work out the global unit number */
#define GLOBAL_UNIT_NUMBER (unit + module_base_unit[module])

/*****************************************************************************/
/*  FUNCTION:    local_callback                                              */
/*                                                                           */
/*  PARAMETERS:  module - the module number of the caller of this status     */
/*                   function.                                               */
/*               unit - the unit number of the caller of this status         */
/*                   function.                                               */
/*               type - the enumerated type of the status callback.          */
/*               callback_data - pointer to data structure containing data   */
/*                   about this status callback.                             */
/*                                                                           */
/*  DESCRIPTION: This function serves as an intermediary for module level    */
/*               status callbacks.  When a user registers a status callback  */
/*               function, that callback address is saved locally.  This     */
/*               function is then registered with the module level driver as */
/*               its status function callback.  That way when the module     */
/*               makes a status callback, this function receives it and can  */
/*               translate <module,unit> to the appropriate flat unit        */
/*               callback.                                                   */
/*                                                                           */
/*  RETURNS:     nothing.                                                    */
/*                                                                           */
/*  CONTEXT:     May be called from an interrupt or non-interrupt context.   */
/*                                                                           */
/*****************************************************************************/
static void local_callback(u_int32              module,
                           u_int32              unit,
                           DEMOD_CALLBACK_TYPE  type,
                           void                 *callback_data)
{
   int   ii;

   /* Convert from module/unit to flat unit. */
   unit += module_base_unit[module];

   /* Fork this callback out for all registered clients for this unit. */
   for (ii = 0; ii < MAX_CALLBACKS; ++ii)
   {
      if (callback_table[unit][ii])
      {
         callback_table[unit][ii](unit, type, callback_data);
      }
   }
}

/******************************************************************************/
/* Function Name: StateTask                                                   */
/*                                                                            */
/* Description  : The KAL task which keeps the satellite NIM in acquisition.  */
/*                                                                            */
/* Parameters   : parm         Pointer to parameter block - not used          */
/*                                                                            */
/* Returns      : Nothing - Never Terminates                                  */
/*                                                                            */
/******************************************************************************/

#define DEMOD_Q_TIMEOUT (35)  /* Queue wait timeout (ms) */

#define STATE_INFO(x)   (unit_state_machine_info[x])
#define MY_MODULE(x)    (unit_xlat_table[x])
#define MY_UNIT(x)      ((x) - module_base_unit[MY_MODULE(x)])

static u_int32 debounce_time = 250;
#define NUMBER_DEBOUNCE    (5)
#define DEBOUNCE_TIMEOUT   (debounce_time / NUMBER_DEBOUNCE)
#define POLL_TIMEOUT       (250)

void cnxt_demod_set_debounce_time(u_int32 time)
{
   debounce_time = time;
}

static queue_id_t          demod_queue;
static DEMOD_CALLBACK_DATA callback_struct;
static int nCallBacked = 0;
static int nResult;
static unsigned long  nPercent;

static void call_back(u_int32              unit,
                      DEMOD_CALLBACK_TYPE  type,
                      DEMOD_ASYNC_RESULT   result,
                      TUNING_SPEC          *tune_spec)
{
   callback_struct.parm.type = result;
   if (tune_spec != NULL)
   {
      callback_struct.parm.tune = *tune_spec;
   }
   else  /* No tuning spec supplied means call to get_tuning is required */
   {
      if (function_table[MY_MODULE(unit)].get_tuning != NULL)
      {
         function_table[MY_MODULE(unit)].get_tuning(MY_UNIT(unit),
                                                    &(callback_struct.parm.tune));
      }
      else
      {
         callback_struct.parm.tune = unit_state_machine_info[unit].tuning_spec;
      }
   }

   local_callback(MY_MODULE(unit), MY_UNIT(unit), type, &callback_struct);
   return;
}

static DEBOUNCE_STATUS get_debounce(u_int32 unit)
{
   DEBOUNCE_STATUS   retval;
   switch (debounce_status_array[unit])
   {
   case 1:
      retval = BOUNCED_OUT;
      debounce_status_array[unit] = 0;
      break;
   case 0:
      retval = LOCKED_OUT;
      break;
   case (-1):
      debounce_status_array[unit] = NUMBER_DEBOUNCE;
      retval = JUST_LOST;
      break;
   default:
      debounce_status_array[unit]--;
      retval = BOUNCING;
      break;
   }

   return(retval);
}

static void un_debounce(u_int32 unit)
{
   debounce_status_array[unit] = 1;
   return;
}

static void set_debounce(u_int32 unit)

⌨️ 快捷键说明

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