source: rtems/c/src/lib/libbsp/powerpc/eth_comm/console/console.c @ 9e5c391

4.104.114.84.9
Last change on this file since 9e5c391 was 9e5c391, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 18, 1999 at 3:09:59 PM

Added or corrected CVS Id strings.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1#define I_WANT_TERMIOS
2/*
3 *  BSP specific Serial I/O Functions for the eth-comm BSP
4 *
5 * This file contains the BSP specific functions for
6 * performing serial I/O. These are the functions
7 * RTEMS uses (the 6 listed in the device driver
8 * structure)
9 *
10 * The SCCs and SMCs are assigned as follows
11 *
12 *   Channel     Device      Minor   Termios
13 *    SMC1      /dev/tty0      0       no
14 *    SMC2      /dev/tty1      1       no
15 *    SCC1      ethernet
16 *    SCC2      /dev/console   3       yes
17 *    SCC3      /dev/tty3      4       no
18 *    SCC4      /dev/tty4      5       no
19 *
20 * FIXME: This should use termios for /dev/console, but it doesn't
21 *  appear to work correctly yet. On startup, with termios enabled,
22 *  the board hangs for a few seconds before running correctly
23 *
24 * Author: Jay Monkman (jmonkman@frasca.com)
25 * Copyright (C) 1998 by Frasca International, Inc.
26 *
27 *  $Id$
28 */
29
30#include <rtems/libio.h>
31#include <mpc860.h>
32#include <mpc860/console.h>
33#include <termios.h>
34
35rtems_device_driver console_initialize(rtems_device_major_number major,
36                                       rtems_device_minor_number minor,
37                                       void *arg)
38{
39  rtems_status_code status;
40  rtems_isr_entry old_handler;
41  rtems_status_code sc;
42 
43#ifdef I_WANT_TERMIOS
44  /*
45   * Set up TERMIOS (for /dev/console)
46   */
47  rtems_termios_initialize();
48#endif
49
50  /*
51   * Set up Buffer Descriptors
52   */
53  m860_console_initialize();
54
55  /*
56   * Do device-specific initialization
57   */
58  m860_scc_initialize(2);  /* /dev/console */
59  m860_scc_initialize(3);  /* /dev/tty3   */
60  m860_scc_initialize(4);  /* /dev/tty4   */
61  m860_smc_initialize(1);  /* /dev/tty0   */
62  m860_smc_initialize(2);  /* /dev/tty1   */
63 
64  sc = rtems_interrupt_catch (m860_scc2_console_interrupt_handler,
65                              PPC_IRQ_CPM_SCC2,
66                              &old_handler);
67  sc = rtems_interrupt_catch (m860_scc3_console_interrupt_handler,
68                              PPC_IRQ_CPM_SCC3,
69                              &old_handler);
70  sc = rtems_interrupt_catch (m860_scc4_console_interrupt_handler,
71                              PPC_IRQ_CPM_SCC4,
72                              &old_handler);
73  sc = rtems_interrupt_catch (m860_smc1_console_interrupt_handler,
74                              PPC_IRQ_CPM_SMC1,
75                              &old_handler);
76  sc = rtems_interrupt_catch (m860_smc2_console_interrupt_handler,
77                              PPC_IRQ_CPM_SMC2,
78                              &old_handler);
79
80  /*
81   * Register the devices
82   */
83  status = rtems_io_register_name ("/dev/console", major, SCC2_MINOR);
84  if (status != RTEMS_SUCCESSFUL)
85    rtems_fatal_error_occurred (status);
86  status = rtems_io_register_name ("/dev/tty0", major, SMC1_MINOR);
87  if (status != RTEMS_SUCCESSFUL)
88    rtems_fatal_error_occurred (status);
89  status = rtems_io_register_name ("/dev/tty1", major, SMC2_MINOR);
90  if (status != RTEMS_SUCCESSFUL)
91    rtems_fatal_error_occurred (status);
92  status = rtems_io_register_name ("/dev/tty3", major, SCC3_MINOR);
93  if (status != RTEMS_SUCCESSFUL)
94    rtems_fatal_error_occurred (status);
95  status = rtems_io_register_name ("/dev/tty4", major, SCC4_MINOR);
96  if (status != RTEMS_SUCCESSFUL)
97    rtems_fatal_error_occurred (status);
98  return RTEMS_SUCCESSFUL;
99}
100 
101rtems_device_driver console_open(rtems_device_major_number major,
102                                 rtems_device_minor_number minor,
103                                 void *arg)
104{
105  volatile m860SCCRegisters_t *sccregs;
106
107#ifdef I_WANT_TERMIOS
108  static const rtems_termios_callbacks sccPollCallbacks = {
109    NULL,                       /* firstOpen */
110    NULL,                       /* lastClose */
111    m860_char_poll_read,        /* pollRead */
112    m860_char_poll_write,       /* write */
113    m860_scc_set_attributes,    /* setAttributes */
114    NULL,                       /* stopRemoteTx */
115    NULL,                       /* startRemoteTx */
116    0                           /* outputUsesInterrupts */
117  };
118#endif /* I_WANT_TERMIOS */
119
120  sccregs = 0;
121
122  switch (minor) {
123  case 0:
124    m860.smc1.smcm = 1;           /* Enable SMC1 RX interrupts */
125    m860.cimr |= 1UL <<  4;       /* Enable SMC1 interrupts */
126    break;
127  case 1:
128    m860.smc2.smcm = 1;           /* Enable SMC2 RX interrupts */
129    m860.cimr |= 1UL <<  3;       /* Enable SMC2 interrupts */
130    break;
131  case 2:
132    m860.cimr |= 1UL << 30;      /* Enable SCC1 interrupts */
133    sccregs = &m860.scc1;
134    break;
135  case 3: 
136#ifndef I_WANT_TERMIOS
137    m860.cimr |= 1UL << 29;      /* Enable SCC2 interrupts */
138#endif /* I_WANT_TERMIOS */
139    sccregs = &m860.scc2;
140    break;
141  case 4:
142    m860.cimr |= 1UL << 28;      /* Enable SCC3 interrupts */
143    sccregs = &m860.scc3;
144    break;
145  case 5:
146    m860.cimr |= 1UL << 27;      /* Enable SCC4 interrupts */
147    sccregs = &m860.scc4;
148    break;
149  default:
150    rtems_panic ("CONSOLE: bad minor number");
151  }
152
153  if (sccregs)
154    sccregs->sccm=0x3;
155
156#ifdef I_WANT_TERMIOS
157  if (minor == SCC2_MINOR) {
158    return rtems_termios_open (major, minor, arg, &sccPollCallbacks);
159  }
160  else { 
161    return RTEMS_SUCCESSFUL;
162  }
163#else
164  return RTEMS_SUCCESSFUL;
165#endif
166}
167
168rtems_device_driver console_close(rtems_device_major_number major,
169                                  rtems_device_minor_number minor,
170                                  void *arg)
171{
172#ifdef I_WANT_TERMIOS
173  if (minor == SCC2_MINOR) {
174    return rtems_termios_close (arg);
175  }
176  else {
177    return RTEMS_SUCCESSFUL;
178  }
179#else
180  return RTEMS_SUCCESSFUL;
181#endif
182}
183
184rtems_device_driver console_read(rtems_device_major_number major,
185                                 rtems_device_minor_number minor,
186                                 void *arg)
187{
188#ifdef I_WANT_TERMIOS
189  if (minor == SCC2_MINOR) {
190    return rtems_termios_read(arg);
191  }
192  else {
193    return m860_console_read(major, minor, arg);
194  }
195#else
196  return m860_console_read(major, minor, arg);
197#endif
198}
199
200rtems_device_driver console_write(rtems_device_major_number major,
201                                  rtems_device_minor_number minor,
202                                  void *arg)
203{
204#ifdef I_WANT_TERMIOS
205  if (minor == SCC2_MINOR) {
206    return rtems_termios_write(arg);
207  }
208  else {
209    return m860_console_write(major, minor, arg);
210  }
211#else
212  return m860_console_write(major, minor, arg);
213#endif
214}
215
216/*
217 * Handle ioctl request.
218 * Should set hardware line speed, bits/char, etc.
219 */
220rtems_device_driver console_control(rtems_device_major_number major,
221                                    rtems_device_minor_number minor,
222                                    void *arg)
223{ 
224#ifdef I_WANT_TERMIOS
225  if (minor == SCC2_MINOR) {
226    return rtems_termios_ioctl (arg);
227  }
228  else {
229    return RTEMS_SUCCESSFUL;
230  }
231#else
232  return RTEMS_SUCCESSFUL;
233#endif
234}
235
Note: See TracBrowser for help on using the repository browser.