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

📄 snimdriv.c

📁 ST5100 driver files for ST chipset
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************Zarlink Semiconductor Swindon UK******************************\
*   $Workfile::   SnimDriv.c                       $                              *
*   $Revision::   1.0                              $                              *
*   Author:      Colin E Undery                                                   *
*   $Date::   10 Oct 2006 11:21:28                 $                              *
*   Description:                                                                  *
*               Driver for MT312 based DVB_S and DSS satellite demodulator        *
*   Revision History:                                                             *
*   Version    Reason                              Author          Date           *
*     4.0      Snim15 release                      Colin E Undery  30/07/2004     *
*                                                                                 * 
*********************************************************************************** 
*                                                                                 *
* Copyright ?Zarlink Semiconductor Ltd.,2000-2004. All rights reserved. This     *
* copyrighted work constitutes an unpublished work created in 2004. Use of the    *
* copyright notice is intended to provide notice that Zarlink Semiconductor Ltd   *
* owns a copyright in this unpublished work; the copyright notice is not an       *
* admission that publication has occurred. This work contains confidential,       *
* proprietary information and trade secrets of Zarlink Semiconductor Ltd; it may  *
* not be used,reproduced, transmitted,or modified, in whole or in part, in any    *
* form or by any means without the prior written permission of Zarlink            *
* Semiconductor Ltd. This work is provided on a right to use basis subject to     *
* additional restrictions set out in the applicable license or other agreement.   *
*                                                                                 *
\*******************Zarlink Semiconductor Swindon UK******************************/


#include "Htype.h"

const char SNIM_Version[]="ZL10312/3 Demod driver v4.0 Copyright 2004 Zarlink Semiconductor Ltd.";

/***************   INCLUDE FILES   ******************************************/
#if defined(_SNIM_DLL)  
#include "snimdll.h"     /*include driver and DLL exports*/
#else
#include "snimdriv.h"	 /*driver exports only */
#endif

#include "snimdefs.h"
#include "Snimtune.h"
#include "ZL10312.h"   /* register definitions and other non-exported stuff*/
#include "dtvtimer.h"



//#define SNIMDRV_DEBUG 		(0)	
//#define SNIMDRV_ERROR		(1)
#if 	defined(SNIMDRV_DEBUG)
#define	printSnimDrv(x)		DDI_UART_Print x
#else
#define	printSnimDrv(x)	
#endif

#if 	defined(SNIMDRV_ERROR)
#define	printSnimDrvError(x) 		DDI_UART_Print x
#else
#define	printSnimDrvError(x)	
#endif

/***************************CONSTANTS*************************************/

/* look up table of division ratios for each bit in the SYM_RATE register */
const Uint8T  g_byaClockDivBits[]=
 {
		128,		/* bit 0 (min) */
		96,			/* bit 0 (max) bit 1 (min)*/
		64,			/* bit 1 (max) bit 2 (min)*/
		48,			/* bit 2 (max) bit 3 (min)*/
		32,			/* bit 3 (max) bit 4 (min)*/
		24,			/* bit 4 (max) bit 5 (min)*/
		16,			/* bit 5 (max) bit 6 (min)*/
		12,			/* bit 6 (max) bit 7 (min)*/
		8,			/* bit 7 (max) bit 8 (min)*/
		6,			/* bit 8 (max) bit 9 (min)*/
		4,			/* bit 9 (max) bit 10 (min)*/
		3,		    /* bit 10 (max) bit 11 (min)*/
		2			/* bit 11 (max) */
		
 };
/* Look up table for pll/crystal combinations*/
const struct g_PLLtable
{
	Uint8T pllratio;  /* pll ratio*/ 
	Uint16T Xtal;    /* max crystal frequency for these bits*/
}

g_PLLtable[]=
{			 /* pll bits*/
	3,31000, /* 0 00 */
	4,23250, /* 0 01 */
	6,15500, /* 0 10 */
	9,10333, /* 0 11 */
	11,8455, /* 1 00 + ZL10312_CONTROL:b1 = 1*/
	15,6200, /* 1 01 + ZL10312_CONTROL:b1 = 1*/
	23,4040  /* 1 10 + ZL10312_CONTROL:b1 = 1*/
};
#define MT312_MAXPLL	3
#define ZL10312_MAXPLL  6


/*macros for state machines */
/* convert passed handle to snim structure */
#define PSSNIM  ((PSSNIMCTL )hSnim)

#define SNIM_ADD_EVENT_FLAG(x)  (PSSNIM->dwEvents |= (x))

#if defined(_INCLUDE_DISEQC)
#define SNIM_DISEQCFSM_NEWSTATE(wNewstate) {_dtvTimerSet(PSSNIM->hTimer, SNIM_DISEQC_TIMER,DTV_TIMER_NOW); PSSNIM->DiSEqCFsmState=wNewstate;}         
#endif                                                 
#define SNIM_MAX_BANDWIDTH    50 /* requests maximum bandwidth prior to lock, or when bandwidth function disabled */

/* bandwidth for DSS mode */
#define SNIM_DSS_SYMBOLRATE        20000   /* DSS kSymb/sec */

/* get channel or DSS symbol rate depending on mode*/
#define SNIM_SYMBOL_RATEKHZ    ((hSnim->DSSmode==1)?(SNIM_DSS_SYMBOLRATE):hSnim->Channel.kRs)

/* bandwidth to use when in lock =  0.8 Symbol rate */
#define SNIM_LOCKED_BANDWIDTH   Uint8T ( (SNIM_SYMBOL_RATEKHZ + 625 )/1250 )

/* bandwidth to use when not in lock =  Locked bandwidth + Capture range + large margin*/
/*#define SNIM_UNLOCKED_BANDWIDTH   Uint8T((SNIM_LOCKED_BANDWIDTH) + SNIM_FR_LIM_ACQ/8 +5) */
#define  SNIM_UNLOCKED_BANDWIDTH    SNIM_MAX_BANDWIDTH

/* values controling Snim_GetLNBFreq(()*/
#define _LNBFREQ_MODE_ASTUNED     0      /*reads LNB frequency as tuned */
#define _LNBFREQ_MODE_SRCHCNTR    1      /*reads LNB search centre (i.e. allows for FROFF setting)*/
#define _LNBFREQ_MODE_ACTUAL      2      /*read actual transponder frequency (only valid if locked)*/ 



/**********************Local functions***********************************************************/
void Snim_DemodMain(PSSNIMCTL hSnim);
void Snim_LockFsm(PSSNIMCTL hSnim);                                /*FSM to acquire lock*/
void Snim_NewDemodState(PSSNIMCTL hSnim,Uint16T wNewstate);        /* FSM helper function for Demod */
void Snim_NewLockBPSstate(PSSNIMCTL hSnim,Uint16T wNewstate);     /*FSM helper for  Lock and BPS */
void Snim_CalcScanProgress(PSSNIMCTL hSnim);                       /* calculates the progress of the scan */
void Snim_DecodeCommand(PSSNIMCTL hSnim);							/* decode commands passed to state machine*/
BOOL Snim_IsTunerLocked(PSSNIMCTL hSnim);                          /* test for tuner lock*/
BOOL Snim_CheckPointers(PSSNIMCTL hSnim);                          /* Verifies hSnim and  pointers */
BOOL Snim_NextFreqScan(PSSNIMCTL hSnim);                               /* Frequency control for scan*/ 
BOOL Snim_NextPolarScan(PSSNIMCTL hSnim);                          /*  Polarisation control for non interleaved H/V scan*/
BOOL Snim_NextSatScan(PSSNIMCTL hSnim);                            /* Satellite switching for scan*/
BOOL Snim_ReadInterrupts(PSSNIMCTL hSnim);                          /* read IRQs into dwIRQcache*/

BOOL Snim_RestoreTone(PSSNIMCTL hSnim);                             /* restores the 22kHz tone */
BOOL Snim_InitialiseChannel(PSSNIMCTL hSnim);						/* Initialise system chip prior to channel acquisition*/
BOOL Snim_Initialise(PSSNIMCTL hSnim);								/* initialise Demod chip after reset */
BOOL Snim_InitialiseScan(PSSNIMCTL hSnim);							/* Initialise system chip prior to scan*/
BOOL Snim_SetSymbolSearch(PSSNIMCTL hSnim);						/* sets search bitfield according to symbol rate search range */
BOOL Snim_ProgramTuner(PSSNIMCTL hSnim);							/* Calculates synth frequency from LNB data and programs the tuner*/
Uint16T Snim_GetSymbolRate(PSSNIMCTL hSnim);          /*Reads the symbol rate*/
Uint8T Snim_GetCodeRate(PSSNIMCTL hSnim);                          /*gets the current code rate */
Sint32T Snim_GetFrequencyOffset(PSSNIMCTL hSnim);/* reads frequency offset from QPSK core*/
Uint32T Snim_GetLNBFreq(PSSNIMCTL hSnim,Uint8T ucMode);
Sint32T Snim_CalcQPSKBER(PSSNIMCTL hSnim);
Sint32T Snim_CalcViterbiBER(PSSNIMCTL hSnim);
BOOL Snim_SetMpegClock(PSSNIMCTL hSnim,Sint32T lClock);
Sint32T Snim_GetMpegClock(PSSNIMCTL hSnim);
BOOL Snim_CentreTuner(PSSNIMCTL hSnim);							 /*Centres the tuner to trim LNB drift*/
BOOL Snim_SetBandwidth(PSSNIMCTL hSnim,Uint8T ucBWMHz);			/* sets the tuner bandwidth */
Uint32T Snim_BPSFsm(PSSNIMCTL hSnim);						/* FSM to control band/polarisation and satellite*/
BOOL Snim_ReadRegisterValue(PSSNIMCTL hSnim, Uint8T byReg,Sint8T cCount,Uint32T * pdwValue);
BOOL Snim_WriteRegisterValue(PSSNIMCTL hSnim, Uint8T byReg,Sint8T cCount,Uint32T dwValue);
BOOL Snim_ReadTuner(void* hSnim,Uint8T ucAddress,Uint8T *pBuffer,Uint8T byCount); /* access tuner bus via pass through port*/
BOOL Snim_WriteTuner(void * hSnim,Uint8T ucAddress,Uint8T *pBuffer,Uint8T byCount);/* access tuner bus via pass through port*/
void Snim_UpdateRsUBC(PSSNIMCTL hSnim);
ESnimState Snim_GetDemodState(PSSNIMCTL hSnim);
Sint32T Snim_ReadMonitor(PSSNIMCTL hSnim,Uint8T ucSelect);
BOOL Snim_RegisterWrite(HANDLE hSnim,Uint8T byReg,Uint8T *byBuffer,Uint8T byCount);
BOOL Snim_RegisterRead(HANDLE hSnim,Uint8T byReg,Uint8T *byBuffer,Uint8T byCount);
BOOL Snim_WriteExtra(PSSNIMCTL hSnim,Uint8T ucSelect,Uint8T ucData );
BOOL Snim_ReadExtra(PSSNIMCTL hSnim,Uint8T ucSelect,Uint8T *ucData );
#if defined(_INCLUDE_DISEQC)
void Snim_DiSEqC(PSSNIMCTL hSnim);
#endif

/***************************************************************************************************************************\
*                                                                                                                           *
*                                           DEMODULATOR EXPORTED FUNCTIONS                                                  *
*                                                                                                                           *
\***************************************************************************************************************************/


/************************Zarlink Semiconductor*********************************
*   Name:SnimCreate()
*   Purpose: Create a snim structure on the heap
*   Remarks: 
*   Inputs:
*
*   Outputs: return value handle to snim
*
********************************************************************************/

HANDLE SnimCreate(unsigned long unitId, PSSNIMCONFIG psConfig)
{
	PSSNIMCTL hSnim;
	SSnimTunerCreate sCreateTunerStruct;
	ENTER_SNIM_CONTENTION_LOCK;

	hSnim=calloc(1,sizeof(SSnimControl));
	if (hSnim)
	{
		sCreateTunerStruct.hSnim = hSnim;
		sCreateTunerStruct.pfDemodRead = Snim_RegisterRead;
		sCreateTunerStruct.pfDemodWrite = Snim_RegisterWrite;
		sCreateTunerStruct.pfRead =  Snim_ReadTuner;
		sCreateTunerStruct.pfWrite =  Snim_WriteTuner;
		hSnim->hTuner = _SnimTunerCreate(&sCreateTunerStruct);
		if (hSnim->hTuner)
		{
			hSnim->unitId = unitId; // to know which tuner.
			hSnim->XtalkHz =MT312_XTAL;
			hSnim->ucAddress = psConfig->ucAddress;	
			hSnim->wConfig = psConfig->wConfig;
			hSnim->DelaySat =10;	//  										 
			hSnim->VitBerTime=20;										 
			hSnim->pfRegisterRead =psConfig->pfRegRead;			 
			hSnim->pfRegisterWrite =psConfig->pfRegWrite;		 
			hSnim->pfSlaveAccess = psConfig->pfSlaveAccess;		 
			hSnim->pfEnable= psConfig->pfEnable;							 
			hSnim->pfnDiSEqCCallBack = psConfig->pfnDiSEqCCallBack;							 
			hSnim->EnableNo = psConfig->ucEnableNo;
			hSnim->hTimer = _dtvTimerCreate(SNIM_TIMERS_QTY);
			if (hSnim->hTimer)
			{
				_dtvTimerSet(hSnim->hTimer, SNIM_RSUBC_TIMER, SNIM_TIMEINTERVAL_RSUBC);

			}
			else
			{
				free(hSnim->hTuner);
			}

		}
		else
		{
			free(hSnim);
			hSnim=NULL;
		}
	}
	EXIT_SNIM_CONTENTION_LOCK;
	return (HANDLE) hSnim;
}

/************************Zarlink Semiconductor*********************************
*   Name:SnimDelete()
*   Purpose: delete the snim structure
*   Remarks: 
*   Inputs:
*
*   Outputs: none
*
********************************************************************************/

void   SnimDelete(HANDLE hSnim)
{
    ENTER_SNIM_CONTENTION_LOCK;
    if (PSSNIM->hTuner) free(PSSNIM->hTuner);
    if (PSSNIM->hTimer) free(PSSNIM->hTimer);
    free(hSnim);
    EXIT_SNIM_CONTENTION_LOCK;
}


/************************Zarlink Semiconductor*********************************
*   Name:SnimMain()
*   Purpose:  Runs the demod and DiSEqC state machines
*   Remarks: 
*   Inputs:
*
*   Outputs: Flags etc
*
********************************************************************************/

Uint32T   SnimMain(HANDLE hSnim,Uint32T dwTimeNow)
{
	Uint32T dwEvents;
	if (!Snim_CheckPointers(PSSNIM)) return SNIM_ERROR_GENERAL;
	
	ENTER_SNIM_CONTENTION_LOCK;
	_dtvTimerSetRTC(PSSNIM->hTimer,dwTimeNow);
	Snim_ReadInterrupts(PSSNIM); /* read the interrupts*/
	Snim_DecodeCommand(PSSNIM); /*decode commands*/
	Snim_DemodMain(PSSNIM);     /* run the demod state machine */
#if defined(_INCLUDE_DISEQC)
	Snim_DiSEqC(PSSNIM);
#endif
	Snim_UpdateRsUBC(PSSNIM);
	dwEvents = PSSNIM->dwEvents;
	PSSNIM->dwEvents =0;
	EXIT_SNIM_CONTENTION_LOCK;
	
	return dwEvents;
}

/************************Zarlink Semiconductor*********************************
*   Name:SnimRead()
*   Purpose:
*   Remarks: returns selected value, if active.
*   Inputs: 
*
*   Outputs: generally returns -1 if an error occurs
*
********************************************************************************/

Sint32T SnimRead(HANDLE hSnim,Uint16T nSelect)
{
    Sint32T lResult = -1;   /* default return values*/
    Uint8T ucBuffer;
    if (!Snim_CheckPointers(hSnim))return lResult ;
    ENTER_SNIM_CONTENTION_LOCK;

    // Always do these 
    switch (nSelect)
    {
    case SNIM_DATA_DEMODSTATE:
        lResult = Snim_GetDemodState(PSSNIM);
        break;

    case SNIM_DATA_SATDELAY:
        lResult = PSSNIM->DelaySat;
        break;
    case  SNIM_DATA_DEBUGFLAGS: 
        lResult = PSSNIM->wDebugFlags;
        break;

    case  SNIM_DATA_POSTVITPERIOD:
        lResult = PSSNIM->VitBerTime;
        break;
    case  SNIM_DATA_RSUBCSEC:
        lResult = PSSNIM->wRSUBCsec;
        break;

    case  SNIM_DATA_RSUBCRUN:
        lResult = PSSNIM->wRSUBCsample;
        PSSNIM->wRSUBCsample = 0;
        break;

#if defined(_INCLUDE_DISEQC)
    case  SNIM_DATA_DISEQCOPTIONS:
        lResult = 0;
        if (PSSNIM->SatToneBurstDisable) lResult |= SNIM_DISOPT_SATELLITE;
        if (PSSNIM->BandToneDisable) lResult |= SNIM_DISOPT_BANDSWITCH;
        if (PSSNIM->PolarVoltsDisable) lResult |= SNIM_DISOPT_POLARISATION;
        break;
#endif

   
    default:
        if (nSelect<SNIM_DATA_FIRST)
        {
            lResult = _SnimTunerRead(PSSNIM->hTuner,nSelect);
        }
        break;
    }
    
    if (SNIM_DEMODFSM_STANDBY<=PSSNIM->DemodFsmState)
    {
        // if we are active (standby or higher) do these
          
        switch (nSelect)
            {
            

⌨️ 快捷键说明

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