Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:48

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  This file contains the MVME147 console IO package.
0005  */
0006 
0007 /*
0008  *  COPYRIGHT (c) 1989-1999.
0009  *  On-Line Applications Research Corporation (OAR).
0010  *
0011  * Redistribution and use in source and binary forms, with or without
0012  * modification, are permitted provided that the following conditions
0013  * are met:
0014  * 1. Redistributions of source code must retain the above copyright
0015  *    notice, this list of conditions and the following disclaimer.
0016  * 2. Redistributions in binary form must reproduce the above copyright
0017  *    notice, this list of conditions and the following disclaimer in the
0018  *    documentation and/or other materials provided with the distribution.
0019  *
0020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0030  * POSSIBILITY OF SUCH DAMAGE.
0031  *
0032  *  MVME147 port for TNI - Telecom Bretagne
0033  *  by Dominique LE CAMPION (Dominique.LECAMPION@enst-bretagne.fr)
0034  *  May 1996
0035  *
0036  *  This file was taken from the DMV152 bsp
0037  */
0038 
0039 #define M147_INIT
0040 
0041 #include <rtems/console.h>
0042 #include <rtems/libio.h>
0043 #include <rtems/zilog/z8530.h>
0044 #include <rtems/iosupp.h>
0045 #include <bsp.h>
0046 
0047 /*  console_initialize
0048  *
0049  *  This routine initializes the console IO driver.
0050  */
0051 rtems_device_driver console_initialize(
0052   rtems_device_major_number  major,
0053   rtems_device_minor_number  minor,
0054   void                      *arg
0055 )
0056 {
0057   rtems_status_code status;
0058 
0059   status = rtems_io_register_name(
0060     "/dev/console",
0061     major,
0062     (rtems_device_minor_number) 0
0063   );
0064 
0065   if (status != RTEMS_SUCCESSFUL)
0066     rtems_fatal_error_occurred(status);
0067 
0068   return RTEMS_SUCCESSFUL;
0069 }
0070 
0071 /*  inbyte
0072  *
0073  *  This routine reads a character from the SCC.
0074  */
0075 static char inbyte( void )
0076 {
0077   uint8_t         rr_0;
0078   char ch;
0079 
0080   for ( ; ; ) {
0081     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
0082     if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 )
0083       break;
0084   }
0085 
0086   Z8x30_READ_DATA( CONSOLE_DATA, ch );
0087   return ( ch );
0088 }
0089 
0090 /*  outbyte
0091  *
0092  *  This routine transmits a character out the SCC.  It supports
0093  *  XON/XOFF flow control.
0094  */
0095 static void outbyte(
0096   char ch
0097 )
0098 {
0099   uint8_t         rr_0;
0100   char            flow_control;
0101 
0102   for ( ; ; ) {
0103     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
0104     if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
0105       break;
0106   }
0107 
0108   for ( ; ; ) {
0109     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
0110     if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 )
0111       break;
0112 
0113     Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
0114 
0115     if ( flow_control == XOFF )
0116       do {
0117         do {
0118           Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
0119         } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 );
0120         Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
0121       } while ( flow_control != XON );
0122   }
0123 
0124   Z8x30_WRITE_DATA( CONSOLE_DATA, ch );
0125 }
0126 
0127 /*
0128  *  Open entry point
0129  */
0130 rtems_device_driver console_open(
0131   rtems_device_major_number major,
0132   rtems_device_minor_number minor,
0133   void                    * arg
0134 )
0135 {
0136   return RTEMS_SUCCESSFUL;
0137 }
0138 
0139 /*
0140  *  Close entry point
0141  */
0142 rtems_device_driver console_close(
0143   rtems_device_major_number major,
0144   rtems_device_minor_number minor,
0145   void                    * arg
0146 )
0147 {
0148   return RTEMS_SUCCESSFUL;
0149 }
0150 
0151 /*
0152  * read bytes from the serial port. We only have stdin.
0153  */
0154 rtems_device_driver console_read(
0155   rtems_device_major_number major,
0156   rtems_device_minor_number minor,
0157   void                    * arg
0158 )
0159 {
0160   rtems_libio_rw_args_t *rw_args;
0161   char *buffer;
0162   int maximum;
0163   int count = 0;
0164 
0165   rw_args = (rtems_libio_rw_args_t *) arg;
0166 
0167   buffer = rw_args->buffer;
0168   maximum = rw_args->count;
0169 
0170   for (count = 0; count < maximum; count++) {
0171     buffer[ count ] = inbyte();
0172     if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
0173       buffer[ count++ ]  = '\n';
0174       break;
0175     }
0176   }
0177 
0178   rw_args->bytes_moved = count;
0179   return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
0180 }
0181 
0182 /*
0183  * write bytes to the serial port. Stdout and stderr are the same.
0184  */
0185 rtems_device_driver console_write(
0186   rtems_device_major_number major,
0187   rtems_device_minor_number minor,
0188   void                    * arg
0189 )
0190 {
0191   int count;
0192   int maximum;
0193   rtems_libio_rw_args_t *rw_args;
0194   char *buffer;
0195 
0196   rw_args = (rtems_libio_rw_args_t *) arg;
0197 
0198   buffer = rw_args->buffer;
0199   maximum = rw_args->count;
0200 
0201   for (count = 0; count < maximum; count++) {
0202     if ( buffer[ count ] == '\n') {
0203       outbyte('\r');
0204     }
0205     outbyte( buffer[ count ] );
0206   }
0207 
0208   rw_args->bytes_moved = maximum;
0209   return 0;
0210 }
0211 
0212 /*
0213  *  IO Control entry point
0214  */
0215 rtems_device_driver console_control(
0216   rtems_device_major_number major,
0217   rtems_device_minor_number minor,
0218   void                    * arg
0219 )
0220 {
0221   return RTEMS_SUCCESSFUL;
0222 }