source: rtems/c/src/lib/libbsp/powerpc/score603e/console/console.c @ bb41881e

4.104.114.84.95
Last change on this file since bb41881e was bb41881e, checked in by Jennifer Averett <Jennifer.Averett@…>, on 04/28/05 at 14:16:29

2005-04-28 Jennifer Averett <jennifer.averett@…>

  • score603e/Makefile.am, score603e/configure.ac, score603e/console/console.c, score603e/include/bsp.h, score603e/include/gen2.h, score603e/include/tm27.h, score603e/startup/bspstart.c: Update score603e to new exception model NOTE: These modifications have not been tested on hardware.
  • Property mode set to 100644
File size: 10.2 KB
Line 
1/*
2 *  This file contains the TTY driver for the serial ports on the SCORE603e.
3 *
4 *  This driver uses the termios pseudo driver.
5 *
6 *  Currently only polled mode is supported.
7 *
8 *  COPYRIGHT (c) 1989-1997.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#include <bsp.h>
19#include <rtems/libio.h>
20#include <stdlib.h>
21#include <assert.h>
22
23#include "consolebsp.h"
24#include <rtems/bspIo.h>
25
26#if (1)
27/*
28 * The Port Used for the Console interface is based upon which
29 * debugger is being used.  The SDS debugger uses a binary
30 * interface on port 0 as part of the debugger.  Thus port 0 can
31 * not be used as the console port for the SDS debugger.
32 */
33
34#if (SCORE603E_USE_SDS)
35#define USE_FOR_CONSOLE_DEF  1
36
37#elif (SCORE603E_USE_OPEN_FIRMWARE)
38#define USE_FOR_CONSOLE_DEF  0
39
40#elif (SCORE603E_USE_NONE)
41#define USE_FOR_CONSOLE_DEF  0
42
43#elif (SCORE603E_USE_DINK)
44#define USE_FOR_CONSOLE_DEF  0
45
46#else
47#error "SCORE603E CONSOLE.C -- what ROM monitor are you using"
48#endif
49
50#endif
51
52#if (0)
53extern int USE_FOR_CONSOLE;
54#endif
55
56int USE_FOR_CONSOLE = USE_FOR_CONSOLE_DEF;
57
58/*
59 *
60 *  Console Device Driver Entry Points
61 */
62
63/* PAGE
64 *
65 *  DEBUG_puts
66 *
67 *  This should be safe in the event of an error.  It attempts to insure
68 *  that no TX empty interrupts occur while it is doing polled IO.  Then
69 *  it restores the state of that external interrupt.
70 *
71 *  Input parameters:
72 *    string  - pointer to debug output string
73 *
74 *  Output parameters:  NONE
75 *
76 *  Return values:      NONE
77 */
78
79void DEBUG_puts(
80  char *string
81)
82{
83  char *s;
84  int   console;
85  volatile uint8_t         *csr;
86
87  console = USE_FOR_CONSOLE;
88
89  csr = Ports_85C30[ console ].ctrl;
90
91  /* should disable interrupts here */
92
93  for ( s = string ; *s ; s++ )
94    outbyte_polled_85c30( csr, *s );
95
96  outbyte_polled_85c30( csr, '\r' );
97  outbyte_polled_85c30( csr, '\n' );
98
99  /* should enable interrupts here */
100}
101
102/* PAGE
103 *
104 *  console_inbyte_nonblocking
105 *
106 *  Console Termios polling input entry point.
107 */
108
109int console_inbyte_nonblocking(
110  int minor
111)
112{
113  int                       port = minor;
114
115  /*
116   * verify port Number
117   */
118  assert ( port < NUM_Z85C30_PORTS );
119
120  /*
121   * return a character from the 85c30 port.
122   */
123  return inbyte_nonblocking_85c30( &Ports_85C30[ port ] );
124}
125
126rtems_device_driver console_close(
127  rtems_device_major_number major,
128  rtems_device_minor_number minor,
129  void                    * arg
130)
131{
132  return rtems_termios_close (arg);
133}
134
135rtems_device_driver console_read(
136  rtems_device_major_number major,
137  rtems_device_minor_number minor,
138  void                    * arg
139)
140{
141  return rtems_termios_read (arg);
142}
143
144rtems_device_driver console_write(
145  rtems_device_major_number major,
146  rtems_device_minor_number minor,
147  void                    * arg
148)
149{
150  return rtems_termios_write (arg);
151}
152
153rtems_device_driver console_control(
154  rtems_device_major_number major,
155  rtems_device_minor_number minor,
156  void                    * arg
157)
158{
159  return rtems_termios_ioctl (arg);
160}
161
162/*
163 *  Interrupt driven console IO
164 */
165
166#if CONSOLE_USE_INTERRUPTS
167
168rtems_isr console_isr(
169  rtems_vector_number vector
170)
171{
172  int  i;
173
174  for (i=0; i < NUM_Z85C30_PORTS; i++){
175      ISR_85c30_Async( &Ports_85C30[i] );
176
177#if (0) /* XXX - TO TEST LOOP BACKS comment this out. */
178    if ( Ports_85C30[i].Chip->vector == vector ) {
179      ISR_85c30_Async( &Ports_85C30[i] );
180    }
181#endif
182  }
183}
184
185void console_exit()
186{
187  int i;
188  volatile Ring_buffer_t *buffer;
189  uint32_t         ch;
190
191  for ( i=0 ; i < NUM_Z85C30_PORTS ; i++ ) {
192
193    buffer = &( Ports_85C30[i].Protocol->TX_Buffer);
194
195    while ( !Ring_buffer_Is_empty( buffer ) ) {
196      Ring_buffer_Remove_character( buffer, ch );
197      outbyte_polled_85c30( Ports_85C30[i].ctrl, ch );
198    }
199  }
200}
201
202void console_initialize_interrupts( void )
203{
204  volatile Ring_buffer_t     *buffer;
205  Console_Protocol  *protocol;
206  int               i;
207
208  for ( i=0 ; i < NUM_Z85C30_PORTS ; i++ ) {
209    protocol = Ports_85C30[i].Protocol;
210
211    /*
212     * Initialize the ring buffer and set to not transmitting.
213     */
214    buffer = &protocol->TX_Buffer;
215    Ring_buffer_Initialize( buffer );
216    protocol->Is_TX_active = FALSE;
217  }
218
219  /*
220   * Connect each vector to the interupt service routine.
221   */
222  for (i=0; i < NUM_Z85C30_CHIPS; i++)
223    set_vector( console_isr, Chips_85C30[i].vector, 1 );
224
225  atexit( console_exit );
226
227}
228void console_outbyte_interrupts(
229  const Port_85C30_info *Port,
230  char ch
231);
232
233/* XXXXXX */
234#endif
235
236/* PAGE
237 *
238 *  console_initialize
239 *
240 *  Routine called to initialize the console device driver.
241 */
242rtems_device_driver console_initialize(
243  rtems_device_major_number  major,
244  rtems_device_minor_number  minor,
245  void                      *arg
246)
247{
248  rtems_status_code          status;
249  rtems_device_minor_number  console;
250  int                        port, chip, p0,p1;
251
252  /*
253   * initialize the termio interface.
254   */
255  rtems_termios_initialize();
256
257  /*
258   *  Register Device Names
259   */
260  console = USE_FOR_CONSOLE;
261  status = rtems_io_register_name( "/dev/console", major, console );
262  if (status != RTEMS_SUCCESSFUL)
263    rtems_fatal_error_occurred(status);
264
265  /*
266   *  Initialize Hardware
267   */
268
269/*
270 * INITIALIZE_COM_PORTS is defined in the linker script.  If it is
271 * true all serial chips on the board are to be reset at startup
272 * otherwise the reset is assumed to occur elsewhere (ie. in the
273 * debugger...)
274 */
275#if ( INITIALIZE_COM_PORTS )
276
277  /*
278   * Force to perform a hardware reset w/o
279   * Master interrupt enable via register 9
280   */
281
282  for (port=0; port<NUM_Z85C30_PORTS; port++){
283    p0 = port;
284    port++;
285    p1 = port;
286    Reset_85c30_chip( Ports_85C30[p0].ctrl, Ports_85C30[p1].ctrl );
287  }
288#else
289  /* TEMP - To see if this makes a diff with the new ports.
290   *        Never reset chip 1 when using the chip as a monitor
291   */
292  for (port=2; port<NUM_Z85C30_PORTS; port++){
293    p0 = port;
294    port++;
295    p1 = port;
296    Reset_85c30_chip( Ports_85C30[p0].ctrl, Ports_85C30[p1].ctrl );
297  }
298#endif
299
300  /*
301   * Initialize each port.
302   * Note:  the ports are numbered such that 0,1 are on the first chip
303   *        2,3 are on the second ....
304   */
305
306  for (port=0; port<NUM_Z85C30_PORTS; port++) {
307    chip = port >> 1;
308    initialize_85c30_port( &Ports_85C30[port] );
309  }
310
311#if CONSOLE_USE_INTERRUPTS
312  console_initialize_interrupts();
313#endif
314
315  return RTEMS_SUCCESSFUL;
316}
317
318/* PAGE
319 *
320 *  console_write_support
321 *
322 *  Console Termios output entry point.
323 *
324 */
325int console_write_support(
326  int   minor,
327  const char *buf,
328  int   len)
329{
330  int nwrite = 0;
331  volatile uint8_t         *csr;
332  int                       port = minor;
333
334  /*
335   * verify port Number
336   */
337  assert ( port < NUM_Z85C30_PORTS );
338
339  /*
340   * Set the csr based upon the port number.
341   */
342  csr = Ports_85C30[ port ].ctrl;
343
344  /*
345   * poll each byte in the string out of the port.
346   */
347  while (nwrite < len) {
348#if (CONSOLE_USE_INTERRUPTS)
349    console_outbyte_interrupts( &Ports_85C30[ port ], *buf++ );
350#else
351    outbyte_polled_85c30( csr, *buf++ );
352#endif
353   nwrite++;
354  }
355
356  /*
357   * return the number of bytes written.
358   */
359  return nwrite;
360}
361
362/* PAGE
363 *
364 *  console_open
365 *
366 *  open a port as a termios console.
367 *
368 */
369rtems_device_driver console_open(
370  rtems_device_major_number major,
371  rtems_device_minor_number minor,
372  void                    * arg
373)
374{
375  rtems_status_code sc;
376  int               port = minor;
377#if (CONSOLE_USE_INTERRUPTS)
378  rtems_libio_open_close_args_t *args = arg;
379  static const rtems_termios_callbacks intrCallbacks = {
380    NULL,                       /* firstOpen */
381    NULL,                       /* lastClose */
382    NULL,                       /* pollRead */
383    console_write_support,      /* write */
384    NULL,                       /* setAttributes */
385    NULL,                       /* stopRemoteTx */
386    NULL,                       /* startRemoteTx */
387    1                           /* outputUsesInterrupts */
388  };
389#else
390  static const rtems_termios_callbacks pollCallbacks = {
391    NULL,                       /* firstOpen */
392    NULL,                       /* lastClose */
393    console_inbyte_nonblocking, /* pollRead */
394    console_write_support,      /* write */
395    NULL,                       /* setAttributes */
396    NULL,                       /* stopRemoteTx */
397    NULL,                       /* startRemoteTx */
398    0                           /* outputUsesInterrupts */
399  };
400#endif
401
402  /*
403   * Verify the minor number is valid.
404   */
405  if (minor < 0)
406    return RTEMS_INVALID_NUMBER;
407
408  if ( port > NUM_Z85C30_PORTS )
409     return RTEMS_INVALID_NUMBER;
410
411  /*
412   *  open the port as a termios console driver.
413   */
414
415#if (CONSOLE_USE_INTERRUPTS)
416   sc = rtems_termios_open( major, minor, arg, &intrCallbacks );
417
418   Ports_85C30[ minor ].Protocol->console_termios_data = args->iop->data1;
419#else
420   sc = rtems_termios_open( major, minor, arg, &pollCallbacks );
421#endif
422
423  return sc;
424}
425
426#if (CONSOLE_USE_INTERRUPTS)
427
428/*
429 *  console_outbyte_interrupts
430 *
431 *  This routine transmits a character out.
432 *
433 *  Input parameters:
434 *    port - port to transmit character to
435 *    ch  - character to be transmitted
436 *
437 *  Output parameters:  NONE
438 *
439 *  Return values:      NONE
440 */
441void console_outbyte_interrupts(
442  const Port_85C30_info *Port,
443  char ch
444)
445{
446  Console_Protocol   *protocol;
447  uint32_t            isrlevel;
448
449  protocol = Port->Protocol;
450
451  /*
452   *  If this is the first character then we need to prime the pump
453   */
454
455  if ( protocol->Is_TX_active == FALSE ) {
456
457    rtems_interrupt_disable( isrlevel );
458    protocol->Is_TX_active = TRUE;
459    outbyte_polled_85c30( Port->ctrl, ch );
460    rtems_interrupt_enable( isrlevel );
461
462    return;
463  }
464
465  while ( Ring_buffer_Is_full( &protocol->TX_Buffer ) );
466
467  Ring_buffer_Add_character( &protocol->TX_Buffer, ch );
468}
469
470#endif
471
472/* const char arg to be compatible with BSP_output_char decl. */
473void
474debug_putc_onlcr(const char c)
475{
476  int                      console;
477  volatile uint8_t         *csr;
478  uint32_t                 isrlevel;
479
480  console = USE_FOR_CONSOLE;
481  csr = Ports_85C30[ console ].ctrl;
482
483  rtems_interrupt_disable( isrlevel );
484  outbyte_polled_85c30( csr, c );
485  rtems_interrupt_enable( isrlevel );
486}
487
488BSP_output_char_function_type   BSP_output_char = debug_putc_onlcr;
489/* const char arg to be compatible with BSP_output_char decl. */
490
Note: See TracBrowser for help on using the repository browser.