source: rtems/c/src/lib/libbsp/sparc/leon3/console/console.c @ d17733c

4.104.115
Last change on this file since d17733c was d17733c, checked in by Joel Sherrill <joel.sherrill@…>, on 05/24/10 at 15:05:19

2010-05-24 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, amba/amba.c, console/console.c, console/debugputs.c, startup/bspstart.c: Rework initialization order so AMBA bus is scanned earlier. This lets us look for UARTs earlier and support printk as early as bsp_start() returning.
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  This file contains the TTY driver for the serial ports on the LEON.
3 *
4 *  This driver uses the termios pseudo driver.
5 *
6 *  COPYRIGHT (c) 1989-1998.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  Modified for LEON3 BSP.
10 *  COPYRIGHT (c) 2004.
11 *  Gaisler Research.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#include <bsp.h>
21#include <rtems/libio.h>
22#include <stdlib.h>
23#include <assert.h>
24#include <rtems/bspIo.h>
25#include <amba.h>
26
27/*
28 *  Should we use a polled or interrupt drived console?
29 *
30 *  NOTE: This is defined in the custom/leon.cfg file.
31 */
32
33/*
34 *  console_outbyte_polled
35 *
36 *  This routine transmits a character using polling.
37 */
38
39void console_outbyte_polled(
40  int  port,
41  char ch
42);
43
44/* body is in debugputs.c */
45
46/*
47 *  console_inbyte_nonblocking
48 *
49 *  This routine polls for a character.
50 */
51
52int console_inbyte_nonblocking( int port );
53
54/* body is in debugputs.c */
55
56
57/*
58 *  Console Termios Support Entry Points
59 *
60 */
61
62ssize_t console_write_support (int minor, const char *buf, size_t len)
63{
64  int nwrite = 0;
65
66  while (nwrite < len) {
67    console_outbyte_polled( minor, *buf++ );
68    nwrite++;
69  }
70  return nwrite;
71}
72
73
74/*
75 *  Console Device Driver Entry Points
76 *
77 */
78int uarts = 0;
79volatile LEON3_UART_Regs_Map *LEON3_Console_Uart[LEON3_APBUARTS];
80
81rtems_device_driver console_initialize(
82  rtems_device_major_number  major,
83  rtems_device_minor_number  minor,
84  void                      *arg
85)
86{
87  rtems_status_code status;
88  int i, uart0;
89  char console_name[16];
90
91  rtems_termios_initialize();
92
93  /* default console to zero and override if multiprocessing */
94  uart0 = 0;
95  #if defined(RTEMS_MULTIPROCESSING)
96    if (rtems_configuration_get_user_multiprocessing_table() != NULL)
97      uart0 =  LEON3_Cpu_Index;
98  #endif
99
100  /*  Register Device Names */
101  if (uarts && (uart0 < uarts)) {
102    status = rtems_io_register_name( "/dev/console", major, 0 );
103    if (status != RTEMS_SUCCESSFUL)
104      rtems_fatal_error_occurred(status);
105
106    strcpy(console_name,"/dev/console_a");
107    for (i = uart0+1; i < uarts; i++) {
108      console_name[13]++;
109      status = rtems_io_register_name( console_name, major, i);
110    }
111  }
112
113  /*
114   *  Initialize Hardware if ONLY CPU or first CPU in MP system
115   */
116
117  #if defined(RTEMS_MULTIPROCESSING)
118    if (rtems_configuration_get_user_multiprocessing_table()->node == 1)
119  #endif
120  {
121    for (i = uart0; i < uarts; i++)
122    {
123      LEON3_Console_Uart[i]->ctrl |=
124        LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
125      LEON3_Console_Uart[i]->status = 0;
126    }
127  }
128
129  return RTEMS_SUCCESSFUL;
130}
131
132rtems_device_driver console_open(
133  rtems_device_major_number major,
134  rtems_device_minor_number minor,
135  void                    * arg
136)
137{
138  rtems_status_code sc;
139
140  static const rtems_termios_callbacks pollCallbacks = {
141    NULL,                        /* firstOpen */
142    NULL,                        /* lastClose */
143    console_inbyte_nonblocking,  /* pollRead */
144    console_write_support,       /* write */
145    NULL,                        /* setAttributes */
146    NULL,                        /* stopRemoteTx */
147    NULL,                        /* startRemoteTx */
148    0                            /* outputUsesInterrupts */
149  };
150
151
152  assert( minor <= LEON3_APBUARTS );
153  if ( minor > LEON3_APBUARTS )
154    return RTEMS_INVALID_NUMBER;
155
156  sc = rtems_termios_open (major, minor, arg, &pollCallbacks);
157
158
159  return RTEMS_SUCCESSFUL;
160}
161
162rtems_device_driver console_close(
163  rtems_device_major_number major,
164  rtems_device_minor_number minor,
165  void                    * arg
166)
167{
168  return rtems_termios_close (arg);
169}
170
171rtems_device_driver console_read(
172  rtems_device_major_number major,
173  rtems_device_minor_number minor,
174  void                    * arg
175)
176{
177  return rtems_termios_read (arg);
178}
179
180rtems_device_driver console_write(
181  rtems_device_major_number major,
182  rtems_device_minor_number minor,
183  void                    * arg
184)
185{
186  return rtems_termios_write (arg);
187}
188
189rtems_device_driver console_control(
190  rtems_device_major_number major,
191  rtems_device_minor_number minor,
192  void                    * arg
193)
194{
195  return rtems_termios_ioctl (arg);
196}
197
Note: See TracBrowser for help on using the repository browser.