📄 drvuart.c
字号:
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2007 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// (¨MStar Confidential Information〃) by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
///@file drvuart.h
///@brief System functions:UART Module
/// This file is vaild when "ENABLE_MSTV_UART_DEBUG" is enable
/// The brief function is get the register content by UART without halt the whole
/// system.
//
///////////////////////////////////////////////////////////////////////////////
#define _DRVUART_C_
#include "mreg51.h"
#include "datatype.h"
#include "hwreg.h"
#include "drvuart.h"
#include "sysinfo.h"
#include "Analog_Reg.h"
#include "drviic.h"
#include "drvDLC.h"
#include "drvTimer.h"
#include "panel.h"
#include "Mapp_globalVar.h"
#include "msAPI_Auto.h"
#include "drvmode.h"
#include "msAPI_Mode.h"
#include "drvScaler.h"
#include "msgpio.h"
#include "VersionInfo.h"
#include "msAPI_DLC.h"
#include "drvsys.h"
//#include "SI2cHost.h"
extern BOOLEAN MDrv_IIC_WriteBytes(U8 u8SlaveID, U8 AddrCnt, U8* pu8addr, U16 u16size, U8* pBuf);// kevin 071027_0
/* original stuff in MDrv_UART_Init() is moved to drvsys.c */
#if (ENABLE_MSTV_UART_DEBUG)
//#define UARTMSG(x) x
#if ((CHANNEL_SCAN_AUTO_TEST == 1) || (SFU_AUTO_TEST == 1))
#include "drvuart_scan.c"
#endif
extern void MApp_OsdLogo_Show(void);
extern void MApp_Init_LoadBin();
/******************************************************************************/
///Initial UART relative variable and flag.
/******************************************************************************/
void MDrv_UART_DebugInit(void)
{
// reset Uart variables
TI = 0;
g_UartCommand.Index = 0;
g_bDebugASCIICommandFlag = 0;
g_bDebugProgStopFlag = FALSE;
g_Uart0CheckTick = 0;
#if (CHANNEL_SCAN_AUTO_TEST == 1)
MDrv_UART_AutoScanTest_Init();
#endif
}
/******************************************************************************/
/// Decode the Command gets from UART port for main chip.
/// Command Buffer [0]:
/// -bit7~bit5 :Command length:1 ~ 6
/// -bit4~bit0 :UART command
/// Command Buffer [1]:
/// -Control address high.
/// Command Buffer [2]:
/// -Control address low.
/// if write command:
/// -Command buffer [3]: control data
/******************************************************************************/
void MDrv_UART_DecodeNormalCommand(void)
{
//printf("MDrv_UART_DecodeNormalCommand %x\n", (U16)UART_CMD );
U8 u8Value;
switch(UART_CMD)
{
case uartWrite_MST_Bank_n:
XBYTE[((U8)UART_CMD_MS_BANK<<8) | (U8)UART_CMD_MS_REGINDEX] = UART_CMD_MS_REGDATA;
putchar(0xF1);
break;
case uartRead_MST_Bank_n:
putchar(0xF2);
putchar(XBYTE[((U8)UART_CMD_MS_BANK<<8)|(U8)UART_CMD_MS_REGINDEX]);
break;
case uartRead_MCU_XDATA:
putchar(0xF2);
putchar(XBYTE[((U8)UART_CMD_MCU_IDX_H<<8)|(U8)UART_CMD_MCU_IDX_L]);
break;
case uartWrite_MCU_XDATA:
XBYTE[((U8)UART_CMD_MCU_IDX_H<<8) | (U8)UART_CMD_MCU_IDX_L] = UART_CMD_MCU_DATA;
putchar(0xF1);
break;
case uartI2C_Device_Write:
MDrv_IIC_WriteByte( UART_CMD_MCU_IDX_H, UART_CMD_MCU_IDX_L, UART_CMD_MCU_DATA);
putchar(0xF1);
break;
case uartI2C_Device_Read:
putchar(0xF2);
if( MDrv_IIC_ReadByte( UART_CMD_MCU_IDX_H, UART_CMD_MCU_IDX_L, &u8Value) )
putchar(u8Value);
else
putchar(0xFF);
break;
case uartEEPROM_Write:
{
extern void msAPI_rmWriteByte(WORD wIndex, BYTE ucVal);
msAPI_rmWriteByte(MAKEWORD(UART_CMD_MCU_IDX_H,UART_CMD_MCU_IDX_L), UART_CMD_MCU_DATA);
putchar(0xF1);
}
break;
case uartEEPROM_Read:
{
extern BYTE msAPI_rmReadByte(WORD wIndex);
u8Value = 0xFF;
putchar(0xF2);
u8Value = msAPI_rmReadByte(MAKEWORD(UART_CMD_MCU_IDX_H,UART_CMD_MCU_IDX_L));
putchar(u8Value);
}
break;
case uartTest_Command:
MDrv_UART_ExecTestCommand();
break;
default:
// printf("Unsupport Normal Command: 0x%x\n", (U16)UART_CMD );
break;
}
}
void MDrv_UART_ExecTestCommand(void)
{
switch( g_UartCommand.Buffer[_UART_CMD_INDEX1_] )
{
case 0x50:
g_bDebugProgStopFlag = !g_bDebugProgStopFlag;
if( g_bDebugProgStopFlag )
{
printf("<Debug>\r\n");
}
else
{
printf("<Free>\r\n");
}
break;
case 0x51:
MApp_DebugInfo_GetCurModel();
break;
case 0x52:
msAPI_Auto_Geometry( AUTO_TUNE_BASIC, &g_PcadcModeSetting, &stGenSetting.g_AdcSetting[ADC_SET_VGA]);
break;
case 0x53:
GPIOWrite(2, 1); // for China demo board ISP
printf("Enter ISP");
break;
case 0x54:
MApp_Init_LoadBin();
break;
case 0x55:
#if (DISPLAY_LOGO)
MApp_OsdLogo_Show();
#endif
break;
case 0x56:
break;
default:
printf("Unsupport Test Command: 0x%x\n", (U16)g_UartCommand.Buffer[_UART_CMD_INDEX1_] );
break;
}
}
/******************************************************************************/
/// Decode the Command gets from UART port for extra device(like tunner/demodulator).
/// Command Buffer [0]:
/// -bit7~bit5 :111b
/// -bit4~bit0 :extra UART command
/// Command Buffer [1~8]:
/// -Extra Control data buffer.
/******************************************************************************/
void MDrv_UART_DecodeExtCommand(void)
{
U8 u8addressCount, u8dataCount;
U8 u8Result, i;
switch( UART_EXT_DEV )
{
#if (ENABLE_DLC_TEST_BY_MSTVTOOL)
case uartExtDev_MstDlcTest:
{
switch(UART_EXT_CMD)
{
case URCMD_MST_DLC_TEST_FORCE_PAUSE:
g_bDebugProgStopFlag = 1; // pause the program
UARTMSG(printf("<Pause>"));
break;
case URCMD_MST_DLC_TEST_FORCE_RUN:
g_bDebugProgStopFlag = 0;
UARTMSG(printf("<Run>"));
break;
case URCMD_MST_DLC_TEST_READ:
{
U8 i;
for (i=0; i<16; i+=2)
{
putchar(0xF3);
putchar(g_ucLumaCurve[i]);
putchar(g_ucLumaCurve[i+1]);
MDrv_Timer_Delayms(50);
UARTMSG(printf(" %d %d", (U16)g_ucLumaCurve[i], (U16)g_ucLumaCurve[i+1]));
}
}
break;
case URCMD_MST_DLC_TEST_WRITE_1:
{
U8 i;
i = (UART_CMD_EXT_LENGTH-4);
for (i=0; i<(UART_CMD_EXT_LENGTH-4); i++)
g_ucLumaCurve[i] = g_UartCommand.Buffer[_UART_CMD_INDEX4_ + i];
}
break;
case URCMD_MST_DLC_TEST_WRITE_2:
{
U8 i;
i = (UART_CMD_EXT_LENGTH-4);
for (i=0; i<(UART_CMD_EXT_LENGTH-4); i++)
g_ucLumaCurve[8 + i] = g_UartCommand.Buffer[_UART_CMD_INDEX4_ + i];
}
break;
case URCMD_MST_DLC_TEST_REINIT:
MDrv_DLC_Init( devPanel_WIDTH(), devPanel_HEIGHT(), &g_ucLumaCurve[0] );
MDrv_DLC_SetOnOff(ENABLE);
break;
case URCMD_MST_DLC_TEST_BOUNDARY_READ:
putchar( 0xF2 );
if( UART_EXT_CMD_MS_DAT1 == 0x04 )
{
putchar( (g_u8_L_L_U << 4) | (g_u8_L_L_D &0x0F) );
}
else if( UART_EXT_CMD_MS_DAT1 == 0x06 )
{
putchar( (g_u8_L_H_U << 4) | (g_u8_L_H_D &0x0F) );
}
else if( UART_EXT_CMD_MS_DAT1 == 0x08 )
{
putchar( g_u8_S_L_U );
}
else if( UART_EXT_CMD_MS_DAT1 == 0x09 )
{
putchar( g_u8_S_L_D );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -