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

📄 uart_test.c

📁 COLDFIRE 5282SC的文件
💻 C
字号:
/*
 * File:		uart_test.c
 * Purpose:		Test both serial ports of the M5282EVB
 *
 * Notes:		Requires loopback cables on both terminals.
 *				See "cables.doc" for assembly instructions
 */

#include "src/init/m5282evb.h"
#include "src/fat/fat.h"

/********************************************************************/
void
uart_test(void)
{
	void uart0_test(void);
	void uart1_test(void);
	
	uart0_test();
	uart1_test();
}
/*********************************************************************/	    
void
uart0_test(void)
{
	int i;
	char ch;
	char tmp;

	RESULTS |= UART0_TEST;
	MCF5282_GPIO_PUAPAR = 0x0F;
	
	/* Flush one character through */
	uart0_out_char('Z');
	for (i = 0; i < 100000; i++)
		if (uart0_char_present())
			break;
	if (i == 100000)
	{
		RESULTS |= UART0_FAIL;
		return;
	}
	
	uart0_in_char();
	
	/* Test with 26 characters */
	for (ch = 'a'; ch <= 'z'; ch++)
	{
		uart0_out_char(ch);
		
		/* Wait for char to be received */
		for (i = 0; i < 100000; i++)
			if (uart0_char_present())
				break;

		/* Did we timeout? */
		if (i == 100000)
		{
			RESULTS |= UART0_FAIL;
			return;
		}
		
		/* Did we receive the character properly? */
		tmp = uart0_in_char();
		if (tmp != ch)
		{
			RESULTS |= UART0_FAIL;
			return;
		}
	}
}
/*********************************************************************/	    
void
uart1_test(void)
{
	int i;
	char ch, tmp1;

	RESULTS |= UART1_TEST;
	
	uart1_out_char('Z');
	
	for (i = 0; i < 100000; i++)
		if (uart1_char_present())
			break;
	if (i == 100000)
	{
		RESULTS |= UART1_FAIL;
		return;
	}
	uart1_in_char();

	for (ch = 'a'; ch <= 'z'; ch++)
	{
		uart1_out_char(ch);

		/* Wait for char to be received */
		for (i = 0; i < 100000; i++)
			if (uart1_char_present())
				break;

		/* Did we timeout? */
		if (i == 100000)
		{
			RESULTS |= UART1_FAIL;
			return;
		}
		/* Did we receive the character properly? */
		tmp1 = uart1_in_char();
		if (tmp1 != ch)
		{
			RESULTS |= UART1_FAIL;
			return;
		}
	}
}
/*********************************************************************/	   

⌨️ 快捷键说明

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