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

📄 uart_dv.c

📁 MXIC旺宏液晶电视芯片MX88V44的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*-------------------------------------------------------------------------
UART_DV.C
	The UART service routine for debug.
	
Copyright 2004 Macronix International Co., Ltd.
-------------------------------------------------------------------------*/
#define _UART_DV_

#include "..\inc\public2.h"
#define		L44_WRID			0x28		//define the 1574 I2C write ID
#define		EEPROM_WRID			0xA0		//EEPROM I2C Wirte ID

	//============== UART Memory Define ================================
	xdata char	Rx_Buf[2][24]	_at_ 0x0000;
	xdata char	Tx_Buf[24]		_at_ 0x0030;
	xdata char	ReTx_Buf[24]	_at_ 0x0050;

	xdata char	UART_RxInUse	_at_ 0x0070;
	xdata char	Rx_Index		_at_ 0x0072;
	xdata char	Tx_Index		_at_ 0x0074;
	xdata char	Data_Length		_at_ 0x0076;
	xdata char	Parse_Length	_at_ 0x0078;
	xdata char	Tx_Length		_at_ 0x007A;
	xdata char	ReTx_Length		_at_ 0x007C;

	xdata char	*ExtMemPtr		_at_ 0x0080;
	xdata char	RW15xx_Addr		_at_ 0x0088;
	xdata char	W15xx_Val		_at_ 0x008A;
	xdata char	R15xx_Length	_at_ 0x008C;

	xdata char	Tempbuf[64]		_at_ 0x00A0;
	xdata char	WR_TestByte[16]	_at_ 0x00E0;

	char	UARTFlag;
	char	UART_Count;

extern char		DEV_Inf[16];

extern void		 Read_OSDReg(BYTE *, BYTE, BYTE, BYTE);
extern void		Write_OSDReg(BYTE *, BYTE, BYTE, BYTE);	
extern BYTE		CVD1_ReadWrite(BYTE, BYTE, BYTE);

/**--------------------------------------------------------------------------
* Name          void UART1(void) interrupt 4 using 1
*
* Description	IRQ function,INT no.4 (Serial PORT) using BANK 1
*				When INT. set flagx,and clear RI/TI
*
* Return
*
* DATE          Author          Description
* ===========================================================================
* 2004/05/12	Eson W.			Just test RI,OK!!
*
**/
void UART1(void) interrupt 4 using 1
{
UART_Count++;
if (UART_Count & 0x08)	LED0 ^= 1;
	if(RI==1)
	{
		UART_RxByte();
		RI=0;
	}

	if(TI==1)
	{
		UART_TxByte();
		TI=0;
	}
	TF1=0;
}

/**--------------------------------------------------------------------------
* Name          void    UART_RxByte(void);
*
* Description	RX one byte from COM port.
*
* Flow Chart	P			Read data from COM port
*				|
*				X---+		SYN1 flag set?
*				|	|
*				|	P		Yes, SYN1 set, Put Rx data to RX buf
*				|	|
*				|	X---+		End of Pack?
*				|	|	P			Yes, set PARSE flag and reset SYN1 flag.
*				|	X				No,  Check is Command length
*				|
*				X---+		NO, SYN1 not set, is SYN1 byte?
*					|
*					P			Yes, is SYN1 byte put it to RX buffer
*								No,  ignore the  noise byte
*
* Return        None
*
* DATE          Author          Description
* ===========================================================================
* 2003-01-20	KM Ho			This is first time implement
* 2004-05-14	Eson W.			Modify for 8051 component
**/
void	UART_RxByte()
{
	char	rx_data;
	struct UART_PACK	*rx_pack;

	rx_data = SBUF;		//RX data from UART Buffer

	if (UARTFlag & RX_SYN1)					//check SYN1 flag is set
	{		//Next byte RX --- put to RX buf and check is EOP
		Rx_Buf[UART_RxInUse][Rx_Index]  = rx_data;
		Rx_Index++;

		if (Rx_Index >= UART_PACK_SIZE)		//Is over Min. length?
		{
			rx_pack = (struct UART_PACK *)Rx_Buf[UART_RxInUse];
			Data_Length = rx_pack->length ;
			if (Rx_Index > 24)				//Is over Max. length?
			{
				UARTFlag &= (RX_SYN1 ^ CLEAN_UARTFlag);
				Rx_Index  = 0;
				Data_Length = 0;
			}

			if (Rx_Index == (Data_Length+UART_PACK_SIZE))	//End Of Pack
			{
				Parse_Length = Data_Length+UART_PACK_SIZE;	//length of parse
				UART_RxInUse ^= 1;			//Ping-pong the buf index
				Rx_Index = 0;

				UARTFlag |= RX_PARSE;		//Set flag, process in timer()
				IE |= 0x02;					//Enable Timer0;
											//Before this,TIMER0 IRQ would be error!!
				UARTFlag &= (RX_SYN1 ^ CLEAN_UARTFlag);
			}
		}
	}
	else
	{		//First byte RX --- is pack begin byte SYN1(0x66)?
		Rx_Index  = 0;
		Data_Length = 0;

		if (rx_data == SYN_BYTE)
		{
			UARTFlag |= RX_SYN1;			//set SYN1 flag
			Rx_Buf[UART_RxInUse][Rx_Index++] = rx_data;
		}									//ignore not pack begin byte
	}
}

/**--------------------------------------------------------------------------
* Name          void    UART_TxByte(void);
*
* Description   TX one byte to UART, Sneding data only from Tx_Buf
*
* Flow Chart	X		Tx flag Set?
*				|
*				X---+	Is send complete
*				|	|
*				|	P		Yes, Send complete so clean TX flag
*				|				 and disable TX interrupt request, return
*				P			No,  continue send put data to THR
*
* Return
*
* DATE          Author          Description
* ===========================================================================
* 2003-01-20	KM Ho			This is first time implement
* 2004-05-14	Eson W.			Modify for 8051 component
**/
void	UART_TxByte()
{
	if (UARTFlag & TX_FLAG)				//check is TX flag setting
	{
		SBUF = Tx_Buf[Tx_Index++];
		if (Tx_Index >= Tx_Length)		//close the TX (send complete)
		{
			UARTFlag &= (TX_FLAG ^ CLEAN_UARTFlag);		//clean TX flag
			if (Tx_Buf[1] != ACK)
				UARTFlag |= TX_WAITACK;					//set wait ACK flag **
		}
	}
}

/**--------------------------------------------------------------------------
* Name          void	UART_SendOut(char cmd_length);
*				char	*sendbuf	sending buffer
*				char	cmd_length	length of command
*
* Description	The Routine will
*					1. wait last time send complete,
*					2. Send First byte
*					3. Set flag.
*
* Flow Chart
*
* Return
*
* DATE          Author          Description
* ===========================================================================
* 2003-01-16	K.M. Ho         This is first time implement
* 2004-05-14	Eson W.			Modify for 8051 component
*/
void	UART_SendOut(char *sendbuf, char send_length)
{
	char	i;
	char	send_times;

	send_times = 0;

	while(1)
	{
		if (UARTFlag & (TX_FLAG|TX_WAITACK))
		{								//UART is busy for last TX
			for (i=0; i<120; i++);
			++send_times;
			if (send_times>120)			//send out fail times > 3
				return;
		}
		else
		{			//Ready to send out first byte

			UARTFlag |= TX_FLAG;					//set flag for send
			for (i=0; i<send_length; i++)			//copy send data to TX buffer
//				Tx_Buf[i] = ReTx_Buf[i] = sendbuf[i];
				Tx_Buf[i] = sendbuf[i];
//			Tx_Length = ReTx_Length = send_length;	//copy sending data length
			Tx_Length = send_length;	//copy sending data length
			Tx_Index = 1;							//Trigger UART TX INT
			SBUF=Tx_Buf[0];							//put first data to THR
			return;
		}
	}
}

/**--------------------------------------------------------------------------
* Name          void	PrepareSendBuf(char buf_index, int addr, char data_length,
*										char  cmd_type);
*				char	*sendbuf	sending buffer (MAX. 24bytes)
*				int		addr		address of Read/Write/Fill
*				char	data_length	data length
*				char	cmd_type	type of command
*
* Description	prepare the sending buffer
*
* Flow Chart
*
* Return		None
*

⌨️ 快捷键说明

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