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

📄 snimdriv.c

📁 ST5100 driver files for ST chipset
💻 C
📖 第 1 页 / 共 5 页
字号:
*   Notes:In most circumstances QPSK lock may occur before the intermediate
*   stages of AGC_Lock etc are detected, hence the routes from tuner lock to 
*   FEC lock are many and various.
********************************************************************************/


void Snim_DemodMain(PSSNIMCTL hSnim)
{
	Uint8T buffer; 
	Sint32T lBuffer;
	BOOL bRepeat;
	Uint16T entryState;
	bRepeat = TRUE;



	/***********************************************************************/


	if (SNIM_DEMODFSM_LOCK==hSnim->DemodFsmState)
	{ /* update the Viterbi progress*/
		hSnim->wPerCent= Uint16T(_dtvTimerElapsedTime(hSnim->hTimer,SNIM_GENERAL_TIMER)/hSnim->VitBerTime);
	}
	
	do
	{
		entryState=hSnim->DemodFsmState;
		switch (hSnim->DemodFsmState)
		{
			/*****************************************************************************************************\
			|                        This section of the state machine handles power control                      |
			\*****************************************************************************************************/
			case SNIM_DEMODFSM_OFF:
			case SNIM_DEMODFSM_STANDBY:
			case SNIM_DEMODFSM_IDLE:
			case SNIM_DEMODFSM_UNLOCK:
			case SNIM_DEMODFSM_LOCK:
				printSnimDrv(("[Snim_DemodMain] DemodFsmState=>[%x] \n",hSnim->DemodFsmState));
				/* All these are rest states, check occasionally to see if anything happens */
				if (_dtvTimerElapsedTime(hSnim->hTimer,SNIM_DEMODFSM_TIMER)>=(SNIM_DEMODFSM_REFRESH_TIME))
				{/*check for chip presence and what state it is in */
					//Snim_RegisterRead(hSnim,SNIM_CONFIG,&buffer,1);
					//printSnimDrv(("$$$ Snim_RegisterRead : %x \n",buffer));
					if (!Snim_RegisterRead(hSnim,SNIM_CONFIG,&buffer,1))
					{/* no response, try later */
						printSnimDrv(("@@@  no response, try later @@@\n"));
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_OFF);
					} 
					else if (!(buffer & SNIM_CONFIG_ENABLE))
					{ /* chip is there but not enabled*/
						printSnimDrv(("[Snim_DemodMain] chip is there but not enabled !!! n"));
						Snim_RegisterRead(hSnim,SNIM_CONFIG,&buffer,1);
						#if 0
						{
							int i =100;
							while(i--)
							{
								Snim_RegisterRead(hSnim,SNIM_CONFIG,&buffer,1);
								printSnimDrv(("@@@ Snim_RegisterRead : %x \n",buffer));
							}
						}
						#endif						
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_STANDBY);
					}
					else if (!Snim_RegisterRead(hSnim,SNIM_FEC_STATUS,&buffer,1))
					{   /* no response, must be off after all*/
						printSnimDrv(("@@@  no response, must be off after all @@@\n"));
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_OFF);
					}
					else if ((buffer & SNIM_FECSTATUS_LOCKED) != SNIM_FECSTATUS_LOCKED)
					{/* enabled, not locked must be idle*/
						printSnimDrv(("[Snim_DemodMain]  enabled, not locked must be idle !!!\n"));
						if (SNIM_DEMODFSM_LOCK==hSnim->DemodFsmState)
						{/* lost lock open up the filter */
							Snim_SetBandwidth(hSnim,SNIM_UNLOCKED_BANDWIDTH);
						}
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
					}
					else if(!(SNIM_DEMODFSM_LOCK==hSnim->DemodFsmState))
					{/* re-entering lock state */
						printSnimDrv(("[Snim_DemodMain]  re-entering lock state !!!\n"));
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_INITLOCK);
					}
					else if (_dtvTimerElapsedTime(hSnim->hTimer,SNIM_GENERAL_TIMER)> (Uint32T(hSnim->VitBerTime)*1000))
					{/*locked and Viterbi timer is expired: save the time and error count*/
						printSnimDrv(("[Snim_DemodMain] locked and Viterbi timer is expired: save the time and error count !!!\n"));
						Snim_ReadRegisterValue(PSSNIM,SNIM_RS_BERCNT,&hSnim->dwErrorCount);
						hSnim->dwErrPer = _dtvTimerElapsedTime(PSSNIM->hTimer,SNIM_GENERAL_TIMER);
						_dtvTimerSet(hSnim->hTimer,SNIM_GENERAL_TIMER, DTV_TIMER_NOW);
						SNIM_ADD_EVENT_FLAG(SNIM_EVENT_VITBER);
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_LOCK);
						bRepeat = FALSE;
					}
					else if (hSnim->dwIRQcache & SNIM_IRQ_FEC_VITERBIMON)
					{/* locked and have new QPSK available*/
						printSnimDrv(("[Snim_DemodMain]  locked and have new QPSK available !!!\n"));
						hSnim->dwIRQcache &= ~SNIM_IRQ_FEC_VITERBIMON;
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_LOCK);
						SNIM_ADD_EVENT_FLAG(SNIM_EVENT_QPSKBER);
						bRepeat = FALSE;
					}
					else
					{/* locked, nothing else to report, centre the tuner */
						printSnimDrv(("[Snim_DemodMain]  locked, nothing else to report, centre the tuner !!!\n"));
						Snim_CentreTuner(hSnim);
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_LOCK);
					}
				}
				else
				{
					//printSnimDrv(("@@@ _dtvTimerElapsedTime NOTHING\n"));
				}
				break;

			case SNIM_DEMODFSM_WAITRESET: /* reset and go to run*/
				printSnimDrv(("[Snim_DemodMain] SNIM_DEMODFSM_WAITRESET!!! \n"));
				if (Snim_RegisterRead(hSnim,SNIM_CONFIG,&buffer,1))
				{/* chip is awake*/
					/* put tuner into run*/
					printSnimDrv(("Snim_DemodMain():/* chip is awake*/!!! \n"));
					if (Snim_Initialise(hSnim))
					{/* intialised ok attempt acquistion*/
						printSnimDrv(("[Snim_DemodMain] intialised ok attempt acquistion !!! \n"));
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_ACQUIRE);
					}
					else
					{
						printSnimDrvError(("[Snim_DemodMain] intialised err !!! \n"));
						SNIM_ADD_EVENT_FLAG(SNIM_ERROR_COMMS);
						bRepeat=FALSE;
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_STANDBY);
					}

				}
				else if (_dtvTimerElapsedTime(hSnim->hTimer,SNIM_DEMODFSM_TIMER)>=SNIM_RESET_WAIT)
				{/* chip did not come out of reset, or its not there/powered down*/
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_OFF);
				}
				break; /* wait for chip to come out of reset */

			/*****************************************************************************************************\
			|                        This section of the state machine handles Tuner training                     |
			\*****************************************************************************************************/
			case SNIM_DEMODFSM_TRAININIT:
				if (_SnimTunerWrite(hSnim->hTuner,SNIM_TUNER_TRAIN,0))
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_TRAIN);
				else
				{
					SNIM_ADD_EVENT_FLAG(SNIM_ERROR_TRAININIT);
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
				}
				break;
			case SNIM_DEMODFSM_TRAIN:
				if (_dtvTimerElapsedTime(hSnim->hTimer,SNIM_DEMODFSM_TIMER)>=(_SnimTunerRead(hSnim->hTuner,TUNER_SELECT_INFO) & TUNER_INFO_TRAINTIME))
				{
					Sint32T TrainProgress= _SnimTunerRead(hSnim->hTuner,SNIM_TUNER_TRAIN);
					hSnim->wPerCent= Uint16T(TrainProgress)*10;

					if (0>= TrainProgress)
					{/* error  */
						SNIM_ADD_EVENT_FLAG(SNIM_ERROR_TRAIN);
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
					}
					else if (100==TrainProgress)
					{/* finished*/
						SNIM_ADD_EVENT_FLAG(SNIM_EVENT_TRAINCOMPLETE);
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
					}
					else
					{/* not finished */
						Snim_NewDemodState(hSnim,SNIM_DEMODFSM_TRAIN);

					}

				}
				break;
			/*****************************************************************************************************\
			|                        This section of the state machine handles known channel acquistion           |
			\*****************************************************************************************************/

			case SNIM_DEMODFSM_ACQUIRE:
				printSnimDrv(("[Snim_DemodMain]: SNIM_DEMODFSM_ACQUIRE !!!  \n"));
				if (Snim_InitialiseChannel(hSnim))
				{ /* start the state machine for band/tones and polar*/
					
					printSnimDrv(("[Snim_DemodMain] New Demod State to SNIM_BPSFSM_STARTSAT !!! \n"));
#if 0//sss_20060227
					hSnim->LockBPSfsmState = SNIM_BPSFSM_STARTSAT;
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_WAITBPS);
#else
					hSnim->LockBPSfsmState = SNIM_LOCKFSM_START;
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_WAITLOCK);
#endif
				}
				else
				{/* error*/
					printSnimDrvError(("[Snim_DemodMain] SNIM_DEMODFSM_ACQUIRE : Snim_InitialiseChannel() makes Error !!! \n"));
					bRepeat=FALSE;
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
				}
				break;
			case SNIM_DEMODFSM_WAITBPS:
			case SNIM_DEMODFSM_WAITBPS_EXT:
				printSnimDrv(("[Snim_DemodMain] SNIM_BPSFSM_STARTSAT= set up the band, polarisation and satellite\n"));
				/* set up the band, polarisation and satellite */
				SNIM_ADD_EVENT_FLAG(Snim_BPSFsm(hSnim)); /* pass any diseqc requests out */
				/* NB: Snim_BPSFsm(hSnim) uses same timer as SnimDemodMain */

				if (hSnim->LockBPSfsmState==SNIM_BPSFSM_DONE)  
				{
					//SSS_DBG(OS,_INFO_,("Snim_DemodMain():STEP 8: New Demod State to SNIM_DEMODFSM_WAITLOCK= \n"));
					hSnim->LockBPSfsmState = SNIM_LOCKFSM_START;
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_WAITLOCK);
				}
				else if (hSnim->LockBPSfsmState==SNIM_BPSFSM_IDLE) 
				{
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
				}
				else if (hSnim->LockBPSfsmState>=SNIM_BPFSM_WAITING) 
				{
					hSnim->DemodFsmState=SNIM_DEMODFSM_WAITBPS_EXT;
				}
				else if (hSnim->LockBPSfsmState>=SNIM_BPFSM_BUSY) 
				{
					hSnim->DemodFsmState=SNIM_DEMODFSM_WAITBPS;
				}

				break;
			case SNIM_DEMODFSM_WAITLOCK:
				
				printSnimDrv(("[Snim_DemodMain] New Demod State to SNIM_DEMODFSM_WAITLOCK= \n"));
				Snim_LockFsm(hSnim);
				/* NB: Snim_LockFsm(hSnim) uses same timer as SnimDemodMain */
				if (hSnim->LockBPSfsmState==SNIM_LOCKFSM_LOCK)  
				{/* lock achieved */
					printSnimDrv(("[Snim_DemodMain]@@@ lock achieved  lock achieved  lock achieved @@@\n"));
					SNIM_ADD_EVENT_FLAG(SNIM_EVENT_LOCKED);
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_INITLOCK);
					//SSS_DBG(OS,_INFO_,("Snim_DemodMain():STEP 10: New Demod State to SNIM_DEMODFSM_INITLOCK= \n"));
				}
				else if (hSnim->LockBPSfsmState>=SNIM_LOCKFSM_PLL_TO)
				{/* lock failed */
					printSnimDrv(("[Snim_DemodMain] @@@ lock failed  lock failed  lock failed  lock failed  Status : %x @@@\n",hSnim->LockBPSfsmState));
					switch (hSnim->LockBPSfsmState)
					{
						case SNIM_LOCKFSM_PLL_TO: SNIM_ADD_EVENT_FLAG(SNIM_EVENT_TUNERTIMEOUT);;break;		
						case SNIM_LOCKFSM_QPSK_TO:SNIM_ADD_EVENT_FLAG(SNIM_EVENT_QPSKTIMEOUT);;break;		
						case SNIM_LOCKFSM_FEC_TO: SNIM_ADD_EVENT_FLAG(SNIM_EVENT_FECTIMEOUT);;break;		
						case SNIM_LOCKFSM_COM_ERR:SNIM_ADD_EVENT_FLAG(SNIM_ERROR_TUNERCOMMS);;break;
						default:SNIM_ADD_EVENT_FLAG(SNIM_ERROR_GENERAL);;break;
					}
					
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_UNLOCK);
					bRepeat = FALSE;
					
				}
				break;
			case SNIM_DEMODFSM_INITLOCK:
				/* start the timer and clear the error count in the chip */ 
				printSnimDrv(("[Snim_DemodMain] start the timer and clear the error count in the chip\n"));
				_dtvTimerSet(hSnim->hTimer,SNIM_GENERAL_TIMER, DTV_TIMER_NOW); 
				if (Snim_ReadRegisterValue(hSnim,SNIM_RS_BERCNT,(Uint32T*)&lBuffer))
				{
					
					printSnimDrv(("[Snim_DemodMain] SNIM_DEMODFSM_INITLOCK=> SNIM_DEMODFSM_LOCK !!!\n\n\n"));
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_LOCK);
				}
				else
				{
					printSnimDrv(("[Snim_DemodMain] SNIM_DEMODFSM_INITLOCK=> SNIM_DEMODFSM_UNLOCK ?\n\n\n\n"));
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_UNLOCK);
					bRepeat=FALSE;
				}

				break;

			/*****************************************************************************************************\
			|                        This section of the state machine handles scanning                           |
			\*****************************************************************************************************/
			case SNIM_DEMODFSM_SCANINIT:
				printSnimDrv(("[Snim_DemodMain] SNIM_DEMODFSM_SCANINIT !!!\n"));
				if (Snim_InitialiseScan(hSnim))
				{/* start the state machine for band/tones and polar*/
					hSnim->LockBPSfsmState = SNIM_BPSFSM_STARTSAT;
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_SCANWAITBPS);
				}
				else
				{
					hSnim->LockBPSfsmState = SNIM_BPSFSM_IDLE;
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_SCANWAITBPS);
					SNIM_ADD_EVENT_FLAG(SNIM_ERROR_SCAN);
				}
				break;
			case SNIM_DEMODFSM_SCANNEW:
				printSnimDrv(("[Snim_DemodMain] SNIM_DEMODFSM_SCANNEW !!! \n"));
				SNIM_ADD_EVENT_FLAG(SNIM_EVENT_SCANPROGRESS);
				hSnim->BPSFlags=0; /* clear flags */
				if (Snim_NextFreqScan(hSnim)){}/* new frequency */
				else if (Snim_NextPolarScan(hSnim)){}/* restart scan with opposite polarisation*/
				else if (Snim_NextSatScan(hSnim)){} /* change satellites and do a new scan*/
				else
				{ /* finished*/
					printSnimDrv(("[Snim_DemodMain] SNIM_DEMODFSM_SCANNEW .....SNIM_EVENT_SCANCOMPLETE... \n"));
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
					SNIM_ADD_EVENT_FLAG(SNIM_EVENT_SCANCOMPLETE);
					hSnim->wPerCent=1000;
					hSnim->bScan =0;
					bRepeat=FALSE;
					break;
				}
				printSnimDrv(("[Snim_DemodMain] SNIM_DEMODFSM_SCANNEW .....SNIM_BPSFSM_STARTSAT.... \n"));
				hSnim->ScanStatus &= ~SNIM_SCANSTAT_FOUND;
				Snim_CalcScanProgress(hSnim);

				/* start the state machine for band/tones and polar*/
				hSnim->LockBPSfsmState = SNIM_BPSFSM_STARTSAT;
				Snim_NewDemodState(hSnim,SNIM_DEMODFSM_SCANWAITBPS);
				break;

			case SNIM_DEMODFSM_SCANWAITBPS:
			case SNIM_DEMODFSM_SCANWAITBPS_EXT:
				/* set up the satellite, band and polarisation */
				SNIM_ADD_EVENT_FLAG(Snim_BPSFsm(hSnim)); /* pass any diseqc requests out */
				/* NB: Snim_BPSFsm(hSnim) uses same timer as SnimDemodMain */

				if (hSnim->LockBPSfsmState==SNIM_BPSFSM_DONE)  
				{
					hSnim->LockBPSfsmState = SNIM_LOCKFSM_START;
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_SCANWAITLOCK);
				}
				else if (hSnim->LockBPSfsmState==SNIM_BPSFSM_IDLE) 
				{
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_IDLE);
				}
				else if (hSnim->LockBPSfsmState>=SNIM_BPFSM_WAITING) 
				{
					hSnim->DemodFsmState=SNIM_DEMODFSM_SCANWAITBPS_EXT;
				}
				else if (hSnim->LockBPSfsmState>=SNIM_BPFSM_BUSY) 
				{
					hSnim->DemodFsmState=SNIM_DEMODFSM_SCANWAITBPS;
				}
				break;

			case SNIM_DEMODFSM_SCANWAITLOCK:
				Snim_LockFsm(hSnim);
				//printSnimDrv(("Snim_DemodMain(): SNIM_DEMODFSM_SCANWAITLOCK !!!\n"));
				/* NB: Snim_LockFsm(hSnim) uses same timer as SnimDemodMain */
				if (hSnim->LockBPSfsmState==SNIM_LOCKFSM_LOCK)  
				{
					printSnimDrv(("[Snim_DemodMain] NB: Snim_LockFsm(hSnim) uses same timer as SnimDemodMain !!!\n"));
					Snim_NewDemodState(hSnim,SNIM_DEMODFSM_SCANFOUND);
				}
				else if (hSnim->LockBPSfsmState>=SNIM_LOCKFSM_PLL_TO) 
				{/* lock failed */
					printSnimDrv(("[Snim_DemodMain] /* lock failed */!!! hSnim->LockBPSfsmState : %x \n",hSnim->LockBPSfsmState));
					switch (hSnim->LockBPSfsmState)
					{
						case SNIM_LOCKFSM_PLL_TO: SNIM_ADD_EVENT_FLAG(SNIM_EVENT_TUNERTIMEOUT);break;		
						case SNIM_LOCKFSM_QPSK_TO:SNIM_ADD_EVENT_FLAG(SNIM_EVENT_QPSKTIMEOUT);break;		
						case SNIM_LOCKFSM_FEC_TO: SNIM_ADD_EVENT_FLAG(SNIM_EVENT_FECTIMEOUT);break;		
						case SNIM_LOCKFSM_COM_ERR:SNIM_ADD_EVENT_FLAG(SNIM_ERROR_TUNERCOMMS);break;
						default:SNIM_ADD_EVENT_FLAG(SNIM_ERROR_GENERAL);break;
					}

⌨️ 快捷键说明

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