demod_hamaro.c

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

C
1,447
字号
/****************************************************************************/ 
/*                   CONEXANT PROPRIETARY AND CONFIDENTIAL                  */
/*                     Conexant Systems Inc. (c) 2002                       */
/*                              Austin, TX                                  */
/*                         All Rights Reserved                              */
/****************************************************************************/
/*
 * Filename: demod_cobra.c
 *
 * Description: This file contains the implementation of the driver module
 *              for the Hamaro family of demod chips (CX24121 and CX24130).
 *              This driver also works for the Camaro/Camaric family.
 *
 * Author: Billy Jackman
 *
 ****************************************************************************/
/* $Id: demod_cobra.c,v 1.37, 2004-07-15 23:06:39Z, Xin Golden$
 ****************************************************************************/

#include "stbcfg.h"
#include "basetype.h"
#include "iic.h"
#include "trace.h"
#include "kal.h"
#include "retcodes.h"
#undef BYTE
#include "demod_module_api.h"
#include "hamaro.h"
#include "lnb.h"

/* This driver works for both the CX24121 (one unit) and CX24130 (two units).
   If you add support for another Hamaro chip with more units, you must check
   for arrays declared with this extent and given initial values.  You must
   assign the appropriate initial values for added units. */
#define MAXIMUM_NUMBER_UNITS (2)

/* These defines are for local state values. */
#define UNINITIALIZED (0)
#define DISCONNECTED (1)
#define CONNECTING (2)
#define CONNECTED (3)
#define SCANNING (4)
#define FADE (5)

/* These defines are for internal commands. */
#define HAMARO_CONNECT (1)
#define HAMARO_DISCONNECT (2)
#define HAMARO_SCAN (3)
#define HAMARO_TIMEOUT (4)
#define HAMARO_INTERRUPT (5)


#ifndef STS_BASE_ADDRESS
#define  STS_BASE_ADDRESS               0x304E1000
#define  STS_APPLY_BASE_ADDRESS         0x00000400  /* Specifies the host SW to use STS base address and do a STS IO */
#endif


/*
 * This global varibale is used to identify the current using NIM,
 * It will be only used by the satellite scan-sky module.
 */
NIM            currentNIM;

/*
 * Add skyscan_flag to supporting the satellite scan-sky function,
 * The default value of skyscan_flag is 0. If it is set to 1, the 
 * hamaro_task will do nothing, and the front end is controlled by 
 * the satellite scan-sky module.
 */
static int     skyscan_flag = 0;

int g_nTunerType = 0;

/* These definitions are related to the Hamaro task message queue. */
#define MAX_HAMARO_MSGS (16)
static queue_id_t hamaro_message_q = (queue_id_t)0;

/* These definitions are related to interrupt operation. */
#define HAMARO_NO_INTERRUPTS (0)
#define HAMARO_CONNECTING_INTERRUPTS (INTR_ACQ_SYNC)
#define HAMARO_SCANNING_INTERRUPTS (INTR_ACQ_SYNC|INTR_ACQ_FAILURE)
#define HAMARO_CONNECTED_INTERRUPTS (INTR_ACQ_FAILURE)
#define HAMARO_NIM_INT INT_GPIO69
#define HAMARO_GPIO_INTERRUPT 69
#define HAMARO_INTERRUPT_BANK   (HAMARO_GPIO_INTERRUPT >> 5)
#define HAMARO_INTERRUPT_BIT    (HAMARO_GPIO_INTERRUPT & 31)
static PFNISR chained_isr = 0;
#define DEMOD_CONNECT_COUNTDOWN (256)
#define DEMOD_SCAN_COUNTDOWN (256)
static u_int32 demod_interrupt = 0;

/* These definitions are related to the tick timer.  Timeout values are in
   milliseconds. */
#if (INTERNAL_DEMOD == INTERNAL_COBRA_LIKE)
#define HAMARO_CONNECTING_TIMEOUT 5000
#define HAMARO_SCANNING_TIMEOUT 5000
#else
#define HAMARO_CONNECTING_TIMEOUT 500
#define HAMARO_SCANNING_TIMEOUT 500
#endif
tick_id_t hHamaroTick[MAXIMUM_NUMBER_UNITS] = { 0, 0 };

#if (HAMARO_REGISGER_SEM == YES)
#define DMD1_SEM_NAME   "DMD1"
#define DMD2_SEM_NAME   "DMD2"
sem_id_t hamaro_sbrw_semaphore = (sem_id_t)(0);
sem_id_t hamaro_regrw_semaphore = (sem_id_t)(0);
#endif


#define BER_WINDOW_SIZE (255)

/* These definitions are related to the demod access method, IIC or ASX. */
#define DEMOD_INITIAL  (0)
#define DEMOD_IIC      (1)
#define DEMOD_REGISTER (2)
#define DEMOD_HYBRID   (3)

static u_int32 demod_access_method = DEMOD_INITIAL;
u_int32 demod_iic_bus = I2C_BUS_NONE;

/* Per-unit data structures. */
static u_int32 local_state[MAXIMUM_NUMBER_UNITS];
static TUNING_SPEC local_tuning[MAXIMUM_NUMBER_UNITS];
static MODULE_STATUS_FUNCTION *callbacks[MAXIMUM_NUMBER_UNITS] = { 0, 0 };
static NIM NIMs[MAXIMUM_NUMBER_UNITS];
static ACQSTATE OldAcqState[MAXIMUM_NUMBER_UNITS];
static LOCKIND OldLock[MAXIMUM_NUMBER_UNITS];
static ACQSTATE NewAcqState[MAXIMUM_NUMBER_UNITS];
static LOCKIND NewLock[MAXIMUM_NUMBER_UNITS];
static int demod_handle[MAXIMUM_NUMBER_UNITS] = { 0, 0 };
static SCAN_SPEC local_scan[MAXIMUM_NUMBER_UNITS];
static u_int32 local_symrates[MAXIMUM_NUMBER_UNITS][16];
static NIM_SATELLITE_POLARISATION local_polarizations[MAXIMUM_NUMBER_UNITS][16];
static u_int32 local_viterbis[MAXIMUM_NUMBER_UNITS];
static struct {
    u_int32 current_symbol_rate;
    u_int32 current_frequency;
    u_int32 current_polarity;
} scan_parms[MAXIMUM_NUMBER_UNITS];
static u_int32 acq_failure_countdown[MAXIMUM_NUMBER_UNITS] = { 0, 0 };

/* Global tuning structure. */
static MPEG_OUT MPEG;

/* Global flags and counters. */
static u_int32 my_module = -1;
static u_int32 initialized = 0;
static int local_unit_count = 0;
static int global_timeout_flag = 0;
static int global_interrupt_flag = 0;
#if HAMARO_INCLUDE_RATTLER
#define HAMARO_SEM_NAME   "HAMARO_S"
sem_id_t hamaro_semaphore = (sem_id_t)(0);
#endif
/* This are the default code rates to try when connecting in auto fec mode */
static unsigned int viterbicoderates = CODERATE_2DIV3 | CODERATE_3DIV4 | CODERATE_4DIV5 | CODERATE_5DIV6 | CODERATE_6DIV7 | CODERATE_7DIV8;

/* Some handy tags for trace level specifications. */
#define TL_ALWAYS  (TRACE_LEVEL_ALWAYS | TRACE_DMD)
#define TL_ERROR   (TRACE_LEVEL_ALWAYS | TRACE_DMD)
#define TL_INFO    (TRACE_LEVEL_3 | TRACE_DMD)
#define TL_FUNC    (TRACE_LEVEL_2 | TRACE_DMD)
#define TL_VERBOSE (TRACE_LEVEL_1 | TRACE_DMD)
extern  LNB_SETTINGS lnb_parameters;

void delay1ms(u_int32 nTimes)
{
   u_int32 pollDelay, toDo;
 
   for(toDo=0; toDo<nTimes; toDo++)
   {
     for(pollDelay=0; pollDelay<0x444; pollDelay++)
     {
       /* takes 1 ms at 133MHz */
     }
   }
}

/*****************************************************************************/
/*  FUNCTION:    NIM_Wait                                                    */
/*                                                                           */
/*  PARAMETERS:  nim - pointer to the NIM structure of the NIM requesting    */
/*                   the delay.                                              */
/*               waitms - the number of milliseconds to delay.               */
/*                                                                           */
/*  DESCRIPTION: This function is used by the NIM-specific code to provide   */
/*               an OS dependent method to delay a specified number of       */
/*               milliseconds.                                               */
/*                                                                           */
/*  RETURNS:     TRUE to indicate success.                                   */
/*                                                                           */
/*  CONTEXT:     Must be called from non-interrupt context.                  */
/*                                                                           */
/*****************************************************************************/
static BOOL NIM_Wait( NIM *nim, int waitms )
{
    task_time_sleep( waitms );
    return TRUE;
}
#if HAMARO_INCLUDE_RATTLER
/*****************************************************************************/
/*  FUNCTION:    TunerSBWrite                                                     */
/*                                                                           */
/*  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.                  */
/*                                                                           */
/*****************************************************************************/
void TunerSBWrite( 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_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
    }
#endif
}
/*****************************************************************************/
/*  FUNCTION:    TunerSBRead                                                      */

⌨️ 快捷键说明

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