在u-boot中实现UART3驱动

/*
* 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)))
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值