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

📄 servo.c

📁 车载电子影音系统dvd播放系统原程序代码
💻 C
📖 第 1 页 / 共 5 页
字号:

//////////////////////////////////////////////////////////////
// ***** Big Modification History Area *****
// LLY2.80a,
//  - remove the codes while define "_ALONE",

// ** TCH0.95; define _DUMP_INFO, will show playing range setting + each play range.
/// #define     _DUMP_INFO


#include "winav.h"

// Chuan0.83b-2, Ser_420 is unnecessary if define HOSTIF
#ifndef INPUT_PATH_HOSTIF


#ifndef  SYSTEM_8051
#include "conio.h"
#include "stdio.h"
#include "stdlib.h"
#endif  //#ifdef DOS_VER

#include <string.h>
// Micky2.31, reduce codes, don't use C string API
#include "ctstring.h"
#include "servo.h"
#include "w99av.h"
#include "cc.h"
#include "cdinfo.h"
#include "ucode.h"
#include "osd.h"
#include "utl.h"
#include "input.h"
#include "hal.h"  // *** LLY.0411
//LJY275e
#include "comutl.h"
#ifdef SERIAL_DEBUG
#include "sysdebug.h"
#endif
#ifdef SUPPORT_PORTABLE_PROJECT
#include "initial.h"   // Added for portable, KCHong, 20031118
#endif
//LJY1.21, remove unnecessary functions
// - Remove SERVO_ISR()       --> ISR.C
// - Remove SERVO_ResetData(), SERVO_SetSpeed(), SERVO_SetFormat(), SERVO_GetFormat(), SERVO_SetDSPMode() --> UTL.C
// - Remove SERVO_DumpSector() --> W99AV2.C
// - Remove SERVO_SetPLL_ACLK(), SERVO_ControlGPIO() --> HAL1.C

//LJY1.00, share TOC buffer with servo
// Micky1.00, must use 08152003 servo codes.
#if SW_VERSION >= 100
#define TOC_SHARE 
#endif

//LJY2.79 ** TCH2.79; begin... 
#define SUPPORT_CHECK_SERVO_STOP
#define TIME_CHECK_STOP     (COUNT_10_SEC * 6)    // Default 60 seconds
#define WAITSTABLE_TIMEOUT  (COUNT_10_SEC * 4)  // LJY1.07
// ** TCH2.79; end... 

// DVD_274Micky, add copyright. Don't remove it!!!!
BYTE    Copyright_CHEERTEK_INC_2002_SERATA;

static BYTE code aDummy;    // Chuan1.00-2, Dummy Byte
//TCC032, use this define to use loop count or timer count, by default, only dostest use loop count
#ifdef NOT_SUPPORT_TIMER
#define COUNTING_BY_LOOP
#else
#define COUNTING_BY_TIMER
#endif

#ifdef   _DUMP_INFO
static  BYTE        _bSRV_Debug;
#endif	// _DUMP_INFO


extern  DWORD       __dwSectorLastSession;      // ** DVD-TCH0.25;

// TCC046
// initial the __bCurrentIF according to current interface
// BITSTREAM_ATAPIIF, Pure ATAPI I/F
// BITSTREAM_DVDIF  , when using DVD_IF(UDE or A/V Bus)
// BITSTREAM_CDIF   , Pure CD-IF
// BITSTREAM_HOSTIF , HOST_IF
BYTE    __bCurrentIF;//=BITSTREAM_DVDIF; //LJY2.31, move to initial.c
BYTE    __bServoAutoCtrl;//=TRUE; //LJY2.80, remove inital value

// TCC036, use to do buffer control or not
BYTE    bThreshold;//=1; //LJY2.80, move to SERVO_Init(()

//LJY0.87, for reading by 4x16 sectors in SERVO_Monitor()
BYTE    _bDMATimes,_bSendSector,_bOneTimeSec, _bDMALoop;

// **********************************************************
#ifdef COUNTING_BY_LOOP
#define LOOP_COUNT              6000
#define LOOP_COUNT_START        LOOP_COUNT
#define LOOP_COUNT_WAIT         LOOP_COUNT
#define LOOP_COUNT_FINISH       LOOP_COUNT
#define LOOP_COUNT_PIO          LOOP_COUNT
#define LOOP_COUNT_TOC          LOOP_COUNT
#define LOOP_COUNT_IDENTIFY     LOOP_COUNT
#define LOOP_DMA                60000
#endif

// **********************************************************
#define ERROR           FALSE

//LJY277
extern BYTE __bModePlay;
// TCC172
BYTE    __bSERVOErrMsg;// = SERVO_ERROR_NONE ; //LJY2.80, remove inital value
// TCC274, add this variable emsure F/W will do one time SERVO_CheckTrayStatus when H/W booting. 
BYTE    __bBootFromHW ;
//WORD    Identify[256];
WORD    *Identify ;
//TRKINFO _trk_TOC[100];
TRKINFO *_trk_TOC;
//Q_CODE  VCD_Qcode[100];
BYTE    _bFirstTrack, _bLastTrack;
// LJY275, _bLastSession reserved
//BYTE    gbFirstSession;
BYTE    _bLastSession; 
// LJY275, for multi-session, gdwLeadOutPos removed
SESSIONINFO *_sessioninfo_TOC ;
// DWORD   gdwLeadOutPos;
BYTE    _bSERVODiscType  ;
//TCC019, dma sector number = 64 if dvd, 32 if vcd
BYTE    _bDMASector;// = 64 ; //LJY2.80, remove inital value
//LJY2.80, move the initial value to SERVO_Init()
DWORD   _dwVBThreshold, _dwABThreshold;
//DWORD   _dwVBThreshold = SERVO_DEFAULT_VIDEO_THRESHOLD, _dwABThreshold = SERVO_DEFAULT_AUDIO_THRESHOLD ;
//DWORD   _dwVBThreshold = 0xbf00L, _dwABThreshold = 0x25000L ;

//BYTE    gbSectorSize;
//BYTE    gbServoDSPMode, gbServoDSPFormat, gbServoDSPSpeed;
//BYTE    _DSP_Format,_Audio_CDROM_Mode ;
//BYTE    _bCDROMMin,_bCDROMSec,_bCDROMFrm;
//BYTE    _bDMAOn = FALSE ;

// TCC040, use byte rather than bit
BYTE    gbServoRunning;//=FALSE ; //LJY2.80, remove inital value
DWORD   gdwNextLBA, gdwEndLBA;
//LJY275e
BYTE _bServoGPIO;       // for GPIO read

BYTE    _bUDEData[6];
DWORD   _dwTitleKey [3], _dwDiscKey [4] ;

//BIT     _btCDROM_CDI;         // TCC276-2nd, remove this variable

//TCC025, for new DMA method, set to 1
//BOOL    _DMA_ON = 1 ;
//TCC024, add copyinfo from dvd title
COPYINFO    cpinfo ;
// TCC276, this variable will store servo status
BYTE    _bSERVOStatus ;
// TCC161, for storing input bitstream sector numbers
BYTE    _bSERVOLastSectorCnt, _bSERVOSectorReq ;
DWORD   _dwSERVOTmp, _dwSERVOCnt1, _dwSERVOCnt2 ;
BYTE    _bSERVOTmp1;//, _bSERVOTmp2 ;
// DVD_275Micky, share the same variable.
#define _bSERVOTmp2  Copyright_CHEERTEK_INC_2002_SERATA
PBYTE   _pbSERVOTmp1 ;
DWORD   _dwTimeOut ;

#ifdef SUPPORT_ANTISHOCK
//Kevin2.37, CDDA_LR
BYTE    _bSERVOPLLUnlock = FALSE;
#endif

// TCC276, define timeout value for waiting ack and result code.
#define UDE_TIMEOUT_WAITACK         COUNT_500_MSEC
#define UDE_TIMEOUT_READTOC         COUNT_10_SEC
#define UDE_TIMEOUT_NORMAL          COUNT_5_SEC 
#define READTIME_INFO               COUNT_500_MSEC //LJY1.00, for showing meeage when ReadData > 500 ms
// **********************************************************
#define UDE_COMMAND_OPENTRAY                            0x00
#define UDE_COMMAND_CLOSETRAY                           0x01
#define UDE_COMMAND_RESTARTUNIT                         0x02
#define UDE_COMMAND_GETDISCTYPE                         0x04
#define UDE_COMMAND_GETTOC                              0x05
#define UDE_COMMAND_GETLBA                              0x06
#define UDE_COMMAND_GETQSUBCHANNEL                      0x08
#define UDE_COMMAND_READCD                      0x09
#define UDE_COMMAND_READDVD                     0x0a
#define UDE_COMMAND_SCAN                        0x0b
#define UDE_COMMAND_PAUSERESUME                 0x0c
#define UDE_COMMAND_ABORT                       0x0d
//LJY278
#define UDE_COMMAND_PRESTART_SERVO             0x0f
//#define UDE_COMMAND_GETSTATUS                 0x10
#define UDE_COMMAND_GETSERVOINFO        0x10 
#define UDE_COMMAND_CONFIGURELOADER             0x11
#define UDE_COMMAND_POWERMANAGEMENT             0x12
#define UDE_COMMAND_READDISCKEY                 0x13
#define UDE_COMMAND_GETSERVODEBUGINFO                   0x17
//#define UDE_COMMAND_GETCOPYRIGHTINFORMATION 0x14
#define UDE_COMMAND_CONTROLGPIO                         0x14
// wyc.277a-2
#define UDE_COMMAND_SETPLL_ACLK                         0x18   // Add by HCC for PLL setting in servo 2002/09/09

#define GETSTATUS                                       0x10
#define GETCOPYRIGHTINFORMATION          0x14
#define GETFWVERSION                                            0x15

#ifdef SHOW_POWERON_BAR //Xuli1.07 for trigger power-on bar
extern void	OSD_TriggerPoweronBar(void);
#endif

// for GetStatus command
// TCC276, change the definition so that we don't need to read twice for different mode
#define UDE_STATUS_PLAYBACK         0x03
#define UDE_STATUS_TRAY             0x0C
#define UDE_STATUS_MEDIA            0x30
#define UDE_STATUS_QUEUE            0x40
#define UDE_STATUS_READ             0x80

#define UDE_STATUS_COMMAND_ERROR    0xff
#define UDE_PLAYBACK_STATUS_STOPPED 0x00
#define UDE_PLAYBACK_STATUS_PAUSING 0x01
#define UDE_PLAYBACK_STATUS_PLAYING 0x02
#define UDE_TRAY_STATUS_OPEN        0x00
#define UDE_TRAY_STATUS_OPENING     0x04
#define UDE_TRAY_STATUS_CLOSE       0x08
#define UDE_TRAY_STATUS_CLOSING     0x0C
#define UDE_MEDIA_STATUS_ANALYZING  0x00
#define UDE_MEDIA_STATUS_PRESENT    0x10
#define UDE_MEDIA_STATUS_NOT_PRESENT    0x20
#define UDE_MEDIA_STATUS_NOT_ANALYZED   0x30
#define UDE_QUEUE_STATUS_NOT_FULL   0x00
#define UDE_QUEUE_STATUS_FULL       0x40
#define UDE_READ_STATUS_NO_ERROR    0x00
#define UDE_READ_STATUS_ERROR       0x80
// **********************************************************
//UDE : get UDE status : (pASCQ: bit 1-0, pASC: bit3-2, pSense: bit5-4)
BYTE UDE_GetStatus(void);
BIT UDE_StartCommand();
BIT UDE_WaitPacket();
extern void UDE_SendPacket(PBYTE pData);
extern PBYTE UDE_WaitRetData(BYTE data_count);  
extern void Service_420(void);
extern BIT INIT_420_2(void);
BYTE UDE_WaitCmdFinish();  //UDE: Read RXD data              //UDE RXD data catch OK
BYTE UDE_ReadData(BYTE *pData, BYTE wArrayLen);
BIT UDE_SendUDECmd(PBYTE pPacketData) ;
//void UDE_ClearPacket (void) ; //LJY2.31, remove UDE_ClearPacket

// **********************************************************
BIT  SERVO_ReadData(DWORD dwStartLBA, WORD wSectorNum);
BIT  _WaitStable (BYTE bShowStatus) ;
//LJY0.87b
BIT _CSS_SentDiscKey () ;
void _CSS_SentTitleKey () ;
///void _HSGtoMSF(DWORD hsgTime) ;
///DWORD _MSFtoHSG(BYTE bMin, BYTE bSec, BYTE bFrm) ;
//BYTE _BCDtoDec (BYTE bBCD) ;
// **********************************************************
// **********************************************************
// define [0]: UDE command code
// define [1]: UDE paramater length (UDE max_length is : 10)
// define [2]~[11]: paramater value
BYTE aPacket [12]; // ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} ; //LJY2.80, remove inital value
BYTE __bServoRevision [5] ;

// Added by Chern Shyh-Chain, 08-30-2001, BEGIN
// Define the structure to keep the title key (40 bit) and relative copyright information
typedef struct  tagTITLE_KEY_COPY_INFO_LOG
{
    DWORD   dwTitleKey32Bit;    // Keep the 32/40 Title Key
    BYTE    bTitleKey8Bit;      // Keep the 8/40 Title Key
    COPYINFO    CopyInfo;       // Keep the relative Copyright Information
} TITLE_KEY_COPY_INFO_LOG, *PTITLE_KEY_COPY_INFO_LOG;

// Record the multiple title keys and copyright information for special title.
// The maximum title keys can be recorded is defined by MAX_TITLE_KEY_NUM (cdinfo.h).
TITLE_KEY_COPY_INFO_LOG _TitleKeyCopyInfoStore[MAX_TITLE_KEY_NUM];

// Keep cuurent title key and copyright information.
TITLE_KEY_COPY_INFO_LOG _CurrentTitleKeyCopyInfo;

#define NULL_TITLE_KEY      0  // This is a empty title key value
// Added by Chern Shyh-Chain, 08-30-2001, END

// ***********************************************************************
//  Function    :   SERVO_Reset
//  Description :   Will do nothing for ude dvdrom
//  Arguments   :   None
//  Return      :   TRUE/FALSE
//  Side Effect :
// ***********************************************************************
BIT  SERVO_Reset(BYTE bShowBar)
{
    // LJY1.02, disable service 420 during reset
    {
        extern BIT INIT_420_1(void);
        // suspend 420's main flow. Only can be released after 420 initial OK.
        INIT_420_1();
    }

    // wyc.278, re-arrange the SERVO_Reset method in different system.
    gbServoRunning = FALSE ;        // TCC275c, disable servo running.
    W99AV_WriteRegDW (PCR, __wW99AVPCRLow|0x01, __wW99AVPCRHigh) ;
    UTL_DelayTime (COUNT_100_MSEC, 1) ;
    W99AV_WriteRegDW (PCR, __wW99AVPCRLow, __wW99AVPCRHigh) ;  

//LJY1.00, share TOC buffer with servo
    #ifdef TOC_SHARE
    _trk_TOC = (TRKINFO*)&__bPool [LENGTH_SHAREPOOL-512] ;   
    #endif
//LJY1.02, init 420 may(D500 report) fail, try 5 more times.   
    for(_bSERVOTmp1=0; _bSERVOTmp1<5; _bSERVOTmp1++)
    {
#ifdef _DEBUG_INFO
        printf("\n INIT servo 420 %hx", _bSERVOTmp1);
#endif                
        if(INIT_420_2())               // Rick, call 420 F/W init routine    
        {
            _bSERVOTmp1 = 0;
            break;
        }
    }
#ifdef _DEBUG_INFO
    if(_bSERVOTmp1 != 0)
    {
        printf("\n INIT servo 420 failed !!");
    }
#endif        

//LJY1.07, for loading status bar display
#ifdef SHOW_POWERON_BAR
    if(bShowBar)
    {
        _bSERVOTmp1 = WAITSTABLE_SLEDGE_SHOW_BAR;
    }
    else
#endif        
    {
        _bSERVOTmp1 = WAITSTABLE_SLEDGE;
    }
    //LJY0.95, wait for servo finish sledge-in state, otherwise the pick-up behavior would be abnormal.
    if(!_WaitStable(_bSERVOTmp1))
        return FALSE;
    return TRUE;
}


// ***********************************************************************
//  Function    :   SERVO_Init
//  Description :   Will do configure loader command

⌨️ 快捷键说明

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