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

📄 servo.c

📁 车载电子影音系统dvd播放系统原程序代码
💻 C
📖 第 1 页 / 共 5 页
字号:
//  Return      :   TRUE/FALSE
//  Side Effect :
// ***********************************************************************
BIT SERVO_Monitor()
{
    WORD   wTmp ;
//LJY0.87, defined it to enable reading data by way of 16x4 sectors.
#define DIVIDE_SECTOR
//LJY1.24, fix pause->play CDDA audio break when pause time exceed TIME_CHECK_STOP
#ifdef SUPPORT_CHECK_SERVO_STOP
    static  DWORD   _dwLastDMATime = 0 ;
#endif

    Service_420 () ;

    if (!__bServoAutoCtrl)
        return TRUE ;
        
    if (gbServoRunning)
    {
        //TCC021, must add 1 to include the last sector
        wTmp = (WORD) MIN(_bDMASector, (gdwEndLBA - gdwNextLBA + 1));
        _bSendSector = (BYTE)wTmp;
        //TCC023, if no data to transfer
        if (wTmp < 1)
            return TRUE ;
//LJY1.05, no need to do AV buffer control for NV data.
        if (__bModePlay != MODE_PLAYCDROM)
        {
        // TCC037, if wTmp==1, it might be NV sector, don't do buffer control
            if (bThreshold && wTmp != 1)
            {
                // TCC019, control video and audio buffer
                if (__wDiscType & BOOK_DVD)
                {
                    W99AV_ReadInfo (W99AV_INFO_VIDEO_REMAIN, &_dwSERVOTmp) ;
//LJY1.21, LJY1.11, reference __dwVOBuffer instead of _dwVBThreshold.                    
#ifdef SUPPORT_ANTISHOCK
                    if (_dwSERVOTmp > __dwVOBuffer)
                    {
#else
                    if (_dwSERVOTmp > _dwVBThreshold)
                    {
#endif                        
                        return TRUE;   
                }
                }
                else
                {  
                    //LJY1.10, for DVD JPEG&MP3
                    if (__bModePlay == MODE_PLAYAUDIO)
                    {
                        // CDDA title, or DVD MP3
                        W99AV_ReadInfo (W99AV_INFO_AUDIO_REMAIN, &_dwSERVOTmp) ;
                        // TCC274, don't check buffer empty but check buffer remainder.
                        // So that we can increase audio buffer w/o modify code.
                        // 15 sectors torelence time is 15/75=200ms.
                        if (_dwSERVOTmp < __dwW99AVABUFFSIZE/2)
                        {
                            //Kevin0.91, read more data instead of 1/2 audio buffer size when audio buffer remainder is less than 1/2 of buffer size
                            //wTmp = __dwW99AVABUFFSIZE/2/588 ;
                            //Kevin1.05, avoid the CDDA broken noise by preventing overflow since PCM audio buffer has been enlarged to 40K DW 
                            ///wTmp = (__dwW99AVABUFFSIZE-_dwSERVOTmp)/588 ;
                            //LJY1.22, LJY1.11b, use SECTOR_607, SECTOR_784 instead of 607 and 784
                            if(__bCDDA_DTS & CDDA_BITSTREAM_PURE)
                            {
                                wTmp = __dwW99AVABUFFSIZE/3/SECTOR_CDDA ; //LJY1.23, use SECTOR_CDDA instead of 588 or 784
                            }
//LJY1.24, use NO_CDG to determine whether CDG is supported.
#ifndef NO_CDG                             
                            else if(__bCDDA_DTS & CDDA_BITSTREAM_CDG)
                            {
                                wTmp = __dwW99AVABUFFSIZE/3/SECTOR_784 ; //with subcode
                            }
#endif                            
                            else
                            {
                                wTmp = __dwW99AVABUFFSIZE/3/SECTOR_588 ; //without subcode                                
                            }                                
                        }
                        else
                            return TRUE ;
                    }
                    else
                    {
                        //DVD JPEG
                        W99AV_ReadInfo (W99AV_INFO_VIDEO_REMAIN, &_dwSERVOTmp) ;
                        if (_dwSERVOTmp < __dwW99AVVBUFFSIZE/2)
                            wTmp = __dwW99AVVBUFFSIZE/3/SECTOR_512; //(2048/4=512)//LJY1.22, LJY1.11b, use SECTOR_512 instead of 512
                        else
                            return TRUE ;
                    }
                    if (gdwNextLBA+wTmp>gdwEndLBA)
                    {  
                        wTmp = gdwEndLBA - gdwNextLBA ;
                    }
                }
            }
        }

//LJY2.79 ** TCH2.79; begin... 
#ifdef SUPPORT_CHECK_SERVO_STOP
    {
        if (UTL_GetSysTimer() - _dwLastDMATime > TIME_CHECK_STOP)  // Over 5 minutes
        {
            // wyc.172, because DVS loader will have problem in Start Up command, so use seek command to replace it and not do 
            // power mode checking.
            SERVO_Seek (gdwNextLBA,TRUE);
        }
        _dwLastDMATime = UTL_GetSysTimer() ;
    }
#endif // ** TCH2.79; end... 
        
// LJY0.87, not for CDDA
#ifdef DIVIDE_SECTOR 
//LJY0.87a, don't do buffer control for NV sector
    if((__wDiscType & BOOK_DVD) && (wTmp != 1))
//    if (__wDiscType & BOOK_DVD)        
    {
        W99AV_ReadInfo (W99AV_INFO_AUDIO_REMAIN, &_dwTitleKey[0]) ;
// LJY2.32, share same flow for both SCF/SCB and other play mode.        
/*
        if ((_dwTitleKey[0] < 2000) || (__bModeCmd == KEY_SCF)|| (__bModeCmd == KEY_SCB))
        {
            
            _bOneTimeSec = _bDMASector; 
            _bDMALoop = 1;
            
#ifdef   _DUMP_INFO     // ** TCH0.95; 
            printf ( "special [%d]", _bOneTimeSec );
#endif	// _DUMP_INFO
            
        }
        else
*/        
        {
            _bOneTimeSec = 16;  //438MHz: OK 

			//Kevin2.33-2, fix Dolby Test DVD TT/CC=30/1 broken noise (DSP performance issue. PCM output repeats for a while)  
			// Decrease SERVO read sectors each time _bOneTimeSec=4 (Burst data into ACFIFO interrupts DSP. Smaller burst size=> less interrups during the same period)
			if(__bAudioType==HAL_AUDIO_AC3)
			{
				W99AV_ReadDRAMData ( W99AV_DRAM_LOGO_START, & _dwSERVOCnt1 );
				if ( ( HIWORD(_dwSERVOCnt1) == 0x1 ) && (_dwSERVOTmp <= 0x30) ) //still mode
				{
					_bOneTimeSec = 4; //399MHz 16:X 8:OK; 360MHz 8:X 16:X 4: OK, but may cause A/V unsmooth (A underflow)
				}
			}

            _bDMALoop = _bDMASector / _bOneTimeSec;
            // Chuan1.00-2, Check Audio Buffer overflow for all case.
            //if ((_dwTitleKey[0] > _dwABThreshold) && (__bAudioType != HAL_AUDIO_LPCM))
//LJY1.21, LJY1.11, reference __dwAOBuffer instead of _dwABThreshold.            
#ifdef SUPPORT_ANTISHOCK
            if (_dwTitleKey[0] > __dwAOBuffer)
#else
            if (_dwTitleKey[0] > _dwABThreshold)
#endif
                return TRUE;

			//Kevin2.33-2, comment
			/*
            if ((__bAudioType != HAL_AUDIO_LPCM) && (_dwSERVOTmp <= 0x30))
            {
                if ( _bSendSector > 10 )    // ** TCH0.91; Add it, other _bSendSector is modified. Fix the bug: Audio of Dolby AC3 title is broken
                    _bSendSector = 10;
// ** TCH0.91;                 _bOneTimeSec = 10;
            }
// ** TCH0.91;             else
// ** TCH0.91;                 _bOneTimeSec = 16;
			*/
        }

        // Read data by several times
        for (_bDMATimes =0; _bDMATimes <_bDMALoop; _bDMATimes++)
        {
            if (_bSendSector > _bOneTimeSec)
                wTmp = (WORD)_bOneTimeSec;
            else
                wTmp = (WORD)_bSendSector;
            if (SERVO_ReadData(gdwNextLBA, wTmp) == TRUE)
            {
            }
#if defined(SUPPORT_PRINTF) || defined(SERIAL_DEBUG)
            else
            {
                printf("\n ReadData[%ld]~[%ld]failed", gdwNextLBA, gdwNextLBA+wTmp);            
            }
#endif

#ifdef   _DUMP_INFO     // ** TCH0.95; 
            {               
                printf ( "[%ld-%ld]", gdwNextLBA, gdwNextLBA+ wTmp- 1 );
                _bSRV_Debug++;
                if ( ! (_bSRV_Debug% 4 ) )
                    printf ( "\n" );
            }
#endif	// _DUMP_INFO
        //LJY1.21, to speed up IR key response for OPEN/CLOSE/NEXT/PREV
        if(UTL_QueryCapability(QUERY_ABORT_SERVO))
        {
            gbServoRunning = FALSE;              
            return FALSE ;
        }

            // ** TCH0.91; begin... 
            _bSendSector-= wTmp;
            gdwNextLBA += wTmp;
            if ( ! _bSendSector )
            {
                break;
            }

            W99AV_ReadInfo (W99AV_INFO_VIDEO_REMAIN, &_dwSERVOTmp) ;
            W99AV_ReadInfo (W99AV_INFO_AUDIO_REMAIN, &_dwSERVOCnt2) ;
            // wyc.170, add video underflow control for some cases video will underflow. When still mode we don't check video underflow status.
            W99AV_ReadDRAMData ( W99AV_DRAM_LOGO_START, & _dwSERVOCnt1 );
//LJY1.21, LJY1.07e            
#ifdef SUPPORT_ANTISHOCK            
            if (((_dwSERVOTmp >= __dwVOBuffer) && (_dwSERVOCnt2 >=1000)) || ((_dwSERVOCnt2 >= __dwAOBuffer) && ((_dwSERVOTmp >= 1000) || (HIWORD(_dwSERVOCnt1) == 0x1))) ) 
#else
//            if (((_dwSERVOTmp >= _dwVBThreshold) && (_dwSERVOCnt2 >=1000)) || ((_dwSERVOCnt2 >= _dwABThreshold) && ((_dwSERVOTmp >= 1000) || (HIWORD(_dwSERVOCnt1) == 0x1))) ) 
//LJY2.32, only reference VRem for video overflow checking.
            if ((_dwSERVOTmp >= _dwVBThreshold) || ((_dwSERVOCnt2 >= _dwABThreshold) && ((_dwSERVOTmp >= 1000) || (HIWORD(_dwSERVOCnt1) == 0x1))) ) 
#endif
            {
                break;
            }
        }
    }
    else
    {
        if (SERVO_ReadData(gdwNextLBA, wTmp) == TRUE)
        {
//LJY1.23, LJY1.11b-2, don't update gdwNextLBA for CDDA otherwise OSD time would be updated when no bitstream input.
#ifdef SUPPORT_ANTISHOCK
            if(__bAttrPlay == ATTR_CDDA)
                gdwNextLBA += wTmp;
#endif            
        }
        else
        {
#if defined(SUPPORT_PRINTF) || defined(SERIAL_DEBUG)            
            printf("\n ReadData[%ld]~[%ld] failed", gdwNextLBA, gdwEndLBA);            
#endif
#ifdef SUPPORT_ANTISHOCK
            //Kevin2.37, fix CDDA L/R swap when beating the player 
            if(__bAttrPlay == ATTR_CDDA)
            {
                if (_bSERVOPLLUnlock)
                {
                    W99AV_Reset(W99AV_RESET_CDIF);
                    HAL_Reset(HAL_RESET_PARSER);
                    HAL_ControlParser(HAL_PARSER_ENABLE, (BYTE)NULL );
                    _bSERVOPLLUnlock = FALSE;
                }
            }
#endif
        }
//LJY1.23, LJY1.11b-2, don't update gdwNextLBA for CDDA otherwise OSD time would be updated when no bitstream input.
#ifdef SUPPORT_ANTISHOCK
            if(__bAttrPlay != ATTR_CDDA)
#endif                   
        gdwNextLBA += wTmp;
    }
#else // #else of DIVIDE_SECTOR
        if (SERVO_ReadData(gdwNextLBA, wTmp) == TRUE)
        {
        }
#if defined(SUPPORT_PRINTF) || defined(SERIAL_DEBUG)
        else
            printf("\n ReadData[%ld]~[%ld] failed", gdwNextLBA, gdwEndLBA);            
#endif
        gdwNextLBA += wTmp;
#endif  // DIVIDE_SECTOR

        if ((wTmp == 0) || (SERVO_CheckDiscEnding()))
        {
            gbServoRunning = FALSE;
        }
    }
//LJY1.24, not perform servo seek in SERVO_Monitor() for pause to fix pause->play CDDA audio break when pause time exceed TIME_CHECK_STOP.
//            The audio buffer may be empty if performed servo seek and the audio break may be occur.
#ifdef SUPPORT_CHECK_SERVO_STOP
    else
    {
        if(__btPause)
            _dwLastDMATime = UTL_GetSysTimer() ;            
    }
#endif        

    return TRUE ;
}

// ***********************************************************************
//  Function    :   SERVO_CheckDiscEnding
//  Description :   Used to check if play end
//  Arguments   :   None
//  Return      :   TRUE/FALSE
//  Side Effect :   
// ***********************************************************************
BIT SERVO_CheckDiscEnding()
{
    if (gdwNextLBA > gdwEndLBA)
        return TRUE;
    else
        return FALSE;
}

// ***********************************************************************
//  Function    :   SERVO_ReadData
//  Description :   Used to read data from ude
//                  1. Send command according to the disc type
//                  2. Check if transfer complete
//  Arguments   :   dwStartLBA : The starting sector number to read
//                  wSectorNum : number of sectors to read
//  Return      :   TRUE/FALSE
//  Side Effect :   
// ***********************************************************************
BIT SERVO_ReadData(DWORD dwStartLBA, WORD wSectorNum)
{
    _dwSERVOTmp = dwStartLBA + ((DWORD) wSectorNum) - 1;

//    UDE_ClearPacket () ; //LJY2.31, remove UDE_ClearPacket

    if (_bSERVODiscType == DISC_TYPE_DVD)
    {
        aPacket[0] = 9;       // command paramater length is 9
        aPacket[1] = UDE_COMMAND_READDVD;    // UDE : Read_DVD command
        aPacket[2] = HIBYTE(HIWORD(dwStartLBA));
        aPacket[3] = LOBYTE(HIWORD(dwStartLBA));
        aPacket[4] = HIBYTE(LOWORD(dwStartLBA));
        aPacket[5] = LOBYTE(LOWORD(dwStartLBA));
        aPacket[6] = HIBYTE(HIWORD(_dwSERVOTmp));
        aPacket[7] = LOBYTE(HIWORD(_dwSERVOTmp));
        aPacket[8] = HIBYTE(LOWORD(_dwSERVOTmp));
        aPacket[9] = LOBYTE(LOWORD(_dwSERVOTmp));
        //LJY277, to distinguish CDROM data, NVPAck or AV data
        aPacket[10] = ((wSectorNum==1)||(__bModePlay==MODE_PLAYCDROM)) ? 0x01 : 0x00; // Data Type      
    }
    else // for non-DVD type, all use cd type if (_bSERVODiscType == DISC_TYPE_VCD)
    {
        aPacket[0] = 7;       // command paramater length is 7
        aPacket[1] = UDE_COMMAND_READCD;    // UDE : Read_CD command
        //_HSGtoMSF(dwStartLBA);
        _dwSERVOCnt1 = COMUTL_HSGtoMSF (dwStartLBA) 

⌨️ 快捷键说明

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