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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [m68k/] [dmv152/] [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 TTY driver for the serial ports on the DMV152.
3
 *  The serial ports use a Zilog Z8530.
4
 *
5
 *  NOTE: This driver uses the termios pseudo driver.
6
 *        This driver is polled only.
7
 *
8
 *  COPYRIGHT (c) 1989-1999.
9
 *  On-Line Applications Research Corporation (OAR).
10
 *
11
 *  The license and distribution terms for this file may be
12
 *  found in the file LICENSE in this distribution or at
13
 *  http://www.OARcorp.com/rtems/license.html.
14
 *
15
 *  $Id: console.c,v 1.2 2001-09-27 12:00:00 chris Exp $
16
 */
17
 
18
#include <bsp.h>
19
#include <rtems/libio.h>
20
#include <stdlib.h>
21
#include <assert.h>
22
 
23
/*
24
 *  console_outbyte_polled
25
 *
26
 *  This routine transmits a character using polling.
27
 */
28
 
29
void console_outbyte_polled(
30
  int  port,
31
  char ch
32
)
33
{
34
  rtems_unsigned32 control;
35
  rtems_unsigned32 data;
36
  rtems_unsigned8  rr_0;
37
 
38
  if ( port == 0 ) {
39
    control = CONSOLE_CONTROL_A;
40
    data    = CONSOLE_DATA_A;
41
  } else {
42
    control = CONSOLE_CONTROL_B;
43
    data    = CONSOLE_DATA_B;
44
  }
45
 
46
  for ( ; ; ) {
47
    Z8x30_READ_CONTROL( control, RR_0, rr_0 );
48
    if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 )
49
      break;
50
  }
51
 
52
  Z8x30_WRITE_DATA( control, ch );
53
}
54
 
55
/*
56
 *  console_inbyte_nonblocking
57
 *
58
 *  This routine polls for a character.
59
 */
60
 
61
int console_inbyte_nonblocking(int port)
62
{
63
  rtems_unsigned32 control;
64
  rtems_unsigned32 data;
65
  rtems_unsigned8  rr_0;
66
  char             ch;
67
 
68
  if ( port == 0 ) {
69
    control = CONSOLE_CONTROL_A;
70
    data    = CONSOLE_DATA_A;
71
  } else {
72
    control = CONSOLE_CONTROL_B;
73
    data    = CONSOLE_DATA_B;
74
  }
75
 
76
  Z8x30_READ_CONTROL( control, RR_0, rr_0 );
77
  if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) )
78
    return -1;
79
 
80
  Z8x30_READ_DATA( data, ch );
81
  return (int) ch;
82
}
83
 
84
/*
85
 *  DEBUG_puts
86
 *
87
 *  This should be safe in the event of an error.  It attempts to insure
88
 *  that no TX empty interrupts occur while it is doing polled IO.  Then
89
 *  it restores the state of that external interrupt.
90
 *
91
 *  Input parameters:
92
 *    string  - pointer to debug output string
93
 *
94
 *  Output parameters:  NONE
95
 *
96
 *  Return values:      NONE
97
 */
98
 
99
void DEBUG_puts(
100
  char *string
101
)
102
{
103
  char *s;
104
 
105
  /* should disable interrupts here */
106
    for ( s = string ; *s ; s++ )
107
      console_outbyte_polled( 0, *s );
108
 
109
    console_outbyte_polled( 0, '\r' );
110
    console_outbyte_polled( 0, '\n' );
111
  /* should enable interrupts here */
112
}
113
 
114
 
115
/*
116
 *  Console Termios Support Entry Points
117
 *
118
 */
119
 
120
int console_write_support (int minor, const char *buf, int len)
121
{
122
  int nwrite = 0;
123
 
124
  while (nwrite < len) {
125
    console_outbyte_polled( minor, *buf++ );
126
    nwrite++;
127
  }
128
  return nwrite;
129
}
130
 
131
/*
132
 *  Console Device Driver Entry Points
133
 *
134
 */
135
 
136
rtems_device_driver console_initialize(
137
  rtems_device_major_number  major,
138
  rtems_device_minor_number  minor,
139
  void                      *arg
140
)
141
{
142
  rtems_status_code          status;
143
  rtems_device_minor_number  console_minor;
144
 
145
  rtems_termios_initialize();
146
 
147
  /*
148
   *  Register Device Names
149
   */
150
 
151
#if (USE_CHANNEL_A == 1)
152
  console_minor = 0;
153
#elif (USE_CHANNEL_B == 1)
154
  console_minor = 1;
155
#else
156
#error "DMV152 Console Driver -- no console port configured!!!"
157
#endif
158
 
159
  status = rtems_io_register_name( "/dev/console", major, console_minor );
160
  if (status != RTEMS_SUCCESSFUL)
161
    rtems_fatal_error_occurred(status);
162
 
163
  status = rtems_io_register_name( "/dev/console_a", major, 0 );
164
  if (status != RTEMS_SUCCESSFUL)
165
    rtems_fatal_error_occurred(status);
166
 
167
  status = rtems_io_register_name( "/dev/console_b", major, 1 );
168
  if (status != RTEMS_SUCCESSFUL)
169
    rtems_fatal_error_occurred(status);
170
 
171
  /*
172
   *  Initialize Hardware
173
   */
174
 
175
  return RTEMS_SUCCESSFUL;
176
}
177
 
178
rtems_device_driver console_open(
179
  rtems_device_major_number major,
180
  rtems_device_minor_number minor,
181
  void                    * arg
182
)
183
{
184
  rtems_status_code sc;
185
  static const rtems_termios_callbacks pollCallbacks = {
186
    NULL,                        /* firstOpen */
187
    NULL,                        /* lastClose */
188
    console_inbyte_nonblocking,  /* pollRead */
189
    console_write_support,       /* write */
190
    NULL,                        /* setAttributes */
191
    NULL,                        /* stopRemoteTx */
192
    NULL,                        /* startRemoteTx */
193
 
194
  };
195
 
196
  assert( minor <= 1 );
197
  if ( minor > 2 )
198
    return RTEMS_INVALID_NUMBER;
199
 
200
  sc = rtems_termios_open (major, minor, arg, &pollCallbacks );
201
 
202
  return RTEMS_SUCCESSFUL;
203
}
204
 
205
rtems_device_driver console_close(
206
  rtems_device_major_number major,
207
  rtems_device_minor_number minor,
208
  void                    * arg
209
)
210
{
211
  return rtems_termios_close (arg);
212
}
213
 
214
rtems_device_driver console_read(
215
  rtems_device_major_number major,
216
  rtems_device_minor_number minor,
217
  void                    * arg
218
)
219
{
220
  return rtems_termios_read (arg);
221
}
222
 
223
rtems_device_driver console_write(
224
  rtems_device_major_number major,
225
  rtems_device_minor_number minor,
226
  void                    * arg
227
)
228
{
229
  return rtems_termios_write (arg);
230
}
231
 
232
rtems_device_driver console_control(
233
  rtems_device_major_number major,
234
  rtems_device_minor_number minor,
235
  void                    * arg
236
)
237
{
238
  return rtems_termios_ioctl (arg);
239
}
240
 

powered by: WebSVN 2.1.0

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