?? 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 "s3c4510.h"#define USTAT_RCV_READY 0x20 /* receive data ready */ #define USTAT_TXB_EMPTY 0x40 /* tx buffer empty */void rt_serial_init(void);/** * @addtogroup S3C4510 *//*@{*//** * 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(){ rt_uint32_t divisor = 0; divisor = 0x500; /* 19200 baudrate, 50MHz */ UARTLCON0 = 0x03; UARTCONT0 = 0x09; UARTBRD0 = divisor; UARTLCON1 = 0x03; UARTCONT1 = 0x09; UARTBRD1 = divisor; for(divisor=0; divisor<100; divisor++);}/** * This function read a character from serial without interrupt enable mode * * @return the read char */char rt_serial_getc(){ while ((UARTSTAT0 & USTAT_RCV_READY) == 0); return UARTRXB0;}/** * 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(!(UARTSTAT0 & USTAT_TXB_EMPTY)); UARTTXH0 = (rt_uint8_t)c;}/*@}*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -