📄 serial.c
字号:
/* * 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 0x01 /* receive data ready */ #define USTAT_TXB_EMPTY 0x02 /* tx buffer empty */#define BPS 19200 /* serial baudrate */void rt_serial_init(void);/** * @addtogroup S3C2410 *//*@{*//** * This function initializes serial */void rt_serial_init(){ unsigned long i, div; GPHCON |= 0xa0; /*PULLUP is enable */ GPHUP |= 0x0c; /* FIFO enable, Tx/Rx FIFO clear */ UFCON0 = 0x1; /* 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 */ UBRD0 = 0x1a; UTXH0 = 0x2; URXH0 = 0x1; /* 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 URXH0;}/** * 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_t)c;}/*@}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -