📄 init.c
字号:
// vSetSharedInfo(SI_HV_SYNC_ENABLE, SV_OFF); //Max'0819'04, initialize this shareinfo to set
// //H and V sync are GPIO.
#if (defined(MT1389_REV_D) || defined(MT1389_REV_K))
#ifdef CVBS2_OUTPUT_ON_G
vSetSharedInfo(SI_CVBS2_OUTPUT, 1);
#else
vSetSharedInfo(SI_CVBS2_OUTPUT, 0);
#endif //#ifdef CVBS2_OUTPUT_ON_G
#endif //#ifdef MT1389_REV_D
#ifdef CVBS_LOW_IMP
vSetSharedInfo(SI_CVBS_LOW_IMP, 1);
#else
vSetSharedInfo(SI_CVBS_LOW_IMP, 0);
#endif
bTvMisc = 0;
#ifdef TVE_YCDELAY_ON
bTvMisc |= SV_YC_DELAY;
#endif
#ifdef TVE_REDGE_ON
bTvMisc |= SV_RISING_EDGE;
#endif
vSetSharedInfo(SI_TVE_MISC, bTvMisc);
#ifndef MTK_TVE
vTvInit(); // for external TVE only
#endif
#ifdef VIDEO_IN_EN
#ifdef VIN_USE_PORT_A
#elif (defined(VIN_USE_PORT_B))
// set GPIO pins as input for port B
ClrBitBIM(BIM_IOENM, IOM_A20 + IOM_BLANK + IOM_HSYN);
ClrBitBIM(BIM_IOENH, IOH_YUV7);
// set ASDATA3/4 as I/O pin
SetBitBIM(BIM_PCTL3, SOFF3 + SOFF4);
#endif /* VIN_USE_PORT_B */
#endif
}
extern BYTE xdata _bAClkDiv;
/***************************************************************************
Function : ResetHardware(void)
Dsecription : Hardware related reset sequences
Parameter : None
Return : None
***************************************************************************/
void ResetHardware(void)
{
MDisableMainINT();
sFlagI2C.fgInited = FALSE; // turn off peripheral service
_rUI.bState = UI_WAIT_INIT; // turn off UI service
_rUI.fgRiscReady = FALSE;
_fgNotify = FALSE;
_fgReturn = FALSE;
#if MAIN_TIMER == 2
MDisableTimer2(); // Disable timer 2 interrupt
#elif MAIN_TIMER == 1
MDisableTimer1(); // Disable timer 1 interrupt
#endif
MEnableTimer0(); // Enable timer 0 interrupt
MStopTimer0Cnt(); // Stop timer 0 counter
MEnableINT();
#ifndef MT1389LK_DIGITAL_SERVO // [2006/11/24] Jethro : 1389L/K remove
#ifdef DLL_RESET
WriteType0Cmd(0x8, bReadType0Cmd(0x08) | 0x4);
SRVDelay500us(2);
WriteType0Cmd(0x8, bReadType0Cmd(0x08) & (~0x04));
SRVDelay500us(2);
WriteSerialCmd(0x57, bReadSerialCmd(0x57) | 0x80);
SRVDelay500us(2);
WriteType0Cmd(0x58, bReadType0Cmd(0x58) | 0x40);
SRVDelay500us(2);
WriteType0Cmd(0x58, bReadType0Cmd(0x58) & (~0x40));
SRVDelay500us(2);
WriteSerialCmd(0x57, bReadSerialCmd(0x57) & (~0x80));
SRVDelay500us(6);
WriteType0Cmd(0x05, bReadType0Cmd(0x05) | (0x10));
SRVDelay500us(1);
WriteType0Cmd(0x05, bReadType0Cmd(0x05) & (~0x10));
SRVDelay500us(1);
#endif // DLL_RESET
#endif // MT1389LK_DIGITAL_SERVO
#ifdef MT1379
/* setting GPIO here */
ClrBitBIM(BIM_IODOM, IOM_BLANK); // Set Pin Low(Reset Disable)
SetBitBIM(BIM_IOENM, IOM_BLANK); // Set this pin to Output pin
#endif
#ifdef MT1389_REV_P
//SetBitBIM(BIM_PCTL2, (1 << 5)); // Set IOUP12->1, to make sure up1_2 become io function, not bank select funtion.
#else
//NOTE: G.T1129:Here is different from 89S.
SetBitBIM(BIM_AOCLKC, AOCLK_PD); // power down audio out clock
#endif
LEDOff(); // Turn Off LED
StopXfer(); // stop PSTART
CalAPLL(); // calibrate APLL band
ClkInit(); // initial clocks
InitTimer(); // Initial Timer Int
PowerUpDiag(); // Self Test & Flash LED if Error !!
vI2CInit(); // initial I2C bus
ADSPInit(); // initial Audio DSP
DECInit(); // Reset decoder
SetSMInitReady(FALSE);
#ifdef SERIAL_FLASH_SUPPORT
// SerialFlashInit
SFIClkSet(0x09, 0x43); //Init to 48M HZ.
#endif //SERIAL_FLASH_SUPPORT
RISCBootSetting(); // Some information must be set before RISC run
#ifdef DISC_UPG_PATCH
vFillPatchData();
#endif
RISCInit(); // initial RISC
_fgReturn = TRUE; // Start service RISC
ResetRISC(); // negate power-on reset
#ifndef DEBUG_RS232_C1C2 // Jethro Add for MMDT debug
StartRISC(); // start RISC
#endif
InitSharedReg();
#ifdef MTK_6CH_ADAC
#if defined(MT1389_REV_P)
SetBitAUD(ADAC_AUTEST, ADAC_RESET); //turn on adac analog part.
#elif defined(MT1389_REV_K)
WriteAUD(ADAC_OUT_CFG0, ADAC_CONFIG_1_A); //Porter AUTEST 1106
SetBitAUD(ADAC_OUT_CFG1, ADAC_RESET); //Porter AUTEST 1106
#endif
#endif
// enable mute
#ifdef DSP_AUTO_MUTE
vAudioMute(1);
#endif
#ifndef MT1336_REV_C
#ifdef MT1389_REV_P
SRVDelay100ms(1);
#else
SRVDelay20ms(1); // 1336 triger level 0.8V, 1369 triger level 1.2V
#endif // we need to wait till 1336 reset properly
#endif
//WriteBIM(BIM_ACLKC, 0x86);
WriteBIM(BIM_ACLKC, ACLK_PD | (bReadBIM(BIM_ACLKC)&(~AC_CLK_MASK)) | _bAClkDiv);
#ifndef TOP_LOADER
TRAYInit(); // [Gary 0811] Determin the TRAY Function (PWM or OPEN Kick)
#endif
#ifdef SERVO_CHECK_IC_VERSION
#ifdef MT1389_REV_D
_bICVersion = 0x1E;
#else
_bICVersion = 0x12; // MT1389C Version
#endif
#endif
SRVInit(); // init SERVO library
//WriteBIM(BIM_ACLKC, 0x6);
WriteBIM(BIM_ACLKC, _bAClkDiv);
// Enable one bit for Prefetch issue.
WriteBIM(BIM_PCTL1, bReadBIM(BIM_PCTL1)|0x80);
#ifdef RS232_LOG
DBGLogS("SRVInit ok.\n");
#endif
/* since we have turn off the audio MCLK out, we must reset ADAC */
#if defined(_NPADAC_)
if (fgIsSoftReset())
{
// don't know why TvEncoderOn does not work here
//PeripheralReset(FALSE, FALSE);
#ifndef MTK_TVE /* for external TVE only */
vTvEncoderOn(TRUE);
#endif
}
else
#endif
{
PeripheralReset(FALSE, TRUE); /* don't hold the reset pin */
}
/* assume 1.5 seconds RISC code decompress here */
// for test
/*
for (_wPauseTimer=0;_wPauseTimer<20000;_wPauseTimer++)
{
vPowerOnDelay10us();
}
*/
PeripheralInit();
PowerOnRstVar(); // reset variables
ResetVar(); // Set default value
ClrCmdBusy(); // Clear BSY Bit
// turn on UI service
_rUI.bState = UI_INIT;
#if MAIN_TIMER == 2
MEnableTimer2(); // Enable timer 2 interrupt
MTrgTimer2Cnt(); // Enable Timer2 Counter
#elif MAIN_TIMER == 1
MEnableTimer1(); // Enable timer 2 interrupt
MTrgTimer1Cnt(); // Enable Timer2 Counter
#endif
#ifndef TRAY_NOT_CONNECT // for initial OSD message
#ifdef THOMSON_TRAY
_bTrayStatus = TRAY_ST_MIDDLE;
#else
if (fgTrayIsIn())
{
_bTrayStatus = TRAY_ST_IN;
}
else if (fgTrayIsOut())
{
_bTrayStatus = TRAY_ST_OUT;
}
else if (_bTrayStatus != TRAY_ST_MIDDLE)
{
_bTrayStatus = TRAY_ST_MIDDLE;
}
#endif
#endif
// wait UI service init finish
StartupUI();
#if !(defined(MT1389_REV_P)||defined(MT1389_REV_K)) // 0 //kaihong
#if (UP_RATE_24M == 1) // assume SDC is 280MHz/3
WriteBIM(BIM_PCLKC, PC_DPL2D16); // 8032 24MHz
#endif
#endif
MEnableMainINT(); // Enable Main interrupt
// tell RISC share memory intial OK and ready to do service
SetSMInitReady(TRUE);
#ifdef MT1389P_TCON
vTFTBackLightEnable();
#endif
}
#ifdef PLAYER_POWERDOWN
/***************************************************************************
Function : PowerDownResetHardware(void)
Dsecription : Hardware related reset sequences
Parameter : None
Return : None
***************************************************************************/
void PowerDownResetHardware(void)
{
MDisableMainINT();
sFlagI2C.fgInited = FALSE; // turn off peripheral service
_rUI.bState = UI_WAIT_INIT; // turn off UI service
_rUI.fgRiscReady = FALSE;
_fgNotify = FALSE;
_fgReturn = FALSE;
#ifdef PLAYER_ACON_STANDBY
if (!fgIsSoftReset())
{
SetDRAMType();
}
#endif
#if MAIN_TIMER == 2
MDisableTimer2(); // Disable timer 2 interrupt
#elif MAIN_TIMER == 1
MDisableTimer1(); // Disable timer 1 interrupt
#endif
MEnableTimer0(); // Enable timer 0 interrupt
MStopTimer0Cnt(); // Stop timer 0 counter
MEnableINT();
LEDOff(); // Turn Off LED
/* StopXfer(); */
/* CalAPLL(); */
// WriteBIM(BIM_DMPLLC, 0x02); // DMPLLC
ClrBitBIM(BIM_APLLC1, APLL_PD); // turn off APLL power down
ClrBitBIM(BIM_AOCLKC, AOCLK_PD); // turn off audio out power down
WriteBIM(BIM_AOCLKC, AOC_1D2 + AOC_APL27M); // set APLL as 27MHz/2, no need to do calibation
#ifdef PLAYER_ACON_STANDBY
if (!fgIsSoftReset())
{
ClkInit();
}
else
#endif
{
#if !(defined(MT1389_REV_P) || defined(MT1389_REV_K))
WriteBIM(BIM_PCLKC, PC_27M); // set 8032 in 27MHz
#else
#ifdef DMPLL_NEW_METHOD
WriteBIM(BIM_PLLS, PS_8032_CLK);
WriteBIM(BIM_PLLD, ((wGetSysClk() / 2 / DEF_8032_CLK) - 1));
WriteBIM(BIM_PCLKC, PC_DPL_CNTR);
#else
WriteBIM(BIM_PCLKC, PC_DPL2D16); //Max'0407'2004, 8032 clock is DMPLL2/16, that is 352/16 = 22M.
#endif
#endif //MT1389_REV_P
}
InitTimer(); // Initial Timer Int
/* no need to test DRAM */
/* PowerUpDiag(); */
/* IEC? */
/* ADSPInit(); */
/* DECInit(); */
#ifndef MT1336_REV_C
#ifndef MT1389_REV_P
SRVDelay20ms(1); // 1336 triger level 0.8V, 1369 triger level 1.2V
#else
SRVDelay100ms(1); // 1336 triger level 0.8V, 1369 triger level 1.2V
#endif // we need to wait till 1336 reset properly
#endif
SRVInit(); /* for pheripheral reset */
#ifdef PLAYER_ACON_STANDBY
if (!fgIsSoftReset())
{
if (!fgTrayIsIn()) // If tray is out ?
{
/* set power mode before restart */
_bPWRMode = PWR_OFF_TRAY_IN_FLAG | SV_PWR_ACTIVE;
vSetSoftReset(PLAYER_SOFTWARE_RESET);
Restart8032(FALSE);
}
}
#endif /* PLAYER_ACON_STANDBY */
#ifdef POWERDOWN_HOLD_RESET
PeripheralReset(TRUE, TRUE); /* hold the reset pin when power down */
VfdInit(FALSE, FALSE); /* from PeripheralInit() */
#else
if (fgIsSoftReset())
{
/* since we have init the peripheral before this, no need to init again */
VfdInit(FALSE, FALSE); /* from PeripheralInit() */
}
else
{
/* in case AC power on standby/sleep, we must reset peripheral */
PeripheralReset(FALSE, TRUE); /* don't hold the reset pin */
PeripheralInit();
}
#endif /* not POWERDOWN_HOLD_RESET */
/* assume these variables are not used */
/* PowerOnRstVar(); */
/* ResetVar(); */
// we will keep in this function until receive power on key
MpegPowerDown(_bPWRMode);
/* set power mode before restart */
_bPWRMode = (_bPWRMode & PWR_ON_EJECT_FLAG) | SV_PWR_ACTIVE;
vSetSoftReset(PLAYER_SOFTWARE_RESET);
Restart8032(FALSE);
}
#endif /* PLAYER_POWERDOWN */
/***************************************************************************
Function : DECInit(void)
Dsecription : Reset MT1369 channel Decoder
Parameter : None
Return : None
***************************************************************************/
void DECInit(void)
{
BYTE bTmp;
#ifdef MT1379
WriteDEC(RW_SCTRL, C2LAST + LMT64 + SCWEN + SCEN); // RAW Sub-Channel Data
#else // MT1369
WriteDEC(RW_SCTRL, LMT64 + SCWEN + SCEN); // RAW Sub-Channel Data
#endif
#ifndef MT1389_512K
WriteBLK(RW_NBLK, _wTotalBlk); // Total Block Numbers
#else
_wTotalBlk = 28;
WriteBLK(RW_NBLK, _wTotalBlk);
#endif
/*------------ Default Interrupt Enable Setting --------------*/
WriteDEC(RW_DIEN, DEIEN + MCIEN + RISCIEN);
// RW_DIEN first, then BIM_RISCIEN, must keep this sequence
#ifdef DRS232_DEBUG
WriteBIM(BIM_RISCIEN, IRIEN+EEVTIEN+RSIEN+HZIEN+POKIEN+SMBIEN+CMDIEN);
#else
WriteBIM(BIM_RISCIEN, IRIEN+EEVTIEN+HZIEN+POKIEN+SMBIEN+CMDIEN);
ClrBitBIM(BIM_PCTL2, DSPT);
#if !defined(MT1389_REV_K) //G.T1129:89K has no such control.
#ifdef DISABLE_LED_ONOFF
ClrBitBIM(BIM_PCTL2, LEDEN);
#else
SetBitBIM(BIM_PCTL2, LEDEN);
#endif
#endif
#endif
#ifdef RISC_1K_SQUARE_WAVE
ClrBitBIM(BIM_PCTL2, DSPT);
SetBitBIM(BIM_PCTL2, LEDEN);
#endif
vHwIrInit();
// Decoder Control : Enable SYNC insert/detect, discrambler
// Set WRRQ
bTmp = 0
#ifdef MT1379
+ BSYEN
#endif
#ifdef ENABLE_BUF_C2PO
+ C2EN
#endif
#ifdef AUTO_CDDA_CIRC
+ DSPEN
#endif
+ SYDEN + SYIEN + DSCEN + WRRQ;
WriteDEC(RW_MCTRL, bTmp);
WriteDEC(RW_IDECC, IDERAON + IDCCHK + POPEN + SMTAR);
WriteDEC(RW_SICE, AREAEN + LAYEN); // DVD Sector Info Check Enable
bTmp = NOEFMEN + TFIEN + TNFIEN
#ifdef ENABLE_BUF_C2PO
+ IHCEN
#endif
#ifdef ENABLE_FIFOTH
+ FIFOTH
#endif
;
WriteDEC(RW_MCIER, bTmp); // ENABLE IHC, TNFI & TFI
WriteDEC(RW_C2POL, C2PO_CNT_LIMIT); // Set C2PO LIMIT
WriteDEC(RW_SCIER, QCLEAN); // Q Clean will Update Q0-Q9
#ifdef MT1389_512K
WriteBLKC(RW_BCL, _wTotalBlk - 17); // Set Buffer Bound
#endif
}
/***************************************************************************
Function : PowerOnRstVar(void)
Dsecription : Initial Status & Status Flags
Parameter : None
Return : None
***************************************************************************/
#ifdef SERIAL_FLASH_SUPPORT
void SFIClkSet(BYTE bMode, BYTE bClk)
{
// SerialFlashInit
WriteBIM(BIM_SFIS, 0x14);
WriteBIM(BIM_SFID, bMode); // bit0 = 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -