[15ebdf1f] | 1 | /* |
---|
| 2 | * This file contains the RBTX4925 console IO package. |
---|
[2d9eceb] | 3 | */ |
---|
| 4 | |
---|
| 5 | /* |
---|
[15ebdf1f] | 6 | * Author: Craig Lebakken <craigl@transition.com> |
---|
| 7 | * |
---|
| 8 | * COPYRIGHT (c) 1996 by Transition Networks Inc. |
---|
| 9 | * |
---|
| 10 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 11 | * without any express or implied warranty: |
---|
| 12 | * permission to use, copy, modify, and distribute this file |
---|
| 13 | * for any purpose is hereby granted without fee, provided that |
---|
| 14 | * the above copyright notice and this notice appears in all |
---|
| 15 | * copies, and that the name of Transition Networks not be used in |
---|
| 16 | * advertising or publicity pertaining to distribution of the |
---|
| 17 | * software without specific, written prior permission. |
---|
| 18 | * Transition Networks makes no representations about the suitability |
---|
| 19 | * of this software for any purpose. |
---|
| 20 | * |
---|
| 21 | * Derived from c/src/lib/libbsp/no_cpu/no_bsp/console/console.c: |
---|
| 22 | * |
---|
| 23 | * COPYRIGHT (c) 1989-1999. |
---|
| 24 | * On-Line Applications Research Corporation (OAR). |
---|
| 25 | * |
---|
| 26 | * The license and distribution terms for this file may be |
---|
| 27 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 28 | * http://www.rtems.org/license/LICENSE. |
---|
[15ebdf1f] | 29 | */ |
---|
| 30 | |
---|
| 31 | #include <ctype.h> |
---|
| 32 | |
---|
[75cd8399] | 33 | #include <rtems/console.h> |
---|
| 34 | #include <rtems/libio.h> |
---|
| 35 | #include <bsp.h> |
---|
| 36 | |
---|
[15ebdf1f] | 37 | /* PMON entry points */ |
---|
[2d9eceb] | 38 | int mon_read(int fd, char *buf, int cnt); /* stdin is fd=0 */ |
---|
| 39 | int mon_write(int fd, char *buf, int cnt); /* stdout is fd=1 */ |
---|
[15ebdf1f] | 40 | |
---|
| 41 | /* console_initialize |
---|
| 42 | * |
---|
| 43 | * This routine initializes the console IO driver. |
---|
| 44 | */ |
---|
| 45 | rtems_device_driver console_initialize( |
---|
| 46 | rtems_device_major_number major, |
---|
| 47 | rtems_device_minor_number minor, |
---|
| 48 | void *arg |
---|
| 49 | ) |
---|
| 50 | { |
---|
| 51 | rtems_status_code status; |
---|
| 52 | |
---|
| 53 | status = rtems_io_register_name( |
---|
| 54 | "/dev/console", |
---|
| 55 | major, |
---|
| 56 | (rtems_device_minor_number) 0 |
---|
| 57 | ); |
---|
[efdfd48] | 58 | |
---|
[15ebdf1f] | 59 | if (status != RTEMS_SUCCESSFUL) |
---|
| 60 | rtems_fatal_error_occurred(status); |
---|
| 61 | |
---|
| 62 | return RTEMS_SUCCESSFUL; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /* inbyte |
---|
| 66 | * |
---|
| 67 | * This routine reads a character from the SOURCE. |
---|
| 68 | */ |
---|
[2d9eceb] | 69 | static char inbyte( void ) |
---|
[15ebdf1f] | 70 | { |
---|
[2d9eceb] | 71 | char buf[10]; |
---|
| 72 | |
---|
[15ebdf1f] | 73 | /* |
---|
| 74 | * If polling, wait until a character is available. |
---|
| 75 | */ |
---|
| 76 | |
---|
[2d9eceb] | 77 | mon_read(0, buf, 1); /* stdin is fd=0, read 1 byte */ |
---|
[15ebdf1f] | 78 | |
---|
[2d9eceb] | 79 | return (buf[0]); |
---|
[15ebdf1f] | 80 | } |
---|
| 81 | |
---|
| 82 | /* outbyte |
---|
| 83 | * |
---|
| 84 | * This routine transmits a character out the SOURCE. It may support |
---|
| 85 | * XON/XOFF flow control. |
---|
| 86 | */ |
---|
[2d9eceb] | 87 | static void outbyte( |
---|
[15ebdf1f] | 88 | char ch |
---|
| 89 | ) |
---|
| 90 | { |
---|
[2d9eceb] | 91 | char buf[10]; |
---|
| 92 | |
---|
[15ebdf1f] | 93 | /* |
---|
| 94 | * If polling, wait for the transmitter to be ready. |
---|
| 95 | * Check for flow control requests and process. |
---|
| 96 | * Then output the character. |
---|
| 97 | */ |
---|
[2d9eceb] | 98 | buf[0] = ch; |
---|
[15ebdf1f] | 99 | |
---|
[2d9eceb] | 100 | mon_write( 1, buf, 1 ); /* stdout is fd=1, write 1 byte */ |
---|
[15ebdf1f] | 101 | } |
---|
| 102 | |
---|
| 103 | /* |
---|
| 104 | * Open entry point |
---|
| 105 | */ |
---|
| 106 | rtems_device_driver console_open( |
---|
| 107 | rtems_device_major_number major, |
---|
| 108 | rtems_device_minor_number minor, |
---|
| 109 | void * arg |
---|
| 110 | ) |
---|
| 111 | { |
---|
| 112 | return RTEMS_SUCCESSFUL; |
---|
| 113 | } |
---|
[efdfd48] | 114 | |
---|
[15ebdf1f] | 115 | /* |
---|
| 116 | * Close entry point |
---|
| 117 | */ |
---|
| 118 | rtems_device_driver console_close( |
---|
| 119 | rtems_device_major_number major, |
---|
| 120 | rtems_device_minor_number minor, |
---|
| 121 | void * arg |
---|
| 122 | ) |
---|
| 123 | { |
---|
| 124 | return RTEMS_SUCCESSFUL; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /* |
---|
| 128 | * read bytes from the serial port. We only have stdin. |
---|
| 129 | */ |
---|
| 130 | rtems_device_driver console_read( |
---|
| 131 | rtems_device_major_number major, |
---|
| 132 | rtems_device_minor_number minor, |
---|
| 133 | void * arg |
---|
| 134 | ) |
---|
| 135 | { |
---|
| 136 | rtems_libio_rw_args_t *rw_args; |
---|
| 137 | char *buffer; |
---|
| 138 | int maximum; |
---|
| 139 | int count = 0; |
---|
[efdfd48] | 140 | |
---|
[15ebdf1f] | 141 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 142 | |
---|
| 143 | buffer = rw_args->buffer; |
---|
| 144 | maximum = rw_args->count; |
---|
| 145 | |
---|
| 146 | for (count = 0; count < maximum; count++) { |
---|
| 147 | buffer[ count ] = inbyte(); |
---|
| 148 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 149 | buffer[ count++ ] = '\n'; |
---|
| 150 | break; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | rw_args->bytes_moved = count; |
---|
| 155 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /* |
---|
[efdfd48] | 159 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
[15ebdf1f] | 160 | */ |
---|
| 161 | rtems_device_driver console_write( |
---|
| 162 | rtems_device_major_number major, |
---|
| 163 | rtems_device_minor_number minor, |
---|
| 164 | void * arg |
---|
| 165 | ) |
---|
| 166 | { |
---|
| 167 | int count; |
---|
| 168 | int maximum; |
---|
| 169 | rtems_libio_rw_args_t *rw_args; |
---|
| 170 | char *buffer; |
---|
| 171 | |
---|
| 172 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 173 | |
---|
| 174 | buffer = rw_args->buffer; |
---|
| 175 | maximum = rw_args->count; |
---|
| 176 | |
---|
| 177 | for (count = 0; count < maximum; count++) { |
---|
| 178 | if ( buffer[ count ] == '\n') { |
---|
| 179 | outbyte('\r'); |
---|
| 180 | } |
---|
| 181 | outbyte( buffer[ count ] ); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | rw_args->bytes_moved = maximum; |
---|
| 185 | return 0; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | /* |
---|
| 189 | * IO Control entry point |
---|
| 190 | */ |
---|
| 191 | rtems_device_driver console_control( |
---|
| 192 | rtems_device_major_number major, |
---|
| 193 | rtems_device_minor_number minor, |
---|
| 194 | void * arg |
---|
| 195 | ) |
---|
| 196 | { |
---|
| 197 | return RTEMS_SUCCESSFUL; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | #include <rtems/bspIo.h> |
---|
| 201 | |
---|
[2d9eceb] | 202 | static void RBTX4925_output_char(char c) { outbyte( c ); } |
---|
[15ebdf1f] | 203 | |
---|
| 204 | BSP_output_char_function_type BSP_output_char = RBTX4925_output_char; |
---|
| 205 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|
| 206 | |
---|