Ignore:
Timestamp:
Aug 1, 1995, 3:33:39 PM (26 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
4f90134
Parents:
4a6e64d
Message:

updated mvme162 code from Misha (mms@…)

File:
1 edited

Legend:

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

    r4a6e64d rc6fb8e90  
    2525#include "console.h"
    2626#include "bsp.h"
     27#include "ringbuf.h"
    2728
    28 /*  console_initialize
    29  *
    30  *  This routine initializes the console IO driver.
    31  *
    32  *  Input parameters: NONE
    33  *
    34  *  Output parameters:  NONE
    35  *
    36  *  Return values:
     29Ring_buffer_t  Buffer[2];
     30
     31/*
     32 *  Interrupt handler for receiver interrupts
    3733 */
     34
     35rtems_isr C_Receive_ISR(rtems_vector_number vector)
     36{
     37  register int    ipend, port;
     38
     39  ZWRITE0(1, 0x38);     /* reset highest IUS */
     40
     41  ipend = ZREAD(1, 3);  /* read int pending from A side */
     42
     43  if      (ipend == 0x04) port = 0;   /* channel B intr pending */
     44  else if (ipend == 0x20) port = 1;   /* channel A intr pending */
     45  else return;
     46   
     47  Ring_buffer_Add_character(&Buffer[port], ZREADD(port));
     48 
     49  if (ZREAD(port, 1) & 0x70) {    /* check error stat */
     50    ZWRITE0(port, 0x30);          /* reset error */
     51  }
     52}
    3853
    3954rtems_device_driver console_initialize(
     
    4560)
    4661{
     62  int     i;
     63 
     64  /*
     65   * Initialise receiver interrupts on both ports
     66   */
     67
     68  for (i = 0; i <= 1; i++) {
     69    Ring_buffer_Initialize( &Buffer[i] );
     70    ZWRITE(i, 2, SCC_VECTOR);
     71    ZWRITE(i, 10, 0);
     72    ZWRITE(i, 1, 0x10);     /* int on all Rx chars or special condition */
     73    ZWRITE(i, 9, 8);        /* master interrupt enable */
     74  }
     75   
     76  set_vector(C_Receive_ISR, SCC_VECTOR, 1); /* install ISR for ports A and B */
     77
     78  mcchip->vector_base = 0;
     79  mcchip->gen_control = 2;        /* MIEN */
     80  mcchip->SCC_int_ctl = 0x13;     /* SCC IEN, IPL3 */
     81
    4782  *status = RTEMS_SUCCESSFUL;
    4883}
    4984
    50 
    51 /*  is_character_ready
    52  *
    53  *  This routine returns TRUE if a character is available.
    54  *
    55  *  Input parameters: NONE
    56  *
    57  *  Output parameters:  NONE
    58  *
    59  *  Return values:
     85/*
     86 *   Non-blocking char input
    6087 */
    6188
    62 rtems_boolean is_character_ready(
    63   char *ch
    64 )
     89rtems_boolean char_ready(int port, char *ch)
    6590{
    66   rtems_unsigned8 rr_0;
     91  if ( Ring_buffer_Is_empty( &Buffer[port] ) )
     92    return FALSE;
    6793
    68   Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    69   if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
    70     return( FALSE );
    71 
    72   Z8x30_READ_DATA( CONSOLE_DATA, *ch );
    73 
    74   return(TRUE);
    75 }
    76 
    77 /*  inbyte
    78  *
    79  *  This routine reads a character from the SCC.
    80  *
    81  *  Input parameters: NONE
    82  *
    83  *  Output parameters:  NONE
    84  *
    85  *  Return values:
    86  *    character read from SCC
    87  */
    88 
    89 char inbyte( void )
    90 {
    91   rtems_unsigned8 rr_0;
    92   char ch;
    93 
    94   while ( 1 ) {
    95     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    96     if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 )
    97       break;
    98   }
    99 
    100   Z8x30_READ_DATA( CONSOLE_DATA, ch );
    101   return ch;
    102 }
    103 
    104 
    105 /*  outbyte
    106  *
    107  *  This routine transmits a character out the SCC.  It supports
    108  *  XON/XOFF flow control.
    109  *
    110  *  Input parameters:
    111  *    ch  - character to be transmitted
    112  *
    113  *  Output parameters:  NONE
    114  */
    115 
    116 void outbyte(
    117   char ch
    118 )
    119 {
    120   rtems_unsigned8 rr_0;
    121   char            flow_control;
    122 
    123   while ( 1 ) {
    124     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    125     if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
    126       break;
    127   }
    128 
    129   while ( 1 ) {
    130     Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    131     if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 )
    132       break;
    133 
    134     Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
    135 
    136     if ( flow_control == XOFF )
    137       do {
    138         do {
    139           Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
    140         } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 );
    141         Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
    142       } while ( flow_control != XON );
    143   }
    144 
    145   Z8x30_WRITE_DATA( CONSOLE_DATA, ch );
     94  Ring_buffer_Remove_character( &Buffer[port], *ch );
     95 
     96  return TRUE;
    14697}
    14798
    14899/*
    149  * __read  -- read bytes from the serial port. Ignore fd, since
    150  *            we only have stdin.
     100 *   Block on char input
    151101 */
    152102
    153 int __read(
    154   int fd,
    155   char *buf,
    156   int nbytes
    157 )
     103char char_wait(int port)
    158104{
    159   int i = 0;
     105  unsigned char tmp_char;
     106 
     107  while ( !char_ready(port, &tmp_char) );
     108  return tmp_char;
     109}
     110
     111/* 
     112 *   This routine transmits a character out the SCC.  It no longer supports
     113 *   XON/XOFF flow control.
     114 */
     115
     116void char_put(int port, char ch)
     117{
     118  while (1) {
     119    if (ZREAD0(port) & TX_BUFFER_EMPTY) break;
     120  }
     121  ZWRITED(port, ch);
     122}
     123
     124/*
     125 *    Map port A (1) to stdin, stdout, and stderr.
     126 *    Map everything else to port B (0).
     127 */
     128
     129int __read(int fd, char *buf, int nbytes)
     130{
     131  int i, port;
     132
     133  if ( fd <= 2 ) port = 1;
     134  else           port = 0;
    160135
    161136  for (i = 0; i < nbytes; i++) {
    162     *(buf + i) = inbyte();
     137    *(buf + i) = char_wait(port);
    163138    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
    164139      (*(buf + i++)) = '\n';
     
    171146
    172147/*
    173  * __write -- write bytes to the serial port. Ignore fd, since
    174  *            stdout and stderr are the same. Since we have no filesystem,
    175  *            open will only return an error.
     148 *  Map port A (1) to stdin, stdout, and stderr.
     149 *  Map everything else to port B (0).
    176150 */
    177151
    178 int __write(
    179   int fd,
    180   char *buf,
    181   int nbytes
    182 )
     152int __write(int fd, char *buf, int nbytes)
    183153{
    184   int i;
    185 
     154  int i, port;
     155 
     156  if ( fd <= 2 ) port = 1;
     157  else           port = 0;
     158 
    186159  for (i = 0; i < nbytes; i++) {
    187160    if (*(buf + i) == '\n') {
    188       outbyte ('\r');
     161      char_put (port, '\r');
    189162    }
    190     outbyte (*(buf + i));
     163    char_put (port, *(buf + i));
    191164  }
    192165  return (nbytes);
Note: See TracChangeset for help on using the changeset viewer.