source: rtems/c/src/lib/libbsp/sparc/leon/console/console.c @ b21b0ab

4.104.114.84.95
Last change on this file since b21b0ab was b21b0ab, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 13, 2000 at 10:40:29 PM

2000-11-13 Jiri Gaisler <jgais@…>

  • .cvsignore, ChangeLog?, Makefile.am, README, bsp_specs, configure.in, times, clock/.cvsignore, clock/Makefile.am, clock/ckinit.c, console/.cvsignore, console/Makefile.am, console/console.c, console/consolereserveresources.c, console/debugputs.c, gnatsupp/.cvsignore, gnatsupp/Makefile.am, gnatsupp/gnatsupp.c, include/.cvsignore, include/Makefile.am, include/bsp.h, include/coverhd.h, include/leon.h, start/.cvsignore, start/Makefile.am, startup/.cvsignore, startup/Makefile.am, startup/boardinit.S, startup/linkcmds, startup/setvec.c, startup/spurious.c, timer/.cvsignore, timer/Makefile.am, timer/timer.c, tools/.cvsignore, tools/Makefile.am, tools/configure.in, tools/runtest.in, wrapup/.cvsignore, wrapup/Makefile.am: New file.
  • Property mode set to 100644
File size: 10.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 *  Copyright assigned to U.S. Government, 1994.
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.OARcorp.com/rtems/license.html.
13 *
14 *  $Id$
15 */
16
17#include <bsp.h>
18#include <rtems/libio.h>
19#include <stdlib.h>
20#include <assert.h>
21
22/*
23 *  Should we use a polled or interrupt drived console?
24 * 
25 *  NOTE: This is defined in the custom/leon.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 1.
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 = LEON_REG.UART_Status_1) & LEON_REG_UART_STATUS_DR ) {
100    if (UStat & LEON_REG_UART_STATUS_ERR) {
101      LEON_REG.UART_Status_1 = LEON_REG_UART_STATUS_CLR;
102    }
103    ch = LEON_REG.UART_Channel_1;
104
105    rtems_termios_enqueue_raw_characters( console_termios_data[ 0 ], &ch, 1 );
106  }
107 
108  if ( LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_THE ) {
109    if ( !Ring_buffer_Is_empty( &TX_Buffer[ 0 ] ) ) {
110      Ring_buffer_Remove_character( &TX_Buffer[ 0 ], ch );
111      LEON_REG.UART_Channel_1 = (unsigned32) ch;
112    } else
113     Is_TX_active[ 0 ] = FALSE;
114  }
115 
116  LEON_Clear_interrupt( LEON_INTERRUPT_UART_1_RX_TX );
117}
118
119/*
120 *  console_isr_b
121 *
122 *  This routine is the console interrupt handler for Channel 2.
123 *
124 *  Input parameters:
125 *    vector - vector number
126 *
127 *  Output parameters: NONE
128 *
129 *  Return values:     NONE
130 */
131 
132rtems_isr console_isr_b(
133  rtems_vector_number vector
134)
135{
136  char ch;
137  int UStat;
138
139  if ( (UStat = LEON_REG.UART_Status_2) & LEON_REG_UART_STATUS_DR ) {
140    if (UStat & LEON_REG_UART_STATUS_ERR) {
141      LEON_REG.UART_Status_2 = LEON_REG_UART_STATUS_CLR;
142    }
143    ch = LEON_REG.UART_Channel_2;
144    rtems_termios_enqueue_raw_characters( console_termios_data[ 1 ], &ch, 1 );
145
146  }
147
148  if ( LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_THE ) {
149    if ( !Ring_buffer_Is_empty( &TX_Buffer[ 1 ] ) ) {
150      Ring_buffer_Remove_character( &TX_Buffer[ 1 ], ch );
151      LEON_REG.UART_Channel_2 = (unsigned32) ch;
152    } else
153     Is_TX_active[ 1 ] = FALSE;
154  }
155
156  LEON_Clear_interrupt( LEON_INTERRUPT_UART_2_RX_TX );
157}
158
159/*
160 *  console_exit
161 *
162 *  This routine allows the console to exit by masking its associated interrupt
163 *  vectors.
164 *
165 *  Input parameters:  NONE
166 *
167 *  Output parameters: NONE
168 *
169 *  Return values:     NONE
170 */
171
172void console_exit()
173{
174  rtems_unsigned32 port;
175  rtems_unsigned32 ch;
176
177  /*
178   *  Although the interrupts for the UART are unmasked, the PIL is set to
179   *  disable all external interrupts.  So we might as well do this first.
180   */
181
182  LEON_Mask_interrupt( LEON_INTERRUPT_UART_1_RX_TX );
183  LEON_Mask_interrupt( LEON_INTERRUPT_UART_2_RX_TX );
184
185  for ( port=0 ; port <= 1 ; port++ ) {
186    while ( !Ring_buffer_Is_empty( &TX_Buffer[ port ] ) ) {
187      Ring_buffer_Remove_character( &TX_Buffer[ port ], ch );
188      console_outbyte_polled( port, ch );
189    }
190  }
191
192  /*
193   *  Now wait for all the data to actually get out ... the send register
194   *  should be empty.
195   */
196 
197  while ( (LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_THE) != 
198          LEON_REG_UART_STATUS_THE );
199
200  while ( (LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_THE) != 
201          LEON_REG_UART_STATUS_THE );
202
203  LEON_REG.UART_Control_1 = 0;
204  LEON_REG.UART_Control_2 = 0;
205  LEON_REG.UART_Status_1 = 0;
206  LEON_REG.UART_Status_2 = 0;
207
208
209}
210
211#define CONSOLE_UART_1_TRAP  LEON_TRAP_TYPE( LEON_INTERRUPT_UART_1_RX_TX )
212#define CONSOLE_UART_2_TRAP  LEON_TRAP_TYPE( LEON_INTERRUPT_UART_2_RX_TX )
213
214/*
215 *  console_initialize_interrupts
216 *
217 *  This routine initializes the console's receive and transmit
218 *  ring buffers and loads the appropriate vectors to handle the interrupts.
219 *
220 *  Input parameters:  NONE
221 *
222 *  Output parameters: NONE
223 *
224 *  Return values:     NONE
225 */
226
227#ifdef RDB_BREAK_IN
228  extern unsigned32 trap_table[];
229#endif
230
231void console_initialize_interrupts( void )
232{
233  Ring_buffer_Initialize( &TX_Buffer[ 0 ] );
234  Ring_buffer_Initialize( &TX_Buffer[ 1 ] );
235
236  Is_TX_active[ 0 ] = FALSE;
237  Is_TX_active[ 1 ] = FALSE;
238
239  atexit( console_exit );
240
241  LEON_REG.UART_Control_1 |= LEON_REG_UART_CTRL_RI | LEON_REG_UART_CTRL_TI;
242  LEON_REG.UART_Control_2 |= LEON_REG_UART_CTRL_RI | LEON_REG_UART_CTRL_TI;
243
244  set_vector( console_isr_a, CONSOLE_UART_1_TRAP, 1 );
245#ifdef RDB_BREAK_IN
246  if (trap_table[0x150/4] == 0x91d02000)
247#endif
248  set_vector( console_isr_b, CONSOLE_UART_2_TRAP, 1 );
249}
250
251/*
252 *  console_outbyte_interrupt
253 *
254 *  This routine transmits a character out.
255 *
256 *  Input parameters:
257 *    port - port to transmit character to
258 *    ch  - character to be transmitted
259 *
260 *  Output parameters:  NONE
261 *
262 *  Return values:      NONE
263 */
264 
265void console_outbyte_interrupt(
266  int   port,
267  char  ch
268)
269{
270  /*
271   *  If this is the first character then we need to prime the pump
272   */
273
274  if ( Is_TX_active[ port ] == FALSE ) {
275    Is_TX_active[ port ] = TRUE;
276    console_outbyte_polled( port, ch );
277    return;
278  }
279
280  while ( Ring_buffer_Is_full( &TX_Buffer[ port ] ) );
281
282  Ring_buffer_Add_character( &TX_Buffer[ port ], ch );
283}
284
285#endif /* CONSOLE_USE_INTERRUPTS */
286
287/*
288 *  Console Termios Support Entry Points
289 *
290 */
291
292int console_write_support (int minor, const char *buf, int len)
293{
294  int nwrite = 0;
295
296  while (nwrite < len) {
297#if (CONSOLE_USE_INTERRUPTS)
298    console_outbyte_interrupt( minor, *buf++ );
299#else
300    console_outbyte_polled( minor, *buf++ );
301#endif
302    nwrite++;
303  }
304  return nwrite;
305}
306
307void console_reserve_resources(
308  rtems_configuration_table *configuration
309)
310{
311  rtems_termios_reserve_resources( configuration, 2 );
312}
313
314/*
315 *  Console Device Driver Entry Points
316 *
317 */
318 
319rtems_device_driver console_initialize(
320  rtems_device_major_number  major,
321  rtems_device_minor_number  minor,
322  void                      *arg
323)
324{
325  rtems_status_code status;
326
327  rtems_termios_initialize();
328
329  /*
330   *  Register Device Names
331   */
332
333  status = rtems_io_register_name( "/dev/console", major, 0 );
334  if (status != RTEMS_SUCCESSFUL)
335    rtems_fatal_error_occurred(status);
336
337  status = rtems_io_register_name( "/dev/console_b", major, 1 );
338  if (status != RTEMS_SUCCESSFUL)
339    rtems_fatal_error_occurred(status);
340
341  /*
342   *  Initialize Hardware
343   */
344 
345  LEON_REG.UART_Control_1 = LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
346  LEON_REG.UART_Control_2 = LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE |
347        LEON_REG_UART_CTRL_RI;  /* rx irq default enable for remote debugger */
348  LEON_REG.UART_Status_1 = 0;
349  LEON_REG.UART_Status_2 = 0;
350#if (CONSOLE_USE_INTERRUPTS)
351  console_initialize_interrupts();
352#endif
353
354  return RTEMS_SUCCESSFUL;
355}
356
357rtems_device_driver console_open(
358  rtems_device_major_number major,
359  rtems_device_minor_number minor,
360  void                    * arg
361)
362{
363  rtems_status_code sc;
364#if (CONSOLE_USE_INTERRUPTS)
365  rtems_libio_open_close_args_t *args = arg;
366  static const rtems_termios_callbacks intrCallbacks = {
367    NULL,                        /* firstOpen */
368    NULL,                        /* lastClose */
369    NULL,                        /* pollRead */
370    console_write_support,       /* write */
371    NULL,                        /* setAttributes */
372    NULL,                        /* stopRemoteTx */
373    NULL,                        /* startRemoteTx */
374    0                            /* outputUsesInterrupts */
375  };
376#else
377  static const rtems_termios_callbacks pollCallbacks = {
378    NULL,                        /* firstOpen */
379    NULL,                        /* lastClose */
380    console_inbyte_nonblocking,  /* pollRead */
381    console_write_support,       /* write */
382    NULL,                        /* setAttributes */
383    NULL,                        /* stopRemoteTx */
384    NULL,                        /* startRemoteTx */
385    0                            /* outputUsesInterrupts */
386  };
387#endif
388
389  assert( minor <= 1 );
390  if ( minor > 2 )
391    return RTEMS_INVALID_NUMBER;
392 
393#if (CONSOLE_USE_INTERRUPTS)
394  sc = rtems_termios_open (major, minor, arg, &intrCallbacks);
395
396  console_termios_data[ minor ] = args->iop->data1;
397#else
398  sc = rtems_termios_open (major, minor, arg, &pollCallbacks);
399#endif
400
401  return RTEMS_SUCCESSFUL;
402}
403 
404rtems_device_driver console_close(
405  rtems_device_major_number major,
406  rtems_device_minor_number minor,
407  void                    * arg
408)
409{
410  return rtems_termios_close (arg);
411}
412 
413rtems_device_driver console_read(
414  rtems_device_major_number major,
415  rtems_device_minor_number minor,
416  void                    * arg
417)
418{
419  return rtems_termios_read (arg);
420}
421 
422rtems_device_driver console_write(
423  rtems_device_major_number major,
424  rtems_device_minor_number minor,
425  void                    * arg
426)
427{
428  return rtems_termios_write (arg);
429}
430 
431rtems_device_driver console_control(
432  rtems_device_major_number major,
433  rtems_device_minor_number minor,
434  void                    * arg
435)
436{
437  return rtems_termios_ioctl (arg);
438}
439
Note: See TracBrowser for help on using the repository browser.