From: Erik M. <er...@us...> - 2002-01-02 01:19:00
|
Update of /cvsroot/blob/blob/src/lib In directory usw-pr-cvs1:/tmp/cvs-serv8566/src/lib Modified Files: serial.c Added Files: serial-sa11x0.c Log Message: Happy new year! This is the start of a new serial driver that should make porting blob to non-StrongARM architectures easier. The SA11x0 driver is implemented, but completely untested at the moment. It's trivial to do the rest of the serial code, but I'd better go to bed, or otherwise Jan-Derk will complain that I'm working too late ;) Part two follows tomorrow. --- NEW FILE: serial-sa11x0.c --- /* * serial-sa11x0.c: StrongARM SA11x0 serial port driver * * Copyright (C) 2002 Erik Mouw <J.A...@it...> * * $Id: serial-sa11x0.c,v 1.1 2002/01/02 01:18:57 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-sa11x0.c,v 1.1 2002/01/02 01:18:57 erikm Exp $" #ifdef HAVE_CONFIG_H # include <blob/config.h> #endif #include <blob/arch.h> #include <blob/errno.h> #include <blob/sa1100.h> #include <blob/serial.h> #include <blob/types.h> #if defined USE_SERIAL1 # define SerialUTSR0 Ser1UTSR0 # define SerialUTSR1 Ser1UTSR1 # define SerialUTDR Ser1UTDR # define SerialUTCR0 Ser1UTCR0 # define SerialUTCR1 Ser1UTCR1 # define SerialUTCR2 Ser1UTCR2 # define SerialUTCR3 Ser1UTCR3 #else /* defined USE_SERIAL3 */ /* using an SA11x0 CPU and not having any serial port defined is an * error, but because we're using the driver in the library we can't * bail out over here */ # define SerialUTSR0 Ser3UTSR0 # define SerialUTSR1 Ser3UTSR1 # define SerialUTDR Ser3UTDR # define SerialUTCR0 Ser3UTCR0 # define SerialUTCR1 Ser3UTCR1 # define SerialUTCR2 Ser3UTCR2 # define SerialUTCR3 Ser3UTCR3 #endif /* flush serial input queue. returns 0 on success or negative error * number otherwise */ static int sa11x0_serial_flush_in(void) { volatile u32 tmp; /* keep on reading as long as the receiver is not empty */ while(SerialUTSR1 & UTSR1_RNE) { if(SerialUTSR1 & (UTSR1_PRE | UTSR1_FRE | UTSR1_ROR)) return -ESERIAL; tmp = SerialUTDR; } return 0; } /* flush output queue. returns 0 on success or negative error number * otherwise */ static int sa11x0_serial_flush_out(void) { /* wait until the transmitter is no longer busy */ while(SerialUTSR1 & UTSR1_TBY) { } return 0; } /* initialise serial port at the request baudrate. returns 0 on * success, or a negative error number otherwise */ static int sa11x0_serial_init(serial_baud_t baud) { u32 divisor; /* get correct divisor */ switch(baud) { case baud_1200: divisor = 191; break; case baud_9600: divisor = 23; break; case baud_19200: divisor = 11; break; case baud_38400: divisor = 5; break; case baud_57600: divisor = 3; break; case baud_115200: divisor = 1; break; case baud_230400: divisor = 0; break; default: return -ERANGE; } #if defined USE_SERIAL1 /* select UART use for serial port 1 or otherwise we won't see * anything at all */ Ser1SDCR0 = SDCR0_UART; #endif sa11x0_serial_flush_out(); /* switch receiver and transmitter off */ SerialUTCR3 = 0x00; /* clear sticky bits in control register 3 */ SerialUTSR0 = 0xff; /* set the port to sensible defaults (no break, no interrupts, * no parity, 8 databits, 1 stopbit, transmitter and receiver * enabled) */ SerialUTCR0 = ( UTCR0_1StpBit | UTCR0_8BitData ); SerialUTCR1 = 0; SerialUTCR2 = divisor; /* turn the receiver and transmitter back on */ SerialUTCR3 = ( UTCR3_RXE | UTCR3_TXE ); 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 sa11x0_serial_poll(void) { /* check for errors */ if(SerialUTSR1 & (UTSR1_PRE | UTSR1_FRE | UTSR1_ROR)) return -ESERIAL; if(SerialUTSR1 & UTSR1_RNE) return 1; else return 0; } /* 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 sa11x0_serial_read(void) { int rv; for(;;) { rv = sa11x0_serial_poll(); if(rv < 0) return rv; if(rv > 0) return SerialUTDR & 0xff; } } /* write character to serial port. return 0 on success, or negative * error number on failure. this function is blocking */ static int sa11x0_serial_write(int c) { /* wait for room in the transmit FIFO */ while((SerialUTSR0 & UTSR0_TFS) == 0) { } SerialUTDR = c & 0xff; return 0; } /* export serial driver */ serial_driver_t sa11x0_serial_driver = { init: sa11x0_serial_init, read: sa11x0_serial_read, write: sa11x0_serial_write, poll: sa11x0_serial_poll, flush_in: sa11x0_serial_flush_in, flush_out: sa11x0_serial_flush_out }; Index: serial.c =================================================================== RCS file: /cvsroot/blob/blob/src/lib/serial.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- serial.c 2001/10/31 16:45:52 1.4 +++ serial.c 2002/01/02 01:18:57 1.5 @@ -35,11 +35,16 @@ # include <blob/config.h> #endif + #include <blob/arch.h> #include <blob/led.h> #include <blob/sa1100.h> #include <blob/serial.h> #include <blob/time.h> + + +serial_driver_t *serial_driver; + /* * Initialise the serial port with the given baudrate. The settings |