📄 uart_driver.c
字号:
/*
* uart_driver.c - uart driver ( low-level )
*
* Author: li ming <admin@lumit.org>
* Date: 2005-6-11
* Copyleft: http://www.lumit.org
*/
#include "uart_driver.h"
int UART_BASE;
int UART_BAUD;
/* set uart related gpio */
int uart_open( int uart_base )
{
UART_BASE = uart_base;
/* Disable interrupts */
*(volatile unsigned *) (UART_BASE + UCON) = 0;
/* Set port for 8 bit, one stop, no parity */
*(volatile unsigned *) (UART_BASE + ULCON) = (ULCR8bits);
/* Enable interrupt operation on UART */
*(volatile unsigned *) (UART_BASE + UCON) = UCRRxM | UCRTxM;
return 0;
}
int uart_read( unsigned char * buf, int count )
{
int i;
unsigned char ch;
for( i = 0; i < count; i++ )
{
/* read rx ready flag, when =1 break */
while ( (RX_DATA(GET_STATUS(UART_BASE)))==0 )
;
ch = GET_CHAR(UART_BASE);
*(buf+i) = ch;
}
return count;
}
int uart_write( unsigned char * buf, int count )
{
int i;
unsigned char ch;
for( i = 0; i < count; i++ )
{
ch = *(buf+i);
/* read tx ready flag, when =1 break */
while ( TX_READY(GET_STATUS(UART_BASE))==0)
;
PUT_CHAR(UART_BASE, ch);
}
return count;
}
int uart_ioctl( unsigned int cmd, unsigned long arg )
{
switch( cmd )
{
case UART_SELECT_CHANNEL:
UART_BASE = arg;
break;
case UART_SET_BAUDRATE:
UART_BAUD = arg;
*(volatile unsigned *) (UART_BASE + UBRDIV) = UART_BAUD;
break;
default:
break;
}
return 0;
}
int uart_release( void )
{
// do nothing
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -