source: rtems/c/src/lib/libbsp/i386/i386ex/console/console.c @ 60e2964

4.104.114.84.95
Last change on this file since 60e2964 was 752cd8f, checked in by Joel Sherrill <joel.sherrill@…>, on 10/15/96 at 20:57:04

initial version from Erik

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *  This file contains the Force CPU386 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 F386_INIT
16
17#include <stdlib.h>
18#include <stdio.h>   /* to be removed */
19
20#include <rtems.h>
21#include "console.h"
22#include "bsp.h"
23#include "../startup/80386ex.h"
24
25/*  console_cleanup
26 *
27 *  This routine is called at exit to clean up the console hardware.
28 *
29 *  Input parameters: NONE
30 *
31 *  Output parameters:  NONE
32 *
33 *  Return values:
34 */
35
36void console_cleanup( void )
37{
38  register rtems_unsigned8 ignored;
39
40/* clear the read buffer */
41
42   inport_byte( RBR0, ignored );
43
44/*  inport_byte( RBR0, ignored );
45 *  inport_byte( RBR0, ignored );
46 *  inport_byte( RBR0, ignored );
47 *  inport_byte( RBR0, ignored );
48 */
49
50}
51
52/*  console_initialize
53 *
54 *  This routine initializes the console IO driver.
55 *
56 *  Input parameters: NONE
57 *
58 *  Output parameters:  NONE
59 *
60 *  Return values:
61 */
62
63rtems_device_driver console_initialize(
64  rtems_device_major_number  major,
65  rtems_device_minor_number  minor,
66  void                      *arg,
67  rtems_id                   self,
68  rtems_unsigned32          *status
69)
70{
71   /*
72    *  flush the console now and at exit.  Just in case.
73    */
74
75   console_cleanup();
76
77   atexit( console_cleanup );
78}
79
80
81/*  is_character_ready
82 *
83 *  This routine returns TRUE if a character is available.
84 *
85 *  Input parameters: NONE
86 *
87 *  Output parameters:  NONE
88 *
89 *  Return values:
90 */
91
92rtems_boolean is_character_ready(
93  char *ch
94)
95{
96  register rtems_unsigned8 status;
97
98  inport_byte( LSR1, status );
99
100  if ( Is_rx_ready( status ) ) {
101     inport_byte( RBR1,  status );
102     *ch = status;
103     return TRUE;
104  }
105  return FALSE;
106}
107
108/*  inbyte
109 *
110 *  This routine reads a character from the UART.
111 *
112 *  Input parameters: NONE
113 *
114 *  Output parameters:  NONE
115 *
116 *  Return values:
117 *    character read from UART
118 */
119
120char inbyte( void )
121{
122  register rtems_unsigned8 status;
123  char                     ch;
124
125  do {
126    inport_byte( LSR1, status );
127  } while ( !( status & 0x01 ));/* s/b while ( !( Is_rx_ready( status ) ) ); */
128
129  inport_byte( RBR1, ch );
130
131  return ch;
132}
133
134/*  outbyte
135 *
136 *  This routine transmits a character out the port.  It supports
137 *  XON/XOFF flow control.
138 *
139 *  Input parameters:
140 *    ch  - character to be transmitted
141 *
142 *  Output parameters:  NONE
143 */
144
145void outbyte(
146  char ch
147)
148{
149  rtems_unsigned8 status;
150
151  do {
152    inport_byte( LSR1, status );
153  } while ( ! ( 0x40 & status ) ); /* ( Is_tx_ready( status ) ) );*/
154
155/*
156 *  GDB will NOT use XON/XOFF protocol
157 */
158
159
160#ifdef USE_XON
161 
162  while ( is_character_ready( &status ) == TRUE ) {
163    if ( status == XOFF )
164      do {
165        while ( is_character_ready( &status ) == FALSE ) ;
166      } while ( status != XON );
167  }
168
169#endif
170
171  outport_byte( TBR1, ch );
172
173}
174
175/*
176 * __read  -- read bytes from the serial port. Ignore fd, since
177 *            we only have stdin.
178 */
179
180int __read(
181  int fd,
182  char *buf,
183  int nbytes
184)
185{
186  int i = 0;
187
188  for (i = 0; i < nbytes; i++) {
189    *(buf + i) = inbyte();
190    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
191      (*(buf + i++)) = '\n';
192      (*(buf + i)) = 0;
193      break;
194    }
195  }
196  return (i);
197}
198
199/*
200 * __write -- write bytes to the serial port. Ignore fd, since
201 *            stdout and stderr are the same. Since we have no filesystem,
202 *            open will only return an error.
203 */
204
205int __write(
206  int fd,
207  char *buf,
208  int nbytes
209)
210{
211  int i;
212
213  for (i = 0; i < nbytes; i++) {
214    if (*(buf + i) == '\n') {
215      outbyte ('\r');
216    }
217    outbyte (*(buf + i));
218  }
219  return (nbytes);
220}
Note: See TracBrowser for help on using the repository browser.