source: rtems/c/src/lib/libbsp/m68k/mvme162/console/console.c @ 88d594a

4.104.114.84.95
Last change on this file since 88d594a was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  This file contains the MVME162 console IO package.
3 *
4 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
5 *  On-Line Applications Research Corporation (OAR).
6 *  All rights assigned to U.S. Government, 1994.
7 *
8 *  This material may be reproduced by or for the U.S. Government pursuant
9 *  to the copyright license under the clause at DFARS 252.227-7013.  This
10 *  notice must appear in all copies of this file and its derivatives.
11 *
12 *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
13 *  EISCAT Scientific Association. M.Savitski
14 *
15 *  This material is a part of the MVME162 Board Support Package
16 *  for the RTEMS executive. Its licensing policies are those of the
17 *  RTEMS above.
18 *
19 *  $Id$
20 */
21
22#define M162_INIT
23
24#include <rtems.h>
25#include "console.h"
26#include "bsp.h"
27
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:
37 */
38
39rtems_device_driver console_initialize(
40  rtems_device_major_number  major,
41  rtems_device_minor_number  minor,
42  void                      *arg,
43  rtems_id                   self,
44  rtems_unsigned32          *status
45)
46{
47  *status = RTEMS_SUCCESSFUL;
48}
49
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:
60 */
61
62rtems_boolean is_character_ready(
63  char *ch
64)
65{
66  rtems_unsigned8 rr_0;
67
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
89char 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
116void 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 );
146}
147
148/*
149 * __read  -- read bytes from the serial port. Ignore fd, since
150 *            we only have stdin.
151 */
152
153int __read(
154  int fd,
155  char *buf,
156  int nbytes
157)
158{
159  int i = 0;
160
161  for (i = 0; i < nbytes; i++) {
162    *(buf + i) = inbyte();
163    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
164      (*(buf + i++)) = '\n';
165      (*(buf + i)) = 0;
166      break;
167    }
168  }
169  return (i);
170}
171
172/*
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.
176 */
177
178int __write(
179  int fd,
180  char *buf,
181  int nbytes
182)
183{
184  int i;
185
186  for (i = 0; i < nbytes; i++) {
187    if (*(buf + i) == '\n') {
188      outbyte ('\r');
189    }
190    outbyte (*(buf + i));
191  }
192  return (nbytes);
193}
Note: See TracBrowser for help on using the repository browser.