📄 serial-s3c44b0.c
字号:
/* * serial-s3c44b0.c: StrongARM SA11x0 serial port driver * * Copyright (C) 2002 Erik Mouw <J.A.K.Mouw@its.tudelft.nl> * * $Id: serial-s3c44b0.c,v 1.2 2002/01/03 16:07:18 erikm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#ident "$Id: serial-s3c44b0.c,v 1.2 2002/01/03 16:07:18 erikm Exp $"#ifdef HAVE_CONFIG_H# include <blob/config.h>#endif#include <blob/arch.h>#include <blob/errno.h>#include <blob/serial.h>#include <blob/types.h>/* flush serial input queue. returns 0 on success or negative error * number otherwise */static int s3c44b0_serial_flush_input(void){ volatile u32 tmp; /* keep on reading as long as the receiver is not empty */ while(REG(UTRSTAT0)&0x01) { tmp = REGB(URXH0); } return 0;}/* flush output queue. returns 0 on success or negative error number * otherwise */static int s3c44b0_serial_flush_output(void){ /* wait until the transmitter is no longer busy */ while(!(REG(UTRSTAT0)&0x02)) { } return 0;}/* initialise serial port at the request baudrate. returns 0 on * success, or a negative error number otherwise */static int s3c44b0_serial_init(serial_baud_t baud){ u32 divisor; /* get correct divisor */ switch(baud) { case baud_1200: divisor = 3124; break; case baud_9600: divisor = 390; break; case baud_19200: divisor = 194; break; case baud_38400: divisor = 97; break; case baud_57600: divisor = 64; break; case baud_115200: divisor = 32; break; default: return -ERANGE; } s3c44b0_serial_flush_output(); REG(UFCON0) = 0x0; REG(ULCON0) = 0x03; REG(UCON0) = 0x05; REG(UBRDIV0) = divisor; REG(UFCON1) = 0x0; REG(ULCON1) = 0x03; REG(UCON1) = 0x05; REG(UBRDIV1) = divisor; for(divisor=0; divisor<100; divisor++); return 0;}/* check if there is a character available to read. returns 1 if there * is a character available, 0 if not, and negative error number on * failure */static int s3c44b0_serial_poll(void){ /* check for errors */ if(REG(UERSTAT0)&0x07) return -ESERIAL; return (REG(UTRSTAT0)&0x01);}/* read one character from the serial port. return character (between * 0 and 255) on success, or negative error number on failure. this * function is blocking */static int s3c44b0_serial_read(void){ int rv; for(;;) { rv = s3c44b0_serial_poll(); if(rv < 0) return rv; if(rv > 0) return REGB(URXH0); }}/* write character to serial port. return 0 on success, or negative * error number on failure. this function is blocking */static int s3c44b0_serial_write(int c){ /* wait for room in the transmit FIFO */ while(!(REG(UTRSTAT0)&0x02)); REGB(UTXH0) = (unsigned char)c; return 0;}/* export serial driver */serial_driver_t s3c44b0_serial_driver = { init: s3c44b0_serial_init, read: s3c44b0_serial_read, write: s3c44b0_serial_write, poll: s3c44b0_serial_poll, flush_input: s3c44b0_serial_flush_input, flush_output: s3c44b0_serial_flush_output};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -