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

4.9
Last change on this file since 31a5ec8 was 31a5ec8, checked in by Jennifer Averett <Jennifer.Averett@…>, on 05/05/09 at 16:18:06

2009-05-05 Jennifer Averett <jennifer.averett@…>

  • Makefile.am, README, configure.ac, preinstall.am, PCI_bus/PCI.c, PCI_bus/PCI.h, PCI_bus/flash.c, PCI_bus/universe.c, console/85c30.c, console/85c30.h, console/console.c, console/consolebsp.h, console/tbl85c30.c, include/bsp.h, include/coverhd.h, include/gen2.h, include/irq-config.h, include/tm27.h, irq/FPGA.c, irq/irq.h, irq/irq_init.c, start/start.S, startup/Hwr_init.c, startup/bspstart.c, timer/timer.c, tod/tod.c: Updated and tested with the latest powerpc isr source
  • irq/no_pic.c: New file.
  • irq/irq.c, startup/genpvec.c, startup/setvec.c, startup/vmeintr.c: Removed.
  • Property mode set to 100644
File size: 9.1 KB
RevLine 
[9c448e1]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 *
[31a5ec8]8 *  COPYRIGHT (c) 1989-2009.
[9c448e1]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
[b14e2f2]13 *  http://www.rtems.com/license/LICENSE.
[9c448e1]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"
[bb41881e]24#include <rtems/bspIo.h>
[9c448e1]25
26/*
[6128a4a]27 * The Port Used for the Console interface is based upon which
28 * debugger is being used.  The SDS debugger uses a binary
[9c448e1]29 * interface on port 0 as part of the debugger.  Thus port 0 can
30 * not be used as the console port for the SDS debugger.
31 */
32
33#define USE_FOR_CONSOLE_DEF  0
34int USE_FOR_CONSOLE = USE_FOR_CONSOLE_DEF;
35
36/*
37 *
38 *  Console Device Driver Entry Points
39 */
[6128a4a]40
[9c448e1]41/* PAGE
42 *
[6128a4a]43 *  console_inbyte_nonblocking
[9c448e1]44 *
45 *  Console Termios polling input entry point.
46 */
47
[6128a4a]48int console_inbyte_nonblocking(
49  int minor
[9c448e1]50)
51{
52  int                       port = minor;
53
[6128a4a]54  /*
55   * verify port Number
[9c448e1]56   */
57  assert ( port < NUM_Z85C30_PORTS );
[6128a4a]58
[9c448e1]59  /*
60   * return a character from the 85c30 port.
61   */
62  return inbyte_nonblocking_85c30( &Ports_85C30[ port ] );
63}
[6128a4a]64
[9c448e1]65rtems_device_driver console_close(
66  rtems_device_major_number major,
67  rtems_device_minor_number minor,
68  void                    * arg
69)
70{
71  return rtems_termios_close (arg);
72}
[6128a4a]73
[9c448e1]74rtems_device_driver console_read(
75  rtems_device_major_number major,
76  rtems_device_minor_number minor,
77  void                    * arg
78)
79{
80  return rtems_termios_read (arg);
81}
[6128a4a]82
[9c448e1]83rtems_device_driver console_write(
84  rtems_device_major_number major,
85  rtems_device_minor_number minor,
86  void                    * arg
87)
88{
89  return rtems_termios_write (arg);
90}
[6128a4a]91
[9c448e1]92rtems_device_driver console_control(
93  rtems_device_major_number major,
94  rtems_device_minor_number minor,
95  void                    * arg
96)
97{
98  return rtems_termios_ioctl (arg);
99}
100
101/*
102 *  Interrupt driven console IO
103 */
104
105#if CONSOLE_USE_INTERRUPTS
106
107rtems_isr console_isr(
108  rtems_vector_number vector
109)
110{
111  int  i;
[6128a4a]112
[9c448e1]113  for (i=0; i < NUM_Z85C30_PORTS; i++){
114      ISR_85c30_Async( &Ports_85C30[i] );
[6128a4a]115  }
[9c448e1]116}
117
118void console_exit()
119{
120  int i;
121  volatile Ring_buffer_t *buffer;
[dac4208]122  uint32_t         ch;
[9c448e1]123
124  for ( i=0 ; i < NUM_Z85C30_PORTS ; i++ ) {
[6128a4a]125
[9c448e1]126    buffer = &( Ports_85C30[i].Protocol->TX_Buffer);
127
128    while ( !Ring_buffer_Is_empty( buffer ) ) {
129      Ring_buffer_Remove_character( buffer, ch );
[6128a4a]130      outbyte_polled_85c30( Ports_85C30[i].ctrl, ch );
[9c448e1]131    }
132  }
133}
134
135void console_initialize_interrupts( void )
136{
137  volatile Ring_buffer_t     *buffer;
138  Console_Protocol  *protocol;
139  int               i;
[6128a4a]140
[9c448e1]141  for ( i=0 ; i < NUM_Z85C30_PORTS ; i++ ) {
142    protocol = Ports_85C30[i].Protocol;
143
144    /*
145     * Initialize the ring buffer and set to not transmitting.
146     */
147    buffer = &protocol->TX_Buffer;
148    Ring_buffer_Initialize( buffer );
[3551166d]149    protocol->Is_TX_active = false;
[9c448e1]150  }
151
[6128a4a]152  /*
[9c448e1]153   * Connect each vector to the interupt service routine.
154   */
155  for (i=0; i < NUM_Z85C30_CHIPS; i++)
156    set_vector( console_isr, Chips_85C30[i].vector, 1 );
[6128a4a]157
[9c448e1]158  atexit( console_exit );
[6128a4a]159
[9c448e1]160}
161void console_outbyte_interrupts(
162  const Port_85C30_info *Port,
163  char ch
164);
165
166#endif
167
168/* PAGE
169 *
170 *  console_initialize
171 *
172 *  Routine called to initialize the console device driver.
173 */
174rtems_device_driver console_initialize(
175  rtems_device_major_number  major,
176  rtems_device_minor_number  minor,
177  void                      *arg
178)
179{
180  rtems_status_code          status;
181  rtems_device_minor_number  console;
182  int                        port, chip, p0,p1;
183
184  /*
185   * initialize the termio interface.
186   */
187  rtems_termios_initialize();
188
189  /*
190   *  Register Device Names
191   */
192  console = USE_FOR_CONSOLE;
193  status = rtems_io_register_name( "/dev/console", major, console );
194  if (status != RTEMS_SUCCESSFUL)
195    rtems_fatal_error_occurred(status);
196
197  /*
198   *  Initialize Hardware
199   */
200
201/*
202 * INITIALIZE_COM_PORTS is defined in the linker script.  If it is
203 * true all serial chips on the board are to be reset at startup
204 * otherwise the reset is assumed to occur elsewhere (ie. in the
205 * debugger...)
206 */
207#if ( INITIALIZE_COM_PORTS )
208  /*
209   * Force to perform a hardware reset w/o
210   * Master interrupt enable via register 9
211   */
[6128a4a]212
[9c448e1]213  for (port=0; port<NUM_Z85C30_PORTS; port++){
214    p0 = port;
215    port++;
216    p1 = port;
217    Reset_85c30_chip( Ports_85C30[p0].ctrl, Ports_85C30[p1].ctrl );
218  }
219#else
[6128a4a]220  /* TEMP - To see if this makes a diff with the new ports.
[9c448e1]221   *        Never reset chip 1 when using the chip as a monitor
222   */
223  for (port=2; port<NUM_Z85C30_PORTS; port++){
224    p0 = port;
225    port++;
226    p1 = port;
227    Reset_85c30_chip( Ports_85C30[p0].ctrl, Ports_85C30[p1].ctrl );
228  }
229#endif
230
[6128a4a]231  /*
[9c448e1]232   * Initialize each port.
233   * Note:  the ports are numbered such that 0,1 are on the first chip
234   *        2,3 are on the second ....
235   */
236
[40e7ae2]237  for (port=1; port<NUM_Z85C30_PORTS; port++) {
238   chip = port >> 1;
[9c448e1]239    initialize_85c30_port( &Ports_85C30[port] );
240  }
241
242#if CONSOLE_USE_INTERRUPTS
243  console_initialize_interrupts();
244#endif
245
246  return RTEMS_SUCCESSFUL;
247}
248
249/* PAGE
250 *
251 *  console_write_support
252 *
253 *  Console Termios output entry point.
254 *
255 */
256int console_write_support(
[6128a4a]257  int   minor,
258  const char *buf,
[9c448e1]259  int   len)
260{
261  int nwrite = 0;
[dac4208]262  volatile uint8_t         *csr;
[9c448e1]263  int                       port = minor;
264
[6128a4a]265  /*
266   * verify port Number
[9c448e1]267   */
268  assert ( port < NUM_Z85C30_PORTS );
269
270  /*
271   * Set the csr based upon the port number.
272   */
273  csr = Ports_85C30[ port ].ctrl;
274
275  /*
276   * poll each byte in the string out of the port.
277   */
278  while (nwrite < len) {
279#if (CONSOLE_USE_INTERRUPTS)
280    console_outbyte_interrupts( &Ports_85C30[ port ], *buf++ );
281#else
282    outbyte_polled_85c30( csr, *buf++ );
283#endif
284   nwrite++;
285  }
286
287  /*
288   * return the number of bytes written.
289   */
290  return nwrite;
291}
292
293/* PAGE
294 *
295 *  console_open
296 *
297 *  open a port as a termios console.
298 *
299 */
300rtems_device_driver console_open(
301  rtems_device_major_number major,
302  rtems_device_minor_number minor,
303  void                    * arg
304)
305{
306  rtems_status_code sc;
307  int               port = minor;
308#if (CONSOLE_USE_INTERRUPTS)
309  rtems_libio_open_close_args_t *args = arg;
310  static const rtems_termios_callbacks intrCallbacks = {
311    NULL,                       /* firstOpen */
312    NULL,                       /* lastClose */
313    NULL,                       /* pollRead */
314    console_write_support,      /* write */
315    NULL,                       /* setAttributes */
316    NULL,                       /* stopRemoteTx */
317    NULL,                       /* startRemoteTx */
318    1                           /* outputUsesInterrupts */
319  };
320#else
321  static const rtems_termios_callbacks pollCallbacks = {
322    NULL,                       /* firstOpen */
323    NULL,                       /* lastClose */
324    console_inbyte_nonblocking, /* pollRead */
325    console_write_support,      /* write */
326    NULL,                       /* setAttributes */
327    NULL,                       /* stopRemoteTx */
328    NULL,                       /* startRemoteTx */
329    0                           /* outputUsesInterrupts */
330  };
331#endif
332
333  /*
334   * Verify the minor number is valid.
335   */
336  if (minor < 0)
337    return RTEMS_INVALID_NUMBER;
338
339  if ( port > NUM_Z85C30_PORTS )
340     return RTEMS_INVALID_NUMBER;
341
342  /*
343   *  open the port as a termios console driver.
344   */
345
346#if (CONSOLE_USE_INTERRUPTS)
347   sc = rtems_termios_open( major, minor, arg, &intrCallbacks );
348
349   Ports_85C30[ minor ].Protocol->console_termios_data = args->iop->data1;
350#else
351   sc = rtems_termios_open( major, minor, arg, &pollCallbacks );
352#endif
353
354  return sc;
355}
356
357#if (CONSOLE_USE_INTERRUPTS)
358
359/*
360 *  console_outbyte_interrupts
361 *
362 *  This routine transmits a character out.
363 *
364 *  Input parameters:
365 *    port - port to transmit character to
366 *    ch  - character to be transmitted
367 *
368 *  Output parameters:  NONE
369 *
370 *  Return values:      NONE
371 */
372void console_outbyte_interrupts(
373  const Port_85C30_info *Port,
374  char ch
375)
376{
377  Console_Protocol   *protocol;
[dac4208]378  uint32_t            isrlevel;
[9c448e1]379
380  protocol = Port->Protocol;
[6128a4a]381
[9c448e1]382  /*
383   *  If this is the first character then we need to prime the pump
384   */
385
[3551166d]386  if ( protocol->Is_TX_active == false ) {
[9c448e1]387
388    rtems_interrupt_disable( isrlevel );
[3551166d]389    protocol->Is_TX_active = true;
[9c448e1]390    outbyte_polled_85c30( Port->ctrl, ch );
391    rtems_interrupt_enable( isrlevel );
392
393    return;
394  }
395
396  while ( Ring_buffer_Is_full( &protocol->TX_Buffer ) );
[6128a4a]397
[9c448e1]398  Ring_buffer_Add_character( &protocol->TX_Buffer, ch );
399}
400
401#endif
[bb41881e]402
403/* const char arg to be compatible with BSP_output_char decl. */
404void
405debug_putc_onlcr(const char c)
406{
407  int                      console;
408  volatile uint8_t         *csr;
409  uint32_t                 isrlevel;
410
411  console = USE_FOR_CONSOLE;
412  csr = Ports_85C30[ console ].ctrl;
413
[40e7ae2]414  if ('\n'==c){
415    rtems_interrupt_disable( isrlevel );
416    outbyte_polled_85c30( csr, '\r' );
417    asm volatile("isync");
[31a5ec8]418    rtems_interrupt_enable( isrlevel );
[40e7ae2]419  }
420
[bb41881e]421  rtems_interrupt_disable( isrlevel );
422  outbyte_polled_85c30( csr, c );
[31a5ec8]423  asm volatile("isync");
[bb41881e]424  rtems_interrupt_enable( isrlevel );
425}
426
427BSP_output_char_function_type   BSP_output_char = debug_putc_onlcr;
428/* const char arg to be compatible with BSP_output_char decl. */
429
Note: See TracBrowser for help on using the repository browser.