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

4.104.114.84.95
Last change on this file since 41c9282 was 41c9282, checked in by Ralf Corsepius <ralf.corsepius@…>, on Jan 9, 2006 at 10:41:21 AM

Backport from rtems-4-6-branch.

  • Property mode set to 100644
File size: 5.1 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
26/*
27 *  Should we use a polled or interrupt drived console?
28 * 
29 *  NOTE: This is defined in the custom/leon.cfg file.
30 *
31 *  WARNING:  In sis 1.6, it did not appear that the UART interrupts
32 *            worked in a desirable fashion.  Immediately upon writing
33 *            a character into the TX buffer, an interrupt was generated.
34 *            This did not allow enough time for the program to put more
35 *            characters in the buffer.  So every character resulted in
36 *            "priming" the transmitter.   This effectively results in
37 *            in a polled console with a useless interrupt per character
38 *            on output.  It is reasonable to assume that input does not
39 *            share this problem although it was not investigated.
40 *
41 */
42
43/*
44 *  console_outbyte_polled
45 *
46 *  This routine transmits a character using polling.
47 */
48
49void console_outbyte_polled(
50  int  port,
51  char ch
52);
53
54/* body is in debugputs.c */
55
56/*
57 *  console_inbyte_nonblocking
58 *
59 *  This routine polls for a character.
60 */
61
62int console_inbyte_nonblocking( int port );
63
64/* body is in debugputs.c */
65
66
67/*
68 *  Console Termios Support Entry Points
69 *
70 */
71
72int console_write_support (int minor, const char *buf, int len)
73{
74  int nwrite = 0;
75
76  while (nwrite < len) {
77    console_outbyte_polled( minor, *buf++ );
78    nwrite++;
79  }
80  return nwrite;
81}
82
83
84/*
85 *  Console Device Driver Entry Points
86 *
87 */
88
89volatile LEON3_UART_Regs_Map *LEON3_Console_Uart[LEON3_APBUARTS]; 
90
91rtems_device_driver console_initialize(
92  rtems_device_major_number  major,
93  rtems_device_minor_number  minor,
94  void                      *arg
95)
96{
97  rtems_status_code status;
98  unsigned int iobar, conf;
99  int i, uarts;
100  char *console_name = "/dev/console_a";
101
102
103  rtems_termios_initialize();
104
105  /* Find UARTs */
106 
107  i = 0; uarts = 0;
108  while (i < amba_conf.apbslv.devnr) 
109  {
110    conf = amba_get_confword(amba_conf.apbslv, i, 0);
111    if ((amba_vendor(conf) == VENDOR_GAISLER) && (amba_device(conf) == GAISLER_APBUART))
112    {
113      iobar = amba_apb_get_membar(amba_conf.apbslv, i);     
114      LEON3_Console_Uart[uarts] = (volatile LEON3_UART_Regs_Map *) amba_iobar_start(amba_conf.apbmst, iobar);
115      uarts++;
116    }
117    i++;
118  }
119
120  /*  Register Device Names */
121 
122  if (uarts) 
123  { 
124    status = rtems_io_register_name( "/dev/console", major, 0 );
125    if (status != RTEMS_SUCCESSFUL)
126      rtems_fatal_error_occurred(status);
127
128    for (i = 1; i < uarts; i++)
129    {
130      console_name[13]++;
131      status = rtems_io_register_name( console_name, major, i);
132    }
133  }
134
135
136  /*
137   *  Initialize Hardware
138   */
139
140  for (i = 0; i < uarts; i++)
141  {
142    LEON3_Console_Uart[i]->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
143    LEON3_Console_Uart[i]->status = 0; 
144  }
145
146  return RTEMS_SUCCESSFUL;
147}
148
149rtems_device_driver console_open(
150  rtems_device_major_number major,
151  rtems_device_minor_number minor,
152  void                    * arg
153)
154{
155  rtems_status_code sc;
156
157  static const rtems_termios_callbacks pollCallbacks = {
158    NULL,                        /* firstOpen */
159    NULL,                        /* lastClose */
160    console_inbyte_nonblocking,  /* pollRead */
161    console_write_support,       /* write */
162    NULL,                        /* setAttributes */
163    NULL,                        /* stopRemoteTx */
164    NULL,                        /* startRemoteTx */
165    0                            /* outputUsesInterrupts */
166  };
167
168
169  assert( minor <= LEON3_APBUARTS );
170  if ( minor > LEON3_APBUARTS )
171    return RTEMS_INVALID_NUMBER;
172 
173  sc = rtems_termios_open (major, minor, arg, &pollCallbacks);
174
175
176  return RTEMS_SUCCESSFUL;
177}
178 
179rtems_device_driver console_close(
180  rtems_device_major_number major,
181  rtems_device_minor_number minor,
182  void                    * arg
183)
184{
185  return rtems_termios_close (arg);
186}
187 
188rtems_device_driver console_read(
189  rtems_device_major_number major,
190  rtems_device_minor_number minor,
191  void                    * arg
192)
193{
194  return rtems_termios_read (arg);
195}
196 
197rtems_device_driver console_write(
198  rtems_device_major_number major,
199  rtems_device_minor_number minor,
200  void                    * arg
201)
202{
203  return rtems_termios_write (arg);
204}
205 
206rtems_device_driver console_control(
207  rtems_device_major_number major,
208  rtems_device_minor_number minor,
209  void                    * arg
210)
211{
212  return rtems_termios_ioctl (arg);
213}
214
215/* putchar/getchar for printk */
216
217static void bsp_out_char(char c)
218{
219  console_outbyte_polled(0, c);
220}
221
222BSP_output_char_function_type BSP_output_char = bsp_out_char;
223
224static char bsp_in_char(void)
225{
226  int tmp;
227
228  while ((tmp = console_inbyte_nonblocking(0)) < 0);
229  return (char) tmp;
230}
231
232BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
Note: See TracBrowser for help on using the repository browser.