source: rtems/c/src/lib/libbsp/m68k/dmv152/console/console.c @ 5072b07

4.104.114.84.95
Last change on this file since 5072b07 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.5 KB
Line 
1/*
2 *  This file contains the DMV152 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 *  $Id$
13 */
14
15#define D152_INIT
16
17#include <rtems.h>
18#include "console.h"
19#include "bsp.h"
20
21/*  console_initialize
22 *
23 *  This routine initializes the console IO driver.
24 *
25 *  Input parameters: NONE
26 *
27 *  Output parameters:  NONE
28 *
29 *  Return values:
30 */
31
32rtems_device_driver console_initialize(
33  rtems_device_major_number  major,
34  rtems_device_minor_number  minor,
35  void                      *arg,
36  rtems_id                   self,
37  rtems_unsigned32          *status
38)
39{
40  *status = RTEMS_SUCCESSFUL;
41}
42
43
44/*  is_character_ready
45 *
46 *  This routine returns TRUE if a character is available.
47 *
48 *  Input parameters: NONE
49 *
50 *  Output parameters:  NONE
51 *
52 *  Return values:
53 */
54
55rtems_boolean is_character_ready(
56  char *ch
57)
58{
59  rtems_unsigned8 rr_0;
60
61  for ( ; ; ) {
62    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
63    if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
64      return( FALSE );
65
66    Z8x30_READ_DATA( CONSOLE_DATA, *ch );
67    return( TRUE );
68  }
69}
70
71/*  inbyte
72 *
73 *  This routine reads a character from the SCC.
74 *
75 *  Input parameters: NONE
76 *
77 *  Output parameters:  NONE
78 *
79 *  Return values:
80 *    character read from SCC
81 */
82
83char inbyte( void )
84{
85  rtems_unsigned8 rr_0;
86  char ch;
87
88  for ( ; ; ) {
89    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
90    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 )
91      break;
92  }
93
94  Z8x30_READ_DATA( CONSOLE_DATA, ch );
95  return ( ch );
96}
97
98/*  outbyte
99 *
100 *  This routine transmits a character out the SCC.  It supports
101 *  XON/XOFF flow control.
102 *
103 *  Input parameters:
104 *    ch  - character to be transmitted
105 *
106 *  Output parameters:  NONE
107 */
108
109void outbyte(
110  char ch
111)
112{
113  rtems_unsigned8 rr_0;
114  char            flow_control;
115
116  for ( ; ; ) {
117    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
118    if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
119      break;
120  }
121
122  for ( ; ; ) {
123    Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
124    if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 )
125      break;
126
127    Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
128
129    if ( flow_control == XOFF )
130      do {
131        do {
132          Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 );
133        } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 );
134        Z8x30_READ_DATA( CONSOLE_DATA, flow_control );
135      } while ( flow_control != XON );
136  }
137
138  Z8x30_WRITE_DATA( CONSOLE_DATA, ch );
139}
140
141/*
142 * __read  -- read bytes from the serial port. Ignore fd, since
143 *            we only have stdin.
144 */
145
146int __read(
147  int fd,
148  char *buf,
149  int nbytes
150)
151{
152  int i = 0;
153
154  for (i = 0; i < nbytes; i++) {
155    *(buf + i) = inbyte();
156    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
157      (*(buf + i++)) = '\n';
158      (*(buf + i)) = 0;
159      break;
160    }
161  }
162  return (i);
163}
164
165/*
166 * __write -- write bytes to the serial port. Ignore fd, since
167 *            stdout and stderr are the same. Since we have no filesystem,
168 *            open will only return an error.
169 */
170
171int __write(
172  int fd,
173  char *buf,
174  int nbytes
175)
176{
177  int i;
178
179  for (i = 0; i < nbytes; i++) {
180    if (*(buf + i) == '\n') {
181      outbyte ('\r');
182    }
183    outbyte (*(buf + i));
184  }
185  return (nbytes);
186}
Note: See TracBrowser for help on using the repository browser.