Ignore:
Timestamp:
Oct 23, 1997, 3:11:27 PM (23 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
5993d02
Parents:
b628637
Message:

Overhauled console driver to use termios and to simultaneously support
both ports.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/m68k/dmv152/console/console.c

    rb628637 redd1329f  
    11/*
    2  *  This file contains the DMV152 console IO package.
     2 *  This file contains the TTY driver for the serial ports on the DMV152.
     3 *  The serial ports use a Zilog Z8530.
     4 *
     5 *  NOTE: This driver uses the termios pseudo driver.
     6 *        This driver is polled only.
    37 *
    48 *  COPYRIGHT (c) 1989-1997.
     
    1317 */
    1418
    15 #define D152_INIT
    16 
    1719#include <bsp.h>
    1820#include <rtems/libio.h>
    19  
    20 /*  console_initialize
    21  *
    22  *  This routine initializes the console IO driver.
    23  *
    24  *  Input parameters: NONE
     21#include <stdlib.h>
     22#include <assert.h>
     23
     24/*
     25 *  console_outbyte_polled
     26 *
     27 *  This routine transmits a character using polling.
     28 */
     29
     30void console_outbyte_polled(
     31  int  port,
     32  char ch
     33)
     34{
     35  rtems_unsigned32 control;
     36  rtems_unsigned32 data;
     37  rtems_unsigned8  rr_0;
     38
     39  if ( port == 0 ) {
     40    control = CONSOLE_CONTROL_A;
     41    data    = CONSOLE_DATA_A;
     42  } else {
     43    control = CONSOLE_CONTROL_B;
     44    data    = CONSOLE_DATA_B;
     45  }
     46
     47  for ( ; ; ) {
     48    Z8x30_READ_CONTROL( control, RR_0, rr_0 );
     49    if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
     50      break;
     51  }
     52
     53  Z8x30_WRITE_DATA( control, ch );
     54}
     55
     56/*
     57 *  console_inbyte_nonblocking
     58 *
     59 *  This routine polls for a character.
     60 */
     61
     62int console_inbyte_nonblocking(
     63  int port,
     64  char *c
     65)
     66{
     67  rtems_unsigned32 control;
     68  rtems_unsigned32 data;
     69  rtems_unsigned8  rr_0;
     70  char             ch;
     71
     72  if ( port == 0 ) {
     73    control = CONSOLE_CONTROL_A;
     74    data    = CONSOLE_DATA_A;
     75  } else {
     76    control = CONSOLE_CONTROL_B;
     77    data    = CONSOLE_DATA_B;
     78  }
     79
     80  Z8x30_READ_CONTROL( control, RR_0, rr_0 );
     81  if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
     82    return 0;
     83
     84  Z8x30_READ_DATA( data, ch );
     85  return ch;
     86}
     87
     88/*
     89 *  DEBUG_puts
     90 *
     91 *  This should be safe in the event of an error.  It attempts to insure
     92 *  that no TX empty interrupts occur while it is doing polled IO.  Then
     93 *  it restores the state of that external interrupt.
     94 *
     95 *  Input parameters:
     96 *    string  - pointer to debug output string
    2597 *
    2698 *  Output parameters:  NONE
    2799 *
    28  *  Return values:
     100 *  Return values:      NONE
     101 */
     102
     103void DEBUG_puts(
     104  char *string
     105)
     106{
     107  char *s;
     108
     109  /* should disable interrupts here */
     110    for ( s = string ; *s ; s++ )
     111      console_outbyte_polled( 0, *s );
     112
     113    console_outbyte_polled( 0, '\r' );
     114    console_outbyte_polled( 0, '\n' );
     115  /* should enable interrupts here */
     116}
     117
     118
     119/*
     120 *  Console Termios Support Entry Points
     121 *
     122 */
     123
     124int console_write_support (int minor, char *buf, int len)
     125{
     126  int nwrite = 0;
     127
     128  while (nwrite < len) {
     129    console_outbyte_polled( minor, *buf++ );
     130    nwrite++;
     131  }
     132  return nwrite;
     133}
     134
     135void console_reserve_resources(
     136  rtems_configuration_table *configuration
     137)
     138{
     139  rtems_termios_reserve_resources( configuration, 2 );
     140}
     141
     142/*
     143 *  Console Device Driver Entry Points
     144 *
    29145 */
    30146 
     
    35151)
    36152{
    37   rtems_status_code status;
    38  
    39   status = rtems_io_register_name(
    40     "/dev/console",
    41     major,
    42     (rtems_device_minor_number) 0
    43   );
    44  
     153  rtems_status_code          status;
     154  rtems_device_minor_number  console_minor;
     155
     156  rtems_termios_initialize();
     157
     158  /*
     159   *  Register Device Names
     160   */
     161
     162#if (USE_CHANNEL_A == 1)
     163  console_minor = 0;
     164#elif (USE_CHANNEL_B == 1)
     165  console_minor = 1;
     166#else
     167#error "DMV152 Console Driver -- no console port configured!!!"
     168#endif
     169
     170  status = rtems_io_register_name( "/dev/console", major, console_minor );
    45171  if (status != RTEMS_SUCCESSFUL)
    46172    rtems_fatal_error_occurred(status);
     173
     174  status = rtems_io_register_name( "/dev/console_a", major, 0 );
     175  if (status != RTEMS_SUCCESSFUL)
     176    rtems_fatal_error_occurred(status);
     177
     178  status = rtems_io_register_name( "/dev/console_b", major, 1 );
     179  if (status != RTEMS_SUCCESSFUL)
     180    rtems_fatal_error_occurred(status);
     181
     182  /*
     183   *  Initialize Hardware
     184   */
    47185 
    48186  return RTEMS_SUCCESSFUL;
    49187}
    50188
    51 /*  inbyte
    52  *
    53  *  This routine reads a character from the SCC.
    54  *
    55  *  Input parameters: NONE
    56  *
    57  *  Output parameters:  NONE
    58  *
    59  *  Return values:
    60  *    character read from SCC
    61  */
    62 
    63 char inbyte( void )
    64 {
    65   rtems_unsigned8 rr_0;
    66   char ch;
    67 
    68   for ( ; ; ) {
    69     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    70     if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 )
    71       break;
    72   }
    73 
    74   Z8x30_READ_DATA( CONSOLE_DATA, ch );
    75   return ( ch );
    76 }
    77 
    78 /*  outbyte
    79  *
    80  *  This routine transmits a character out the SCC.  It supports
    81  *  XON/XOFF flow control.
    82  *
    83  *  Input parameters:
    84  *    ch  - character to be transmitted
    85  *
    86  *  Output parameters:  NONE
    87  */
    88 
    89 void outbyte(
    90   char ch
    91 )
    92 {
    93   rtems_unsigned8 rr_0;
    94   char            flow_control;
    95 
    96   for ( ; ; ) {
    97     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    98     if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
    99       break;
    100   }
    101 
    102   for ( ; ; ) {
    103     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    104     if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 )
    105       break;
    106 
    107     Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
    108 
    109     if ( flow_control == XOFF )
    110       do {
    111         do {
    112           Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    113         } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 );
    114         Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
    115       } while ( flow_control != XON );
    116   }
    117 
    118   Z8x30_WRITE_DATA( CONSOLE_DATA, ch );
    119 }
    120 
    121 /*
    122  *  Open entry point
    123  */
    124 
    125189rtems_device_driver console_open(
    126190  rtems_device_major_number major,
     
    129193)
    130194{
     195        rtems_status_code sc;
     196
     197        assert( minor <= 1 );
     198        if ( minor > 2 )
     199          return RTEMS_INVALID_NUMBER;
     200 
     201        sc = rtems_termios_open (major, minor, arg,
     202                        NULL,
     203                        NULL,
     204                        console_inbyte_nonblocking,
     205                        console_write_support);
     206
    131207  return RTEMS_SUCCESSFUL;
    132208}
    133209 
    134 /*
    135  *  Close entry point
    136  */
    137 
    138210rtems_device_driver console_close(
    139211  rtems_device_major_number major,
     
    142214)
    143215{
    144   return RTEMS_SUCCESSFUL;
    145 }
    146 
    147 /*
    148  * read bytes from the serial port. We only have stdin.
    149  */
    150 
     216  return rtems_termios_close (arg);
     217}
     218 
    151219rtems_device_driver console_read(
    152220  rtems_device_major_number major,
     
    155223)
    156224{
    157   rtems_libio_rw_args_t *rw_args;
    158   char *buffer;
    159   int maximum;
    160   int count = 0;
    161  
    162   rw_args = (rtems_libio_rw_args_t *) arg;
    163 
    164   buffer = rw_args->buffer;
    165   maximum = rw_args->count;
    166 
    167   for (count = 0; count < maximum; count++) {
    168     buffer[ count ] = inbyte();
    169     if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
    170       buffer[ count++ ]  = '\n';
    171       break;
    172     }
    173   }
    174 
    175   rw_args->bytes_moved = count;
    176   return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
    177 }
    178 
    179 /*
    180  * write bytes to the serial port. Stdout and stderr are the same.
    181  */
    182 
     225  return rtems_termios_read (arg);
     226}
     227 
    183228rtems_device_driver console_write(
    184229  rtems_device_major_number major,
     
    187232)
    188233{
    189   int count;
    190   int maximum;
    191   rtems_libio_rw_args_t *rw_args;
    192   char *buffer;
    193 
    194   rw_args = (rtems_libio_rw_args_t *) arg;
    195 
    196   buffer = rw_args->buffer;
    197   maximum = rw_args->count;
    198 
    199   for (count = 0; count < maximum; count++) {
    200     if ( buffer[ count ] == '\n') {
    201       outbyte('\r');
    202     }
    203     outbyte( buffer[ count ] );
    204   }
    205 
    206   rw_args->bytes_moved = maximum;
    207   return 0;
    208 }
    209 
    210 /*
    211  *  IO Control entry point
    212  */
    213 
     234  return rtems_termios_write (arg);
     235}
     236 
    214237rtems_device_driver console_control(
    215238  rtems_device_major_number major,
     
    218241)
    219242{
    220   return RTEMS_SUCCESSFUL;
    221 }
     243  return rtems_termios_ioctl (arg);
     244}
     245
Note: See TracChangeset for help on using the changeset viewer.