Changeset a7e2729 in rtems


Ignore:
Timestamp:
Oct 21, 1997, 6:38:24 PM (23 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
4822069
Parents:
cdfd74a5
Message:

Converted to termios style device driver.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/sparc/erc32/console/console.c

    rcdfd74a5 ra7e2729  
    11/*
    2  *  console.c
    3  *
    4  *  This file contains the Sparc Instruction Simulator Console driver.
     2 *  This file contains the TTY driver for the serial ports on the erc32.
     3 *
     4 *  This driver uses the termios pseudo driver.
    55 *
    66 *  COPYRIGHT (c) 1989-1997.
     
    1212 *  http://www.OARcorp.com/rtems/license.html.
    1313 *
    14  *  Ported to ERC32 implementation of the SPARC by On-Line Applications
    15  *  Research Corporation (OAR) under contract to the European Space
    16  *  Agency (ESA).
    17  *
    18  *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
    19  *  European Space Agency.
    20  *
    2114 *  $Id$
    2215 */
     
    2518#include <rtems/libio.h>
    2619#include <stdlib.h>
    27 
    28 /*
    29  *  Define RDB_BREAK_IN if you need to be able to break in to the
    30  *  program with a ctrl-c during remote target debugging. If so,
    31  *  UART B will not be accessible from rtems during remote debugging
    32  *  if interrupt driven console is used. Does not affect UART A, polled
    33  *  mode or when the program runs without remote debugging.
    34  */
    35 
    36 #define RDB_BREAK_IN
     20#include <assert.h>
     21
     22
     23#undef  CONSOLE_USE_POLLED
     24#define CONSOLE_USE_INTERRUPTS
    3725
    3826/*
    3927 *  Should we use a polled or interrupt drived console?
    4028 * 
    41  *  NOTE: Define only one of these by default.
    42  *
    43  *  WARNING:  As of sis 1.6, it did not appear that the UART interrupts
     29 *  NOTE: This is defined in the custom/erc32.cfg file.
     30 *
     31 *  WARNING:  In sis 1.6, it did not appear that the UART interrupts
    4432 *            worked in a desirable fashion.  Immediately upon writing
    4533 *            a character into the TX buffer, an interrupt was generated.
     
    5038 *            on output.  It is reasonable to assume that input does not
    5139 *            share this problem although it was not investigated.
    52  */
    53 
    54 #ifdef CONSOLE_USE_POLLED
    55 #define OUTBYTE console_outbyte_polled
    56 #define INBYTE  console_inbyte_polled
    57 #else
    58 #define OUTBYTE console_outbyte_interrupts
    59 #define INBYTE  console_inbyte_interrupts
    60 #endif
    61 
    62 void console_initialize_interrupts( void );
    63 
    64 /*  console_initialize
    65  *
    66  *  This routine initializes the console IO driver.
    67  *
    68  *  Input parameters:
    69  *    major - console device major number
    70  *    minor - console device minor number
    71  *    arg   - pointer to optional device driver arguments
    72  *
    73  *  Output parameters:  NONE
    74  *
    75  *  Return values:
    76  *    rtems_device_driver status code
    77  */
    78  
    79 rtems_device_driver console_initialize(
    80   rtems_device_major_number  major,
    81   rtems_device_minor_number  minor,
    82   void                      *arg
    83 )
    84 {
    85   rtems_status_code status;
    86  
    87   status = rtems_io_register_name(
    88     "/dev/console",
    89     major,
    90     (rtems_device_minor_number) 0
    91   );
    92  
    93   if (status != RTEMS_SUCCESSFUL)
    94     rtems_fatal_error_occurred(status);
    95 
    96 #ifdef CONSOLE_USE_INTERRUPTS
    97   console_initialize_interrupts();
    98 #endif
    99  
    100   return RTEMS_SUCCESSFUL;
    101 }
    102 
    103 /*  console_inbyte_polled
    104  *
    105  *  This routine reads a character from the UART.
    106  *
    107  *  Input parameters:
    108  *    port - port to read character from
    109  *
    110  *  Output parameters:  NONE
    111  *
    112  *  Return values:
    113  *    character read from UART
    114  */
    115 
    116 char console_inbyte_polled( int port )
    117 {
    118   int UStat;
    119 
    120   if ( port == 0 ) {
    121     while (((UStat = ERC32_MEC.UART_Status) & ERC32_MEC_UART_STATUS_DRA) == 0 )
    122         if (UStat & ERC32_MEC_UART_STATUS_ERRA) {
    123             ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRA;
    124             ERC32_MEC.Control = ERC32_MEC.Control;
    125         }
    126     return (int) ERC32_MEC.UART_Channel_A;
    127   }
    128 
    129   while (((UStat = ERC32_MEC.UART_Status) & ERC32_MEC_UART_STATUS_DRB) == 0 )
    130         if (UStat & ERC32_MEC_UART_STATUS_ERRB) {
    131             ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRB;
    132             ERC32_MEC.Control = ERC32_MEC.Control;
    133         }
    134   return (int) ERC32_MEC.UART_Channel_B;
    135 }
    136 
    137 
    138 /*  console_outbyte_polled
    139  *
    140  *  This routine transmits a character out.
    141  *
    142  *  Input parameters:
    143  *    port - port to transmit character to
    144  *    ch  - character to be transmitted
    145  *
    146  *  Output parameters:  NONE
    147  *
    148  *  Return values: NONE
     40 *
     41 */
     42
     43/*
     44 *  console_outbyte_polled
     45 *
     46 *  This routine transmits a character using polling.
    14947 */
    15048
     
    16563
    16664/*
     65 *  console_inbyte_nonblocking
     66 *
     67 *  This routine polls for a character.
     68 */
     69
     70int console_inbyte_nonblocking(
     71  int port,
     72  char *c
     73)
     74{
     75  int UStat;
     76
     77  UStat = ERC32_MEC.UART_Status;
     78
     79  switch (port) {
     80
     81    case 0:
     82      if (UStat & ERC32_MEC_UART_STATUS_ERRA) {
     83        ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRA;
     84        ERC32_MEC.Control = ERC32_MEC.Control;
     85      }
     86
     87      if ((UStat & ERC32_MEC_UART_STATUS_DRA) == 0)
     88         return 0;
     89      *c = (char) ERC32_MEC.UART_Channel_A;
     90      return 1;
     91
     92    case 1:
     93      if (UStat & ERC32_MEC_UART_STATUS_ERRB) {
     94        ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRB;
     95        ERC32_MEC.Control = ERC32_MEC.Control;
     96      }
     97
     98      if ((UStat & ERC32_MEC_UART_STATUS_DRB) == 0)
     99        return 0;
     100      *c = (char) ERC32_MEC.UART_Channel_B;
     101      return 1;
     102
     103    default:
     104      assert( 0 );
     105  }
     106
     107  return 0;
     108}
     109
     110/*
    167111 *  Interrupt driven console IO
    168112 */
     
    177121 
    178122Ring_buffer_t  TX_Buffer[ 2 ];
    179 Ring_buffer_t  RX_Buffer[ 2 ];
    180123boolean        Is_TX_active[ 2 ];
    181124 
     125void *console_termios_data[ 2 ];
     126
    182127/*
    183128 *  console_isr_a
     
    206151    }
    207152    ch = ERC32_MEC.UART_Channel_A;
    208     if ( !Ring_buffer_Is_full( &RX_Buffer[ 0 ] ) )
    209       Ring_buffer_Add_character( &RX_Buffer[ 0 ], ch );
    210     /* else toss it */
     153
     154    rtems_termios_enqueue_raw_characters( console_termios_data[ 0 ], &ch, 1 );
    211155  }
    212156 
     
    248192    }
    249193    ch = ERC32_MEC.UART_Channel_B;
    250     if ( !Ring_buffer_Is_full( &RX_Buffer[ 1 ] ) )
    251       Ring_buffer_Add_character( &RX_Buffer[ 1 ], ch );
    252     /* else toss it */
     194    rtems_termios_enqueue_raw_characters( console_termios_data[ 1 ], &ch, 1 );
     195
    253196  }
    254197
     
    330273#endif
    331274
    332 void console_initialize_interrupts()
    333 {
    334   Ring_buffer_Initialize( &RX_Buffer[ 0 ] );
    335   Ring_buffer_Initialize( &RX_Buffer[ 1 ] );
    336 
     275void console_initialize_interrupts( void )
     276{
    337277  Ring_buffer_Initialize( &TX_Buffer[ 0 ] );
    338278  Ring_buffer_Initialize( &TX_Buffer[ 1 ] );
     
    350290}
    351291
    352 /*
    353  *  console_inbyte_interrupts
    354  *
    355  *  This routine reads a character from the UART.
    356  *
    357  *  Input parameters: NONE
    358  *
    359  *  Output parameters:  NONE
    360  *
    361  *  Return values:
    362  *    character read from UART
    363  */
    364  
    365 char console_inbyte_interrupts( int port )
    366 {
    367   char ch;
    368 
    369   while ( Ring_buffer_Is_empty( &RX_Buffer[ port ] ) );
    370  
    371   Ring_buffer_Remove_character( &RX_Buffer[ port ], ch );
    372   return ch;
    373 }
    374  
    375292/*
    376293 *  console_outbyte_interrupts
     
    442359
    443360/*
    444  *  console_open
    445  *
    446  *  This routine is the console device driver open entry point.
    447  *
    448  *  Input parameters:
    449  *    major - console device major number
    450  *    minor - console device minor number
    451  *    arg   - pointer to optional device driver arguments
    452  *
    453  *  Output parameters:  NONE
    454  *
    455  *  Return values:
    456  *    rtems_device_driver status code
    457  */
    458  
     361 *  Console Termios Support Entry Points
     362 *
     363 */
     364
     365int console_write_support (int minor, char *buf, int len)
     366{
     367  int nwrite = 0;
     368
     369  while (nwrite < len) {
     370#if defined(CONSOLE_USE_INTERRUPTS)
     371    console_outbyte_polled( minor, *buf++ );
     372#else
     373    console_outbyte_interrupt( minor, *buf++ );
     374#endif
     375    nwrite++;
     376  }
     377  return nwrite;
     378}
     379
     380/*
     381 *  Console Device Driver Entry Points
     382 *
     383 */
     384 
     385rtems_device_driver console_initialize(
     386  rtems_device_major_number  major,
     387  rtems_device_minor_number  minor,
     388  void                      *arg
     389)
     390{
     391  rtems_status_code status;
     392
     393  rtems_termios_initialize();
     394
     395  /*
     396   *  Register Device Names
     397   */
     398
     399  status = rtems_io_register_name( "/dev/console", major, 0 );
     400  if (status != RTEMS_SUCCESSFUL)
     401    rtems_fatal_error_occurred(status);
     402
     403  status = rtems_io_register_name( "/dev/console_b", major, 1 );
     404  if (status != RTEMS_SUCCESSFUL)
     405    rtems_fatal_error_occurred(status);
     406
     407  /*
     408   *  Initialize Hardware
     409   */
     410 
     411#ifdef CONSOLE_USE_INTERRUPTS
     412  console_initialize_interrupts();
     413#endif
     414
     415  return RTEMS_SUCCESSFUL;
     416}
     417
    459418rtems_device_driver console_open(
    460419  rtems_device_major_number major,
     
    463422)
    464423{
     424        rtems_status_code sc;
     425#if defined(CONSOLE_USE_INTERRUPTS)
     426        rtems_libio_open_close_args_t *args = arg;
     427#endif
     428
     429        assert( minor <= 1 );
     430        if ( minor > 2 )
     431          return RTEMS_INVALID_NUMBER;
     432 
     433#if defined(CONSOLE_USE_INTERRUPTS)
     434        sc = rtems_termios_open (major, minor, arg,
     435                        NULL,
     436                        NULL,
     437                        NULL,
     438                        console_write_support);
     439
     440        console_termios_data[ minor ] = args->iop->data1;
     441#else
     442        sc = rtems_termios_open (major, minor, arg,
     443                        NULL,
     444                        NULL,
     445                        console_inbyte_nonblocking,
     446                        console_write_support);
     447#endif
     448
    465449  return RTEMS_SUCCESSFUL;
    466450}
    467  
    468 /*
    469  *  console_close
    470  *
    471  *  This routine is the console device driver close entry point.
    472  *
    473  *  Input parameters:
    474  *    major - console device major number
    475  *    minor - console device minor number
    476  *    arg   - pointer to optional device driver arguments
    477  *
    478  *  Output parameters:  NONE
    479  *
    480  *  Return values:
    481  *    rtems_device_driver status code
    482  */
    483451 
    484452rtems_device_driver console_close(
     
    488456)
    489457{
    490   return RTEMS_SUCCESSFUL;
    491 }
    492  
    493 /*
    494  *  console_read
    495  *
    496  *  This routine is the console device driver read entry point.
    497  *
    498  *  Input parameters:
    499  *    major - console device major number
    500  *    minor - console device minor number
    501  *    arg   - pointer to optional device driver arguments
    502  *
    503  *  Output parameters:  NONE
    504  *
    505  *  Return values:
    506  *    rtems_device_driver status code
    507  *
    508  *  NOTE:  Read bytes from the serial port. We only have stdin.
    509  */
     458  return rtems_termios_close (arg);
     459}
    510460 
    511461rtems_device_driver console_read(
     
    515465)
    516466{
    517   rtems_libio_rw_args_t *rw_args;
    518   char *buffer;
    519   int maximum;
    520   int count = 0;
    521  
    522   rw_args = (rtems_libio_rw_args_t *) arg;
    523  
    524   buffer = rw_args->buffer;
    525   maximum = rw_args->count;
    526  
    527   for (count = 0; count < maximum; count++) {
    528     buffer[ count ] = INBYTE( minor );
    529     if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
    530       buffer[ count++ ]  = '\n';
    531       break;
    532     }
    533   }
    534  
    535   rw_args->bytes_moved = count;
    536   return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
    537 }
    538  
    539 /*
    540  *  console_write
    541  *
    542  *  This routine is the console device driver write entry point.
    543  *
    544  *  Input parameters:
    545  *    major - console device major number
    546  *    minor - console device minor number
    547  *    arg   - pointer to optional device driver arguments
    548  *
    549  *  Output parameters:  NONE
    550  *
    551  *  Return values:
    552  *    rtems_device_driver status code
    553  *
    554  *  NOTE:  Write bytes to the serial port. Stdout and stderr are the same.
    555  */
     467  return rtems_termios_read (arg);
     468}
    556469 
    557470rtems_device_driver console_write(
     
    561474)
    562475{
    563   int count;
    564   int maximum;
    565   rtems_libio_rw_args_t *rw_args;
    566   char *buffer;
    567  
    568   rw_args = (rtems_libio_rw_args_t *) arg;
    569  
    570   buffer = rw_args->buffer;
    571   maximum = rw_args->count;
    572  
    573   for (count = 0; count < maximum; count++) {
    574     OUTBYTE( minor, buffer[ count ] );
    575     if ( buffer[ count ] == '\n') {
    576       OUTBYTE( minor, '\r');
    577     }
    578   }
    579  
    580   rw_args->bytes_moved = maximum;
    581   return RTEMS_SUCCESSFUL;
    582 }
    583  
    584 /*
    585  *  console_control
    586  *
    587  *  This routine is the console device driver control entry point.
    588  *
    589  *  Input parameters:
    590  *    major - console device major number
    591  *    minor - console device minor number
    592  *    arg   - pointer to optional device driver arguments
    593  *
    594  *  Output parameters:  NONE
    595  *
    596  *  Return values:
    597  *    rtems_device_driver status code
    598  */
     476  return rtems_termios_write (arg);
     477}
    599478 
    600479rtems_device_driver console_control(
     
    604483)
    605484{
    606   return RTEMS_SUCCESSFUL;
    607 }
    608 
     485  return rtems_termios_ioctl (arg);
     486}
     487
Note: See TracChangeset for help on using the changeset viewer.