source: rtems/c/src/lib/libbsp/i386/shared/comm/tty_drv.c @ b459526

4.104.114.84.95
Last change on this file since b459526 was b459526, checked in by Joel Sherrill <joel.sherrill@…>, on 08/30/00 at 08:18:56

2000-08-26 Rosimildo da Silva <rdasilva@…>

  • shared/comm: Added "/dev/ttyS1" & "/dev/ttyS2" support for the i386 BSPs.
  • shared/comm/gdb_glue.c: New file.
  • shared/comm/i386_io.c: New file.
  • shared/comm/tty_drv.c: New file.
  • shared/comm/tty_drv.h: New file.
  • shared/comm/Makefile.am: Account for new files.
  • shared/comm/uart.c: Adds support for sending characters to another "line discipline."
  • Property mode set to 100644
File size: 9.9 KB
Line 
1/***************************************************************************
2 *
3 * $Header$
4 *
5 * MODULE DESCRIPTION:
6 * This module implements the RTEMS drivers for the PC serial ports
7 * as /dev/ttyS1 for COM1 and /dev/ttyS2 as COM2. If one of the ports
8 * is used as the console, this driver would fail to initialize.
9 *
10 * This code was based on the console driver. It is based on the
11 * current termios framework. This is just a shell around the
12 * termios support.
13 *
14 * by: Rosimildo da Silva:
15 *     rdasilva@connecttel.com
16 *     http://www.connecttel.com
17 *
18 * MODIFICATION/HISTORY:
19 *
20 * $Log$
21 ****************************************************************************/
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <assert.h>
26
27#include <bsp.h>
28#include <irq.h>
29#include <rtems/libio.h>
30#include <termios.h>
31#include <uart.h>
32#include <libcpu/cpuModel.h>
33
34int BSP_poll_read(int);
35
36/* Internal routines */
37static int tty1_conSetAttr( int minor, const struct termios *t);
38static int tty2_conSetAttr( int minor, const struct termios *t);
39static void isr_on(const rtems_irq_connect_data *);
40static void isr_off(const rtems_irq_connect_data *);
41static int  isr_is_on(const rtems_irq_connect_data *);
42
43
44extern BSP_polling_getchar_function_type BSP_poll_char;
45extern int BSPConsolePort;
46extern void rtems_set_waiting_id_comx( int port,  rtems_id id, rtems_event_set event );
47
48
49/*
50 * Interrupt structure for tty1
51 */
52static rtems_irq_connect_data tty1_isr_data =
53{
54  BSP_UART_COM1_IRQ,
55  BSP_uart_termios_isr_com1,
56  isr_on,
57  isr_off,
58  isr_is_on};
59
60/*
61 * Interrupt structure for tty2
62 */
63static rtems_irq_connect_data tty2_isr_data =
64{
65  BSP_UART_COM2_IRQ,
66  BSP_uart_termios_isr_com2,
67  isr_on,
68  isr_off,
69  isr_is_on};
70
71static void
72isr_on(const rtems_irq_connect_data *unused)
73{
74  return;
75}
76                                                   
77static void
78isr_off(const rtems_irq_connect_data *unused)
79{
80  return;
81}
82
83static int
84isr_is_on(const rtems_irq_connect_data *irq)
85{
86  return BSP_irq_enabled_at_i8259s(irq->name);
87}
88
89void tty_reserve_resources(rtems_configuration_table *conf)
90{
91  rtems_termios_reserve_resources(conf, 1);
92  return;
93}
94
95/*
96 *  TTYS1 - device driver INITIALIZE entry point.
97 */
98rtems_device_driver
99tty1_initialize(rtems_device_major_number major,
100                   rtems_device_minor_number minor,
101                   void                      *arg)
102{
103  rtems_status_code status;
104
105  /* Check if this port is not been used as console */
106  if( BSPConsolePort == BSP_UART_COM1 )
107  {
108    status = -1;
109    printk("TTYS1: port selected as console.\n");
110    rtems_fatal_error_occurred( status );
111  }
112
113  /*
114   * Set up TERMIOS
115   */
116  rtems_termios_initialize();
117 
118  /*
119   * Do device-specific initialization
120   */
121  /* 9600-8-N-1, without hardware flow control */
122  BSP_uart_init( BSP_UART_COM1, 9600, 0 );
123  status = BSP_install_rtems_irq_handler( &tty1_isr_data );
124  if( !status )
125  {
126    printk("Error installing ttyS1 interrupt handler!\n");
127    rtems_fatal_error_occurred(status);
128  }
129  /*
130   * Register the device
131   */
132  status = rtems_io_register_name ("/dev/ttyS1", major, 0);
133  if (status != RTEMS_SUCCESSFUL)
134  {
135      printk("Error registering ttyS1 device!\n");
136      rtems_fatal_error_occurred (status);
137  }
138  printk("Device: /dev/ttyS1 initialized.\n");
139  return RTEMS_SUCCESSFUL;
140} /* tty_initialize */
141
142
143static int tty1_last_close(int major, int minor, void *arg)
144{
145  BSP_remove_rtems_irq_handler( &tty1_isr_data );
146  return 0;
147}
148
149/*
150 * TTY1 - device driver OPEN entry point
151 */
152rtems_device_driver
153tty1_open(rtems_device_major_number major,
154                rtems_device_minor_number minor,
155                void                      *arg)
156{
157  rtems_status_code  status;
158  static rtems_termios_callbacks cb =
159  {
160    NULL,                     /* firstOpen */
161    tty1_last_close,       /* lastClose */
162    NULL,                 /* poll read  */
163    BSP_uart_termios_write_com1, /* write */
164    tty1_conSetAttr,         /* setAttributes */
165    NULL,                     /* stopRemoteTx */
166    NULL,                     /* startRemoteTx */
167    1                         /* outputUsesInterrupts */
168  };
169
170  status = rtems_termios_open( major, minor, arg, &cb );
171  if(status != RTEMS_SUCCESSFUL)
172  {
173     printk("Error openning tty1 device\n");
174     return status;
175  }
176
177  /*
178   * Pass data area info down to driver
179   */
180  BSP_uart_termios_set( BSP_UART_COM1,
181                       ((rtems_libio_open_close_args_t *)arg)->iop->data1 );
182  /* Enable interrupts  on channel */
183  BSP_uart_intr_ctrl( BSP_UART_COM1, BSP_UART_INTR_CTRL_TERMIOS);
184  return RTEMS_SUCCESSFUL;
185}
186
187/*
188 * TTY - device driver CLOSE entry point
189 */
190rtems_device_driver
191tty_close(rtems_device_major_number major,
192              rtems_device_minor_number minor,
193              void                      *arg)
194{
195
196  return (rtems_termios_close (arg));
197 
198} /* tty_close */
199
200 
201/*
202 * TTY device driver READ entry point.
203 * Read characters from the tty device.
204 */
205rtems_device_driver
206tty_read(rtems_device_major_number major,
207             rtems_device_minor_number minor,
208             void                      *arg)
209{
210  return rtems_termios_read (arg);
211} /* tty_read */
212 
213
214/*
215 * TTY device driver WRITE entry point.
216 * Write characters to the tty device.
217 */
218rtems_device_driver
219tty_write(rtems_device_major_number major,
220              rtems_device_minor_number minor,
221              void                    * arg)
222{
223    return rtems_termios_write (arg);
224 
225} /* tty_write */
226
227/*
228 * Handle ioctl request. This is a generic internal
229 * routine to handle both devices.
230 */
231static rtems_device_driver tty_control( int port, void  *arg )
232{
233        rtems_libio_ioctl_args_t *args = arg;
234        switch( args->command )
235        {
236           default:
237      return rtems_termios_ioctl (arg);
238                break;
239   }
240        args->ioctl_return = 0;
241   return RTEMS_SUCCESSFUL;
242}
243
244
245
246/*
247 * Handle ioctl request for ttyS1.
248 */
249rtems_device_driver
250tty1_control(rtems_device_major_number major,
251                rtems_device_minor_number minor,
252                void                      * arg
253)
254{
255  return tty_control( BSP_UART_COM1, arg );
256}
257
258
259static int
260conSetAttr(int port, int minor, const struct termios *t)
261{
262  int baud;
263
264  switch (t->c_cflag & CBAUD)
265    {
266    case B50:   
267      baud = 50;
268      break;
269    case B75:   
270      baud = 75;       
271      break;
272    case B110: 
273      baud = 110;       
274      break;
275    case B134: 
276      baud = 134;       
277      break;
278    case B150: 
279      baud = 150;       
280      break;
281    case B200:
282      baud = 200;       
283      break;
284    case B300: 
285      baud = 300;
286      break;
287    case B600: 
288      baud = 600;       
289      break;
290    case B1200:
291      baud = 1200;
292      break;
293    case B1800:
294      baud = 1800;     
295      break;
296    case B2400:
297      baud = 2400;
298      break;
299    case B4800:
300      baud = 4800;
301      break;
302    case B9600:
303      baud = 9600;
304      break;
305    case B19200:
306      baud = 19200;
307      break;
308    case B38400:
309      baud = 38400;
310      break;
311    case B57600:       
312      baud = 57600;
313      break;
314    case B115200:
315      baud = 115200;
316      break;
317    default:
318      baud = 0;
319      rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR);
320      return 0;
321    }
322  printk("Setting baud, port=%X, baud=%d\n", port, baud );
323  BSP_uart_set_baud( port, baud );
324  return 0;
325}
326
327/*
328 * Handle ioctl request for ttyS2.
329 */
330static int
331tty1_conSetAttr( int minor, const struct termios *t)
332{
333  return conSetAttr( BSP_UART_COM1, minor, t );
334}
335
336
337
338/*
339 * TTY2 device driver INITIALIZE entry point.
340 */
341rtems_device_driver
342tty2_initialize(rtems_device_major_number major,
343                   rtems_device_minor_number minor,
344                   void                      *arg)
345{
346  rtems_status_code status;
347
348  /* Check if this port is not been used as console */
349  if( BSPConsolePort == BSP_UART_COM2 )
350  {
351    status = -1;
352    printk("TTY2: port selected as console.\n");
353    rtems_fatal_error_occurred( status );
354  }
355
356  /*
357   * Set up TERMIOS
358   */
359  rtems_termios_initialize();
360 
361  /*
362   * Do device-specific initialization
363   */
364  /* 9600-8-N-1, without hardware flow control */
365  BSP_uart_init( BSP_UART_COM2, 9600, 0);
366  status = BSP_install_rtems_irq_handler( &tty2_isr_data );
367  if( !status )
368  {
369    printk("Error installing serial console interrupt handler!\n");
370    rtems_fatal_error_occurred(status);
371  }
372  /*
373   * Register the device
374   */
375  status = rtems_io_register_name ("/dev/ttyS2", major, 0);
376  if (status != RTEMS_SUCCESSFUL)
377  {
378      printk("Error registering tty2 device!\n");
379      rtems_fatal_error_occurred (status);
380  }
381  printk("Device: /dev/ttyS2 initialized.\n");
382  return RTEMS_SUCCESSFUL;
383} /* tty_initialize */
384
385
386static int tty2_last_close(int major, int minor, void *arg)
387{
388  BSP_remove_rtems_irq_handler( &tty2_isr_data );
389  return 0;
390}
391
392/*
393 * TTY2 device driver OPEN entry point
394 */
395rtems_device_driver
396tty2_open(rtems_device_major_number major,
397                rtems_device_minor_number minor,
398                void                      *arg)
399{
400  rtems_status_code              status;
401  static rtems_termios_callbacks cb =
402  {
403    NULL,                     /* firstOpen */
404    tty2_last_close,       /* lastClose */
405    NULL,                 /* poll read  */
406    BSP_uart_termios_write_com2, /* write */
407    tty2_conSetAttr,                  /* setAttributes */
408    NULL,                     /* stopRemoteTx */
409    NULL,                     /* startRemoteTx */
410    1                         /* outputUsesInterrupts */
411  };
412
413  status = rtems_termios_open (major, minor, arg, &cb);
414  if(status != RTEMS_SUCCESSFUL)
415  {
416     printk("Error openning tty1 device\n");
417     return status;
418  }
419
420  /*
421   * Pass data area info down to driver
422   */
423  BSP_uart_termios_set( BSP_UART_COM2,
424                         ((rtems_libio_open_close_args_t *)arg)->iop->data1 );
425   /* Enable interrupts  on channel */
426  BSP_uart_intr_ctrl( BSP_UART_COM2, BSP_UART_INTR_CTRL_TERMIOS);
427  return RTEMS_SUCCESSFUL;
428}
429
430/*
431 * Handle ioctl request for TTY2
432 */
433rtems_device_driver
434tty2_control(rtems_device_major_number major,
435                rtems_device_minor_number minor,
436                void                      * arg
437)
438{
439   return tty_control( BSP_UART_COM2, arg );
440}
441
442static int
443tty2_conSetAttr( int minor, const struct termios *t)
444{
445  return conSetAttr( BSP_UART_COM2, minor, t );
446}
Note: See TracBrowser for help on using the repository browser.