Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-1997.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #include <termios.h>
0030 
0031 #include <rtems/console.h>
0032 #include <rtems/libio.h>
0033 #include <bsp.h>
0034 #include "sci.h"
0035 
0036 /*
0037  *  console_open
0038  *
0039  *  open a port as a termios console.
0040  */
0041 rtems_device_driver console_open(
0042   rtems_device_major_number major,
0043   rtems_device_minor_number minor,
0044   void                    * arg
0045 )
0046 {
0047     rtems_status_code status;
0048 
0049     /* the console is opened three times at startup */
0050     /* for standard input, output, and error */
0051 
0052     /* Get correct callback structure for the device */
0053 
0054     /* argument of FALSE gives us interrupt driven serial io */
0055     /* argument of TRUE  gives us polling   based  serial io */
0056 
0057     /* SCI internal uart */
0058 
0059     status = rtems_termios_open( major, minor, arg, SciGetTermiosHandlers( FALSE ) );
0060 
0061     return status;
0062 }
0063 
0064 /*
0065  *  console_close
0066  *
0067  *  This routine closes a port that has been opened as console.
0068  */
0069 rtems_device_driver console_close(
0070   rtems_device_major_number major,
0071   rtems_device_minor_number minor,
0072   void                    * arg
0073 )
0074 {
0075   return rtems_termios_close (arg);
0076 }
0077 
0078 /*
0079  *  console_read
0080  *
0081  *  This routine uses the termios driver to read a character.
0082  */
0083 rtems_device_driver console_read(
0084   rtems_device_major_number major,
0085   rtems_device_minor_number minor,
0086   void                    * arg
0087 )
0088 {
0089   return rtems_termios_read (arg);
0090 }
0091 
0092 /*
0093  *  console_write
0094  *
0095  *  this routine uses the termios driver to write a character.
0096  */
0097 rtems_device_driver console_write(
0098   rtems_device_major_number major,
0099   rtems_device_minor_number minor,
0100   void                    * arg
0101 )
0102 {
0103   return rtems_termios_write (arg);
0104 }
0105 
0106 /*
0107  *  console_control
0108  *
0109  *  this routine uses the termios driver to process io
0110  */
0111 
0112 rtems_device_driver console_control(
0113   rtems_device_major_number major,
0114   rtems_device_minor_number minor,
0115   void                    * arg
0116 )
0117 {
0118   return rtems_termios_ioctl (arg);
0119 }
0120 
0121 /*
0122  *  console_initialize
0123  *
0124  *  Routine called to initialize the console device driver.
0125  */
0126 rtems_device_driver console_initialize(
0127   rtems_device_major_number  major,
0128   rtems_device_minor_number  minor_arg,
0129   void                      *arg
0130 )
0131 {
0132   rtems_status_code          status;
0133 
0134   /*
0135    * initialize the termio interface.
0136    */
0137   rtems_termios_initialize();
0138 
0139   /*
0140    * register the SCI device name for termios
0141    * do this over in the sci driver init routine?
0142    */
0143 
0144   status = rtems_io_register_name( "/dev/sci", major, 0 );
0145 
0146   if (status != RTEMS_SUCCESSFUL)
0147   {
0148     rtems_fatal_error_occurred(status);
0149   }
0150 
0151   /*
0152    * Link the uart device to the console device
0153    */
0154 
0155 #if 1
0156   status = rtems_io_register_name( "/dev/console", major, 0 );
0157 
0158   if (status != RTEMS_SUCCESSFUL)
0159   {
0160     rtems_fatal_error_occurred(status);
0161   }
0162 #else
0163   if ( link( "/dev/sci", "/dev/console") < 0 )
0164   {
0165     rtems_fatal_error_occurred( RTEMS_IO_ERROR );
0166   }
0167 #endif
0168 
0169   /*
0170    * Console Initialize Succesful
0171    */
0172 
0173   return RTEMS_SUCCESSFUL;
0174 }