Back to home page

LXR

 
 

    


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

0001 /*
0002  *  This file contains the IDT 4650 console IO package.
0003  */
0004 
0005 /*
0006  *  Author:     Craig Lebakken <craigl@transition.com>
0007  *
0008  *  COPYRIGHT (c) 1996 by Transition Networks Inc.
0009  *
0010  *  To anyone who acknowledges that this file is provided "AS IS"
0011  *  without any express or implied warranty:
0012  *      permission to use, copy, modify, and distribute this file
0013  *      for any purpose is hereby granted without fee, provided that
0014  *      the above copyright notice and this notice appears in all
0015  *      copies, and that the name of Transition Networks not be used in
0016  *      advertising or publicity pertaining to distribution of the
0017  *      software without specific, written prior permission.
0018  *      Transition Networks makes no representations about the suitability
0019  *      of this software for any purpose.
0020  *
0021  *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/console/console.c:
0022  *
0023  *  COPYRIGHT (c) 1989-1999.
0024  *  On-Line Applications Research Corporation (OAR).
0025  *
0026  *  The license and distribution terms for this file may be
0027  *  found in the file LICENSE in this distribution or at
0028  *  http://www.rtems.org/license/LICENSE.
0029  */
0030 
0031 #include <ctype.h>
0032 
0033 #include <rtems/console.h>
0034 #include <rtems/libio.h>
0035 #include <bsp.h>
0036 
0037 /* PMON entry points */
0038 int mon_read(int fd, char *buf, int cnt);    /* stdin is fd=0 */
0039 int mon_write(int fd, char *buf, int cnt);    /* stdout is fd=1 */
0040 
0041 /*  console_initialize
0042  *
0043  *  This routine initializes the console IO driver.
0044  *
0045  *  Input parameters: NONE
0046  *
0047  *  Output parameters:  NONE
0048  *
0049  *  Return values:
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 SOURCE.
0074  */
0075 static char inbyte( void )
0076 {
0077   char buf[10];
0078 
0079   /*
0080    *  If polling, wait until a character is available.
0081    */
0082   mon_read(0, buf, 1);    /* stdin is fd=0, read 1 byte */
0083 
0084   return (buf[0]);
0085 }
0086 
0087 /*  outbyte
0088  *
0089  *  This routine transmits a character out the SOURCE.  It may support
0090  *  XON/XOFF flow control.
0091  */
0092 static void outbyte(
0093   char ch
0094 )
0095 {
0096   char buf[10];
0097   /*
0098    *  If polling, wait for the transmitter to be ready.
0099    *  Check for flow control requests and process.
0100    *  Then output the character.
0101    */
0102   buf[0] = ch;
0103 
0104   mon_write( 1, buf, 1 );    /* stdout is fd=1, write 1 byte */
0105 }
0106 
0107 /*
0108  *  Open entry point
0109  */
0110 
0111 rtems_device_driver console_open(
0112   rtems_device_major_number major,
0113   rtems_device_minor_number minor,
0114   void                    * arg
0115 )
0116 {
0117   return RTEMS_SUCCESSFUL;
0118 }
0119 
0120 /*
0121  *  Close entry point
0122  */
0123 
0124 rtems_device_driver console_close(
0125   rtems_device_major_number major,
0126   rtems_device_minor_number minor,
0127   void                    * arg
0128 )
0129 {
0130   return RTEMS_SUCCESSFUL;
0131 }
0132 
0133 /*
0134  * read bytes from the serial port. We only have stdin.
0135  */
0136 rtems_device_driver console_read(
0137   rtems_device_major_number major,
0138   rtems_device_minor_number minor,
0139   void                    * arg
0140 )
0141 {
0142   rtems_libio_rw_args_t *rw_args;
0143   char *buffer;
0144   int maximum;
0145   int count = 0;
0146 
0147   rw_args = (rtems_libio_rw_args_t *) arg;
0148 
0149   buffer = rw_args->buffer;
0150   maximum = rw_args->count;
0151 
0152   for (count = 0; count < maximum; count++) {
0153     buffer[ count ] = inbyte();
0154     if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
0155       buffer[ count++ ]  = '\n';
0156       break;
0157     }
0158   }
0159 
0160   rw_args->bytes_moved = count;
0161   return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
0162 }
0163 
0164 /*
0165  * write bytes to the serial port. Stdout and stderr are the same.
0166  */
0167 rtems_device_driver console_write(
0168   rtems_device_major_number major,
0169   rtems_device_minor_number minor,
0170   void                    * arg
0171 )
0172 {
0173   int count;
0174   int maximum;
0175   rtems_libio_rw_args_t *rw_args;
0176   char *buffer;
0177 
0178   rw_args = (rtems_libio_rw_args_t *) arg;
0179 
0180   buffer = rw_args->buffer;
0181   maximum = rw_args->count;
0182 
0183   for (count = 0; count < maximum; count++) {
0184     if ( buffer[ count ] == '\n') {
0185       outbyte('\r');
0186     }
0187     outbyte( buffer[ count ] );
0188   }
0189 
0190   rw_args->bytes_moved = maximum;
0191   return 0;
0192 }
0193 
0194 /*
0195  *  IO Control entry point
0196  */
0197 rtems_device_driver console_control(
0198   rtems_device_major_number major,
0199   rtems_device_minor_number minor,
0200   void                    * arg
0201 )
0202 {
0203   return RTEMS_SUCCESSFUL;
0204 }
0205 
0206 #include <rtems/bspIo.h>
0207 
0208 static void hurricane_output_char(char c) { outbyte( c ); }
0209 
0210 BSP_output_char_function_type           BSP_output_char = hurricane_output_char;
0211 BSP_polling_getchar_function_type       BSP_poll_char = NULL;
0212