/*
* Copyright (C) 2010 ZLGMCU
* All rights reserved.
*
* @Author: Chenxibing
* @Descr: LPC3250 UART5 & UART3 driver for AnyWhere.
*/
#include <common.h>
#include <lpc3250.h>
DECLARE_GLOBAL_DATA_PTR;
初始化,波特率9600,8N1。
int uart3_init(void)
{
int tmp32;
CLKPWR->clkpwr_uart_clk_ctrl |= CLKPWR_UARTCLKCTRL_UART3_EN;
CLKPWR->clkpwr_uart3_clk_ctrl = (254<<0)|(3<<8); //9600
UARTCNTL->ctrl &= (~_BIT(11));
UARTCNTL->clkmode |= (UART_CLKMODE_ON << 4);
UART3->lcr |= UART_LCR_DIVLATCH_EN;
UART3->dlm_ier = 0x00;
UART3->dll_fifo = 0x01;
UART3->lcr = UART_LCR_WLEN_8BITS;
//UART3->iir_fcr = (0x0F | (0x03<<6));
/* Clear FIFOs and set FIFO level */
UART3->iir_fcr = (UART_FCR_RXFIFO_TL16 |
UART_FCR_TXFIFO_TL0 | UART_FCR_FIFO_CTRL |
UART_FCR_FIFO_EN | UART_FCR_TXFIFO_FLUSH |
UART_FCR_RXFIFO_FLUSH);
UART3->dlm_ier = 0; //disable interrupt
tmp32 = UART3->iir_fcr;
tmp32 = UART3->lsr;
return 0;
}
采用查询方式读取一个字节:
unsigned char uart3_read_byte(void)
{
/* Wait for a character from the UART */
while ((UART3->lsr & UART_LSR_RDR) == 0);
return (int) (UART3->dll_fifo & 0xFF);
}
发送一个字节,等待发送完毕:
void uart3_write_byte(unsigned char c)
{
/* Wait for FIFO to become empty */
while ((UART3->lsr & UART_LSR_THRE) == 0);
UART3->dll_fifo = (u32) c;
}
通过UART3发送字符串:
void uart3_write_str(unsigned char *s, int len)
{
int i;
for(i=0; i<len; i++) {
uart3_write_byte(*s);
s++;
}
}
#define DPRINTK(nlevel, klevel, fmt, args...) ((void)((NETIF_MSG_##nlevel & pdata->msg_enable) && printk(KERN_##klevel "%s: %s: " fmt "\n", pdata->dev->name, __func__, ## args)))
阅读(326) | 评论(0) | 转发(0) |