source: rtems/c/src/lib/libbsp/sparc/erc32/console/console.c @ 73c2d23

Last change on this file since 73c2d23 was 73c2d23, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 5, 2005 at 7:25:07 PM

2005-10-05 Jiri Gaisler <jiri@…>

Edvin Catovic <edvin@…>
Konrad Eisele <konrad@…>

PR 827/bsps

  • ChangeLog?, configure.ac, console/Makefile.am, console/console.c, console/debugputs.c, startup/Makefile.am, startup/linkcmds, tools/Makefile.am: Portion of large update of SPARC BSPs. Includes addition of sis, leon2 and leon3 BSPs, deletion of leon BSP, addition of SMC91111 NIC driver and much more.
  • Property mode set to 100644
File size: 9.9 KB
Line 
1/*
2 *  This file contains the TTY driver for the serial ports on the erc32.
3 *
4 *  This driver uses the termios pseudo driver.
5 *
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#include <bsp.h>
17#include <rtems/libio.h>
18#include <stdlib.h>
19#include <assert.h>
20#include <rtems/bspIo.h>
21
22/*
23 *  Should we use a polled or interrupt drived console?
24 * 
25 *  NOTE: This is defined in the custom/erc32.cfg file.
26 *
27 *  WARNING:  In sis 1.6, it did not appear that the UART interrupts
28 *            worked in a desirable fashion.  Immediately upon writing
29 *            a character into the TX buffer, an interrupt was generated.
30 *            This did not allow enough time for the program to put more
31 *            characters in the buffer.  So every character resulted in
32 *            "priming" the transmitter.   This effectively results in
33 *            in a polled console with a useless interrupt per character
34 *            on output.  It is reasonable to assume that input does not
35 *            share this problem although it was not investigated.
36 *
37 */
38
39/*
40 *  console_outbyte_polled
41 *
42 *  This routine transmits a character using polling.
43 */
44
45void console_outbyte_polled(
46  int  port,
47  char ch
48);
49
50/* body is in debugputs.c */
51
52/*
53 *  console_inbyte_nonblocking
54 *
55 *  This routine polls for a character.
56 */
57
58int console_inbyte_nonblocking( int port );
59
60/* body is in debugputs.c */
61
62/*
63 *  Interrupt driven console IO
64 */
65
66#if (CONSOLE_USE_INTERRUPTS)
67
68/*
69 *  Buffers between task and ISRs
70 */
71
72#include <ringbuf.h>
73 
74Ring_buffer_t  TX_Buffer[ 2 ];
75boolean        Is_TX_active[ 2 ];
76 
77void *console_termios_data[ 2 ];
78
79/*
80 *  console_isr_a
81 *
82 *  This routine is the console interrupt handler for Channel A.
83 *
84 *  Input parameters:
85 *    vector - vector number
86 *
87 *  Output parameters: NONE
88 *
89 *  Return values:     NONE
90 */
91
92rtems_isr console_isr_a(
93  rtems_vector_number vector
94)
95{ 
96  char ch;
97  int UStat;
98 
99  if ( (UStat = ERC32_MEC.UART_Status) & ERC32_MEC_UART_STATUS_DRA ) {
100    if (UStat & ERC32_MEC_UART_STATUS_ERRA) {
101      ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRA;
102      ERC32_MEC.Control = ERC32_MEC.Control;
103    }
104    ch = ERC32_MEC.UART_Channel_A;
105
106    rtems_termios_enqueue_raw_characters( console_termios_data[ 0 ], &ch, 1 );
107  }
108 
109  if ( ERC32_MEC.UART_Status & ERC32_MEC_UART_STATUS_THEA ) {
110    if ( !Ring_buffer_Is_empty( &TX_Buffer[ 0 ] ) ) {
111      Ring_buffer_Remove_character( &TX_Buffer[ 0 ], ch );
112      ERC32_MEC.UART_Channel_A = (unsigned32) ch;
113    } else
114     Is_TX_active[ 0 ] = FALSE;
115  }
116 
117  ERC32_Clear_interrupt( ERC32_INTERRUPT_UART_A_RX_TX );
118}
119
120/*
121 *  console_isr_b
122 *
123 *  This routine is the console interrupt handler for Channel B.
124 *
125 *  Input parameters:
126 *    vector - vector number
127 *
128 *  Output parameters: NONE
129 *
130 *  Return values:     NONE
131 */
132 
133rtems_isr console_isr_b(
134  rtems_vector_number vector
135)
136{
137  char ch;
138  int UStat;
139
140  if ( (UStat = ERC32_MEC.UART_Status) & ERC32_MEC_UART_STATUS_DRB ) {
141    if (UStat & ERC32_MEC_UART_STATUS_ERRB) {
142      ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRB;
143      ERC32_MEC.Control = ERC32_MEC.Control;
144    }
145    ch = ERC32_MEC.UART_Channel_B;
146    rtems_termios_enqueue_raw_characters( console_termios_data[ 1 ], &ch, 1 );
147
148  }
149
150  if ( ERC32_MEC.UART_Status & ERC32_MEC_UART_STATUS_THEB ) {
151    if ( !Ring_buffer_Is_empty( &TX_Buffer[ 1 ] ) ) {
152      Ring_buffer_Remove_character( &TX_Buffer[ 1 ], ch );
153      ERC32_MEC.UART_Channel_B = (unsigned32) ch;
154    } else
155     Is_TX_active[ 1 ] = FALSE;
156  }
157
158  ERC32_Clear_interrupt( ERC32_INTERRUPT_UART_B_RX_TX );
159}
160
161/*
162 *  console_exit
163 *
164 *  This routine allows the console to exit by masking its associated interrupt
165 *  vectors.
166 *
167 *  Input parameters:  NONE
168 *
169 *  Output parameters: NONE
170 *
171 *  Return values:     NONE
172 */
173
174void console_exit()
175{
176  rtems_unsigned32 port;
177  rtems_unsigned32 ch;
178
179  /*
180   *  Although the interrupts for the UART are unmasked, the PIL is set to
181   *  disable all external interrupts.  So we might as well do this first.
182   */
183
184  ERC32_Mask_interrupt( ERC32_INTERRUPT_UART_A_RX_TX );
185  ERC32_Mask_interrupt( ERC32_INTERRUPT_UART_B_RX_TX );
186
187  for ( port=0 ; port <= 1 ; port++ ) {
188    while ( !Ring_buffer_Is_empty( &TX_Buffer[ port ] ) ) {
189      Ring_buffer_Remove_character( &TX_Buffer[ port ], ch );
190      console_outbyte_polled( port, ch );
191    }
192  }
193
194  /*
195   *  Now wait for all the data to actually get out ... the send register
196   *  should be empty.
197   */
198 
199  while ( (ERC32_MEC.UART_Status & ERC32_MEC_UART_STATUS_THEA) != 
200          ERC32_MEC_UART_STATUS_THEA );
201
202  while ( (ERC32_MEC.UART_Status & ERC32_MEC_UART_STATUS_THEB) != 
203          ERC32_MEC_UART_STATUS_THEB );
204
205}
206
207#define CONSOLE_UART_A_TRAP  ERC32_TRAP_TYPE( ERC32_INTERRUPT_UART_A_RX_TX )
208#define CONSOLE_UART_B_TRAP  ERC32_TRAP_TYPE( ERC32_INTERRUPT_UART_B_RX_TX )
209
210/*
211 *  console_initialize_interrupts
212 *
213 *  This routine initializes the console's receive and transmit
214 *  ring buffers and loads the appropriate vectors to handle the interrupts.
215 *
216 *  Input parameters:  NONE
217 *
218 *  Output parameters: NONE
219 *
220 *  Return values:     NONE
221 */
222
223#ifdef RDB_BREAK_IN
224  extern unsigned32 trap_table[];
225#endif
226
227void console_initialize_interrupts( void )
228{
229  Ring_buffer_Initialize( &TX_Buffer[ 0 ] );
230  Ring_buffer_Initialize( &TX_Buffer[ 1 ] );
231
232  Is_TX_active[ 0 ] = FALSE;
233  Is_TX_active[ 1 ] = FALSE;
234
235  atexit( console_exit );
236
237  set_vector( console_isr_a, CONSOLE_UART_A_TRAP, 1 );
238#ifdef RDB_BREAK_IN
239  if (trap_table[0x150/4] == 0x91d02000)
240#endif
241  set_vector( console_isr_b, CONSOLE_UART_B_TRAP, 1 );
242}
243
244/*
245 *  console_outbyte_interrupt
246 *
247 *  This routine transmits a character out.
248 *
249 *  Input parameters:
250 *    port - port to transmit character to
251 *    ch  - character to be transmitted
252 *
253 *  Output parameters:  NONE
254 *
255 *  Return values:      NONE
256 */
257 
258void console_outbyte_interrupt(
259  int   port,
260  char  ch
261)
262{
263  /*
264   *  If this is the first character then we need to prime the pump
265   */
266
267  if ( Is_TX_active[ port ] == FALSE ) {
268    Is_TX_active[ port ] = TRUE;
269    console_outbyte_polled( port, ch );
270    return;
271  }
272
273  while ( Ring_buffer_Is_full( &TX_Buffer[ port ] ) );
274
275  Ring_buffer_Add_character( &TX_Buffer[ port ], ch );
276}
277
278#endif /* CONSOLE_USE_INTERRUPTS */
279
280/*
281 *  Console Termios Support Entry Points
282 *
283 */
284
285int console_write_support (int minor, const char *buf, int len)
286{
287  int nwrite = 0;
288
289  while (nwrite < len) {
290#if (CONSOLE_USE_INTERRUPTS)
291    console_outbyte_interrupt( minor, *buf++ );
292#else
293    console_outbyte_polled( minor, *buf++ );
294#endif
295    nwrite++;
296  }
297  return nwrite;
298}
299
300/*
301 *  Console Device Driver Entry Points
302 *
303 */
304 
305rtems_device_driver console_initialize(
306  rtems_device_major_number  major,
307  rtems_device_minor_number  minor,
308  void                      *arg
309)
310{
311  rtems_status_code status;
312
313  rtems_termios_initialize();
314
315  /*
316   *  Register Device Names
317   */
318
319  status = rtems_io_register_name( "/dev/console", major, 0 );
320  if (status != RTEMS_SUCCESSFUL)
321    rtems_fatal_error_occurred(status);
322
323  status = rtems_io_register_name( "/dev/console_b", major, 1 );
324  if (status != RTEMS_SUCCESSFUL)
325    rtems_fatal_error_occurred(status);
326
327  /*
328   *  Initialize Hardware
329   */
330 
331#if (CONSOLE_USE_INTERRUPTS)
332  console_initialize_interrupts();
333#endif
334
335  return RTEMS_SUCCESSFUL;
336}
337
338rtems_device_driver console_open(
339  rtems_device_major_number major,
340  rtems_device_minor_number minor,
341  void                    * arg
342)
343{
344  rtems_status_code sc;
345#if (CONSOLE_USE_INTERRUPTS)
346  rtems_libio_open_close_args_t *args = arg;
347  static const rtems_termios_callbacks intrCallbacks = {
348    NULL,                        /* firstOpen */
349    NULL,                        /* lastClose */
350    NULL,                        /* pollRead */
351    console_write_support,       /* write */
352    NULL,                        /* setAttributes */
353    NULL,                        /* stopRemoteTx */
354    NULL,                        /* startRemoteTx */
355    0                            /* outputUsesInterrupts */
356  };
357#else
358  static const rtems_termios_callbacks pollCallbacks = {
359    NULL,                        /* firstOpen */
360    NULL,                        /* lastClose */
361    console_inbyte_nonblocking,  /* pollRead */
362    console_write_support,       /* write */
363    NULL,                        /* setAttributes */
364    NULL,                        /* stopRemoteTx */
365    NULL,                        /* startRemoteTx */
366    0                            /* outputUsesInterrupts */
367  };
368#endif
369
370  assert( minor <= 1 );
371  if ( minor > 2 )
372    return RTEMS_INVALID_NUMBER;
373 
374#if (CONSOLE_USE_INTERRUPTS)
375  sc = rtems_termios_open (major, minor, arg, &intrCallbacks);
376
377  console_termios_data[ minor ] = args->iop->data1;
378#else
379  sc = rtems_termios_open (major, minor, arg, &pollCallbacks);
380#endif
381
382  return RTEMS_SUCCESSFUL;
383}
384 
385rtems_device_driver console_close(
386  rtems_device_major_number major,
387  rtems_device_minor_number minor,
388  void                    * arg
389)
390{
391  return rtems_termios_close (arg);
392}
393 
394rtems_device_driver console_read(
395  rtems_device_major_number major,
396  rtems_device_minor_number minor,
397  void                    * arg
398)
399{
400  return rtems_termios_read (arg);
401}
402 
403rtems_device_driver console_write(
404  rtems_device_major_number major,
405  rtems_device_minor_number minor,
406  void                    * arg
407)
408{
409  return rtems_termios_write (arg);
410}
411 
412rtems_device_driver console_control(
413  rtems_device_major_number major,
414  rtems_device_minor_number minor,
415  void                    * arg
416)
417{
418  return rtems_termios_ioctl (arg);
419}
420
421/* putchar/getchar for printk */
422
423static void bsp_out_char (char c)
424{
425  console_outbyte_polled(0, c);
426}
427
428BSP_output_char_function_type BSP_output_char = bsp_out_char;
429
430static char bsp_in_char(void)
431{
432  int tmp;
433
434  while ((tmp = console_inbyte_nonblocking(0)) < 0);
435  return (char) tmp;
436}
437
438BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
439
440
Note: See TracBrowser for help on using the repository browser.