📄 demod_hamaro.c
字号:
/****************************************************************************/
/* CONEXANT PROPRIETARY AND CONFIDENTIAL */
/* Conexant Systems Inc. (c) 2002 */
/* Austin, TX */
/* All Rights Reserved */
/****************************************************************************/
/*
* Filename: demod_hamaro.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_hamaro.c,v 1.22, 2007-08-17 07:35:30Z, Tim Lu$
****************************************************************************/
#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)
#define CONT_CONNECTING (6)
/* 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)
#define HAMARO_DISEQC_SEND (6)
#define HAMARO_DISEQC_RECEIVE (7)
#define HAMARO_SIGSTATS (8)
#define HAMARO_SET_SIGPATH (9)
#define HAMARO_SET_POL (10)
#define HAMARO_SET_TONE (11)
static unsigned int diseqc_state; /* global variable to communicate between task and caller */
static unsigned int sigstats_state; /* global variable to communicate between task and caller */
static unsigned int pol_state;
static unsigned int tone_state;
#define DISEQC_REQUESTED 1
#define DISEQC_COMPLETE 2
#define DISEQC_FAILED 3
#define POL_REQUESTED 1
#define POL_COMPLETE 2
#define POL_FAILED 3
#define TONE_REQUESTED 1
#define TONE_COMPLETE 2
#define TONE_FAILED 3
#define SIGSTATS_REQUESTED 1
#define SIGSTATS_COMPLETE 2
#define SIGSTATS_FAILED 3
#define MSG_REV_TIME 10
#define MSG_FADE_BACK_TIME 15
#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;
/* 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 DEMOD_CONNECT_COUNTDOWN (256)
#define DEMOD_SCAN_COUNTDOWN (256)
/* 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 };
#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 DISEQC_MESSAGE local_diseqcmsg[MAXIMUM_NUMBER_UNITS];
static NIM_SATELLITE_POLARISATION local_polmsg[MAXIMUM_NUMBER_UNITS];
static bool local_tonemsg[MAXIMUM_NUMBER_UNITS];
static SIGNAL_STATS local_sigstats[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;
/* 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)
static void process_signal_stats_message(int unit, SIGNAL_STATS *signal_stats);
static void process_set_pol_message(int unit, NIM_SATELLITE_POLARISATION *data);
static void cnxt_demod_reset_sig_path();
static BOOL NIM_Wait( NIM *nim, int waitms );
/*****************************************************************************/
/* FUNCTION: xlat_diseqc_rxmode */
/* */
/* PARAMETERS: rxmode - The RX mode to receive DiSEqC message. */
/* */
/* DESCRIPTION: This function translates an RX mode from the enumeration */
/* used by multi-instance demod to that used by San Diego */
/* driver code. */
/* */
/* RETURNS: The San Diego driver code equivalent RX mode. */
/* */
/* CONTEXT: May be called from interrupt or non-interrupt context. */
/* */
/*****************************************************************************/
static RXMODE xlat_diseqc_rxmode( DISEQC_RXMODE rxmode )
{
switch ( rxmode )
{
case DISEQC_RXMODE_INTERROGATION: return RXMODE_INTERROGATION;
case DISEQC_RXMODE_QUICKREPLY: return RXMODE_QUICKREPLY;
case DISEQC_RXMODE_NOREPLY: return RXMODE_NOREPLY;
case DISEQC_RXMODE_DEFAULT: return RXMODE_DEFAULT;
default: return RXMODE_DEFAULT;
}
}
/*****************************************************************************/
/* FUNCTION: process_diseqc_send_message */
/* */
/* PARAMETERS: unit - the unit number for which the ioctl operation is */
/* requested. */
/* diseqc_message - address of DiSEqC message data */
/* */
/* DESCRIPTION: This function implements the internal function to send a */
/* DiSEqC command to the hardware */
/* */
/* RETURNS: none */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
static void process_diseqc_send_message(int unit, DISEQC_MESSAGE *dmDiseqcMessage)
{
if(dmDiseqcMessage == 0)
{
diseqc_state = DISEQC_FAILED;
return;
}
/* Send the message */
if ( !API_SendDiseqcMessage(&NIMs[unit],
(unsigned char *)dmDiseqcMessage->pMessage,
(unsigned char)dmDiseqcMessage->ui8MessageLength,
(BOOL)dmDiseqcMessage->bLastMessage,
(BURST_TYPE)dmDiseqcMessage->btBurstType) )
{
diseqc_state = DISEQC_FAILED;
trace_new( DEMOD_ERROR, "Cobra demod received bad data parameter for the DiSEcQ message to be sent!\n" );
}
else
{
diseqc_state = DISEQC_COMPLETE;
}
}
/*****************************************************************************/
/* FUNCTION: process_diseqc_rcv_message */
/* */
/* PARAMETERS: unit - the unit number for which the ioctl operation is */
/* requested. */
/* diseqc_message - address of DiSEqC message data */
/* */
/* DESCRIPTION: This function implements the internal function to send a */
/* DiSEqC command to the hardware */
/* */
/* RETURNS: none */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/*****************************************************************************/
#ifdef HAMARO_INCLUDE_DISEQC2
static void process_diseqc_rcv_message(int unit, DISEQC_MESSAGE *dmDiseqcMessage)
{
RXMODE rxmode;
/* translate the RX mode */
rxmode = xlat_diseqc_rxmode(dmDiseqcMessage->rxmode);
if( !API_DiseqcReceiveMessage(&NIMs[unit],
dmDiseqcMessage->pMessage,
(int)(dmDiseqcMessage->bufferlen),
(int *)(&dmDiseqcMessage->receivedlen),
rxmode,
(int *)(&dmDiseqcMessage->parityerr)) )
{
trace_new( DEMOD_ERROR, "Hamaro demod received bad data parameter for the DiSEcQ message to be received!\n" );
diseqc_state = DISEQC_FAILED;
}
else
{
diseqc_state = DISEQC_COMPLETE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -