Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:05

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  This file contains the hardware independent portion of a polled
0005  *  console device driver.  If a BSP chooses to use this, then it
0006  *  only has to provide a few board dependent routines.
0007  */
0008 
0009 /*
0010  *  COPYRIGHT (c) 1989-1997.
0011  *  On-Line Applications Research Corporation (OAR).
0012  *
0013  * Redistribution and use in source and binary forms, with or without
0014  * modification, are permitted provided that the following conditions
0015  * are met:
0016  * 1. Redistributions of source code must retain the above copyright
0017  *    notice, this list of conditions and the following disclaimer.
0018  * 2. Redistributions in binary form must reproduce the above copyright
0019  *    notice, this list of conditions and the following disclaimer in the
0020  *    documentation and/or other materials provided with the distribution.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032  * POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #include <bsp.h>
0036 #include <rtems/libio.h>
0037 #include <stdlib.h>
0038 #include <assert.h>
0039 
0040 #include <bsp/console-polled.h>
0041 #include <bsp/fatal.h>
0042 #include <rtems/console.h>
0043 
0044 /*
0045  *  Prototypes
0046  */
0047 ssize_t console_write_support(int, const char *, size_t);
0048 
0049 /*
0050  *  Console Termios Support Entry Points
0051  *
0052  */
0053 ssize_t console_write_support (
0054   int         minor,
0055   const char *bufarg,
0056   size_t      len
0057 )
0058 {
0059   int nwrite = 0;
0060   const char *buf = bufarg;
0061 
0062   while (nwrite < len) {
0063     console_outbyte_polled( minor, *buf++ );
0064     nwrite++;
0065   }
0066   return nwrite;
0067 }
0068 
0069 /*
0070  *  Console Device Driver Entry Points
0071  *
0072  */
0073 
0074 rtems_device_driver console_initialize(
0075   rtems_device_major_number  major,
0076   rtems_device_minor_number  minor,
0077   void                      *arg
0078 )
0079 {
0080   rtems_status_code status;
0081 
0082   /*
0083    *  Ensure Termios is initialized
0084    */
0085   rtems_termios_initialize();
0086 
0087   /*
0088    *  Make sure the hardware is initialized.
0089    */
0090   console_initialize_hardware();
0091 
0092   /*
0093    *  Register Device Names
0094    */
0095   status = rtems_io_register_name( "/dev/console", major, 0 );
0096   if (status != RTEMS_SUCCESSFUL)
0097     rtems_fatal_error_occurred(BSP_FATAL_CONSOLE_REGISTER_DEV_2);
0098 
0099   return RTEMS_SUCCESSFUL;
0100 }
0101 
0102 rtems_device_driver console_open(
0103   rtems_device_major_number major,
0104   rtems_device_minor_number minor,
0105   void                    * arg
0106 )
0107 {
0108   static const rtems_termios_callbacks pollCallbacks = {
0109     NULL,                        /* firstOpen */
0110     NULL,                        /* lastClose */
0111     console_inbyte_nonblocking,  /* pollRead */
0112     console_write_support,       /* write */
0113     NULL,                        /* setAttributes */
0114     NULL,                        /* stopRemoteTx */
0115     NULL,                        /* startRemoteTx */
0116     TERMIOS_POLLED               /* outputUsesInterrupts */
0117   };
0118 
0119   assert( minor == 0 );
0120   if ( minor != 0 )
0121     return RTEMS_INVALID_NUMBER;
0122 
0123   rtems_termios_open( major, minor, arg, &pollCallbacks );
0124 
0125   return RTEMS_SUCCESSFUL;
0126 }
0127 
0128 rtems_device_driver console_close(
0129   rtems_device_major_number major,
0130   rtems_device_minor_number minor,
0131   void                    * arg
0132 )
0133 {
0134   return rtems_termios_close( arg );
0135 }
0136 
0137 rtems_device_driver console_read(
0138   rtems_device_major_number major,
0139   rtems_device_minor_number minor,
0140   void                    * arg
0141 )
0142 {
0143   return rtems_termios_read( arg );
0144 }
0145 
0146 rtems_device_driver console_write(
0147   rtems_device_major_number major,
0148   rtems_device_minor_number minor,
0149   void                    * arg
0150 )
0151 {
0152   return rtems_termios_write( arg );
0153 }
0154 
0155 rtems_device_driver console_control(
0156   rtems_device_major_number major,
0157   rtems_device_minor_number minor,
0158   void                    * arg
0159 )
0160 {
0161   return rtems_termios_ioctl( arg );
0162 }