OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [powerpc/] [psim/] [console/] [console.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  This file contains the hardware specific portions of the TTY driver
3
 *  for the serial ports on the erc32.
4
 *
5
 *  COPYRIGHT (c) 1989-1997.
6
 *  On-Line Applications Research Corporation (OAR).
7
 *  Copyright assigned to U.S. Government, 1994.
8
 *
9
 *  The license and distribution terms for this file may be
10
 *  found in the file LICENSE in this distribution or at
11
 *  http://www.OARcorp.com/rtems/license.html.
12
 *
13
 *  $Id: console.c,v 1.2 2001-09-27 12:01:02 chris Exp $
14
 */
15
 
16
#include <bsp.h>
17
#include <rtems/libio.h>
18
#include <stdlib.h>
19
#include <assert.h>
20
 
21
/* external prototypes for monitor interface routines */
22
 
23
void outbyte( char );
24
char inbyte( void );
25
 
26
/*
27
 *  console_outbyte_polled
28
 *
29
 *  This routine transmits a character using polling.
30
 */
31
 
32
void console_outbyte_polled(
33
  int  port,
34
  char ch
35
)
36
{
37
  outbyte( ch );
38
}
39
 
40
/*
41
 *  console_inbyte_nonblocking
42
 *
43
 *  This routine polls for a character.
44
 */
45
 
46
int console_inbyte_nonblocking(
47
  int port
48
)
49
{
50
  char c;
51
 
52
  c = inbyte();
53
  if (!c)
54
    return -1;
55
  return c;
56
}
57
 
58
/*
59
 *  DEBUG_puts
60
 *
61
 *  This should be safe in the event of an error.  It attempts to insure
62
 *  that no TX empty interrupts occur while it is doing polled IO.  Then
63
 *  it restores the state of that external interrupt.
64
 *
65
 *  Input parameters:
66
 *    string  - pointer to debug output string
67
 *
68
 *  Output parameters:  NONE
69
 *
70
 *  Return values:      NONE
71
 */
72
 
73
void DEBUG_puts(
74
  char *string
75
)
76
{
77
  char *s;
78
 
79
  /* XXX should disable interrupts around this if interrupt driven */
80
 
81
  for ( s = string ; *s ; s++ )
82
    console_outbyte_polled( 0, *s );
83
 
84
  console_outbyte_polled( 0, '\r' );
85
  console_outbyte_polled( 0, '\n' );
86
}
87
 
88
 
89
/*
90
 *  Console Termios Support Entry Points
91
 *
92
 */
93
 
94
int console_write_support (
95
  int minor,
96
  const char *bufarg,
97
  int len
98
)
99
{
100
  int nwrite = 0;
101
  const char *buf = bufarg;
102
 
103
  while (nwrite < len) {
104
    console_outbyte_polled( minor, *buf++ );
105
    nwrite++;
106
  }
107
  return nwrite;
108
}
109
 
110
/*
111
 *  Console Device Driver Entry Points
112
 *
113
 */
114
 
115
rtems_device_driver console_initialize(
116
  rtems_device_major_number  major,
117
  rtems_device_minor_number  minor,
118
  void                      *arg
119
)
120
{
121
  rtems_status_code status;
122
 
123
  rtems_termios_initialize();
124
 
125
  /*
126
   *  Register Device Names
127
   */
128
 
129
  status = rtems_io_register_name( "/dev/console", major, 0 );
130
  if (status != RTEMS_SUCCESSFUL)
131
    rtems_fatal_error_occurred(status);
132
 
133
  return RTEMS_SUCCESSFUL;
134
}
135
 
136
rtems_device_driver console_open(
137
  rtems_device_major_number major,
138
  rtems_device_minor_number minor,
139
  void                    * arg
140
)
141
{
142
  rtems_status_code sc;
143
  static const rtems_termios_callbacks pollCallbacks = {
144
    NULL,                        /* firstOpen */
145
    NULL,                        /* lastClose */
146
    console_inbyte_nonblocking,  /* pollRead */
147
    console_write_support,       /* write */
148
    NULL,                        /* setAttributes */
149
    NULL,                        /* stopRemoteTx */
150
    NULL,                        /* startRemoteTx */
151
 
152
  };
153
 
154
 
155
  assert( minor <= 1 );
156
  if ( minor > 2 )
157
    return RTEMS_INVALID_NUMBER;
158
 
159
  sc = rtems_termios_open (major, minor, arg, &pollCallbacks );
160
 
161
  return RTEMS_SUCCESSFUL;
162
}
163
 
164
rtems_device_driver console_close(
165
  rtems_device_major_number major,
166
  rtems_device_minor_number minor,
167
  void                    * arg
168
)
169
{
170
  return rtems_termios_close (arg);
171
}
172
 
173
rtems_device_driver console_read(
174
  rtems_device_major_number major,
175
  rtems_device_minor_number minor,
176
  void                    * arg
177
)
178
{
179
  return rtems_termios_read (arg);
180
}
181
 
182
rtems_device_driver console_write(
183
  rtems_device_major_number major,
184
  rtems_device_minor_number minor,
185
  void                    * arg
186
)
187
{
188
  return rtems_termios_write (arg);
189
}
190
 
191
rtems_device_driver console_control(
192
  rtems_device_major_number major,
193
  rtems_device_minor_number minor,
194
  void                    * arg
195
)
196
{
197
  return rtems_termios_ioctl (arg);
198
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.