Back to index

glibc  2.9
console.c
Go to the documentation of this file.
00001 /* Copyright (C) 1994, 1997 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 "i386.h"
00023 
00024 /* Console IO routines for a FORCE CPU386 board. */
00025 
00026 /* Force CPU/386 specific IO addressing
00027  *
00028  * The following determines whether Port B or the Console should
00029  * be used for console I/O.  Setting ONE (and only ONE) of these to 1
00030  * enables I/O on that port.
00031  *
00032  *     PORT A - DUSCC MC68562 Channel A  (*** not supported here ***)
00033  *     PORT B - DUSCC MC68562 Channel B
00034  *     PORT C - MFP MC68901 Channel      (*** FORCEbug console ***)
00035  */
00036 
00037 #define PORTB         1               /* use port b as console */
00038 #define PORTC         0               /* use console port as console */
00039 
00040 #if ( PORTB == 1 )
00041 #define TX_STATUS     0x1b6           /* DUSCC General Status Register */
00042 #define RX_STATUS     0x1b6           /* DUSCC General Status Register */
00043 #define TX_BUFFER     0x1e0           /* DUSCC Transmitter Channel B */
00044 #define RX_BUFFER     0x1e8           /* DUSCC Receiver Channel B */
00045 #define Is_tx_ready( _status ) ( (_status) & 0x20 )
00046 #define Is_rx_ready( _status ) ( (_status) & 0x10 )
00047 #endif
00048 
00049 #if ( PORTC == 1 )
00050 #define TX_STATUS     0x12c           /* MFP Transmit Status Register */
00051 #define RX_STATUS     0x12a           /* MFP Receive Status Register */
00052 #define TX_BUFFER     0x12e           /* MFP Transmitter Channel  */
00053 #define RX_BUFFER     0x12e           /* MFP Receiver Channel  */
00054 #define Is_tx_ready( _status ) ( (_status) & 0x80 )
00055 #define Is_rx_ready( _status ) ( (_status) & 0x80 )
00056 #endif
00057 
00058 /* _Console_Initialize
00059 
00060 On the Force board the console require some initialization. */
00061 
00062 void
00063 _Console_Initialize ()
00064 {
00065   register unsigned8 ignored;
00066 
00067   /* FORCE technical support mentioned that it may be necessary to
00068      read the DUSCC RX_BUFFER port four times to remove all junk.
00069      This code is a little more paranoid.  */
00070 
00071   inport_byte( RX_BUFFER, ignored );
00072   inport_byte( RX_BUFFER, ignored );
00073   inport_byte( RX_BUFFER, ignored );
00074   inport_byte( RX_BUFFER, ignored );
00075   inport_byte( RX_BUFFER, ignored );
00076 }
00077 
00078 /* Miscellaneous support for console IO */
00079 
00080 static inline int _Force386_is_rx_ready ()
00081 {
00082   register unsigned8 status;
00083 
00084   inport_byte( RX_STATUS, status );
00085 
00086   if ( Is_rx_ready( status ) ) return 1;
00087   else                         return 0;
00088 }
00089 
00090 static inline int _Force386_is_tx_ready ()
00091 {
00092   register unsigned8 status;
00093 
00094   inport_byte( TX_STATUS, status );
00095 
00096   if ( Is_tx_ready( status ) ) return 1;
00097   else                         return 0;
00098 }
00099 
00100 
00101 static inline int _Force386_read_data ()
00102 {
00103   register unsigned8 ch;
00104 
00105 #if ( PORTB == 1 )
00106     /* Force example code resets the Channel B Receiver here.
00107      * It appears to cause XON's to be lost.
00108      */
00109 
00110      /* outport_byte( RX_STATUS, 0x10 );  */
00111 #endif
00112 
00113   inport_byte( RX_BUFFER, ch );
00114 
00115   return ch;
00116 }
00117 
00118 /* _Console_Putc
00119 
00120 This routine transmits a character.  It supports XON/XOFF flow control.  */
00121 
00122 #define XON             0x11            /* control-Q */
00123 #define XOFF            0x13            /* control-S */
00124 
00125 int
00126 _Console_Putc (ch)
00127      char ch;
00128 {
00129   register unsigned8 inch;
00130 
00131   while ( !_Force386_is_tx_ready() );
00132 
00133   while ( _Force386_is_rx_ready() == 1 ) {      /* must be an XOFF */
00134     inch = _Force386_read_data();
00135     if ( inch == XOFF )
00136       do {
00137         while ( _Force386_is_rx_ready() == 0 );
00138         inch = _Force386_read_data();
00139       } while ( inch != XON );
00140   }
00141 
00142   outport_byte( TX_BUFFER, ch );
00143   return( 0 );
00144 }
00145 
00146 /* _Console_Getc
00147 
00148 This routine reads a character from the UART and returns it. */
00149 
00150 int
00151 _Console_Getc (poll)
00152      int poll;
00153 {
00154   if ( poll ) {
00155     if ( !_Force386_is_rx_ready() )
00156       return -1;
00157     else
00158       return _Force386_read_data();
00159   } else {
00160     while ( !_Force386_is_rx_ready() );
00161     return _Force386_read_data();
00162   }
00163 }