Back to home page

LXR

 
 

    


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

0001 /*
0002  *  This file contains the RBTX4925 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 rtems_device_driver console_initialize(
0046   rtems_device_major_number  major,
0047   rtems_device_minor_number  minor,
0048   void                      *arg
0049 )
0050 {
0051   rtems_status_code status;
0052 
0053   status = rtems_io_register_name(
0054     "/dev/console",
0055     major,
0056     (rtems_device_minor_number) 0
0057   );
0058 
0059   if (status != RTEMS_SUCCESSFUL)
0060     rtems_fatal_error_occurred(status);
0061 
0062   return RTEMS_SUCCESSFUL;
0063 }
0064 
0065 /*  inbyte
0066  *
0067  *  This routine reads a character from the SOURCE.
0068  */
0069 static char inbyte( void )
0070 {
0071   char buf[10];
0072 
0073   /*
0074    *  If polling, wait until a character is available.
0075    */
0076 
0077   mon_read(0, buf, 1);    /* stdin is fd=0, read 1 byte */
0078 
0079   return (buf[0]);
0080 }
0081 
0082 /*  outbyte
0083  *
0084  *  This routine transmits a character out the SOURCE.  It may support
0085  *  XON/XOFF flow control.
0086  */
0087 static void outbyte(
0088   char ch
0089 )
0090 {
0091   char buf[10];
0092 
0093   /*
0094    *  If polling, wait for the transmitter to be ready.
0095    *  Check for flow control requests and process.
0096    *  Then output the character.
0097    */
0098   buf[0] = ch;
0099 
0100   mon_write( 1, buf, 1 );    /* stdout is fd=1, write 1 byte */
0101 }
0102 
0103 /*
0104  *  Open entry point
0105  */
0106 rtems_device_driver console_open(
0107   rtems_device_major_number major,
0108   rtems_device_minor_number minor,
0109   void                    * arg
0110 )
0111 {
0112   return RTEMS_SUCCESSFUL;
0113 }
0114 
0115 /*
0116  *  Close entry point
0117  */
0118 rtems_device_driver console_close(
0119   rtems_device_major_number major,
0120   rtems_device_minor_number minor,
0121   void                    * arg
0122 )
0123 {
0124   return RTEMS_SUCCESSFUL;
0125 }
0126 
0127 /*
0128  * read bytes from the serial port. We only have stdin.
0129  */
0130 rtems_device_driver console_read(
0131   rtems_device_major_number major,
0132   rtems_device_minor_number minor,
0133   void                    * arg
0134 )
0135 {
0136   rtems_libio_rw_args_t *rw_args;
0137   char *buffer;
0138   int maximum;
0139   int count = 0;
0140 
0141   rw_args = (rtems_libio_rw_args_t *) arg;
0142 
0143   buffer = rw_args->buffer;
0144   maximum = rw_args->count;
0145 
0146   for (count = 0; count < maximum; count++) {
0147     buffer[ count ] = inbyte();
0148     if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
0149       buffer[ count++ ]  = '\n';
0150       break;
0151     }
0152   }
0153 
0154   rw_args->bytes_moved = count;
0155   return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
0156 }
0157 
0158 /*
0159  * write bytes to the serial port. Stdout and stderr are the same.
0160  */
0161 rtems_device_driver console_write(
0162   rtems_device_major_number major,
0163   rtems_device_minor_number minor,
0164   void                    * arg
0165 )
0166 {
0167   int count;
0168   int maximum;
0169   rtems_libio_rw_args_t *rw_args;
0170   char *buffer;
0171 
0172   rw_args = (rtems_libio_rw_args_t *) arg;
0173 
0174   buffer = rw_args->buffer;
0175   maximum = rw_args->count;
0176 
0177   for (count = 0; count < maximum; count++) {
0178     if ( buffer[ count ] == '\n') {
0179       outbyte('\r');
0180     }
0181     outbyte( buffer[ count ] );
0182   }
0183 
0184   rw_args->bytes_moved = maximum;
0185   return 0;
0186 }
0187 
0188 /*
0189  *  IO Control entry point
0190  */
0191 rtems_device_driver console_control(
0192   rtems_device_major_number major,
0193   rtems_device_minor_number minor,
0194   void                    * arg
0195 )
0196 {
0197   return RTEMS_SUCCESSFUL;
0198 }
0199 
0200 #include <rtems/bspIo.h>
0201 
0202 static void RBTX4925_output_char(char c) { outbyte( c ); }
0203 
0204 BSP_output_char_function_type           BSP_output_char = RBTX4925_output_char;
0205 BSP_polling_getchar_function_type       BSP_poll_char = NULL;
0206