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

📄 ucode.c

📁 车载电子影音系统dvd播放系统原程序代码
💻 C
📖 第 1 页 / 共 4 页
字号:
BIT UCODE_Check(void)
{
// Chuan1.05, define it to check ucode
#ifdef  CHECK_UCODE_LOAD    
    // Check IRAM
    if (!UCODE_CheckCode (UCODE_IRAM, (BYTE)NULL))
        return FALSE ;

    ////////////////////////////////////////
    // Check download PRAM procedure
    if (!UCODE_CheckCode (UCODE_PRAM, UCODE_PRAM_VCD))
        return FALSE ;

    // TCC041.2, should load dsp code according to setup's setting.
    // Or next power-on will still load normal one.
    // TCC2.78b-2, fix setup as spdif_raw, start up as CDDA mode, it will hang problem, reported by Paragon/Mustek(IC issue).
    // The solution is to load normal set of dsp code first, then load iec part. Don't know why.
    // Chuan 2002/10/28: Check DSP PRAM/ERAM together
    // Chuan0.8x, Move DSP Code to UCODE 2
    if (!UCODE2_CheckCode (UCODE_DSPRAM, UCODE_DSPRAM_NORMAL))
        return FALSE ;
#endif
    return TRUE;
}


// ********************************************************************
//  Function    :   UCODE_LoadCode
//  Description :   Download the desired micro-code
//  Arguments   :   bRam, the desired ucode;
//                  bCode, the subtype of the desired code
//  Return      :   TRUE or FALSE
//  Side Effect :
// ********************************************************************
#pragma DISABLE
BYTE UCODE_LoadCode(BYTE bRam, BYTE bCode)
{
    extern  void _WriteInternalRegW_IO(BYTE bReg, WORD wLo);

    // DWORD   dwRegister; // Chuan DVD_171 12/11/2001: Useless variable
    // for download uram code variable
    // Chuan DVD_171 12/11/2001: Declare as code *. If want know in detail, please refer to tracernote 100
    // Chuan 278 2002/10/28: Move to Global
    // WORD code *wptr;  // pointer to WORD

    bRet = TRUE ;

    switch (bRam)
    {
    case UCODE_IRAM :
#ifdef SYSTEM_8051
        dwRAM = _dwIRAM;
#else   
        // Read iram.inc and copy to _dwUcode
        bRet = _OpenUCODE ("iram.inc"); 
#endif  

#ifdef SUPPORT_DRAM_PROTECTION
        //Kevin1.01, unprotect IRAM
        W99AV_WriteRegDW( UPR, 0x0000, 0x1E00);
#endif

        // ** TCH-Lucky; begin...
        // First 14 DW IRAM.INC must download in last time.
        // So must re-adjust the download procedure.
        // [1] download 15 ~ end first
        // Chuan2.80a, Now 28AF has 16 ret code. CT908 has 17 ret code.
        if ( ! W99AV_WriteDRAMBurst( (IRAM_ADDR+17), &dwRAM[START+17], (WORD)(dwRAM[1]-17)))
        {
#ifdef SUPPORT_PRINTF
            printf ( "\n **** DownLoad IRAM Failure...." );
#endif
            bRet = FALSE ;
        }

        // [2] Download 1 ~ 17 last
        if ( ! W99AV_WriteDRAMBurst (IRAM_ADDR, &dwRAM[START], (WORD)(17)))
        {
#ifdef SUPPORT_PRINTF
            printf ( "\n **** DownLoad IRAM Failure...." );
#endif
            bRet = FALSE ;
        }

#ifdef SUPPORT_DRAM_PROTECTION        
        //Kevin1.01, protect IRAM form IRAM_ADDR to IRAM_END_ADDR
        dwTemp = 0x1F000000 | ((DWORD)(IRAM_END_ADDR>>8)<<12) | IRAM_ADDR>>8;
        W99AV_WriteRegDW( UPR, LOWORD(dwTemp), HIWORD(dwTemp));
#endif

        // ** TCH-Lucky; end...         
        break ;

     case UCODE_PRAM :
        if (bCode == _bPramCur)
        {
            // TCC040, let upper level know that code not changed
            bRet = UCODE_LOAD_NONE ;
            break ;
        }

        // Keep the desired subtype code in current variable
        _bPramCur = bCode ;
        // Chuan1.10, Move Parser Code to UCODE4
        UCODE4_LoadCode(bRam, bCode);
        break ;
 
    case    UCODE_URAM :
#ifdef SUPPORT_DRAM_SCAN_POWERON //alex1.24a, Scan Dram
    case    UCODE_URAM_DRAMTEST :     
      if (bRam == UCODE_URAM_DRAMTEST)
      {
#ifdef SYSTEM_8051
        dwRAM = _dwURAMTest;
#else
        bRet = _OpenUCODE ("uramtest.inc");   
#endif
      }  
      else  
#endif //#ifdef SUPPORT_DRAM_SCAN_POWERON
      {
#ifdef SYSTEM_8051
        dwRAM = _dwURAM;
#else
        bRet = _OpenUCODE ("uram.inc"); 
#endif
      }

        wptr=(WORD code *)& dwRAM[START];

        // Step 1 : Reset URAM
        __dwW99AVCmdArg[0]=1;
        __dwW99AVCmdArg[1]=CMDARG_URAMRST;
        if(!W99AV_CommandN(COMMAND_URAMRST))  // Chuan2.80p, Use define instead of number
            bRet =FALSE;

        // Step 2 : set URAM write enable
        _WriteInternalRegW_IO(CFR,0x0060);    // CF, to stall CPU
        _WriteInternalRegW_IO(RMADRR,0x0080);    // rm_adr
        _WriteInternalRegDW_IO(DCCTLR,0x0,0x1); // Chuan-Test0.01
        
        // Step 3 : load nonzero URAM data to register

        for(_UCODEIndex=0; _UCODEIndex<dwRAM[1];_UCODEIndex++)
        {
            if(dwRAM[_UCODEIndex+START]!=0)
            {
                _WriteInternalRegW_IO(RMADRR,(WORD)(0x0080|((_UCODEIndex&0x00FF)<<8)));
#ifdef USE_LITTLE_ENDIAN
                _WriteInternalRegW_IO (DIR0R, (*wptr)) ;
                _WriteInternalRegW_IO (DIR1R, (*(wptr+1))) ;
#else
                _WriteInternalRegW_IO (DIR0R, (*(wptr+1))) ;
                _WriteInternalRegW_IO (DIR1R, (*wptr)) ;
#endif
            }
            wptr+=2;
        }
        // Step 4 : set URAM write disable
        _WriteInternalRegW_IO(RMADRR,0x0000);
        _WriteInternalRegW_IO(CFR,0x0000);
        // Chuan-Test0.01, Enable URAM_EN
        __wW99AVPCRHigh |= 0x0004;  // PCR[18]:URAM_EN
        W99AV_WriteRegDW(PCR,(WORD)(__wW99AVPCRLow|0x10), __wW99AVPCRHigh);
        W99AV_WriteRegDW(PCR,(WORD)__wW99AVPCRLow, __wW99AVPCRHigh);        
        break ;
    /*        
    case    UCODE_CRAM :
        // Chuan2.80, Load CRAM Code for CT908.
#ifdef SYSTEM_8051
        dwRAM = _dwCRAM ;
#else
        bRet = _OpenUCODE ( "cram.inc" );
#endif
        for (_UCODEIndex=0; _UCODEIndex<dwRAM[1]; _UCODEIndex++)
        {
            W99AV_OutIndex (W99AV_AIRID_RISCCRAM | _UCODEIndex) ;
            W99AV_OutData (dwRAM [_UCODEIndex+START]) ;            
        }
        break;
    */       
    
//alex1.24a SCAN DRAM at poweron
#ifdef SUPPORT_DRAM_SCAN_POWERON
    case    UCODE_CRAM_DRAMTEST :
#ifdef SYSTEM_8051
        dwRAM = _dwCRAMTest ;
#else
        bRet = _OpenUCODE ("cramtest.inc");   
#endif
        for (_UCODEIndex=0; _UCODEIndex<dwRAM[1]; _UCODEIndex++)
        {
            W99AV_OutIndex (W99AV_AIRID_RISCCRAM | _UCODEIndex) ;
            W99AV_OutData (dwRAM [_UCODEIndex+START]) ;            
        }
        break;       
#endif //#ifdef SUPPORT_DRAM_SCAN_POWERON    
     
    }

#ifndef SYSTEM_8051
    if (pdwUcode)
    {
        _hfree(pdwUcode);
        pdwUcode = NULL;
    }
#endif

    return bRet ;
}


// ********************************************************************
//  Function    :   UCODE_CheckCode
//  Description :   Check the desired micro-code
//  Arguments   :   bRam, the desired ucode;
//                  bCode, the subtype of the desired code
//  Return      :   TRUE or FALSE
//  Side Effect :
// ********************************************************************
#pragma DISABLE
BYTE UCODE_CheckCode (BYTE bRam, BYTE bCode)
{
    bRet = TRUE ;
// Chuan1.05, define it to check ucode
#ifdef  CHECK_UCODE_LOAD

    switch (bRam)
    {
    case UCODE_IRAM :
#ifdef SYSTEM_8051
        dwRAM = _dwIRAM;
#else
        bRet = _OpenUCODE ("iram.inc"); 
#endif

        for (_UCODEIndex=0; _UCODEIndex<dwRAM[1]; _UCODEIndex++)
        {
            W99AV_ReadDRAMData (IRAM_ADDR+_UCODEIndex, &dwData);
            if (dwData != dwRAM[_UCODEIndex+START])
            {
#ifdef SUPPORT_PRINTF
                printf ("\nCheck IRAM code %d error, [0x%lx]--[0x%lx]", _UCODEIndex, dwData, dwRAM[_UCODEIndex+START]) ;
#endif
                bRet = FALSE ;
                break ;
            }
        }
        break;

    case UCODE_PRAM :
        // Chuan1.10, Move Parser Code to UCODE4
        UCODE4_CheckCode(bRam, bCode);
        break;
        
    case UCODE_URAM :
#ifdef SYSTEM_8051
        dwRAM = _dwURAM;
#else
        bRet = _OpenUCODE ("uram.inc");
#endif
        wptr=(WORD code *)& dwRAM[START];

        // Step 2 : set URAM write enable
        _WriteInternalRegW_IO(CFR,0x0060);    // CF, to stall CPU
        _WriteInternalRegW_IO(RMADRR,0x00c0);    // rm_adr
        __wW99AVPCRHigh |= 0x0004;  // PCR[18]:URAM_EN
        W99AV_WriteRegDW(PCR,(WORD)__wW99AVPCRLow, __wW99AVPCRHigh);
        
        // Step 3 : load nonzero URAM data to register

        for(_UCODEIndex=0; _UCODEIndex<dwRAM[1];_UCODEIndex++)
        {
            _WriteInternalRegW_IO(PCRR,(WORD)(_UCODEIndex+0x800));
            _WriteInternalRegW_IO(RMADRR,(WORD)(0x00c4|((_UCODEIndex&0x00FF)<<8)));
            dwData = _ReadInternalRegW_IO (DIR0R) ;
            dwTemp = _ReadInternalRegW_IO (DIR1R) ;
            dwData = MAKELONG(dwData,dwTemp);
            if(dwData!=dwRAM[_UCODEIndex+START])
            {
#ifdef SUPPORT_PRINTF
                printf ("\nCheck URAM %d Error [0x%lx] != [0x%lx]", _UCODEIndex, dwData, dwRAM[_UCODEIndex+START]) ;
#endif
                bRet = FALSE ;
                break ;
            }
        }

        // Step 4 : set URAM write disable
        _WriteInternalRegW_IO(RMADRR,0x0000);
        _WriteInternalRegW_IO(CFR,0x0000);
        W99AV_WriteRegDW(PCR,(WORD)(__wW99AVPCRLow|0x10), __wW99AVPCRHigh);
        W99AV_WriteRegDW(PCR,(WORD)(__wW99AVPCRLow), __wW99AVPCRHigh);
        break ;
    }

#ifndef SYSTEM_8051
    if (pdwUcode)
    {
        _hfree(pdwUcode);
        pdwUcode = NULL;
    }
#endif

#endif // #ifdef  CHECK_UCODE_LOAD
    return bRet ;
}

#endif  // #ifdef SUPPORT_GZIP_COMPRESSION

#ifndef SYSTEM_8051
void _ReadUcode(FILE *stream, DWORD *pdwUcodeBuffer)
{
    char ch;
    char *pcFile;
    char *cStopString;
    BYTE bSize = 0;
    WORD wIndex = 0;
    DWORD   *pdwBuffer;

    WORD   TCHCount= 0;

    pdwBuffer = pdwUcodeBuffer;

    pcFile = cFile;

    while (!feof(stream))
    {
        ch = fgetc(stream);

        if ((ch != 10) && (ch != ','))
        {
            *pcFile = (char)ch;
            pcFile++;
            bSize++;
        }

        if ( bSize >= 20 )
        {
            printf ( "**** ERROR...." );
            EXIT_APP_MACRO(); // Chuan 172r 2002/03/29: call EXIT_APP_MACRO() instead of exit(0)
        }

        if (ch == ',')
        {
            wIndex++;
            if (wIndex > 2)
                *pdwBuffer = strtoul(&cFile[2], &cStopString, 16);
            else
                *pdwBuffer = atol(cFile);

            pdwBuffer++;
            TCHCount++;
            pcFile = cFile;
            for (_UCODEIndex = 0; _UCODEIndex < bSize; _UCODEIndex++)
                cFile[_UCODEIndex] = 0;
            bSize = 0;
        }
    }

#ifdef SUPPORT_PRINTF
///    printf ( "\n *** Size = %d * 4 (DWORD unit..." , TCHCount );
#endif
}
#endif

#ifndef SYSTEM_8051
BYTE   _OpenUCODE ( char * pName )
{
    char        ch;
    FILE        * file;
    DWORD       dwLen;

    if( (file = fopen( pName, "r+t" )) == NULL )
    {
#ifdef SUPPORT_PRINTF
        printf ("\nFile (%s) Open failure!", pName );
#endif
        return  FALSE;
    }

    dwLen= 0;
    while ( ! feof(file) )
    {
        ch = fgetc(file);
        if (ch == ',')
            dwLen++;
    }
    //dwLen= (dwLen+ 1)/ 2;     // 2 char == 1 bytes max.

    fseek ( file, NULL, SEEK_SET );

    // Allocate the buffer
    pdwUcode = (DWORD *) _halloc ( dwLen*4, 1);
    if (pdwUcode == NULL)
    {
#ifdef SUPPORT_PRINTF
        printf ("\nUcode allocate buffer error!");
#endif
        fclose ( file );
        return FALSE;
    }

    _ReadUcode ( file, pdwUcode );
    fclose (file);

    dwRAM = pdwUcode;

    return TRUE;
}
#endif

⌨️ 快捷键说明

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