Back to home page

LXR

 
 

    


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

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