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

📄 serial.c.svn-base

📁 RT-Thread是发展中的下一代微内核嵌入式实时操作系统
💻 SVN-BASE
字号:
/*
 * File      : serial.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.fayfayspace.org/license/LICENSE.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-02-26     Bernard      first version
 */

#include "AT91RM9200.h"

/*!
 * \addtogroup xgAT91RM9200
 */
/*@{*/

/*!
 * \brief display a string on console
 *
 * this function is used to display a string on console, normally, it's 
 * invoked by rt_kprintf
 *
 * \param str the displayed string
 */
void rt_console_puts(const char* str)
{
	while (*str)
	{
		serial_putc (*str++);
	}
}

/*!
 * \brief init serial
 *
 * initialize serial
 */
void rt_serial_init()
{
	/* make any port initializations specific to this port */
	AT91C_PIOA_PDR = AT91C_PA17_TXD0 | AT91C_PA18_RXD0;
	AT91C_PMC_PCER |= 1 << AT91C_ID_USART0;	/* enable clock */

	/* note: do not setup the baudrate */
	AT91C_US0_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
	AT91C_US0_CR = AT91C_US_RXEN | AT91C_US_TXEN;
	AT91C_US0_MR = (AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS |
		 AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT);
	AT91C_US0_IMR = ~0ul;

	return (0);
}

/*!
 * \brief read a char from serial
 *
 * read a char from serial without interrupt enable mode 
 *
 * \return the read char
 */
char rt_serial_getc()
{
	while ((AT91C_US0_CSR & AT91C_US0_RXRDY) == 0);
	return AT91C_US0_RHR;
}

/*!
 * \brief write a char to serial
 *
 * write a char to serial without interrupt enable mode
 *
 * \param c the char to write
 */
void rt_serial_putc(const char c)
{
	if (c == '\n') serial_putc ('\r');

	while ((AT91C_US0_CSR & AT91C_US0_TXRDY) == 0);
	AT91C_US0_THR = c;
}

/*@}*/

⌨️ 快捷键说明

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