Back to index

glibc  2.9
console.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994, 1996 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil),
00004    On-Line Applications Research Corporation.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <standalone.h>
00022 #include "m68020.h"
00023 
00024 /* Console IO routines for a Motorola MVME135/MVME136 board.
00025 
00026 They currently use the B port.  It should be possible to
00027 use the A port by filling in the reset of the chip structure,
00028 adding an ifdef for PORTA/PORTB, and switching the addresses,
00029 and maybe the macros based on the macro. */
00030 
00031 /* M68681 DUART chip register structures and constants */
00032 
00033 typedef struct {
00034   volatile unsigned char fill1[ 5 ];     /* channel A regs ( not used ) */
00035   volatile unsigned char isr;            /* interrupt status reg */
00036   volatile unsigned char fill2[ 2 ];     /* counter regs (not used) */
00037   volatile unsigned char mr1mr2b;        /* MR1B and MR2B regs */
00038   volatile unsigned char srb;            /* status reg channel B */
00039   volatile unsigned char fill3;          /* do not access */
00040   volatile unsigned char rbb;            /* receive buffer channel B */
00041   volatile unsigned char ivr;            /* interrupt vector register */
00042 } r_m681_info;
00043 
00044 typedef struct {
00045   volatile unsigned char fill1[ 4 ];     /* channel A regs (not used) */
00046   volatile unsigned char acr;            /* auxillary control reg */
00047   volatile unsigned char imr;            /* interrupt mask reg */
00048   volatile unsigned char fill2[ 2 ];     /* counter regs (not used) */
00049   volatile unsigned char mr1mr2b;        /* MR1B and MR2B regs */
00050   volatile unsigned char csrb;           /* clock select reg */
00051   volatile unsigned char crb;            /* command reg */
00052   volatile unsigned char tbb;            /* transmit buffer channel B */
00053   volatile unsigned char ivr;            /* interrupt vector register */
00054 } w_m681_info;
00055 
00056 #define RD_M68681     ((r_m681_info *)0xfffb0040)   /* ptr to the M68681 */
00057 #define WR_M68681     ((w_m681_info *)0xfffb0040)   /* ptr to the M68681 */
00058 #define RXRDYB        0x01               /* status reg recv ready mask */
00059 #define TXRDYB        0x04               /* status reg trans ready mask */
00060 
00061 /* _Console_Putc
00062 
00063 This routine transmits a character out the M68681.  It supports
00064 XON/XOFF flow control.  */
00065 
00066 #define XON             0x11            /* control-Q */
00067 #define XOFF            0x13            /* control-S */
00068 
00069 int
00070 _Console_Putc (ch)
00071      char ch;
00072 {
00073   while ( ! (RD_M68681->srb & TXRDYB) ) ;
00074   while ( RD_M68681->srb & RXRDYB )        /* must be an XOFF */
00075     if ( RD_M68681->rbb == XOFF )
00076       do {
00077         while ( ! (RD_M68681->srb & RXRDYB) ) ;
00078       } while ( RD_M68681->rbb != XON );
00079 
00080   WR_M68681->tbb = ch;
00081   return( 0 );
00082 }
00083 
00084 /* _Console_Getc
00085 
00086 This routine reads a character from the UART and returns it. */
00087 
00088 int
00089 _Console_Getc (poll)
00090      int poll;
00091 {
00092   if ( poll ) {
00093     if ( !(RD_M68681->srb & RXRDYB) )
00094       return -1;
00095     else
00096       return RD_M68681->rbb;
00097   } else {
00098     while ( !(RD_M68681->srb & RXRDYB) );
00099     return RD_M68681->rbb;
00100   }
00101 }