rtems bbb板uart驱动编写
进行串口驱动编写,主要参考源码中的console-config.c文件
以下是代码:
void beagle_console_init(void)
{
if(init_needed)
{
const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
CONSOLE_SYSC = 2;
while ((CONSOLE_SYSS & 1) == 0)
;
if ((CONSOLE_LSR & (CONSOLE_LSR_THRE | CONSOLE_LSR_TEMT)) == CONSOLE_LSR_THRE)
{
CONSOLE_LCR = 0x83;
CONSOLE_DLL = div;
CONSOLE_DLM = (div >> 8) & 0xff;
CONSOLE_LCR = 0x03;
CONSOLE_ACR = 0x00;
}
while ((CONSOLE_LSR & CONSOLE_LSR_TEMT) == 0)
;
CONSOLE_LCR = 0x80 | 0x03;
CONSOLE_DLL = 0x00;
CONSOLE_DLM = 0x00;
CONSOLE_LCR = 0x03;
CONSOLE_MCR = 0x03;
CONSOLE_FCR = 0x07;
CONSOLE_LCR = 0x83;
CONSOLE_DLL = div;
CONSOLE_DLM = (div >> 8) & 0xff;
CONSOLE_LCR = 0x03;
CONSOLE_ACR = 0x00;
init_needed = 0;
}
}
以下是发送部分程序:
#include <stdio.h>
#include <stdlib.h>
#include <bsp.h>
#define Control_Module_Registers1 (*(volatile uint32_t *)(0x44E10000+0x984))
#define UART1_THR (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x00))
#define UART1_RHR (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x00))
#define UART1_IER (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x04))
#define UART1_DLL (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x00))
#define UART1_DLM (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x04))
#define UART1_LCR (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x0c))
#define UART1_LSR (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x14))
#define UART1_MDR1 (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x20))
#define UART1_SYSC (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x54))
#define UART1_SYSS (*(volatile uint32_t *)(BEAGLE_BASE_UART_2+0x58))
#define TX_FIFO_E (1<<5)
#define RX_FIFO_E (1<<0)
发送函数:
int uart_send_command(rtems_task_argument ignored)
{
uint32_t div;
Control_Module_Registers1 = 0x00;
UART1_SYSC = 2; // software reset
while((UART1_SYSS & 1) == 0) ;
UART1_LCR = 0x83;
div = UART_CLOCK / 16 / 115200;
UART1_DLL = div;
UART1_DLM = (div >> 8) & 0xff;
UART1_LCR = 0x03;
UART1_MDR1 = 0x00;
char c;
while(1) {
for(c = 'A'; c <= 'Z'; c++) {
UART1_THR = c;
rtems_task_wake_after(rtems_clock_get_ticks_per_second());
}
}
return 0;
}
接收部分下次再聊。
posted on 2016-09-23 23:25 sichenzhao 阅读(177) 评论(0) 编辑 收藏 举报