[61ba9763] | 1 | /* |
---|
| 2 | * This file contains the hardware specific portions of the TTY driver |
---|
| 3 | * for the serial ports on the erc32. |
---|
| 4 | * |
---|
| 5 | * COPYRIGHT (c) 1989-1997. |
---|
| 6 | * On-Line Applications Research Corporation (OAR). |
---|
| 7 | * |
---|
| 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
| 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include <bsp.h> |
---|
| 16 | #include <rtems/libio.h> |
---|
| 17 | #include <stdlib.h> |
---|
| 18 | #include <assert.h> |
---|
| 19 | |
---|
| 20 | #include <simio.h> |
---|
| 21 | |
---|
| 22 | /* |
---|
| 23 | * console_outbyte_polled |
---|
| 24 | * |
---|
| 25 | * This routine transmits a character using polling. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | void console_outbyte_polled( |
---|
| 29 | int port, |
---|
| 30 | char ch |
---|
| 31 | ); |
---|
| 32 | |
---|
| 33 | /* |
---|
| 34 | * console_inbyte_nonblocking |
---|
| 35 | * |
---|
| 36 | * This routine polls for a character. |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | int console_inbyte_nonblocking( |
---|
| 40 | int port |
---|
| 41 | ); |
---|
| 42 | |
---|
| 43 | /* |
---|
| 44 | * Console Termios Support Entry Points |
---|
| 45 | * |
---|
| 46 | */ |
---|
| 47 | |
---|
| 48 | int console_write_support ( |
---|
| 49 | int minor, |
---|
| 50 | const char *bufarg, |
---|
| 51 | int len |
---|
| 52 | ) |
---|
| 53 | { |
---|
| 54 | int nwrite = 0; |
---|
| 55 | const char *buf = bufarg; |
---|
| 56 | |
---|
| 57 | while (nwrite < len) { |
---|
| 58 | if ( *buf ) |
---|
| 59 | console_outbyte_polled( minor, *buf & 0x7f ); |
---|
| 60 | buf++; |
---|
| 61 | nwrite++; |
---|
| 62 | } |
---|
| 63 | return nwrite; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /* |
---|
| 67 | * Console Device Driver Entry Points |
---|
| 68 | * |
---|
| 69 | */ |
---|
| 70 | |
---|
| 71 | rtems_device_driver console_initialize( |
---|
| 72 | rtems_device_major_number major, |
---|
| 73 | rtems_device_minor_number minor, |
---|
| 74 | void *arg |
---|
| 75 | ) |
---|
| 76 | { |
---|
| 77 | rtems_status_code status; |
---|
| 78 | |
---|
| 79 | rtems_termios_initialize(); |
---|
| 80 | |
---|
| 81 | /* |
---|
| 82 | * Register Device Names |
---|
| 83 | */ |
---|
| 84 | |
---|
| 85 | status = rtems_io_register_name( "/dev/console", major, 0 ); |
---|
| 86 | if (status != RTEMS_SUCCESSFUL) |
---|
| 87 | rtems_fatal_error_occurred(status); |
---|
| 88 | |
---|
| 89 | return RTEMS_SUCCESSFUL; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | rtems_device_driver console_open( |
---|
| 93 | rtems_device_major_number major, |
---|
| 94 | rtems_device_minor_number minor, |
---|
| 95 | void * arg |
---|
| 96 | ) |
---|
| 97 | { |
---|
| 98 | rtems_status_code sc; |
---|
| 99 | static const rtems_termios_callbacks pollCallbacks = { |
---|
| 100 | NULL, /* firstOpen */ |
---|
| 101 | NULL, /* lastClose */ |
---|
| 102 | console_inbyte_nonblocking, /* pollRead */ |
---|
| 103 | console_write_support, /* write */ |
---|
| 104 | NULL, /* setAttributes */ |
---|
| 105 | NULL, /* stopRemoteTx */ |
---|
| 106 | NULL, /* startRemoteTx */ |
---|
| 107 | 0 /* outputUsesInterrupts */ |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | assert( minor <= 1 ); |
---|
| 112 | if ( minor > 2 ) |
---|
| 113 | return RTEMS_INVALID_NUMBER; |
---|
| 114 | |
---|
| 115 | sc = rtems_termios_open (major, minor, arg, &pollCallbacks ); |
---|
| 116 | |
---|
| 117 | return RTEMS_SUCCESSFUL; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | rtems_device_driver console_close( |
---|
| 121 | rtems_device_major_number major, |
---|
| 122 | rtems_device_minor_number minor, |
---|
| 123 | void * arg |
---|
| 124 | ) |
---|
| 125 | { |
---|
| 126 | return rtems_termios_close (arg); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | rtems_device_driver console_read( |
---|
| 130 | rtems_device_major_number major, |
---|
| 131 | rtems_device_minor_number minor, |
---|
| 132 | void * arg |
---|
| 133 | ) |
---|
| 134 | { |
---|
| 135 | return rtems_termios_read (arg); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | rtems_device_driver console_write( |
---|
| 139 | rtems_device_major_number major, |
---|
| 140 | rtems_device_minor_number minor, |
---|
| 141 | void * arg |
---|
| 142 | ) |
---|
| 143 | { |
---|
| 144 | return rtems_termios_write (arg); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | rtems_device_driver console_control( |
---|
| 148 | rtems_device_major_number major, |
---|
| 149 | rtems_device_minor_number minor, |
---|
| 150 | void * arg |
---|
| 151 | ) |
---|
| 152 | { |
---|
| 153 | return rtems_termios_ioctl (arg); |
---|
| 154 | } |
---|