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

4.104.114.95
Last change on this file since 2088669 was 2088669, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 21:53:35

2007-12-11 Joel Sherrill <joel.sherrill@…>

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