source: rtems/c/src/lib/libbsp/powerpc/mpc8260ads/console/console.c @ 62c912e

5
Last change on this file since 62c912e was 629555cf, checked in by Joel Sherrill <joel@…>, on 03/29/16 at 18:10:52

powerpc/mpc8260ads: Remove include of <rtems/console.h> from <bsp.h> and fix warnings

  • Property mode set to 100644
File size: 12.9 KB
Line 
1/*
2 *  This file contains the MBX8xx termios serial I/O package.
3 *  Only asynchronous I/O is supported.
4 *
5 *  The SCCs and SMCs are assigned as follows
6 *
7 *   Channel     Device      Minor   Note
8 *    SMC1      /dev/tty0      0
9 *    SMC2      /dev/tty1      1
10 *    SCC1                     2     N/A. Hardwired as ethernet port
11 *    SCC2      /dev/tty2      3
12 *    SCC3      /dev/tty3      4
13 *    SCC4      /dev/tty4      5
14 *
15 * The SCCs and SMCs on the eval board are assigned as follows
16 *
17 *   Channel     Device      Minor   Termios
18 *    SMC1      /dev/tty3      4       no
19 *    SMC2      /dev/tty4      5       no
20 *    SCC1      /dev/tty0      0       no
21 *    SCC2      /dev/console   1       yes
22 *    SCC3      /dev/tty1      2       no       * USED FOR NETWORK I/F
23 *    SCC4      /dev/tty2      3       no       * USED FOR NETWORK I/F
24 *
25 *  All ports support termios. The use of termios is recommended for real-time
26 *  applications. Termios provides buffering and input processing. When not
27 *  using termios, processing is limited to the substitution of LF for CR on
28 *  input, and the output of a CR following the output of a LF character.
29 *  Note that the terminal should not send CR/LF pairs when the return key
30 *  is pressed, and that output lines are terminated with LF/CR, not CR/LF
31 *  (although that would be easy to change).
32 *
33 *  I/O may be interrupt-driven (recommended for real-time applications) or
34 *  polled. Polled I/O may be performed by this device driver entirely, or
35 *  in part by EPPCBug. With EPPCBug 1.1, polled I/O is limited to the
36 *  EPPCBug debug console. This is a limitation of the firmware. Later
37 *  firmware may be able to do I/O through any port. This code assumes
38 *  that the EPPCBug console is the default: SMC1. If the console and
39 *  printk ports are set to anything else with EPPCBug polled I/O, the
40 *  system will hang. Only port SMC1 is usable with EPPCBug polled I/O.
41 *
42 *  LIMITATIONS:
43 *
44 *  It is not possible to use different I/O modes on the different ports. The
45 *  exception is with printk. The printk port can use a different mode from
46 *  the other ports. If this is done, it is important not to open the printk
47 *  port from an RTEMS application.
48 *
49 *  Currently, the I/O modes are determined at build time. It would be much
50 *  better to have the mode selected at boot time based on parameters in
51 *  NVRAM.
52 *
53 *  Interrupt-driven I/O requires termios.
54 *
55 *  TESTS:
56 *
57 *  TO RUN THE TESTS, USE POLLED I/O WITHOUT TERMIOS SUPPORT. Some tests
58 *  play with the interrupt masks and turn off I/O. Those tests will hang
59 *  when interrupt-driven I/O is used. Other tests, such as cdtest, do I/O
60 *  from the static constructors before the console is open. This test
61 *  will not work with interrupt-driven I/O. Because of the buffering
62 *  performed in termios, test output may not be in sequence.The tests
63 *  should all be fixed to work with interrupt-driven I/O and to
64 *  produce output in the expected sequence. Obviously, the termios test
65 *  requires termios support in the driver.
66 *
67 *  Set CONSOLE_MINOR to the appropriate device minor number in the
68 *  config file. This allows the RTEMS application console to be different
69 *  from the EPPBug debug console or the GDB port.
70 *
71 *  This driver handles all five available serial ports: it distinguishes
72 *  the sub-devices using minor device numbers. It is not possible to have
73 *  other protocols running on the other ports when this driver is used as
74 *  currently written.
75 */
76
77/*
78 *  Based on code (alloc860.c in eth_comm port) by
79 *  Jay Monkman (jmonkman@frasca.com),
80 *  Copyright (C) 1998 by Frasca International, Inc.
81 *
82 *  Modifications by Darlene Stewart <Darlene.Stewart@iit.nrc.ca>
83 *  and Charles-Antoine Gauthier <charles.gauthier@iit.nrc.ca>.
84 *  Copyright (c) 2000, National Research Council of Canada
85 *
86 *  Modifications by Andy Dachs <iwe@fsmal.net> for MPC8260
87 *  support.
88 */
89#include <stdarg.h>
90#include <stdio.h>
91#include <termios.h>
92
93#include <rtems/console.h>
94#include <rtems/bspIo.h>
95#include <rtems/libio.h>
96#include <bsp.h>
97
98static void _BSP_output_char( char c );
99static rtems_status_code do_poll_read( rtems_device_major_number major, rtems_device_minor_number minor, void * arg);
100static rtems_status_code do_poll_write( rtems_device_major_number major, rtems_device_minor_number minor, void * arg);
101
102BSP_output_char_function_type     BSP_output_char = _BSP_output_char;
103BSP_polling_getchar_function_type BSP_poll_char = NULL;
104
105/*
106 *  do_poll_read
107 *
108 *  Input characters through polled I/O. Returns has soon as a character has
109 *  been received. Otherwise, if we wait for the number of requested characters,
110 *  we could be here forever!
111 *
112 *  CR is converted to LF on input. The terminal should not send a CR/LF pair
113 *  when the return or enter key is pressed.
114 *
115 *  Input parameters:
116 *    major - ignored. Should be the major number for this driver.
117 *    minor - selected channel.
118 *    arg->buffer - where to put the received characters.
119 *    arg->count  - number of characters to receive before returning--Ignored.
120 *
121 *  Output parameters:
122 *    arg->bytes_moved - the number of characters read. Always 1.
123 *
124 *  Return value: RTEMS_SUCCESSFUL
125 *
126 *  CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O!
127 */
128static rtems_status_code do_poll_read(
129  rtems_device_major_number major,
130  rtems_device_minor_number minor,
131  void                    * arg
132)
133{
134  rtems_libio_rw_args_t *rw_args = arg;
135  int c;
136
137#define BSP_READ  m8xx_uart_pollRead
138
139  while( (c = BSP_READ(minor)) == -1 );
140  rw_args->buffer[0] = (uint8_t)c;
141  if( rw_args->buffer[0] == '\r' )
142      rw_args->buffer[0] = '\n';
143  rw_args->bytes_moved = 1;
144  return RTEMS_SUCCESSFUL;
145}
146
147/*
148 *  do_poll_write
149 *
150 *  Output characters through polled I/O. Returns only once every character has
151 *  been sent.
152 *
153 *  CR is transmitted AFTER a LF on output.
154 *
155 *  Input parameters:
156 *    major - ignored. Should be the major number for this driver.
157 *    minor - selected channel
158 *    arg->buffer - where to get the characters to transmit.
159 *    arg->count  - the number of characters to transmit before returning.
160 *
161 *  Output parameters:
162 *    arg->bytes_moved - the number of characters read
163 *
164 *  Return value: RTEMS_SUCCESSFUL
165 *
166 *  CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O!
167 */
168static rtems_status_code do_poll_write(
169  rtems_device_major_number major,
170  rtems_device_minor_number minor,
171  void                    * arg
172)
173{
174  rtems_libio_rw_args_t *rw_args = arg;
175  uint32_t   i;
176  char cr ='\r';
177
178#define BSP_WRITE m8xx_uart_pollWrite
179
180  for( i = 0; i < rw_args->count; i++ ) {
181    BSP_WRITE(minor, &(rw_args->buffer[i]), 1);
182    if ( rw_args->buffer[i] == '\n' )
183      BSP_WRITE(minor, &cr, 1);
184  }
185  rw_args->bytes_moved = i;
186  return RTEMS_SUCCESSFUL;
187
188}
189
190/*
191 *  Print functions prototyped in bspIo.h
192 */
193
194static void _BSP_output_char( char c )
195{
196  char cr = '\r';
197
198  /*
199   *  Can't rely on console_initialize having been called before this function
200   *  is used, so it may fail unless output is done through EPPC-Bug.
201   */
202#define PRINTK_WRITE m8xx_uart_pollWrite
203
204  PRINTK_WRITE( PRINTK_MINOR, &c, 1 );
205  if( c == '\n' )
206    PRINTK_WRITE( PRINTK_MINOR, &cr, 1 );
207
208}
209
210/*
211 ***************
212 * BOILERPLATE *
213 ***************
214 *
215 *  All these functions are prototyped in rtems/c/src/lib/include/console.h.
216 */
217
218/*
219 * Initialize and register the device
220 */
221rtems_device_driver console_initialize(
222  rtems_device_major_number major,
223  rtems_device_minor_number minor,
224  void *arg
225)
226{
227  rtems_status_code status;
228  rtems_device_minor_number console_minor;
229
230  /*
231   * Set up TERMIOS if needed
232   */
233
234    console_minor = CONSOLE_MINOR;
235
236#if UARTS_USE_TERMIOS == 1
237
238    rtems_termios_initialize ();
239#else
240    rtems_termios_initialize ();
241#endif /* UARTS_USE_TERMIOS */
242
243  /*
244   *  Do common initialization.
245   */
246  m8xx_uart_initialize();
247
248  /*
249   * Do device-specific initialization
250   */
251#if 0
252  m8xx_uart_smc_initialize(SMC1_MINOR); /* /dev/tty4 */
253  m8xx_uart_smc_initialize(SMC2_MINOR); /* /dev/tty5 */
254#endif
255
256  m8xx_uart_scc_initialize(SCC1_MINOR); /* /dev/tty0    */
257  m8xx_uart_scc_initialize(SCC2_MINOR); /* /dev/tty1    */
258
259#if 0  /* used as network connections */
260  m8xx_uart_scc_initialize(SCC3_MINOR); /* /dev/tty2    */
261  m8xx_uart_scc_initialize(SCC4_MINOR); /* /dev/tty3    */
262#endif
263
264  /*
265   * Set up interrupts
266   */
267  m8xx_uart_interrupts_initialize();
268
269  status = rtems_io_register_name ("/dev/tty0", major, SCC1_MINOR);
270  if (status != RTEMS_SUCCESSFUL)
271    rtems_fatal_error_occurred (status);
272  chmod("/dev/tty0",0660);
273  chown("/dev/tty0",2,0);
274
275  status = rtems_io_register_name ("/dev/tty1", major, SCC2_MINOR);
276  if (status != RTEMS_SUCCESSFUL)
277    rtems_fatal_error_occurred (status);
278  chmod("/dev/tty1",0660);
279  chown("/dev/tty1",2,0);
280
281#if 0
282  status = rtems_io_register_name ("/dev/tty2", major, SCC3_MINOR);
283  if (status != RTEMS_SUCCESSFUL)
284    rtems_fatal_error_occurred (status);
285
286  status = rtems_io_register_name ("/dev/tty3", major, SCC4_MINOR);
287  if (status != RTEMS_SUCCESSFUL)
288    rtems_fatal_error_occurred (status);
289
290  status = rtems_io_register_name ("/dev/tty4", major, SMC1_MINOR);
291  if (status != RTEMS_SUCCESSFUL)
292    rtems_fatal_error_occurred (status);
293
294  status = rtems_io_register_name ("/dev/tty5", major, SMC2_MINOR);
295  if (status != RTEMS_SUCCESSFUL)
296    rtems_fatal_error_occurred (status);
297#endif
298  /* Now register the RTEMS console */
299  status = rtems_io_register_name ("/dev/console", major, console_minor);
300  if (status != RTEMS_SUCCESSFUL)
301    rtems_fatal_error_occurred (status);
302  chmod("/dev/console",0666);
303  chown("/dev/console",2,0);
304
305  return RTEMS_SUCCESSFUL;
306}
307
308/*
309 * Open the device
310 */
311rtems_device_driver console_open(
312  rtems_device_major_number major,
313  rtems_device_minor_number minor,
314  void *arg
315)
316{
317#if UARTS_IO_MODE == 1  /* RTEMS interrupt-driven I/O with termios */
318  /* Used to track termios private data for callbacks */
319  extern struct rtems_termios_tty *ttyp[];
320  rtems_libio_open_close_args_t *args = arg;
321
322  static const rtems_termios_callbacks intrCallbacks = {
323    NULL,                               /* firstOpen */
324    NULL,                               /* lastClose */
325    NULL,                         /* pollRead */
326    m8xx_uart_write,                  /* write */
327    m8xx_uart_setAttributes,            /* setAttributes */
328    NULL,                               /* stopRemoteTx */
329    NULL,                               /* startRemoteTx */
330    1                                   /* outputUsesInterrupts */
331  };
332#else
333#if (UARTS_USE_TERMIOS == 1) && (UARTS_IO_MODE != 1)
334  static const rtems_termios_callbacks pollCallbacks = {
335    NULL,                               /* firstOpen */
336    NULL,                               /* lastClose */
337    m8xx_uart_pollRead,           /* pollRead */
338    m8xx_uart_pollWrite,          /* write */
339    m8xx_uart_setAttributes,      /* setAttributes */
340    NULL,                               /* stopRemoteTx */
341    NULL,                               /* startRemoteTx */
342    0                                   /* outputUsesInterrupts */
343  };
344#endif
345
346#endif
347
348  rtems_status_code sc;
349
350  if ( minor > NUM_PORTS-1 )
351    return RTEMS_INVALID_NUMBER;
352
353#if UARTS_USE_TERMIOS == 1
354
355#if UARTS_IO_MODE == 1  /* RTEMS interrupt-driven I/O with termios */
356  sc = rtems_termios_open( major, minor, arg, &intrCallbacks );
357  ttyp[minor] = args->iop->data1;        /* Keep cookie returned by termios_open */
358#else                     /* RTEMS polled I/O with termios */
359  sc = rtems_termios_open( major, minor, arg, &pollCallbacks );
360#endif
361
362#else /* UARTS_USE_TERMIOS != 1 */
363  /* no termios -- default to polled I/O */
364  sc = RTEMS_SUCCESSFUL;
365#endif /* UARTS_USE_TERMIOS != 1 */
366
367  return sc;
368
369}
370
371/*
372 * Close the device
373 */
374rtems_device_driver console_close(
375  rtems_device_major_number major,
376  rtems_device_minor_number minor,
377  void *arg
378)
379{
380  if ( minor > NUM_PORTS-1 )
381    return RTEMS_INVALID_NUMBER;
382
383#if UARTS_USE_TERMIOS == 1
384  return rtems_termios_close( arg );
385#else
386  return RTEMS_SUCCESSFUL;
387#endif
388
389}
390
391/*
392 * Read from the device
393 */
394rtems_device_driver console_read(
395  rtems_device_major_number major,
396  rtems_device_minor_number minor,
397  void *arg
398)
399{
400  if ( minor > NUM_PORTS-1 )
401    return RTEMS_INVALID_NUMBER;
402
403#if UARTS_USE_TERMIOS == 1
404  return rtems_termios_read( arg );
405#else
406  return do_poll_read( major, minor, arg );
407#endif
408
409}
410
411/*
412 * Write to the device
413 */
414rtems_device_driver console_write(
415  rtems_device_major_number major,
416  rtems_device_minor_number minor,
417  void *arg
418)
419{
420  if ( minor > NUM_PORTS-1 )
421    return RTEMS_INVALID_NUMBER;
422
423#if UARTS_USE_TERMIOS == 1
424  return rtems_termios_write( arg );
425#else
426    /* no termios -- default to polled */
427  return do_poll_write( major, minor, arg );
428#endif
429
430}
431
432/*
433 * Handle ioctl request.
434 */
435rtems_device_driver console_control(
436  rtems_device_major_number major,
437  rtems_device_minor_number minor,
438  void *arg
439)
440{
441  if ( minor > NUM_PORTS-1 )
442    return RTEMS_INVALID_NUMBER;
443
444#if UARTS_USE_TERMIOS == 1
445  return rtems_termios_ioctl( arg );
446#else
447  return RTEMS_SUCCESSFUL;
448#endif
449
450}
451
452/*
453 *  Support routine for console-generic
454 */
455int mbx8xx_console_get_configuration(void)
456{
457#if UARTS_IO_MODE == 1
458  return 0x02;
459#else
460  return 0;
461#endif
462
463}
Note: See TracBrowser for help on using the repository browser.