📄 serial.c.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://openlab.rt-thread.com/license/LICENSE * * Change Logs: * Date Author Notes * 2006-03-13 Bernard first version */#include <rtthread.h>#include <rthw.h>#include "s3c2410.h"#define USTAT_RCV_READY 0x20 /* receive data ready */ #define USTAT_TXB_EMPTY 0x40 /* tx buffer empty */#define BPS 19200 /* serial baudrate */extern rt_uint32 PCLK;void rt_serial_init(void);/** * @addtogroup S3C2410 *//*@{*//** * 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) { rt_serial_putc (*str++); }}/** * This function initializes serial */void rt_serial_init(){ unsigned long i, div; /* FIFO enable, Tx/Rx FIFO clear */ UFCON0 = 0x07; /* disable the flow control */ UMCON0= 0x0; /* Normal,No parity,1 stop,8 bit */ ULCON0 = 0x3; /* * tx=level,rx=edge,disable timeout int.,enable rx error int., * normal,interrupt or polling */ UCON0= 0x245; /* * UBRDIVn = (int)(PCLK / (bps x 16) ) –1 */ div = (int)(PCLK / (16 * BPS)) - 1; UBRD0 = div; // UBRD0 = 0x500; /* baudrate = 19200bps */ UFCON1 = 0x07; UMCON0 = 0x0; ULCON1 = 0x3; UCON1 = 0x245; UBRD1 = div; // UBRDIV1 = 0x500; /* output PCLK to UART0/1, PWMTIMER */ CLKCON = 0x0D00; for (i = 0; i < 100; i++);}/** * This function read a character from serial without interrupt enable mode * * @return the read char */char rt_serial_getc(){ while ((USTAT0 & USTAT_RCV_READY) == 0); return URXB0;}/** * This function will write a character to serial without interrupt enable mode * * @param c the char to write */void rt_serial_putc(const char c){ /* to be polite with serial console add a line feed to the carriage return character */ if (c=='\n')rt_serial_putc('\r'); /* wait for room in the transmit FIFO */ while(!(USTAT0 & USTAT_TXB_EMPTY)); UTXH0 = (rt_uint8)c;}/*@}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -