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

📄 servo.c

📁 车载电子影音系统dvd播放系统原程序代码
💻 C
📖 第 1 页 / 共 5 页
字号:
//  Function    :   SERVO_SetSectors    // ** TCH0.27;
//  Description :   Record the play range
//  Arguments   :   dwStartPos  : the starting sector
//                  dwEndPos    : the ending sector
//  Return      :   FALSE if ( End < Start )
//  Side Effect :   It may set (End<Start) conscious sometime. In this condition,
//                  Servo will stop to send anything except re-set the range.
//  *********************************************************************
BIT SERVO_SetSectors (DWORD dwStartPos, DWORD dwEndPos)
{
    // Always record the LBA, If the wrong of LBA can inhibit the process of SERVO
    gdwEndLBA=dwEndPos;
    gdwNextLBA = dwStartPos ;
    if (dwEndPos < dwStartPos)
    {
        return FALSE;
    }

#ifdef   _DUMP_INFO     // ** TCH0.95; 
    printf ( "\nRange [%ld-%ld],", gdwNextLBA, gdwEndLBA );
    _bSRV_Debug= NULL;
#endif	// _DUMP_INFO

    // TCC050, move to here since UTL_PlayFromTime won't call SERVO_ReadSectors
    gbServoRunning = TRUE ;

    if (__wW99AVPCRLow | 0x0800)
    {
        __wW99AVPCRLow &= ~0x0800 ;
        // TCC173-2, vcd/mp3->dvd PCR will be in CDIF reset state
        W99AV_WriteRegDW (PCR, __wW99AVPCRLow, __wW99AVPCRHigh) ;
    }
    //REQ enable & disable EDC
    W99AV_WriteRegDW(DCR, 0x1, 0x0);    // TCC276, this register seems will be reset

#ifdef ENABLE_SCMS
    // Process SCMS
    if (!(__wDiscType & BOOK_DVD))
    {
        extern STATUS    gcShowStatus;

        // TCC1.00, if < 1, might be doing cdrom decode.
        if (gcShowStatus.wCurrentTrack < 1)
            return TRUE ;

        if (_trk_TOC [gcShowStatus.wCurrentTrack-1].Ctl & 0x40) // Data Track
            return TRUE ;

        ATAPI_ReadSubQ () ;

        switch ((_trk_TOC [gcShowStatus.wCurrentTrack-1].Ctl & 0x0F))
        {
            case 0: // May not be audio track
            case 1: // Without copy restriction
                W99AV_WriteDM (W99AV_DM_SCMS, 1) ;
                break ;
            case 2: // One copy permitted
                W99AV_WriteDM (W99AV_DM_SCMS, 0) ;
                break ;
            case 3: // No copy permitted
                W99AV_WriteDM (W99AV_DM_SCMS, 2) ;
                break ;
        }
    }
#endif

    // TCC172.
    if (!__bServoAutoCtrl)
        SERVO_ReadData (dwStartPos, 0xFFFFFFFF) ;
        
    return TRUE;
}
// ** TCH0.27; end...

// ***********************************************************************
//  Function    :   SERVO_GetCurrentPos
//  Description :   Used to get the last sent sector number
//  Arguments   :   None.
//  Return      :   TRUE/FALSE
//  Side Effect :
// ***********************************************************************
BIT SERVO_GetCurrentPos(PDWORD pCurrentPos)
{
#if 1   // TCC172, CDDA 4X needn't read q-code
    // TCC171, CDDA should get Q-Code to know current position.
    // TCC274, check playing mode method has updated
    //if ( __bModePlay == MODE_PLAYCDDA )
    //if (__bAttrPlay == ATTR_CDDA)
    // TCC274, VCD/SVCD/MP3 need to do q-channel torelence check.
    if (!__bServoAutoCtrl)
    {
        *pCurrentPos = 0 ;
        // TCC171, this command has been modified that will return 4 bytes(Ctl/ADR, Min, Sec, Frm) instead of 12 bytes as UDE's spec.
        //UDE_ClearPacket () ; //LJY2.31, remove UDE_ClearPacket
        aPacket[0] = 0x00;  // paramater length is 0
        aPacket[1] = UDE_COMMAND_GETQSUBCHANNEL ;     //UDE : GetQSubchannel Command

        if (!UDE_SendUDECmd (aPacket))
            return ERROR ;          
///        *pCurrentPos = _MSFtoHSG (_bUDEData[1], _bUDEData[2], _bUDEData[3]) ;
        *pCurrentPos = COMUTL_MSFtoHSG ( MAKE_MSF(_bUDEData[1], _bUDEData[2], _bUDEData[3])) ;
        return TRUE ;
    }
#endif
    // TCC022, must minus 1 to return the current position, or VCD playing not smooth
    // TCC040, add protection if next position is 0, then current position will become -1
    if (gdwNextLBA <= 0)
        *pCurrentPos = 0 ;
    else
        *pCurrentPos = gdwNextLBA - 1 ;

    return TRUE;
}

// **********************************************************
//DVD020LLY, because scan function will call this function to jump to another position
// ***********************************************************************
//  Function    :   SERVO_JumpGroove
//  Description :   Used to get the position for scan function
//  Arguments   :   None.
//  Return      :   The next scan position
//  Side Effect :
// ***********************************************************************
DWORD SERVO_JumpGroove(BYTE bForward, DWORD dwTime)
{
    extern WORD    __wScanGap;
    if ( bForward )   // KEY_SCF
    {
        // the jump time range
        dwTime+= __wScanGap;
    }
    else
    {
        if ( dwTime > (__wScanGap+ SCB_EXTRA) )
            dwTime-= (__wScanGap+ SCB_EXTRA);
        else
            dwTime= (DWORD) NULL;
    }
    // the time need jump to
    return dwTime;

}

// ***********************************************************************
//  Function    :   SERVO_GetDiscInfo
//  Description :   Used to get some the following informations from disc (not for DVD)
//  Arguments   :   pMinTrack : the minimum track number
//                  pMaxTrack : the maximum track number
//                  pMaxSector : the maximum sector number of the disc
//  Return      :   TRUE/FALSE
//  Side Effect :
// ***********************************************************************
BIT SERVO_GetDiscInfo(PBYTE pMinTrack, PBYTE pMaxTrack, PDWORD pMaxSector)
{
    *pMinTrack = _bFirstTrack;
    // TCC104, for "CD Extra" cd type, remove the last few tracks that's not audio track
    if ((__wDiscType == BOOK_CDDA) && (_dwDiscKey [0]==0))
    {
        // TCC161, only do this once is enough
        _dwDiscKey [0] = 1 ;
        _bSERVOTmp1 = _bLastTrack ;
        while (_bSERVOTmp1 > _bFirstTrack)
        {
            if (_trk_TOC[_bSERVOTmp1-1].Ctl & 0x40)  // Data Track
                _bSERVOTmp1 -- ;
            else
                break ;
        }
        _bLastTrack = _bSERVOTmp1 ;
    }
    *pMaxTrack = _bLastTrack;
    *pMaxSector = _sessioninfo_TOC [_bLastSession-1].dwLeadOutPos; // LJY275
    return TRUE;
}

// ***********************************************************************
//  Function    :   SERVO_GetDiscLength
//  Description  :   Used to get length for the disc (not for DVD)
//                  It will take session information into consideration.
//  Arguments   :   pLength : length of the disc
//  Return      :   TRUE/FALSE
//  Side Effect  :
// ***********************************************************************
BIT SERVO_GetDiscLength(PDWORD pLength)
{
    if (__wDiscType & BOOK_DVD)
    {
#ifdef SUPPORT_PRINTF        
        printf ("SERVO_GetDiscLength is not supported for DVD title\n") ;
#endif
        return TRUE ;
    }
    //LJY0.87, fix the wrong total disc time bug of Abex 721 CDDA test title
    *pLength = _sessioninfo_TOC [_bLastSession-1].dwLeadOutPos + TRACK_GAP;
    //LJY1.25, WYC1.25, fix CDDA gototime issue. Leadout should be the discend.
    *pLength = _sessioninfo_TOC [_bLastSession-1].dwLeadOutPos;// + TRACK_GAP;
    return TRUE;   
}

// ***********************************************************************
//  Function    :   SERVO_GetTrackEnd
//  Description  :   Used to get length for the track (not for DVD)
//  Arguments   :   bTrackNum : the track number you want to get the length
//                  pLength : length of the track
//  Return      :   TRUE/FALSE
//  Side Effect  :
// ***********************************************************************
BIT SERVO_GetTrackEnd(BYTE bTrackNum, PDWORD pLength)
{
    if (__wDiscType & BOOK_DVD)
    {
#ifdef SUPPORT_PRINTF        
        printf ("SERVO_GetTrackLength is not supported for DVD title\n") ;
#endif
        return FALSE ;
    }
    // LJY275, for multi-session 2002/6/28
    for (_bSERVOTmp2=0; _bSERVOTmp2<_bLastSession; _bSERVOTmp2++)
    {
        if ((bTrackNum >= _sessioninfo_TOC [_bSERVOTmp2].bFirstTrack) && (bTrackNum <= _sessioninfo_TOC [_bSERVOTmp2].bLastTrack))
            break ;
    }
    if (_bSERVOTmp2 >= _bLastSession)
    {
//LJY0.87, the track end of last track should be the sector of (leadout - 1)
        *pLength = _sessioninfo_TOC [_bLastSession-1].dwLeadOutPos - 1; //real track end
//      *pLength = _sessioninfo_TOC [_bLastSession-1].dwLeadOutPos;
        return FALSE ;
    }
    if (bTrackNum == _sessioninfo_TOC [_bSERVOTmp2].bLastTrack)
    {
//LJY0.87, the track end of last track should be the sector of (leadout - 1)
        *pLength = _sessioninfo_TOC [_bSERVOTmp2].dwLeadOutPos - 1; //real track end        
//        *pLength = _sessioninfo_TOC [_bSERVOTmp2].dwLeadOutPos;
    }
    else
    {
///        *pLength = _MSFtoHSG (_trk_TOC[bTrackNum].Min, _trk_TOC[bTrackNum].Sec, _trk_TOC[bTrackNum].Frm)- 1 ;
        *pLength = COMUTL_MSFtoHSG ( MAKE_MSF(_trk_TOC[bTrackNum].Min, _trk_TOC[bTrackNum].Sec, _trk_TOC[bTrackNum].Frm))- 1 ;
    }
   
    return TRUE ;
}

// ***********************************************************************
//  Function    :   SERVO_GetTrackInfo
//  Description :   Used to get informations from the track (not for DVD)
//  Arguments   :   bTrackNum : the track number you want to get information
//                  pTrackCtl : used to distinguish if the track is data or CDDA
//                  pStartPos : the starting sector number of the track
//  Return      :   TRUE/FALSE
//  Side Effect :
// ***********************************************************************
BIT SERVO_GetTrackInfo(BYTE bTrackNum, PBYTE pTrackCtl, PDWORD pStartPos)
{
    BYTE bIndex = bTrackNum - _bFirstTrack;

    // TCC172, except DVD & CDDA, all other types are not auto-control
    __bServoAutoCtrl=FALSE;
    //__dwTimeTorelence = 5 ;           // TCC171
    // TCC040, Set track type to DATA TRACK if disc type is DVD.
    // prevent stop->play fast/slow become invalid problem
    if (_bSERVODiscType == DISC_TYPE_DVD)
    {
        *pTrackCtl = DATA_TRACK ;
        __bServoAutoCtrl=TRUE;
        //__dwTimeTorelence = 0 ;               // TCC171
        return TRUE ;
    }
    else if (_bSERVODiscType == DISC_TYPE_CDI)
#if 0   // TCC276-2nd, don't use this variable.
    if (_btCDROM_CDI)   // CDI Disc
#endif
    {
        *pTrackCtl = 0x40 ;
        return FALSE ;
    }

    *pTrackCtl = _trk_TOC[bIndex].Ctl ;
    // TCC, ADR/Ctl read from ude dvdrom
    // cdda   -> 1
    // vcd    -> 41
    // MP3 m1 -> 61
    // MP3 m2 -> 41
    //if (*pTrackCtl & 40)
    if (*pTrackCtl & 0x40)      // TCC173
        *pTrackCtl = DATA_TRACK;        // ** DVD-TCH0.19;
    else    // Audio Track
    {
        *pTrackCtl = 0x0 ;
        __bServoAutoCtrl=TRUE;
        //__dwTimeTorelence = 0 ;               // TCC171
//LJY0.87b, servo can support interpolation for CT908.
#if 0 
        // TCC274, check Abex Title 721R/725B and enable interpolation by DSP.
        if ((_bLastTrack==15 && _sessioninfo_TOC [_bLastSession-1].dwLeadOutPos == 0x2f4bd)     //0x2f4bd
            // TCC276, add PHILIPS SBC 444A
            || (_bLastTrack==24 && _sessioninfo_TOC [_bLastSession-1].dwLeadOutPos == 0x41906))
            W99AV_WriteDM (0x518, 1) ;  // Enable dsp interpolation, only dbb dsp code support
        else
            W99AV_WriteDM (0x518, 0) ;  // Disable dsp interpolation
        W99AV_WriteDM (0x511, 30000) ;  // Threshold for dsp to do interpolation
#endif        
    }


///    *pStartPos = _MSFtoHSG (_trk_TOC[bIndex].Min, _trk_TOC[bIndex].Sec, _trk_TOC[bIndex].Frm) ;
    *pStartPos = COMUTL_MSFtoHSG( MAKE_MSF(_trk_TOC[bIndex].Min, _trk_TOC[bIndex].Sec, _trk_TOC[bIndex].Frm)) ;
    return TRUE;
}

//LJY278, for pre-start servo
BYTE SERVO_Seek (DWORD dwSeekLBA, BYTE  bWaitBusy)
{
    //UDE_ClearPacket () ; //LJY2.31, remove UDE_ClearPacket

    aPacket[1] = UDE_COMMAND_PRESTART_SERVO;   
    if (_bSERVODiscType == DISC_TYPE_DVD)
    {
        aPacket[0] = 4;       // command paramater length is 4
        aPacket[2] = HIBYTE(HIWORD(dwSeekLBA));
        aPacket[3] = LOBYTE(HIWORD(dwSeekLBA));
        aPacket[4] = HIBYTE(LOWORD(dwSeekLBA));
        aPacket[5] = LOBYTE(LOWORD(dwSeekLBA));
    }
    else 
    {
        aPacket[0] = 3;       // command paramater length is 3
        dwSeekLBA = COMUTL_HSGtoMSF (dwSeekLBA) ;
        aPacket[2] = MSF_MINUTE (dwSeekLBA) ;
        aPacket[3] = MSF_SECOND (dwSeekLBA) ;
        aPacket[4] = MSF_FRAME (dwSeekLBA) ;
    }
    
    if (UDE_SendUDECmd(aPacket) != TRUE)
         return ERROR;
    
    return TRUE ;
}


// ***********************************************************************
//  Function    :   SERVO_Monitor
//  Description :   Used to monitor the dma process
//                  1. Will check gbServoRunning to see if servo is running.
//                  2. Calculate number of sector for DMA
//                  3. Check if buffer is full (Won't check if only 1 sector (Maybe NV))
//                  4. Call SERVO_ReadData to really transfer bitstream
//                  5. Check if playing end
//  Arguments   :   None

⌨️ 快捷键说明

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