Back to home page

LXR

 
 

    


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

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