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

4.104.115
Last change on this file since 44b06ca was 44b06ca, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 15:33:28

Whitespace removal.

  • Property mode set to 100644
File size: 4.6 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
62int console_write_support (int minor, const char *buf, int 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;
79static int isinit = 0;
80volatile LEON3_UART_Regs_Map *LEON3_Console_Uart[LEON3_APBUARTS];
81
82int scan_uarts(void) {
83  int i;
84  amba_apb_device apbuarts[LEON3_APBUARTS];
85
86  if (isinit == 0) {
87    i = 0;
88    uarts = 0;
89
90    uarts = amba_find_apbslvs(
91      &amba_conf, VENDOR_GAISLER, GAISLER_APBUART, apbuarts, LEON3_APBUARTS);
92    for(i=0; i<uarts; i++) {
93      LEON3_Console_Uart[i] = (volatile LEON3_UART_Regs_Map *)apbuarts[i].start;
94    }
95    isinit = 1;
96  }
97  return uarts;
98}
99
100rtems_device_driver console_initialize(
101  rtems_device_major_number  major,
102  rtems_device_minor_number  minor,
103  void                      *arg
104)
105{
106  rtems_status_code status;
107  int i, uart0;
108  char console_name[16];
109
110  rtems_termios_initialize();
111
112  /* Find UARTs */
113  scan_uarts();
114
115  /* default to zero and override if multiprocessing */
116  uart0 = 0;
117  #if defined(RTEMS_MULTIPROCESSING)
118    if (rtems_configuration_get_user_multiprocessing_table() != NULL)
119      uart0 =  LEON3_Cpu_Index;
120  #endif
121
122  /*  Register Device Names */
123
124  if (uarts && (uart0 < uarts))
125  {
126    status = rtems_io_register_name( "/dev/console", major, 0 );
127    if (status != RTEMS_SUCCESSFUL)
128      rtems_fatal_error_occurred(status);
129
130    strcpy(console_name,"/dev/console_a");
131    for (i = uart0+1; i < uarts; i++)
132    {
133      console_name[13]++;
134      status = rtems_io_register_name( console_name, major, i);
135    }
136  }
137
138
139  /*
140   *  Initialize Hardware if ONLY CPU or first CPU in MP system
141   */
142
143  #if defined(RTEMS_MULTIPROCESSING)
144    if (rtems_configuration_get_user_multiprocessing_table()->node == 1)
145  #endif
146  {
147    for (i = uart0; i < uarts; i++)
148    {
149      LEON3_Console_Uart[i]->ctrl |=
150        LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
151      LEON3_Console_Uart[i]->status = 0;
152    }
153  }
154
155  return RTEMS_SUCCESSFUL;
156}
157
158rtems_device_driver console_open(
159  rtems_device_major_number major,
160  rtems_device_minor_number minor,
161  void                    * arg
162)
163{
164  rtems_status_code sc;
165
166  static const rtems_termios_callbacks pollCallbacks = {
167    NULL,                        /* firstOpen */
168    NULL,                        /* lastClose */
169    console_inbyte_nonblocking,  /* pollRead */
170    console_write_support,       /* write */
171    NULL,                        /* setAttributes */
172    NULL,                        /* stopRemoteTx */
173    NULL,                        /* startRemoteTx */
174    0                            /* outputUsesInterrupts */
175  };
176
177
178  assert( minor <= LEON3_APBUARTS );
179  if ( minor > LEON3_APBUARTS )
180    return RTEMS_INVALID_NUMBER;
181
182  sc = rtems_termios_open (major, minor, arg, &pollCallbacks);
183
184
185  return RTEMS_SUCCESSFUL;
186}
187
188rtems_device_driver console_close(
189  rtems_device_major_number major,
190  rtems_device_minor_number minor,
191  void                    * arg
192)
193{
194  return rtems_termios_close (arg);
195}
196
197rtems_device_driver console_read(
198  rtems_device_major_number major,
199  rtems_device_minor_number minor,
200  void                    * arg
201)
202{
203  return rtems_termios_read (arg);
204}
205
206rtems_device_driver console_write(
207  rtems_device_major_number major,
208  rtems_device_minor_number minor,
209  void                    * arg
210)
211{
212  return rtems_termios_write (arg);
213}
214
215rtems_device_driver console_control(
216  rtems_device_major_number major,
217  rtems_device_minor_number minor,
218  void                    * arg
219)
220{
221  return rtems_termios_ioctl (arg);
222}
223
Note: See TracBrowser for help on using the repository browser.