📄 gdtservo.c
字号:
/* Copyright 1998-1999, ESS Technology, Inc. *//* SCCSID @(#)gdtservo.c 1.22 02/26/04 *//* Based on tcservo.c 2.11 03/02/01 *//* * This is based on version 1.9(01/08/99) of dsat.c for VCD * This is for GDTSERVO *//* * Many of the DSA routines are actual SERVO routines if -DSERVO */#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include "buffer.h"#include "common.h"#include "const.h"#include "cd.h"#include "constvar.h"#include "debug.h"#include "display.h"#include "dsa.h"#ifdef TWO_FIELDS_OSD #include "cg.h"#else#include "fsosd.h"#endif#include "micro.h"#include "sysinfo.h"#include "tdm.h"#include "timedef.h"#include "util.h"#include "mvd.h"#include "play.h"#include "vcxi.h"#include "xport.h"#include "vp.h"#include "echo.h"#include "servogdt.h"#include "config.h" #ifdef FRACTINT#include "fractint.h"#endif#define xGDT_DEBUGint search_timer;unsigned char Qcode[10];/************************************************************************ * DSA variables , for CD control * ************************************************************************/extern long int run_time; /* absolute time format ttmmssff */extern unsigned char SERVO_Qarray_current[];extern int target_min, target_sec, target_frame;extern int SERVO_stop();extern void system_reset(void);extern void system_start(void);extern void system_audio_partial_reset(int par);extern void hardware_reset(int par);extern int mode_flags;extern int SERVO_mode;extern int SERVO_state;extern int servo_flags;extern int vcd20_start, vcd20_end;/* * CD-module's mode bits * 2:0 sets the speed * 000: illegal * 001: normal CD-DA speed * 010: double speed * other values are reserved * 3 0: audio mode; 1: CD-ROM mode * 5:4 Actual Title, time, index (ATTI) setting * 00: no title, index, or time send during play modes * 01: sending title, index, and absolute time (min/sec) * 10: sending title, index and relative time (min/sec) * 11: reserved * 7-6 reserved */#define MODE_SPEED_NORMAL 0x1#define MODE_SPEED_DOUBLE 0x2#define MODE_AUDIO 0x0#define MODE_CDROM 0x8#define MODE_ATTI_NONE 0x0#define MODE_ATTI_ABS 0x10#define MODE_ATTI_REL 0x20/************************************************************************ * Global variables * ************************************************************************/CDINFO CDinfo;int power_up = 1; /* Flag is set to 0 after system starts. */int num_of_track; /* # of tracks in the CD */int first_seg_ad; /* BCD sector location for first segment * * address. Comes from INFO.VCD. It is * * always in MM:SS:FF form. Should be * * XXYY00. In most case, XX is 00 and * * YY is 05 but there is no guarantee. * * (From INFO.VCD) */int CDinited = 0; /* 0: key info of CD has not been read * * 1: CD info has been read/stored */char forceDSAabort = 0; /* Force DSA to quit and return as if * * command succeed. */unsigned int err_code = 0; /* Error code from DSA routines */unsigned char servo_track_changed;/*A flag indicates new track has come. */unsigned int servo_info; /* store TTMMSSFF info from servo. */unsigned int last_servo_info;/* store previous TTMMSSFF info from servo. */int currentTVmode; /* TV_NTSC or TV_PAL */int bcd_num_of_track; /* used in OSD */int save_ramcode = -1;unsigned char *CDI_ptr;static int cdda_glbTimer; /* record the time when we start cdda. *//************************************************************************ * Variables local to this module * ************************************************************************/unsigned int CDDA_play_time;unsigned int CDDA_track_start_time;int currDSAmode = 0; /* Current CDROM's DSA mode. We'll only * * issue dsa_mode command if the new * * mode is different from the current * * mode. *//* States in dsa_go_step_by_step */#define DSA_GO_INIT 0#define DSA_GO_SEARCHING 1#define DSA_GO_FOUND_TARGET 2int dsa_go_state = DSA_GO_INIT;IMPORT int DiscMode;/************************************************************************ * Debug variables * ************************************************************************/# if 0DEBUGVAR(go_time, 0); /* The last dsa_go time */DEBUGVAR(dbgDSAclose, 0); /* Debug variable for dsa_close routine */DEBUGVAR(dbgDSAgo, 0); /* Debug variable for dsa_go routine */DEBUGVAR(dbgDSAmode, 0); /* Debug variable for dsa_mode routine */DEBUGVAR(dbgDSAopen, 0); /* Debug variable for dsa_open routine */DEBUGVAR(dbgDSApause, 0); /* Debug variable for dsa_pause routine */DEBUGVAR(dbgDSApauserelease, 0);/* Debug variable for dsa_pauserelease */DEBUGVAR(dbgDSArelease, 0); /* Debug variable for dsa_release */DEBUGVAR(dbgDSArcv, 0); /* Debug variable for receive_dsa */DEBUGVAR(dbgDSAstop, 0); /* Debug variable for dsa_stop routine */DEBUGVAR(dbgPlaySector, 0); /* Can't find the given sector from 20 * * frames ealier. */DEBUGVAR(dbgGetSector, 0); /* Can't get the sector (because SYNC * * pattern is not found). */DEBUGVAR(glbSec, 0); /* Global time in seconds */DEBUGVAR(dbgReceiveDsa, 0); /* Debug variable for receive_dsa */DEBUGVAR(dbgServiceVcxi, 0); /* Number of time service_vcxi is called */DEBUGVAR(dbgSafeServiceVcxi, 0);/* Number of "save" service_vcxi calls */DEBUGVAR(dbgMaxRDSA, 0); /* Max. RDSATimeCount */DEBUGVAR(dbgMaxRcvAll, 0); /* Max. number of receive_dsa calls * * before we get a full piece of data */DEBUGVAR(dbgMaxLtocCnt, 0); /* Max. number of LTOC replies */#endif/************************************************************************ * Functions declared and used within this module only. * ************************************************************************/int dsa_mode(int);int dsa_go(unsigned int);int dsa_go_step_by_step(unsigned int);void init_dsa(void);int processCDI(unsigned int *, int);void reset_dsa_go();/************************************************************************ * Imported functions * ************************************************************************/IMPORT void microEngine();IMPORT void DISP_cigam();IMPORT void DISP_naicigam();void CUST_init(){ vcx_cd_drive = CD_GDT3000; vcx_xfer_mode = 5;}void dsa_reset(){ servo_info = 0;}#if 1 /* TESTING */int abc;unsigned int abc_data[100];int fyh_min = 10;void test_dsa(){ extern int key0; if (key0 != -1) abc = key0&0xff; if (abc == 4 || abc == 5 ){ if (SERVO_mode != 2 && SERVO_state != 0) { SET_servo_adj; SERVO_mode = Mode_Focusing; SERVO_state = Focus_Para; do { /* Monitor Servo Stability in dsa_ltoc() */ GDT_SERVO_process(); if (SERVO_STATUS == SERVO_RET_Qcode) break; if (SERVO_STATUS == SERVO_RET_int) return ; if (SERVO_STATUS == SERVO_RET_clvok) break; if((SERVO_STATUS==SERVO_RET_loss) || (SERVO_STATUS==SERVO_RET_clvng)){ CDinfo.type = CD_NODISC; return ; } } while (1); } } switch (abc) { case 1: dsa_open(); break; case 2: dsa_close(0); break; case 3: SET_servo_adj; SERVO_mode = Mode_Focusing; SERVO_state = Focus_Para; do { /* Monitor Servo Stability in dsa_ltoc() */ GDT_SERVO_process(); if (SERVO_STATUS == SERVO_RET_Qcode) break; if (SERVO_STATUS == SERVO_RET_int) return ; if (SERVO_STATUS == SERVO_RET_clvok) break; if((SERVO_STATUS==SERVO_RET_loss) || (SERVO_STATUS==SERVO_RET_clvng)){ CDinfo.type = CD_NODISC; return ; } } while (1); break; case 4: begCDtime = 0x000004; endCDtime = 0x595974; system_reset(); system_start(); TDM_isCDDA = 1; playCDDA(0x00004, 0x00004, 0x555555); TDM_turn_on(); break; case 5: begCDtime = 0x000004; endCDtime = 0x595974; system_reset(); system_start(); TDM_isCDDA = 0; XPORT_play20video(XPORT_OFFSET_FUZZY_PLAY, 0xe0); TDM_turn_on(); break; case 6: SERVO_near_jump(0, 100); break; case 7: SERVO_near_jump(1, 100); break; case 8: dsa_ltoc(abc_data, 100); break; case 9: target_min = fyh_min; target_sec = 48; target_frame = 16; SERVO_mode = Mode_Seek; SERVO_state = Seek_Initial; break; case 10: dsa_go(0x00104816); break; case 11: playSectors(0x104816, 0xe0, 2324); begCDtime = 0x104816; endCDtime = 0x999999; break; case 13: begCDtime = 0x104816; endCDtime = 0x999999; dsa_go(0x104816); system_reset(); system_start(); TDM_isCDDA = 0; XPORT_play20video(XPORT_OFFSET_FUZZY_PLAY, 0xe0); TDM_turn_on(); break; case 14:#if 0 system_reset(); system_start(); playCDDA(0x010000, 0x100000); TDM_turn_on();#endif break; default: break; } abc = 0;}#endif/* * Service microcontroller, CD ROM (etc) */void CUST_background(){ /* If the NTSC/PAL switch is changed, then change TV mode accordingly. */#ifdef POLL_TV_SWITCH #ifdef DSC if ((!IS_POWER_DOWN) && (power_up)) /* detect tv only when powerup */#endif { PREPARE_DETECTION; if (currentTVmode == TV_NTSC) { if (!DETECT_NTSC) { play_change_tv_mode(); } } else { if (DETECT_NTSC) { play_change_tv_mode(); } } }#endif if (power_up) { initMicroObject(); init_dsa();#ifndef GDT_DEBUG /*************************************************************/ initCD();#endif power_up = 0; } else { receive_dsa();#ifdef GDT_DEBUG test_dsa();#endif#ifndef TWO_FIELDS_OSD OSD_schedule_check();#else CG_service(1);#endif upper_state_machine(1); /* Customize your play state machine */ }}/************************************************************************ * Utility routines * ************************************************************************//* * Read "num" sectors into the start of the system buffer. This routine is * only called to get system information (not MPEG A/V data) * * Inputs: * begin: CD sector time in MMSSFF (each is in BCD) * num: number of CD sectors to copy. This number has to be * smaller than sys_buf_size/size. * size: Size of a CD sector (in bytes) * * Return: * -2: force abort * -1: failed dsa_go() or servo problem * 0: if failed * 1: if successful */int getSectors(begin, num, dest)unsigned int begin;int num, dest;{ unsigned int dsatime, tmp; unsigned int next_time; int xfer_done; int counter; int timeout; int ii; begCDtime = begin; endCDtime = adjCDtime(begCDtime, logical2physical(num), 1); /* Set DSA_GO time to be 4d frames ealier than user specified */ dsatime = adjCDtime(begCDtime, 0x4, -1); /* Only change DSA mode if the current mode is not CDROM */ TDM_isCDDA = 0; /* Data is scrambled (as opposed to CDDA)*/ XPORT_load_ucode((dest) ? DATA_PS : MP3_PS); dsa_mode(MODE_ATTI_REL | MODE_CDROM | MODE_SPEED_NORMAL); counter = 0; do { xfer_done = 0; if (counter >= 2) { OUTOSD(10, "SCT_ERR0", "SCT_ERR0", 0); err_code = ERR_GETSECTOR; return (0); } counter++; if (!dsa_go(dsatime)) { /* DSA_GO command failed */ if (counter >= 2) { OUTOSD(10, "SCT_ERR1", "SCT_ERR1", 0); return (-1); } else { counter++; continue; /* Time not specified, don't go */ } } system_reset(); system_start(); TDM_isCDDA = 0; XPORT_play20video(XPORT_OFFSET_GET_SECTOR, 2048); TDM_turn_on(); next_time = glbTimer + TWO_SECOND; timeout = 0; while (!TDM_found_begCDtime) { /* * There may not be any SYNC pattern (CDDA disk), so we'll * conclude that we are not getting the data if we have been * sitting here for .5 second */ if ((glbTimer > next_time) || (currCDtime > endCDtime)) { /* * Check one more time. In case CDI_get is cleared since I * checked it the last time. If we just turn off TDM, then * there is some chance that nobody will turn TDM on again * (because CDI_get is cleared) */ timeout = 1; break; }#ifdef ECHO MIC_service();#endif /* Servo Process in getSectors() */ SERVO_service(); if ((SERVO_STATUS == SERVO_RET_int) || (SERVO_STATUS == SERVO_RET_fng) || (SERVO_STATUS == SERVO_RET_clvng)) return (-1); } /* check if the data tranfer is done */ if (!timeout) { /* Timeout to avoid hanging */#ifdef FLASH_UPDATE /* we may use getsectors() for "big" files */ tmp = (num>>6 - num>>9); /* ~(num/75) */ tmp = TWO_SECOND + tmp*ONE_SECOND; next_time = glbTimer + tmp;#else next_time = glbTimer + TWO_SECOND;#endif do { if (forceDSAabort) return(-2);#ifdef ECHO MIC_service();#endif } while (XPORT_active && (glbTimer < next_time)); xfer_done = 1; TDM_found_begCDtime = 0; } if (CDinfo.type == CD_CDDA && timeout) return 0; } while (!xfer_done); /* * Victor: Because TDM will set end_of_play when CD_end is reached. We * will need to reset end_of_play here. It should be safe because when we * are getting PSD means we are not playing any playitem. */ end_of_play = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -