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

📄 sn15test.c

📁 ST5100 driver files for ST chipset
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************Zarlink Semiconductor Swindon UK****************************\
*   $Workfile::   Sn15Test.c                      $                          *
*   $Revision::   1.0                              $                          *
*   Author:      Colin E Undery                                               *
*   $Date::   10 Oct 2006 11:21:28                 $                          *
*   Description:                                                              *
*          SNIM9 and Snim15 driver test program                               *
*                                                                             *
*   Revision History:                                                         *
*   Version    Reason                              Author          Date       *
*   1          Created                             Colin E Undery  2001       *
*                                                                             *
*   Copyright ?2000-2001, Zarlink Semiconductor Ltd.  All rights Reserved.   *
*                                                                             *
\*****************Zarlink Semiconductor Swindon UK****************************/
#include "cmpopt.h"

#include "dtdattyp.h"
//#include "2wirebus.h"
#include "SnimDriv.h"
#include "Snimdefs.h"
#include "snimtune.h"
#include "zl1003x.h"

#include "ZL10312.h"//thomson  

#include "sn15test.h"

#include "drv_tuner_com.h"//thomson  
#include "drv_tuner_sat.h"//thomson  
#if defined (DOS)
#include <conio.h>
#include <stdlib.h>
extern unsigned long getSysTime(void); /* from zdostime.lib */
#elif defined(__arm)
#include <stdlib.h>
#include <string.h>
#else
//thomson  

//#include <task.h>
#include <stdlib.h>
#include <string.h>
//end
#endif

//#define SN15TEST_DEBUG 	(0)
//#define	SN15TEST_CONSOLE		(0)
//#define	SN15TEST_ERROR		(0)

#if 	defined(SN15TEST_DEBUG)
#define	printSn15(x)			DDI_UART_Print x
#else
#define	printSn15(x)	
#endif

#if 	defined(SN15TEST_DEBUG)
#define	printSn15Error(x) 		DDI_UART_Print x
#else
#define	printSn15Error(x)
#endif

#if 	defined(SN15TEST_CONSOLE)
#define	printSn15Console 			DDI_UART_Print 
#else
#define	printSn15Console 			
#endif


/*
This file was written and debugged as a console application running under
windows 32, and as a DOS application.
dtdattyp.h and native variable types are used, the latter are used for compiler
native compatibility with library functions such as scanf.
However it is intended that this program should run on an embedded system, as 
its main purpose is to demonstrate the operation of the SNIM drivers. The 
user interface is therefore deliberately simplistic, as the debug user interface 
available may (like my ARM system) be very basic, and may well behave like a 
simple terminal device.
To make this run on an embedded target, you will have to modify the following 
routines:

*/

//   _2006_06_020 to shorten the timing.
#define	TUNER_TIMING_SHORTEN

/**********Target dependent routines*******************************************/
BOOL TestsnimOpenPort(Uint8T * pName);
void TestsnimPlatformInitialise(void);   /* initialises platform specific hardware */
void TestsnimPlatformRelease(void);       /* removes any platform hooks on prgram exit*/
//void TestsnimUpdateClock(void);  /* reads the millisecond time into g_dwClock*/
Uint32T TestsnimUpdateClock(Uint32T *_Clock);
void TestsnimGets(char *pBuffer,int MaxCount);/* equivalent to gets*/
BOOL TestsnimKBHit(void);                         /* checks for keyboard hit*/




/**********Target Independent routines*****************************************/
int  TestsnimGetMenuChoice(pMenuType pMenu);  /* displays menu and gets command number*/
void TestsnimProcessCommands(void);        /* reads the keyboard and actions commands */
void TestsnimSetPowerState(void);      /* sets the Snim power condition */
void TestsnimAcquireChannel(void);     
void TestsnimPrintStatus(void);
void TestsnimPrintStatusHdr(void);
void TestsnimSetLNB(void);
void TestsnimClearChannelList(void);
void TestsnimStartScan(void);
BOOL TestsnimAddChannel(PSSNIMCHANNEL pChannel,Uint32T dwTunerFreq,Uint16T wAGC, Uint8T ucEbno);
void TestsnimPrintChannelList(void);
PSSNIMCHANNEL TestsnimGetChannelFromList(int index);
int TestsnimGetKBnumber(char* pPrompt,long iMin,long iMax,BOOL bAcceptZero);
char TestsnimGetKBletter(char* pPrompt,char* pValid,BOOL bMakeUpper);
long TestsnimGetKBfloat(char* pPrompt,long iMin_x1000,long iMax_x1000);
void TestsnimSplash(void);
void TestDumpRegisters(void);
void TestsnimSetXtal(void);



/****************2wire bus interception routines*******************************/
BOOL TestsnimRR(unsigned long unitId, Uint8T byID,Uint8T byReg, Uint8T *pBuffer,Uint8T byCount);
BOOL TestsnimRW(unsigned long unitId, Uint8T byID,Uint8T byReg, Uint8T *pBuffer,Uint8T byCount);
BOOL TestsnimSA(unsigned long unitId, Uint8T byID,Uint8T bySlaveID,Uint8T byReg,Uint8T byOpen,Uint8T byClose,Uint8T * pBuffer,Sint8T cCount);
BOOL TestsnimE(BOOL bWantOn, Uint8T byEnableNo);



/*********************MACROS**************************************/

/*convert symbol rate e.g. 27.5 Msym/s (27500) into digits 27 and 500 for display*/
#define RS_INT(x)   ((x)/1000)
#define RS_FRAC(x) (int)((((long)(x)))%1000)

/* text for display*/
#define TXT_OFF			"Off     "
#define TXT_STANDBY		"Standby "
#define TXT_IDLE		"Idle    "
#define TXT_BUSY		"Busy    "
#define TXT_WAITING		"Waiting "
#define TXT_LOCKED		"Locked  "
#define TXT_SCANNING	"Scanning"
#define TXT_BLANK		" -------"


/*****************************GLOBAL*******************************************/

Uint8T  	g_strPort[10] ="LPT1";

Uint32T 	g_dwClock;	/* millisecond clock*/

Uint32T  g_ClocksPerMilllisecond;//thomson  

BOOL    	g_isPortOpen =FALSE;      /* Port open flag*/
BOOL 	g_isActive = TRUE; /* termination variable*/
BOOL	g_isScanning=FALSE; 


HANDLE g_hTheSnim;     /* main structure for demodulator */


typedef struct scanitem
{
	SSnimChannel Channel; /* required information for tuning */
	Uint16T wAGC;         /* additional info (not required for retuning*/
	Uint8T ucEBn0;         /* additional info (not required for retuning*/
	Uint32T dwTunerFreq;    /* additional info (not required for retuning*/
	struct scanitem * pNext;
}scanitem, *pScanItem;

pScanItem g_pScanListHead = NULL;    /* pointer to scan list first entry*/
pScanItem g_pScanListTail = NULL;     /*pointer to scan list last entry */
int g_ChannelCount =0;

//Uint32T dwDemodEvents;//thomson  
/* Form Feed*/
/******************************MAIN********************************************/


#ifdef AAA
int main(void)
{
	/*****************************Variables****************************************/

	Sint16T ExitCode =0;  /* termination return value */
	SSnimLnb lnb;
	SSnimConfig SnimCreateStruct;

	Uint32T dwDemodEvents;
	/*****************************Initialise***************************************/


	TestsnimPlatformInitialise();

	g_isPortOpen = TestsnimOpenPort(g_strPort);
	SnimCreateStruct.pfEnable = NULL;//TestsnimE;
	SnimCreateStruct.pfRegRead =  TestsnimRR;
	SnimCreateStruct.pfRegWrite =TestsnimRW;
	/* TODO: fixme*/
	SnimCreateStruct.pfSlaveAccess = TestsnimSA;
	SnimCreateStruct.ucAddress = 28;
	SnimCreateStruct.ucEnableNo =0;
	SnimCreateStruct.wConfig = SNIM_DEFAULT_WCONFIG;
//	g_hTheSnim = SnimCreate(&SnimCreateStruct);
	//   _060707_ 
	g_hTheSnim = SnimCreate(0, &SnimCreateStruct);
	if (!g_hTheSnim) return 1; 

	lnb.HiBandLO=10600;
	lnb.LoBandLO=9750;
	lnb.LoHiSwap=11700;
	lnb.Delay_ms = 10;
	SnimSetLnb(g_hTheSnim,&lnb);
	TestsnimPrintStatusHdr();
	/*****************************Main loop****************************************/
	do
	{
		TestsnimUpdateClock();        /* update the time */
		/* run the demodulator state machine */

		dwDemodEvents=SnimMain(g_hTheSnim,g_dwClock);
		/* decode any events that occur */

		if (dwDemodEvents& SNIM_EVENT_FOUND)
		{
			SSnimChannel chan;

			SnimReadChannel(g_hTheSnim,&chan); 

			if (TestsnimAddChannel(&chan,Uint32T(SnimRead(g_hTheSnim,SNIM_DATA_TUNERFREQ)),Uint16T(SnimRead(g_hTheSnim,SNIM_DATA_AGC)),Uint8T(SnimRead(g_hTheSnim,SNIM_DATA_EBNOx10))))
			{/* successful*/
				SnimCommand(g_hTheSnim,SNIM_COMMAND_SCAN_CONTINUE);
			}
			else
			{/* no memory left so stop */
				SnimCommand(g_hTheSnim,SNIM_COMMAND_SCAN_ABORT);
				g_isScanning=FALSE;
			}
		}

		if (dwDemodEvents& SNIM_EVENT_SCANCOMPLETE)
		{
			TestsnimPrintStatus();
			g_isScanning=FALSE;
			TestsnimPrintStatusHdr();
		}


		TestsnimProcessCommands();/* operator interface */
		TestsnimPrintStatus();


	}while (g_isActive);

	TestsnimPlatformRelease();
	return ExitCode;

}

#endif


void ParseDemodEvents(Uint32T DemodEvents, Uint32T dwClock)
{

	/* decode any events that occur */
	if (DemodEvents& SNIM_EVENT_SCANPROGRESS)
	{
		PSSNIMCTL phTheSnim = ( PSSNIMCTL) g_hTheSnim;
		unsigned long progress;
		SSnimChannel chan;
		unsigned long TPFrequency;

		/* Read Channel */
		SnimReadChannel(g_hTheSnim,&chan); 

		/* Get Progress */
		progress = phTheSnim->wPerCent/10;

		/* Get Frequency */
		TPFrequency = chan.MHz;

		/* progress Notify always */
		//if(( phTheSnim->wPerCent > g_BlindSearchProgress ) && (phTheSnim->wPerCent <= 1000))
		{
			//  thomson g_BlindSearchProgress = phTheSnim->wPerCent + 20;
			//  thomson SSS_DBG(CH,_INFO_,("[CH] ParseDemodEvents():: SNIM_EVENT_SCANPROGRESS 3 [time:%10d] [%d%%],[%02d]MHz/START[%d]/STOP[%d]\n\r",dwClock, phTheSnim->wPerCent/10,chan.MHz, phTheSnim->wScanStart, phTheSnim->wScanStop));
			//  thomson DRV_CHANNEL_SCAN_Progress_Notify(WM_CH_BLIND_TUNE_PROGRESS_NOTIFY, 0, phTheSnim->wPerCent/10, chan.MHz |(((chan.ucExt>>3)&0x1)<<31) );
		}
	}
	
	if (DemodEvents& SNIM_EVENT_FOUND)
	{
		PSSNIMCTL phTheSnim = ( PSSNIMCTL) g_hTheSnim;
		SSnimChannel chan;
		unsigned long TPFrequency;

		SnimReadChannel(g_hTheSnim,&chan); 

		//  thomson SSS_DBG(CH,_INFO_,("[CH]ParseDemodEvents(): SNIM_EVENT_FOUND!\t\t[%10d]!! \n\r", dwClock));
		//TPFrequency = FE_CalculationOfTPFrequency (chan.MHz);
		TPFrequency = chan.MHz;


		//  thomson DRV_CHANNEL_CheckSignal( &(g_WmInfo[0].ucSignalStrength), &(g_WmInfo[0].ucSignalQuality));
		//  thomson g_WmInfo[0].ucTunerLock = 1;


		// Add New TP.
		if (TestsnimAddChannel(&chan,Uint32T(SnimRead(g_hTheSnim,SNIM_DATA_TUNERFREQ)),Uint16T(SnimRead(g_hTheSnim,SNIM_DATA_AGC)),Uint8T(SnimRead(g_hTheSnim,SNIM_DATA_EBNOx10))))
		{/* successful*/
			//Temp only
			//  thomson SSS_DBG(CH,_INFO_,("[CH]ParseDemodEvents(): Channel Found During Scan process**********SNIM_EVENT_FOUND EVENTS*******\n\r"));
			printSn15Error(("[CH]ParseDemodEvents(): Channel Found During Scan process**********SNIM_EVENT_FOUND EVENTS*******\n\r"));
			SnimCommand(g_hTheSnim,SNIM_COMMAND_SCAN_CONTINUE);
		}
		else
		{/* no memory left so stop */
			//  thomsonSSS_DBG(CH,_INFO_,("[CH]ParseDemodEvents(): Channel Found During Scan process**********SNIM_EVENT_FOUND****Critical Error ::: No memory **********\n\r"));
			printSn15Error(("[CH]ParseDemodEvents(): Channel Found During Scan process**********SNIM_EVENT_FOUND****Critical Error ::: No memory **********\n\r"));
			//SnimCommand(g_hTheSnim,SNIM_COMMAND_SCAN_ABORT);
			//SSS_ASSERT(CH,(0));
		}

#if 0
		/* progress Notify : report always. */
		//if(( phTheSnim->wPerCent > g_BlindSearchProgress ) && (phTheSnim->wPerCent <= 1000))
		{
		//g_BlindSearchProgress += 20;
		g_BlindSearchProgress = phTheSnim->wPerCent + 20;
		printSn15Error(("[CH] SNIM_EVENT_FOUND -> SNIM_EVENT_SCANPROGRESS 2 [time:%10d] [%d%%], [%02d]MHz/START[%d]/STOP[%d]\n\r",dwClock, phTheSnim->wPerCent/10,chan.MHz, phTheSnim->wScanStart, phTheSnim->wScanStop));
		DRV_CHANNEL_SCAN_Progress_Notify(WM_CH_BLIND_TUNE_PROGRESS_NOTIFY, 0, phTheSnim->wPerCent/10, chan.MHz |(((chan.ucExt>>3)&0x1)<<31) );
		}
#endif
		/* Send TP Found Events */
		//DRV_CHANNEL_SCAN_TP_FOUND_EVENTS(WM_CH_BLIND_TUNE_TP_FOUND_EVENTS, TPFrequency, (unsigned long)g_pScanListTail/*Channel List Tail*/, g_ChannelCount/*HV*/);

	}
	
	if (DemodEvents& SNIM_EVENT_SCANCOMPLETE)
	{
		//  thomson SSS_DBG(CH,_INFO_,("[CH]ParseDemodEvents(): SNIM_EVENT_SCANCOMPLETE:[time:%10d] Scan Completed, found %d channels**********\n", dwClock, g_ChannelCount));
		//  thomson SSS_DBG(CH,_INFO_,("[CH]ParseDemodEvents(): SNIM_EVENT_SCANCOMPLETE: \n"));

		printSn15Error(("[CH]ParseDemodEvents(): SNIM_EVENT_SCANCOMPLETE: \n\r"));

		//TestsnimPrintStatus();
		//TestsnimPrintStatusHdr();
		FE_Wait(100);
		// search end.
		//  thomson DRV_CHANNEL_SCAN_End (WM_CH_BLIND_TUNE_END, 0, 0, 0);
		//  thomson g_isBlindScanning=FALSE;
		//  thomsong_BlindSearchProgress = 1000;

	}
	if (DemodEvents& SNIM_EVENT_STATECHANGE)
	{
		//printSn15Error(("ParseDemodEvents():: SNIM_EVENT_STATECHANGE[State: [%d]!\t\t[%10d]!! \n\r", SnimRead(g_hTheSnim, SNIM_DATA_DEMODSTATE), dwClock));
		if (SnimRead(g_hTheSnim, SNIM_DATA_DEMODSTATE) == SNIM_STATE_LOCKED) 
			printSn15Error(("[LOCK]!! \t\t[%10d]",/* SnimRead(g_hTheSnim, SNIM_DATA_DEMODSTATE),*/ dwClock));
	}

	if (DemodEvents& SNIM_EVENT_VITBER)
		printSn15Error(("[CH]ParseDemodEvents(): SNIM_EVENT_VITBER!\t\t[%10d]!! \n\r", dwClock));
	if (DemodEvents& SNIM_EVENT_QPSKBER)
		printSn15Error(("[CH]ParseDemodEvents(): SNIM_EVENT_QPSKBER!\t\t[%10d]!! \n\r", dwClock));

	if (DemodEvents& SNIM_EVENT_TRAINCOMPLETE)
	{
		printSn15Error(("[CH]ParseDemodEvents():: SNIM_EVENT_TRAINCOMPLETE!\t\t[%10d]!! \n\r", dwClock));
	}
	if (DemodEvents& SNIM_EVENT_HORZ)
	{
		//  thomson SSS_DBG(CH,_ERROR_,("[CH]ParseDemodEvents():: SNIM_EVENT_HORZ!\t\t[%10d]!! \n\r", dwClock));
		printSn15Error(("[CH]ParseDemodEvents():: SNIM_EVENT_HORZ!\t\t[%10d]!! \n\r", dwClock));
		//  thomson g_DiSEqCEvents = SNIM_EVENT_HORZ;
		//  thomson SSS_DBG(CH,_INFO_,("[CH] ParseDemodEvents() g_DiSEqCEvents = 0x%08x, \n\r", g_DiSEqCEvents )); 
		/* Processing DiSEqC Operation at here */
		//FE_DRV_main(SNIM_DRV_DISEQCDONE);
		//  thomson WM_SendMessage(g_ChannelInfo[CHANNEL0_DiSEqC_SESSION].msgHandle /*g_ChannelInfo[CHANNEL0_TUNE_SESSION].msgHandle*/, CH_CH_DISEQC_DISEQC_SET, g_DiSEqCEvents, 0, 0);  
	}
	if (DemodEvents& SNIM_EVENT_VERT)
	{
		//  thomson SSS_DBG(CH,_ERROR_,("[CH]ParseDemodEvents():: SNIM_EVENT_VERT!\t\t[%10d]!! \n\r", dwClock));
		printSn15Error(("[CH]ParseDemodEvents():: SNIM_EVENT_VERT!\t\t[%10d]!! \n\r", dwClock));
		//  thomson g_DiSEqCEvents = SNIM_EVENT_VERT;
		//  thomson SSS_DBG(CH,_INFO_,("[CH] ParseDemodEvents() g_DiSEqCEvents = 0x%08x, \n\r", g_DiSEqCEvents )); 
		/* Processing DiSEqC Operation at here */
		//FE_DRV_main(SNIM_DRV_DISEQCDONE);
		//  thomson WM_SendMessage(g_ChannelInfo[CHANNEL0_DiSEqC_SESSION].msgHandle /*g_ChannelInfo[CHANNEL0_TUNE_SESSION].msgHandle*/, CH_CH_DISEQC_DISEQC_SET, g_DiSEqCEvents, 0, 0);  
	}
	if (DemodEvents& SNIM_EVENT_SATA)
	{
		//  thomsonSSS_DBG(CH,_ERROR_,("[CH]ParseDemodEvents():: SNIM_EVENT_SATA!\t\t[%10d]!! \n\r", dwClock));
		printSn15Error(("[CH]ParseDemodEvents():: SNIM_EVENT_SATA!\t\t[%10d]!! \n\r", dwClock));
		//  thomsong_DiSEqCEvents = SNIM_EVENT_SATA;
		//  thomsonSSS_DBG(CH,_INFO_,("[CH] ParseDemodEvents() g_DiSEqCEvents = 0x%08x, \n\r", g_DiSEqCEvents )); 
		/* Processing DiSEqC Operation at here */
		//FE_DRV_main(SNIM_DRV_DISEQCDONE);
		//  thomsonWM_SendMessage(g_ChannelInfo[CHANNEL0_DiSEqC_SESSION].msgHandle /*g_ChannelInfo[CHANNEL0_TUNE_SESSION].msgHandle*/, CH_CH_DISEQC_DISEQC_SET, g_DiSEqCEvents, 0, 0);  
	}
	if (DemodEvents& SNIM_EVENT_SATB)
	{
		//  thomsonSSS_DBG(CH,_ERROR_,("[CH]ParseDemodEvents():: SNIM_EVENT_SATB!\t\t[%10d]!! \n\r", dwClock));
		printSn15Error(("[CH]ParseDemodEvents():: SNIM_EVENT_SATB!\t\t[%10d]!! \n\r", dwClock));
		//  thomsong_DiSEqCEvents = SNIM_EVENT_SATB;
		//  thomsonSSS_DBG(CH,_INFO_,("[CH] ParseDemodEvents() g_DiSEqCEvents = 0x%08x, \n\r", g_DiSEqCEvents )); 
		/* Processing DiSEqC Operation at here */
		//FE_DRV_main(SNIM_DRV_DISEQCDONE);
		//  thomsonWM_SendMessage(g_ChannelInfo[CHANNEL0_DiSEqC_SESSION].msgHandle /*g_ChannelInfo[CHANNEL0_TUNE_SESSION].msgHandle*/, CH_CH_DISEQC_DISEQC_SET, g_DiSEqCEvents, 0, 0);  
	}
	if (DemodEvents& SNIM_EVENT_HIBAND)
	{
		//  thomson SSS_DBG(CH,_ERROR_,("[CH]ParseDemodEvents():: SNIM_EVENT_HIBAND!\t\t[%10d]!! \n\r", dwClock));
		printSn15Error(("[CH]ParseDemodEvents():: SNIM_EVENT_HIBAND!\t\t[%10d]!! \n\r", dwClock));
		//  thomson g_DiSEqCEvents = SNIM_EVENT_HIBAND;
		//  thomson SSS_DBG(CH,_INFO_,("[CH] ParseDemodEvents() g_DiSEqCEvents = 0x%08x, \n\r", g_DiSEqCEvents )); 
		/* Processing DiSEqC Operation at here */
		//FE_DRV_main(SNIM_DRV_DISEQCDONE);
		//  thomson WM_SendMessage(g_ChannelInfo[CHANNEL0_DiSEqC_SESSION].msgHandle /*g_ChannelInfo[CHANNEL0_TUNE_SESSION].msgHandle*/, CH_CH_DISEQC_DISEQC_SET, g_DiSEqCEvents, 0, 0);  
	}
	if (DemodEvents& SNIM_EVENT_LOBAND)
	{
		//  thomson SSS_DBG(CH,_ERROR_,("[CH]ParseDemodEvents():: SNIM_EVENT_LOBAND!\t\t[%10d]!! \n\r", dwClock));
		//  thomson g_DiSEqCEvents = SNIM_EVENT_LOBAND;

⌨️ 快捷键说明

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