[16a384cf] | 1 | /*-------------------------------------------------------------------------+ |
---|
| 2 | | console.c v1.1 - i386ex BSP - 1997/08/07 |
---|
| 3 | +--------------------------------------------------------------------------+ |
---|
[6128a4a] | 4 | | This file contains the i386ex console I/O package. It is just a termios |
---|
[16a384cf] | 5 | | wrapper. |
---|
| 6 | +--------------------------------------------------------------------------+ |
---|
| 7 | | (C) Copyright 1997 - |
---|
| 8 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
| 9 | | |
---|
| 10 | | http://pandora.ist.utl.pt |
---|
| 11 | | |
---|
| 12 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
| 13 | +--------------------------------------------------------------------------+ |
---|
| 14 | | Disclaimer: |
---|
| 15 | | |
---|
| 16 | | This file is provided "AS IS" without warranty of any kind, either |
---|
| 17 | | expressed or implied. |
---|
| 18 | +--------------------------------------------------------------------------+ |
---|
| 19 | | This code is based on: |
---|
| 20 | | console.c,v 1.4 1995/12/19 20:07:23 joel Exp - go32 BSP |
---|
| 21 | | console.c,v 1.15 pc386 BSP |
---|
| 22 | | With the following copyright notice: |
---|
| 23 | | ************************************************************************** |
---|
[08311cc3] | 24 | | * COPYRIGHT (c) 1989-1999. |
---|
[16a384cf] | 25 | | * On-Line Applications Research Corporation (OAR). |
---|
| 26 | | * |
---|
| 27 | | * The license and distribution terms for this file may be |
---|
[3e8cdf8] | 28 | | * found in the file LICENSE in this distribution or at |
---|
[e61df10] | 29 | | * http://www.rtems.com/license/LICENSE. |
---|
[16a384cf] | 30 | | ************************************************************************** |
---|
| 31 | | |
---|
| 32 | | $Id$ |
---|
| 33 | +--------------------------------------------------------------------------*/ |
---|
| 34 | |
---|
| 35 | #include <stdio.h> |
---|
| 36 | #include <stdlib.h> |
---|
| 37 | #include <assert.h> |
---|
[202ed85] | 38 | #include <rtems/error.h> |
---|
[16a384cf] | 39 | |
---|
| 40 | #include <bsp.h> |
---|
[48ad38db] | 41 | #include <bsp/irq.h> |
---|
[16a384cf] | 42 | #include <rtems/libio.h> |
---|
| 43 | #include <termios.h> |
---|
| 44 | #include <uart.h> |
---|
| 45 | #include <libcpu/cpuModel.h> |
---|
[8ca0b68] | 46 | #include <rtems/termiostypes.h> |
---|
[16a384cf] | 47 | |
---|
| 48 | /* |
---|
| 49 | * Possible value for console input/output : |
---|
| 50 | * BSP_UART_COM1 |
---|
| 51 | * BSP_UART_COM2 |
---|
[6128a4a] | 52 | * BSP_CONSOLE_PORT_CONSOLE is not valid in this BSP. |
---|
[16a384cf] | 53 | * All references to either keyboard or video handling have been removed. |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | int BSPConsolePort = BSP_UART_COM2; |
---|
| 57 | int BSPBaseBaud = 115200; |
---|
| 58 | int BSP_poll_read(int); |
---|
| 59 | |
---|
| 60 | extern BSP_polling_getchar_function_type BSP_poll_char; |
---|
| 61 | |
---|
| 62 | static int conSetAttr(int minor, const struct termios *); |
---|
| 63 | static void isr_on(const rtems_irq_connect_data *); |
---|
| 64 | static void isr_off(const rtems_irq_connect_data *); |
---|
| 65 | static int isr_is_on(const rtems_irq_connect_data *); |
---|
| 66 | |
---|
| 67 | /* |
---|
| 68 | * Change references to com2 if required. |
---|
| 69 | */ |
---|
| 70 | |
---|
[6128a4a] | 71 | static rtems_irq_connect_data console_isr_data = |
---|
[16a384cf] | 72 | { BSP_UART_COM2_IRQ, |
---|
| 73 | BSP_uart_termios_isr_com2, |
---|
[109cec1] | 74 | 0, |
---|
[16a384cf] | 75 | isr_on, |
---|
| 76 | isr_off, |
---|
| 77 | isr_is_on}; |
---|
| 78 | |
---|
| 79 | static void |
---|
| 80 | isr_on(const rtems_irq_connect_data *unused) |
---|
| 81 | { |
---|
| 82 | return; |
---|
| 83 | } |
---|
[6128a4a] | 84 | |
---|
[16a384cf] | 85 | static void |
---|
| 86 | isr_off(const rtems_irq_connect_data *unused) |
---|
| 87 | { |
---|
| 88 | return; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | static int |
---|
| 92 | isr_is_on(const rtems_irq_connect_data *irq) |
---|
| 93 | { |
---|
| 94 | return BSP_irq_enabled_at_i8259s(irq->name); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /*-------------------------------------------------------------------------+ |
---|
| 98 | | Console device driver INITIALIZE entry point. |
---|
| 99 | +--------------------------------------------------------------------------+ |
---|
| 100 | | Initilizes the I/O console (keyboard + VGA display) driver. |
---|
| 101 | +--------------------------------------------------------------------------*/ |
---|
| 102 | rtems_device_driver |
---|
| 103 | console_initialize(rtems_device_major_number major, |
---|
| 104 | rtems_device_minor_number minor, |
---|
| 105 | void *arg) |
---|
| 106 | { |
---|
| 107 | rtems_status_code status; |
---|
| 108 | |
---|
| 109 | /* |
---|
| 110 | * Set up TERMIOS |
---|
| 111 | */ |
---|
| 112 | rtems_termios_initialize (); |
---|
[6128a4a] | 113 | |
---|
[16a384cf] | 114 | /* |
---|
| 115 | * Do device-specific initialization |
---|
| 116 | */ |
---|
[6128a4a] | 117 | |
---|
[16a384cf] | 118 | /* 115200-8-N-1, without hardware flow control */ |
---|
[c4be3475] | 119 | BSP_uart_init(BSPConsolePort, 115200, CHR_8_BITS, 0, 0, 0); |
---|
[6128a4a] | 120 | |
---|
[16a384cf] | 121 | /* Set interrupt handler */ |
---|
| 122 | if(BSPConsolePort == BSP_UART_COM1) |
---|
| 123 | { |
---|
| 124 | console_isr_data.name = BSP_UART_COM1_IRQ; |
---|
| 125 | console_isr_data.hdl = BSP_uart_termios_isr_com1; |
---|
[6128a4a] | 126 | |
---|
[16a384cf] | 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | assert(BSPConsolePort == BSP_UART_COM2); |
---|
| 131 | console_isr_data.name = BSP_UART_COM2_IRQ; |
---|
| 132 | console_isr_data.hdl = BSP_uart_termios_isr_com2; |
---|
| 133 | } |
---|
[6128a4a] | 134 | |
---|
[16a384cf] | 135 | status = BSP_install_rtems_irq_handler(&console_isr_data); |
---|
[6128a4a] | 136 | |
---|
[16a384cf] | 137 | if (!status){ |
---|
| 138 | printk("Error installing serial console interrupt handler!\n"); |
---|
| 139 | rtems_fatal_error_occurred(status); |
---|
| 140 | } |
---|
| 141 | /* |
---|
| 142 | * Register the device |
---|
| 143 | */ |
---|
| 144 | status = rtems_io_register_name ("/dev/console", major, 0); |
---|
| 145 | if (status != RTEMS_SUCCESSFUL) |
---|
| 146 | { |
---|
| 147 | printk("Error registering console device!\n"); |
---|
| 148 | rtems_fatal_error_occurred (status); |
---|
| 149 | } |
---|
[6128a4a] | 150 | |
---|
[16a384cf] | 151 | if(BSPConsolePort == BSP_UART_COM1) |
---|
| 152 | { |
---|
| 153 | printk("Initialized console on port COM1 115200-8-N-1\n\n"); |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | printk("Initialized console on port COM2 115200-8-N-1\n\n"); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | return RTEMS_SUCCESSFUL; |
---|
| 161 | } /* console_initialize */ |
---|
| 162 | |
---|
| 163 | static int console_last_close(int major, int minor, void *arg) |
---|
| 164 | { |
---|
| 165 | BSP_remove_rtems_irq_handler (&console_isr_data); |
---|
| 166 | |
---|
| 167 | return 0; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | /*-------------------------------------------------------------------------+ |
---|
| 171 | | Console device driver OPEN entry point |
---|
| 172 | +--------------------------------------------------------------------------*/ |
---|
| 173 | rtems_device_driver |
---|
| 174 | console_open(rtems_device_major_number major, |
---|
| 175 | rtems_device_minor_number minor, |
---|
| 176 | void *arg) |
---|
| 177 | { |
---|
| 178 | rtems_status_code status; |
---|
[6128a4a] | 179 | static rtems_termios_callbacks cb = |
---|
[16a384cf] | 180 | { |
---|
| 181 | NULL, /* firstOpen */ |
---|
| 182 | console_last_close, /* lastClose */ |
---|
| 183 | NULL, /* poll read */ |
---|
[1d4048b2] | 184 | BSP_uart_termios_write_com1, /* write */ |
---|
[16a384cf] | 185 | conSetAttr, /* setAttributes */ |
---|
| 186 | NULL, /* stopRemoteTx */ |
---|
| 187 | NULL, /* startRemoteTx */ |
---|
| 188 | 1 /* outputUsesInterrupts */ |
---|
| 189 | }; |
---|
| 190 | |
---|
| 191 | if(BSPConsolePort == BSP_UART_COM2) |
---|
| 192 | { |
---|
| 193 | cb.write = BSP_uart_termios_write_com2; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | status = rtems_termios_open (major, minor, arg, &cb); |
---|
| 197 | |
---|
| 198 | if(status != RTEMS_SUCCESSFUL) |
---|
| 199 | { |
---|
| 200 | printk("Error openning console device\n"); |
---|
| 201 | return status; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | /* |
---|
| 205 | * Pass data area info down to driver |
---|
| 206 | */ |
---|
[6128a4a] | 207 | BSP_uart_termios_set(BSPConsolePort, |
---|
[16a384cf] | 208 | ((rtems_libio_open_close_args_t *)arg)->iop->data1); |
---|
[6128a4a] | 209 | |
---|
[16a384cf] | 210 | /* Enable interrupts on channel */ |
---|
| 211 | BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS); |
---|
| 212 | |
---|
| 213 | return RTEMS_SUCCESSFUL; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | /*-------------------------------------------------------------------------+ |
---|
| 217 | | Console device driver CLOSE entry point |
---|
| 218 | +--------------------------------------------------------------------------*/ |
---|
| 219 | rtems_device_driver |
---|
| 220 | console_close(rtems_device_major_number major, |
---|
| 221 | rtems_device_minor_number minor, |
---|
| 222 | void *arg) |
---|
| 223 | { |
---|
| 224 | |
---|
| 225 | return (rtems_termios_close (arg)); |
---|
[6128a4a] | 226 | |
---|
[16a384cf] | 227 | } /* console_close */ |
---|
| 228 | |
---|
| 229 | /*-------------------------------------------------------------------------+ |
---|
| 230 | | Console device driver READ entry point. |
---|
| 231 | +--------------------------------------------------------------------------+ |
---|
| 232 | | Read characters from the I/O console. We only have stdin. |
---|
| 233 | +--------------------------------------------------------------------------*/ |
---|
| 234 | rtems_device_driver |
---|
| 235 | console_read(rtems_device_major_number major, |
---|
| 236 | rtems_device_minor_number minor, |
---|
| 237 | void *arg) |
---|
| 238 | { |
---|
| 239 | rtems_status_code sc; |
---|
| 240 | |
---|
| 241 | sc = rtems_termios_read (arg); |
---|
| 242 | |
---|
| 243 | if ( sc != RTEMS_SUCCESSFUL ) |
---|
| 244 | printk("console_read: fails %s\n",rtems_status_text(sc)); |
---|
| 245 | |
---|
| 246 | return sc; |
---|
| 247 | |
---|
| 248 | } /* console_read */ |
---|
[6128a4a] | 249 | |
---|
[16a384cf] | 250 | /*-------------------------------------------------------------------------+ |
---|
| 251 | | Console device driver WRITE entry point. |
---|
| 252 | +--------------------------------------------------------------------------+ |
---|
| 253 | | Write characters to the I/O console. Stderr and stdout are the same. |
---|
| 254 | +--------------------------------------------------------------------------*/ |
---|
| 255 | rtems_device_driver |
---|
| 256 | console_write(rtems_device_major_number major, |
---|
| 257 | rtems_device_minor_number minor, |
---|
| 258 | void * arg) |
---|
| 259 | { |
---|
| 260 | return rtems_termios_write (arg); |
---|
[6128a4a] | 261 | |
---|
[16a384cf] | 262 | } /* console_write */ |
---|
| 263 | |
---|
| 264 | /* |
---|
| 265 | * Handle ioctl request. |
---|
| 266 | */ |
---|
[6128a4a] | 267 | rtems_device_driver |
---|
[16a384cf] | 268 | console_control(rtems_device_major_number major, |
---|
| 269 | rtems_device_minor_number minor, |
---|
| 270 | void * arg |
---|
| 271 | ) |
---|
[6128a4a] | 272 | { |
---|
[16a384cf] | 273 | return rtems_termios_ioctl (arg); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | static int |
---|
| 277 | conSetAttr(int minor, const struct termios *t) |
---|
| 278 | { |
---|
[8ca0b68] | 279 | rtems_termios_baud_t baud; |
---|
[16a384cf] | 280 | |
---|
[8ca0b68] | 281 | baud = rtems_termios_baud_to_number(t->c_cflag & CBAUD); |
---|
[6825d06] | 282 | if ( baud > 115200 ) |
---|
| 283 | rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR); |
---|
[16a384cf] | 284 | |
---|
| 285 | BSP_uart_set_baud(BSPConsolePort, baud); |
---|
| 286 | |
---|
| 287 | return 0; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | /* |
---|
| 291 | * BSP initialization |
---|
| 292 | */ |
---|
| 293 | |
---|
[6128a4a] | 294 | BSP_output_char_function_type BSP_output_char = |
---|
[16a384cf] | 295 | (BSP_output_char_function_type) BSP_output_char_via_serial; |
---|
| 296 | |
---|
[6128a4a] | 297 | BSP_polling_getchar_function_type BSP_poll_char = |
---|
[16a384cf] | 298 | (BSP_polling_getchar_function_type) BSP_poll_char_via_serial; |
---|
| 299 | |
---|
| 300 | int BSP_poll_read(int ttyMinor){ |
---|
[6128a4a] | 301 | |
---|
[16a384cf] | 302 | return BSP_poll_char_via_serial(); |
---|
| 303 | } |
---|