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

📄 sysdebug.c

📁 车载电子影音系统dvd播放系统原程序代码
💻 C
📖 第 1 页 / 共 4 页
字号:
#include <stdlib.h>
#include "winav.h"
#include "w99av.h"
#include "comdef.h"
#include "sysdebug.h"
#include "osd.h"
#include "hal.h"
#include "utl.h"
#include "cc.h"
#include "setup.h"
#include "cdinfo.h"
#include "isr.h"

//Open this define will remove most of the functions. Only "printf", set SERVO/MPEG debug level and IR can work.
///#define SYSDEBUG_SUPPORT_MIN_FUNCTION

//Open this define to support macrovision test
//#define SYSDEBUG_SUPPORT_MACROVISION_TEST

//If you want to use other serial debug tool link PCPlus, please open it.
//#define SERIAL_DEBUG_TOOL_OTHERS

//Open the define to support "help" command
//#define SYSDEBUG_SUPPORT_HELP

//The default size for dumping memory
//Please modify it to the size that you want to download 
#define SYSDEBUG_DUMP_SIZE 16

//The type of memory
#define SYSDEBUG_DRAM_DATA  0
#define SYSDEBUG_DM_DATA    1

#define EMPTY_DATA_IN_BUFFER    0

#define SYSDEBUG_COMMAND_SPACE          0x0100

static BYTE code pbSIOhexASCII[]=
{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

#ifdef SERIAL_DEBUG

BYTE _bRXCommandLen;
BYTE _bRXCommandData[RX_COMMAND_SIZE];

BYTE _bSIOrxReady;
BYTE _bSIOtxReady;
BYTE _bBackupCommandLen;

DWORD   _dwSYSDEBUGTemp, _dwSYSDEBUGTemp1, _dwSYSDEBUGTemp2, _dwSYSDEBUGTemp3, _dwSYSDEBUGTemp4;
WORD    _wSYSDEBUGTemp, _wSYSDEBUGTemp1;
BYTE    _bSYSDEBUGTemp, _bSYSDEBUGTemp1, _bSYSDEBUGTemp2, _bSYSDEBUGTemp3;
BYTE    _bSYSDEBUGLen, _bSYSDEBUGLen1;
BYTE *pbMem;

//The variables for "serial debug tool"
BYTE _bRxFg;                            //TRUE=Rx one cmd end from RS232
BYTE _bChangeRxToRomBuffer;             //TRUE=change rx buffer to rom buffer
 
BYTE _bROMDataBuf[RX_DATA_SIZE];        //RX data buffer, to receive the data when _bChangeRxToRomBuffer = TRUE
BYTE _bSCONinBufWriteIndex;             //RS232 Rx buf write index
BYTE _bSCONinBufReadIndex;              //RS232 Rx buf read index
WORD _wROMdataBufIndex;                 //index of buffer for reading and writing to flash

WORD _wROMSize;
BYTE _bCurrentCommand;
BYTE _bSYSDEBUGType;

BYTE *_bpROMBuf;
BYTE _bAutoUpgrade;
BYTE _bStartTextCmd;
WORD _wTextCmdTimeOut;
BYTE _bDisableCMD;    // Chuan.Test

extern BIT     __btDIGEST;
extern BYTE    _bINITIALTemp;
extern BYTE   _REG[26];
extern BYTE IDATA __bISRKey;
extern DWORD IDATA __dwTemp;
// LLY2.37p, remove __bISRKeyRead, because we will split IR and F/W key to __bISRKey and __bFWKey
// So, it's un-necessary to reference it to decide input key source                 
//extern BYTE    __bISRKeyRead;
#endif

BYTE _bBinMode = FALSE;         //The flag to judge if the client is "serial debug tool" or PCPlus.
extern BYTE xdata gbDBFlag;
extern void    _ShowDebug();
/****************************************************************************
 ** Function:           putHEX
 ** Description:        This function will print a "BYTE" in hexadecimal form
 ** Parameters:         The number to be printed.
 ** Return:             none.
 ***************************************************************************/
void putHEX(BYTE bHEX)
{
#if defined (SERIAL_DEBUG) || defined(SUPPORT_PRINTF)
    putchar_SBUF(pbSIOhexASCII[(bHEX >> 4) & 0x0f]);
    putchar_SBUF(pbSIOhexASCII[ bHEX       & 0x0f]);
#endif
}

/****************************************************************************
 ** Function:       put_WORD
 ** Description:    This function will print a "WORD" in hexadecimal form
 ** Parameters:     The number to be printed.
 ** Return:         none.
 ***************************************************************************/
void put_WORD(WORD wHEX)
{
#if defined (SERIAL_DEBUG) || defined(SUPPORT_PRINTF)
    putHEX((BYTE) ((wHEX >> 8) & 0x00ff));
    putHEX((BYTE) ( wHEX       & 0x00ff));
#endif
}

/****************************************************************************
 ** Function:       put_DWORD
 ** Description:    This function will print a print a "DWORD" in hexadecimal form
 ** Parameters:     
 ** Return:         none.
 ***************************************************************************/
void put_DWORD(DWORD dwHEX)
{
#if defined (SERIAL_DEBUG) || defined(SUPPORT_PRINTF)
    putHEX((BYTE) ((HIWORD(dwHEX) >> 8) & 0x00ff));
    putHEX((BYTE) ( HIWORD(dwHEX)       & 0x00ff));
    putHEX((BYTE) ((LOWORD(dwHEX) >> 8) & 0x00ff));
    putHEX((BYTE) ( LOWORD(dwHEX)       & 0x00ff));
#endif
}

/****************************************************************************
 ** Function:           putchar_SBUF
 ** Description:        This function will put the data to SBUF directly.
 ** Parameters:         The number to be put.
 ** Return:             none.
 ***************************************************************************/
#pragma NOAREGS         // be called in ISR
#pragma DISABLE
void putchar_SBUF(BYTE bHEX)
{
#ifdef SERIAL_DEBUG

    SBUF = bHEX;
    while (!TI);
    TI = 0;

#else

#ifdef SUPPORT_PRINTF
    putchar(bHEX);
#endif

#endif
}

#ifdef SERIAL_DEBUG
/****************************************************************************
 ** Function:           SYSDEBUG_Init
 ** Description:        Call this function to initialize serial debug 
 ** Parameters:         none.
 ** Return:             none.
 ***************************************************************************/
void SYSDEBUG_Init(void)
{
    /* -CoCo, the SFR will be initialized in INITIAL_uProcessor
    SCON=0x50;      //Mode1
    T2CON=0x30;     //Enable mode1 and mode 3 for Timer2
    RCAP2H=R2HV;    //set baud rate
    RCAP2L=R2LV;    //set baud rate
    TR2=1;          //Enable Timer 2
    ES = 1;         //Enable serial port interrupt
    TI = 0;         //The flag for Tx
    IP = 0x10;      //Set the interrupt of serial port as high priority
    */
    
    _bAutoUpgrade = FALSE;
    _bStartTextCmd = FALSE;
    _wTextCmdTimeOut = 0;

    //init RX command 
    _bRXCommandLen = 0;

    //set flag to indicate we are allowed to send another character
    _bSIOrxReady=FALSE;

    //Initialize the variables for "serial debug tool"
    _bBinMode = FALSE;
    _bRxFg = FALSE;
    _bChangeRxToRomBuffer=FALSE;
 
    _bSCONinBufWriteIndex=0;
    _bSCONinBufReadIndex=0;

    _bpROMBuf = _bROMDataBuf;
}

/****************************************************************************
 ** Function:           SYSDEBUG_SerialIntHandler
 ** Description:        This function will handle the dat through RxD. It is called in ISR.
 ** Parameters:         none.
 ** Return:             none.
 ***************************************************************************/
#pragma NOAREGS // called in ISR
#pragma DISABLE // will disable all interrupt for the duration of function
void SYSDEBUG_SerialIntHandler(void)
{     
    BYTE data bCh;

    {
        if (_bSIOrxReady == TRUE)
        {
            //SIOrxReady, not yet process input data, ignore new input data
            return;
        }

        bCh=SBUF; //for serial debug

#ifndef SYSDEBUG_SUPPORT_MIN_FUNCTION
        if (bCh == START_BIN_MODE_CMD)        
            _bBinMode = TRUE;
#endif
        
        if (!_bBinMode)
        {
#ifdef SERIAL_DEBUG_TOOL_OTHERS
            SBUF=bCh; //add UART Echo 
            while (!TI);
            TI = 0;
#endif
            
#ifndef SERIAL_DEBUG_TOOL_OTHERS
            if (bCh == START_TEXT_MODE_CMD)
            {
                _bRXCommandLen = 0;
                _bStartTextCmd = TRUE;
                
                SBUF = ACK_START_TEXT_MODE_CMD;
                while (!TI);
                TI = 0;

                _wTextCmdTimeOut = 0;
            }
            
            while (_bStartTextCmd)
            {
                _wTextCmdTimeOut++;

                if (_wTextCmdTimeOut > 20000)
                {
                    _bStartTextCmd = FALSE;
                    return;
                }

                if (RI)
                {                                        
                    RI = 0;
                    bCh=SBUF;
#endif                   
                    if (bCh == START_TEXT_MODE_CMD)
                    {
                        SBUF = ACK_START_TEXT_MODE_CMD;
                        while (!TI);
                        TI = 0;

                        _wTextCmdTimeOut = 0;
                        continue;
                    }
                    
                    //increment write index < RX_BUFFER_SIZE
                    if (_bRXCommandLen < RX_COMMAND_SIZE)
                    {
#ifdef SERIAL_DEBUG_TOOL_OTHERS
                        if (bCh == 0x08)    //"Back Space" key
                        {
                            if (_bRXCommandLen > 0)
                                _bRXCommandLen--;
                        }
                        else if (bCh == 'P') // repeat last command
                        {
                            _bRXCommandLen = _bBackupCommandLen;
                            _bSIOrxReady=1; //Do the "repeat" command directly.
                        }               
                        else
#endif
                        {
                            _bRXCommandData[_bRXCommandLen]=bCh;
                            _bRXCommandLen++;   
                        }
                    }
                    
                    if (bCh == '\r')
                    {
                        if (_bRXCommandData[0] == 'K') //Input IR key
                        {                        
                            __bISRKey = (BYTE) _SYSDEBUG_StrToHexval(&_bRXCommandData[1], 2);    //BYTE
                            // LLY2.37p, remove __bISRKeyRead, because we will split IR and F/W key to __bISRKey and __bFWKey
                            // So, it's un-necessary to reference it to decide input key source                                            
                            //__bISRKeyRead = TRUE;                        
                        }
                        else
                        {
                            //input one command complete, SIOrxReady
                            _bSIOrxReady=1;
                        }
                        _bStartTextCmd = FALSE;
                        return;
                    }
#ifndef SERIAL_DEBUG_TOOL_OTHERS
                }
            }
#endif
        }
#ifndef SYSDEBUG_SUPPORT_MIN_FUNCTION
        else
        {
            //Add code for serial debug tool.
            if (!_bChangeRxToRomBuffer)
            {
                if (bCh == END_CMD)
                {
                    _bRxFg=TRUE;
                }
                
                _bRXCommandData[_bSCONinBufWriteIndex++]=bCh;
                
                _bSCONinBufWriteIndex = _bSCONinBufWriteIndex%RX_COMMAND_SIZE;                
            }
            else  // _bChangeRxToRomBuffer==TRUE, use ROM data buffer to save data
            {
                /*
                if (_wROMdataBufIndex <= (_wROMSize-2))   
                    _bpROMBuf[_wROMdataBufIndex++] = bCh;
                else if (_wROMdataBufIndex == (_wROMSize-1))
                {
                    _bpROMBuf[_wROMdataBufIndex++] = bCh;
                    _bRxFg=TRUE;  
                }
                */
                _bpROMBuf[_wROMdataBufIndex++] = bCh;
                if (_wROMdataBufIndex == _wROMSize)   
                    _bRxFg=TRUE;
            }
        }
#endif //SYSDEBUG_SUPPORT_MIN_FUNCTION
    }
    return;   
}

/****************************************************************************
 ** Function:           SYSDEBUG_Poll
 ** Description:        This function is polling the data in Rx buffer.
 **                     Please add it to your loop to pool the command.
 ** Parameters:         none.
 ** Return:             none.
 ***************************************************************************/
void SYSDEBUG_Poll(void)
{
    if (!_bBinMode)
        _SYSDEBUG_CheckRX();
#ifndef SYSDEBUG_SUPPORT_MIN_FUNCTION
    else    //poling "serial debug tool"
    {
        if (_bRxFg)
        {       
            _bRxFg=FALSE;
            
            if (!_bChangeRxToRomBuffer) 

⌨️ 快捷键说明

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