source: rtems/c/src/lib/libbsp/powerpc/gen5200/console/console.c @ a6b5e836

4.115
Last change on this file since a6b5e836 was a6b5e836, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/01/11 at 08:16:05

2011-12-01 Ralf Corsépius <ralf.corsepius@…>

  • console/console.c: Eliminate unused var "nb_overflow".
  • Property mode set to 100644
File size: 22.4 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic MPC5200 BSP                              |
3+-----------------------------------------------------------------+
4| Partially based on the code references which are named below.   |
5| Adaptions, modifications, enhancements and any recent parts of  |
6| the code are:                                                   |
7|                    Copyright (c) 2005                           |
8|                    Embedded Brains GmbH                         |
9|                    Obere Lagerstr. 30                           |
10|                    D-82178 Puchheim                             |
11|                    Germany                                      |
12|                    rtems@embedded-brains.de                     |
13+-----------------------------------------------------------------+
14| The license and distribution terms for this file may be         |
15| found in the file LICENSE in this distribution or at            |
16|                                                                 |
17| http://www.rtems.com/license/LICENSE.                           |
18|                                                                 |
19+-----------------------------------------------------------------+
20| this file contains the console driver functions                 |
21\*===============================================================*/
22/***********************************************************************/
23/*                                                                     */
24/*   Module:       console.c                                           */
25/*   Date:         07/17/2003                                          */
26/*   Purpose:      RTEMS MPC5x00 console driver                        */
27/*                                                                     */
28/*---------------------------------------------------------------------*/
29/*                                                                     */
30/*   Description:                                                      */
31/*                                                                     */
32/*  The PSCs of mpc5200 are assigned as follows                        */
33/*                                                                     */
34/*              Channel     Device      Minor   Note                   */
35/*                PSC1      /dev/tty0      0                           */
36/*                PSC2      /dev/tty1      1                           */
37/*                PSC3      /dev/tty2      2                           */
38/*                                                                     */
39/*---------------------------------------------------------------------*/
40/*                                                                     */
41/*   Code                                                              */
42/*   References:   Serial driver for MPC8260ads                        */
43/*   Module:       console-generic.c                                   */
44/*   Project:      RTEMS 4.6.0pre1 / MPC8260ads BSP                    */
45/*   Version       1.3                                                 */
46/*   Date:         2002/11/04                                          */
47/*                                                                     */
48/*   Author(s) / Copyright(s):                                         */
49/*                                                                     */
50/*   Author: Jay Monkman (jmonkman@frasca.com)                         */
51/*   Copyright (C) 1998 by Frasca International, Inc.                  */
52/*                                                                     */
53/*   Derived from c/src/lib/libbsp/m68k/gen360/console/console.c       */
54/*   written by:                                                       */
55/*   W. Eric Norum                                                     */
56/*   Saskatchewan Accelerator Laboratory                               */
57/*   University of Saskatchewan                                        */
58/*   Saskatoon, Saskatchewan, CANADA                                   */
59/*   eric@skatter.usask.ca                                             */
60/*                                                                     */
61/*   COPYRIGHT (c) 1989-2008.                                          */
62/*   On-Line Applications Research Corporation (OAR).                  */
63/*                                                                     */
64/*   Modifications by Darlene Stewart <Darlene.Stewart@iit.nrc.ca>     */
65/*   and Charles-Antoine Gauthier <charles.gauthier@iit.nrc.ca>        */
66/*   Copyright (c) 1999, National Research Council of Canada           */
67/*                                                                     */
68/*   Modifications by Andy Dachs <a.dachs@sstl.co.uk> to add MPC8260   */
69/*   support.                                                          */
70/*   Copyright (c) 2001, Surrey Satellite Technology Ltd               */
71/*                                                                     */
72/*   The license and distribution terms for this file may be           */
73/*   found in the file LICENSE in this distribution or at              */
74/*   http://www.rtems.com/license/LICENSE.                        */
75/*                                                                     */
76/*---------------------------------------------------------------------*/
77/*                                                                     */
78/*   Partially based on the code references which are named above.     */
79/*   Adaptions, modifications, enhancements and any recent parts of    */
80/*   the code are under the right of                                   */
81/*                                                                     */
82/*         IPR Engineering, Dachauer Straße 38, D-80335 MÃŒnchen        */
83/*                        Copyright(C) 2003                            */
84/*                                                                     */
85/*---------------------------------------------------------------------*/
86/*                                                                     */
87/*   IPR Engineering makes no representation or warranties with        */
88/*   respect to the performance of this computer program, and          */
89/*   specifically disclaims any responsibility for any damages,        */
90/*   special or consequential, connected with the use of this program. */
91/*                                                                     */
92/*---------------------------------------------------------------------*/
93/*                                                                     */
94/*   Version history:  1.0                                             */
95/*                                                                     */
96/***********************************************************************/
97
98#include <assert.h>
99
100#include <rtems.h>
101#include "../include/mpc5200.h"
102#include <bsp.h>
103#include <bsp/irq.h>
104
105#include <rtems/bspIo.h>
106#include <rtems/libio.h>
107#include <string.h>
108#include <rtems/termiostypes.h>
109
110
111#define NUM_PORTS       MPC5200_PSC_NO
112
113#define PSC1_MINOR      0
114#define PSC2_MINOR      1
115#define PSC3_MINOR      2
116#define PSC4_MINOR      3
117#define PSC5_MINOR      4
118#define PSC6_MINOR      5
119
120uint32_t mpc5200_uart_avail_mask = BSP_UART_AVAIL_MASK;
121
122#if defined(UARTS_USE_TERMIOS_INT)
123  uint8_t psc_minor_to_irqname[NUM_PORTS] = {
124     BSP_SIU_IRQ_PSC1,
125     BSP_SIU_IRQ_PSC2,
126     BSP_SIU_IRQ_PSC3,
127     BSP_SIU_IRQ_PSC4,
128     BSP_SIU_IRQ_PSC5,
129     BSP_SIU_IRQ_PSC6
130  };
131
132  static int mpc5200_psc_irqname_to_minor(int name) {
133    int      minor;
134    uint8_t *chrptr;
135
136    chrptr = memchr(psc_minor_to_irqname, name, sizeof(psc_minor_to_irqname));
137    if (chrptr != NULL) {
138      minor = chrptr - psc_minor_to_irqname;
139    } else {
140      minor = -1;
141    }
142    return minor;
143  }
144#endif
145
146static void A_BSP_output_char(char c);
147static int A_BSP_get_char(void);
148BSP_output_char_function_type BSP_output_char = A_BSP_output_char;
149
150BSP_polling_getchar_function_type BSP_poll_char = A_BSP_get_char;
151
152/* Used to handle premature outputs of printk */
153bool console_initialized = false;
154
155/* per channel info structure */
156struct per_channel_info {
157  uint16_t shadow_imr;
158  uint8_t shadow_mode1;
159  uint8_t shadow_mode2;
160  int cur_tx_len;
161  int rx_interrupts;
162  int tx_interrupts;
163  int rx_characters;
164  int tx_characters;
165  int breaks_detected;
166  int framing_errors;
167  int parity_errors;
168  int overrun_errors;
169};
170
171/* Used to handle more than one channel */
172struct per_channel_info channel_info[NUM_PORTS];
173
174/*
175 * XXX: there are only 6 PSCs, but PSC6 has an extra register gap
176 *      from PSC5, therefore we instantiate seven(!) PSC register sets
177 */
178uint8_t psc_minor_to_regset[MPC5200_PSC_NO] = {0,1,2,3,4,6};
179
180/* Used to track termios private data for callbacks */
181struct rtems_termios_tty *ttyp[NUM_PORTS];
182
183int mpc5200_psc_setAttributes(
184  int                   minor,
185  const struct termios *t
186)
187{
188  int baud;
189  uint8_t csize=0, cstopb, parenb, parodd;
190  struct mpc5200_psc *psc =
191    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
192
193  /* Baud rate */
194  baud = rtems_termios_baud_to_number(t->c_cflag & CBAUD);
195  if (baud > 0) {
196   /*
197    * Calculate baud rate
198    * round divider to nearest!
199    */
200    baud = (IPB_CLOCK + baud *16) / (baud * 32);
201  }
202
203  /* Number of data bits */
204  switch ( t->c_cflag & CSIZE ) {
205    case CS5:     csize = 0x00;  break;
206    case CS6:     csize = 0x01;  break;
207    case CS7:     csize = 0x02;  break;
208    case CS8:     csize = 0x03;  break;
209  }
210
211  /* Stop bits */
212  if(csize == 0) {
213    if(t->c_cflag & CSTOPB)
214      cstopb = 0x0F;           /* Two stop bits */
215    else
216      cstopb = 0x00;           /* One stop bit */
217  } else {
218    if(t->c_cflag & CSTOPB)
219      cstopb = 0x0F;           /* Two stop bits */
220    else
221      cstopb = 0x07;           /* One stop bit */
222  }
223
224  /* Parity */
225  if (t->c_cflag & PARENB)
226    parenb = 0x00;             /* Parity enabled on Tx and Rx */
227  else
228    parenb = 0x10;             /* No parity on Tx and Rx */
229
230  if (t->c_cflag & PARODD)
231    parodd = 0x04;             /* Odd parity */
232  else
233    parodd = 0x00;
234
235 /*
236  * Set upper timer counter
237  */
238  psc->ctur = (uint8_t) (baud >> 8);
239
240 /*
241  * Set lower timer counter
242  */
243  psc->ctlr = (uint8_t) baud;
244
245 /*
246  * Reset mode pointer
247  */
248  psc->cr = ((1 << 4) << 8);
249
250 /*
251  * Set mode1 register
252  */
253  channel_info[minor].shadow_mode1 &= ~(0x1F);
254  psc->mr = channel_info[minor].shadow_mode1 | (csize | parenb | parodd);
255
256 /*
257  * Set mode2 register
258  */
259  channel_info[minor].shadow_mode2 &= ~(0x0F);
260  psc->mr = channel_info[minor].shadow_mode2 | cstopb;
261
262  return 0;
263
264}
265
266
267int mpc5200_uart_setAttributes(int minor, const struct termios *t)
268{
269  /*
270   * Check that port number is valid
271   */
272  if( (minor < PSC1_MINOR) || (minor > NUM_PORTS-1) )
273    return 0;
274
275  return mpc5200_psc_setAttributes(minor, t);
276
277}
278
279#ifdef UARTS_USE_TERMIOS_INT
280/*
281 * Interrupt handlers
282 */
283static void mpc5200_psc_interrupt_handler(rtems_irq_hdl_param handle)
284{
285  unsigned char c;
286  uint16_t isr;
287  int minor = (int)handle;
288  struct mpc5200_psc *psc =
289    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
290
291  /*
292   * get content of psc interrupt status
293   */
294  isr = psc->isr_imr;
295
296  /*
297   * Character received?
298   */
299  if (isr & ISR_RX_RDY_FULL) {
300
301    channel_info[minor].rx_interrupts++;
302
303
304#ifndef SINGLE_CHAR_MODE
305    while(psc->rfnum) {
306#endif
307      /*
308       * get the character
309       */
310       c = (psc->rb_tb >> 24);
311
312      if (ttyp[minor] != NULL) {
313        rtems_termios_enqueue_raw_characters(
314           (void *)ttyp[minor], (char *)&c, (int)1);
315        channel_info[minor].rx_characters++;
316      }
317
318#ifndef SINGLE_CHAR_MODE
319    }
320#endif
321
322  }
323
324  /*
325   * Character transmitted ?
326   */
327  if (isr & ISR_TX_RDY & channel_info[minor].shadow_imr) {
328    channel_info[minor].tx_interrupts++;
329
330    /*
331     * mask interrupt
332     */
333    psc->isr_imr = channel_info[minor].shadow_imr &= ~(IMR_TX_RDY);
334
335    if (ttyp[minor] != NULL) {
336      #ifndef SINGLE_CHAR_MODE
337        rtems_termios_dequeue_characters(
338           (void *)ttyp[minor], channel_info[minor].cur_tx_len);
339        channel_info[minor].tx_characters += channel_info[minor].cur_tx_len;
340      #else
341        rtems_termios_dequeue_characters((void *)ttyp[minor], (int)1);
342        channel_info[minor].tx_characters++;
343      #endif
344    }
345  }
346
347  if(isr & ISR_ERROR) {
348    if(isr & ISR_RB)
349      channel_info[minor].breaks_detected++;
350    if(isr & ISR_FE)
351      channel_info[minor].framing_errors++;
352    if(isr & ISR_PE)
353      channel_info[minor].parity_errors++;
354    if(isr & ISR_OE)
355      channel_info[minor].overrun_errors++;
356
357    /*
358     *  Reset error status
359     */
360    psc->cr = ((4 << 4) << 8);
361  }
362}
363
364void mpc5200_psc_enable(
365  const rtems_irq_connect_data* ptr
366)
367{
368  struct mpc5200_psc *psc;
369  int minor =  mpc5200_psc_irqname_to_minor(ptr->name);
370
371  if (minor >= 0) {
372    psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
373    psc->isr_imr = channel_info[minor].shadow_imr |=
374      (IMR_RX_RDY_FULL | IMR_TX_RDY);
375  }
376}
377
378
379void mpc5200_psc_disable(
380  const rtems_irq_connect_data* ptr
381)
382{
383  struct mpc5200_psc *psc;
384  int minor =  mpc5200_psc_irqname_to_minor(ptr->name);
385
386  if (minor >= 0) {
387    psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
388    psc->isr_imr = channel_info[minor].shadow_imr &=
389      ~(IMR_RX_RDY_FULL | IMR_TX_RDY);
390  }
391}
392
393int mpc5200_psc_isOn(
394  const rtems_irq_connect_data* ptr
395)
396{
397  struct mpc5200_psc *psc;
398  int minor =  mpc5200_psc_irqname_to_minor(ptr->name);
399
400  if (minor >= 0) {
401    psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
402    return ((psc->isr_imr & IMR_RX_RDY_FULL) & (psc->isr_imr & IMR_TX_RDY));
403  }
404  return false;
405}
406
407
408static rtems_irq_connect_data consoleIrqData;
409#endif
410
411void mpc5200_uart_psc_initialize(
412  int minor
413)
414{
415  uint32_t baud_divider;
416  struct mpc5200_psc *psc =
417    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
418
419  /*
420   * Check that minor number is valid
421   */
422  if ((minor < PSC1_MINOR) || (minor >= (PSC1_MINOR + NUM_PORTS)))
423    return;
424
425  /*
426   * Clear per channel info
427   */
428  memset((void *)&channel_info[minor], 0, sizeof(struct per_channel_info));
429
430  /*
431   * Reset receiver and transmitter
432   */
433  psc->cr = ((2 << 4) << 8);
434  psc->cr = ((3 << 4) << 8);
435
436  /*
437   * Reset mode pointer
438   */
439  psc->cr = ((1 << 4) << 8);
440
441  /*
442   * Set clock select register
443   */
444  psc->sr_csr = 0;
445
446  /*
447   * Set mode1 register
448   */
449  psc->mr = channel_info[minor].shadow_mode1 = 0x33; /* 8Bit / no parity */
450
451  /*
452   * Set mode2 register
453   */
454  psc->mr = channel_info[minor].shadow_mode2 = 7; /* 1 stop bit */
455
456  /*
457   * Set rx FIFO alarm
458   */
459  psc->rfalarm = RX_FIFO_SIZE - 1;
460
461  /*
462   * Set tx FIFO alarm
463   */
464  psc->tfalarm = 1;
465
466  baud_divider =
467    (IPB_CLOCK + GEN5200_CONSOLE_BAUD *16) / (GEN5200_CONSOLE_BAUD * 32);
468
469  /*
470   * Set upper timer counter
471   */
472  psc->ctur = baud_divider >> 16;
473
474  /*
475   * Set lower timer counter
476   */
477
478  psc->ctlr = baud_divider & 0x0000ffff;
479
480  /*
481   * Disable Frame mode / set granularity 0
482   */
483  psc->tfcntl = 0;
484
485#ifdef UARTS_USE_TERMIOS_INT
486  /*
487   * Tie interrupt dependent routines
488   */
489  consoleIrqData.on     = mpc5200_psc_enable;
490  consoleIrqData.off    = mpc5200_psc_disable;
491  consoleIrqData.isOn   = mpc5200_psc_isOn;
492  consoleIrqData.handle = (rtems_irq_hdl_param)minor;
493  consoleIrqData.hdl    = (rtems_irq_hdl)mpc5200_psc_interrupt_handler;
494
495  /*
496   * Tie interrupt handler
497   */
498  consoleIrqData.name = psc_minor_to_irqname[minor];
499
500  /*
501   * Install rtems irq handler
502   */
503  assert(BSP_install_rtems_irq_handler(&consoleIrqData) == 1);
504#endif
505
506  /*
507   * Reset rx fifo errors Error/UF/OF
508   */
509  psc->rfstat |= 0x70;
510
511  /*
512   * Reset tx fifo errors Error/UF/OF
513   */
514  psc->tfstat |= 0x70;
515
516#ifdef UARTS_USE_TERMIOS_INT
517  /*
518   * Unmask receive interrupt
519   */
520  psc->isr_imr = channel_info[minor].shadow_imr = IMR_RX_RDY_FULL;
521#endif
522
523  /*
524   * Enable receiver
525   */
526  psc->cr = ((1 << 0) << 8);
527
528  /*
529   * Enable transmitter
530   */
531  psc->cr = ((1 << 2) << 8);
532}
533
534
535int mpc5200_uart_pollRead(
536  int minor
537)
538{
539  unsigned char c;
540  struct mpc5200_psc *psc =
541    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
542
543  if (psc->sr_csr & (1 << 8))
544     c = (psc->rb_tb >> 24);
545  else
546     return -1;
547
548  return c;
549}
550
551
552ssize_t mpc5200_uart_pollWrite(
553  int minor,
554  const char *buf,
555  size_t len
556)
557{
558  size_t retval = len;
559  const char *tmp_buf = buf;
560  struct mpc5200_psc *psc =
561    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
562
563  while(len--) {
564    while(!(psc->sr_csr & (1 << 11)))
565      continue;
566
567    /*rtems_cache_flush_multiple_data_lines( (void *)buf, 1);*/
568
569    psc->rb_tb = (*tmp_buf << 24);
570
571    tmp_buf++;
572
573  }
574  return retval;
575
576}
577
578ssize_t mpc5200_uart_write(
579  int         minor,
580  const char *buf,
581  size_t len
582)
583{
584  int frame_len = len;
585  const char *frame_buf = buf;
586  struct mpc5200_psc *psc =
587    (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]);
588
589 /*
590  * Check tx fifo space
591  */
592  if(len > (TX_FIFO_SIZE - psc->tfnum))
593    frame_len = TX_FIFO_SIZE - psc->tfnum;
594
595#ifndef SINGLE_CHAR_MODE
596  channel_info[minor].cur_tx_len = frame_len;
597#else
598  frame_len = 1;
599#endif
600
601 /*rtems_cache_flush_multiple_data_lines( (void *)frame_buf, frame_len);*/
602
603  while (frame_len--)
604    /* perform byte write to avoid extra NUL characters */
605    (* (volatile char *)&(psc->rb_tb)) = *frame_buf++;
606
607 /*
608  * unmask interrupt
609  */
610  psc->isr_imr = channel_info[minor].shadow_imr |= IMR_TX_RDY;
611
612  return 0;
613}
614
615/*
616 *  Print functions prototyped in bspIo.h
617 */
618static void A_BSP_output_char(
619  char c
620)
621{
622  char cr = '\r';
623
624  /*
625   *  If we are using U-Boot, then the console is already initialized
626   *  and we can just poll bytes out at any time.
627   */
628  #if !defined(HAS_UBOOT)
629    if (console_initialized == false)
630     return;
631  #endif
632
633#define PRINTK_WRITE mpc5200_uart_pollWrite
634
635    PRINTK_WRITE(PRINTK_MINOR, &c, 1 );
636
637    if( c == '\n' )
638      PRINTK_WRITE( PRINTK_MINOR, &cr, 1 );
639}
640
641static int A_BSP_get_char(void)
642{
643  /*
644   *  If we are using U-Boot, then the console is already initialized
645   *  and we can just poll bytes in at any time.
646   */
647  #if !defined(HAS_UBOOT)
648    if (console_initialized == false)
649     return -1;
650  #endif
651
652  return mpc5200_uart_pollRead(0);
653}
654
655/*
656 ***************
657 * BOILERPLATE *
658 ***************
659 *
660 *  All these functions are prototyped in rtems/c/src/lib/include/console.h.
661 */
662
663/*
664 * Initialize and register the device
665 */
666rtems_device_driver console_initialize(
667  rtems_device_major_number major,
668  rtems_device_minor_number minor,
669  void *arg
670)
671{
672  rtems_status_code status;
673  rtems_device_minor_number console_minor;
674  char dev_name[] = "/dev/ttyx";
675  uint32_t tty_num = 0;
676  bool first = true;
677
678  /*
679   * Always use and set up TERMIOS
680   */
681  console_minor = PSC1_MINOR;
682  rtems_termios_initialize();
683
684  for (console_minor = PSC1_MINOR;
685       console_minor < PSC1_MINOR + NUM_PORTS;
686       console_minor++) {
687     /*
688      * check, whether UART is available for this board
689      */
690    if (0 != ((1 << console_minor) & (mpc5200_uart_avail_mask))) {
691      /*
692       * Do device-specific initialization and registration for Motorola IceCube
693       */
694      mpc5200_uart_psc_initialize(console_minor); /* /dev/tty0 */
695      dev_name[8] = '0' + tty_num;
696      status = rtems_io_register_name (dev_name, major, console_minor);
697      assert(status == RTEMS_SUCCESSFUL);
698
699      #ifdef MPC5200_PSC_INDEX_FOR_GPS_MODULE
700        if (console_minor == MPC5200_PSC_INDEX_FOR_GPS_MODULE) {
701          status = rtems_io_register_name("/dev/gps", major, console_minor);
702          assert(status == RTEMS_SUCCESSFUL);
703        }
704      #endif
705
706      if (first) {
707        first = false;
708
709        /* Now register the RTEMS console */
710        status = rtems_io_register_name ("/dev/console", major, console_minor);
711        assert(status == RTEMS_SUCCESSFUL);
712      }
713
714      tty_num++;
715    }
716  }
717
718  console_initialized = true;
719  return RTEMS_SUCCESSFUL;
720}
721
722/*
723 * Open the device
724 */
725rtems_device_driver console_open(
726  rtems_device_major_number  major,
727  rtems_device_minor_number  minor,
728  void                      *arg
729)
730{
731  rtems_libio_open_close_args_t *args = arg;
732  rtems_status_code sc;
733
734#ifdef UARTS_USE_TERMIOS_INT
735  static const rtems_termios_callbacks intrCallbacks = {
736    NULL,                           /* firstOpen */
737    NULL,                           /* lastClose */
738    NULL,                           /* pollRead */
739    mpc5200_uart_write,             /* write */
740    mpc5200_uart_setAttributes,     /* setAttributes */
741    NULL,
742    NULL,
743    1                               /* outputUsesInterrupts */
744  };
745#else
746  static const rtems_termios_callbacks pollCallbacks = {
747    NULL,                           /* firstOpen */
748    NULL,                           /* lastClose */
749    mpc5200_uart_pollRead,          /* pollRead */
750    mpc5200_uart_pollWrite,         /* write */
751    mpc5200_uart_setAttributes,     /* setAttributes */
752    NULL,
753    NULL,
754    0                               /* output don't use Interrupts */
755  };
756#endif
757
758  if(minor > NUM_PORTS - 1)
759    return RTEMS_INVALID_NUMBER;
760
761#ifdef UARTS_USE_TERMIOS_INT
762  sc = rtems_termios_open( major, minor, arg, &intrCallbacks );
763#else                               /* RTEMS polled I/O with termios */
764  sc = rtems_termios_open( major, minor, arg, &pollCallbacks );
765#endif
766
767  ttyp[minor] = args->iop->data1;   /* Keep cookie returned by termios_open */
768
769  if ( !sc )
770    rtems_termios_set_initial_baud( ttyp[minor], GEN5200_CONSOLE_BAUD );
771
772  return sc;
773}
774
775
776/*
777 * Close the device
778 */
779rtems_device_driver console_close(
780  rtems_device_major_number  major,
781  rtems_device_minor_number  minor,
782  void                      *arg
783)
784{
785  if ( minor > NUM_PORTS-1 )
786    return RTEMS_INVALID_NUMBER;
787
788  ttyp[minor] = NULL; /* mark for int handler: tty no longer open */
789
790  return rtems_termios_close( arg );
791}
792
793
794/*
795 * Read from the device
796 */
797rtems_device_driver console_read(
798  rtems_device_major_number  major,
799  rtems_device_minor_number  minor,
800  void                      *arg
801)
802{
803  if(minor > NUM_PORTS-1)
804    return RTEMS_INVALID_NUMBER;
805
806  return rtems_termios_read(arg);
807}
808
809/*
810 * Write to the device
811 */
812rtems_device_driver console_write(
813  rtems_device_major_number  major,
814  rtems_device_minor_number  minor,
815  void                      *arg
816)
817{
818  if ( minor > NUM_PORTS-1 )
819    return RTEMS_INVALID_NUMBER;
820  return rtems_termios_write(arg);
821}
822
823/*
824 * Handle ioctl request.
825 */
826rtems_device_driver console_control(
827  rtems_device_major_number  major,
828  rtems_device_minor_number  minor,
829  void                      *arg
830)
831{
832  if ( minor > NUM_PORTS-1 )
833    return RTEMS_INVALID_NUMBER;
834
835  return rtems_termios_ioctl(arg);
836}
Note: See TracBrowser for help on using the repository browser.