source: rtems/c/src/lib/libcpu/powerpc/ppc403/console/console.c.polled @ 458bd34

4.104.114.84.95
Last change on this file since 458bd34 was 458bd34, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 5, 1999 at 4:44:02 PM

This is another pass at making sure that nothing outside the BSP
unnecessarily uses any variables defined by the BSP. On this
sweep, use of BSP_Configuration and Cpu_table was eliminated.

A significant part of this modification was the addition of
macros to access fields in the RTEMS configuration structures.

This is necessary to strengthen the division between the BSP independent
parts of RTEMS and the BSPs themselves. This started after
comments and analysis by Ralf Corsepius <corsepiu@…>.

  • Property mode set to 100644
File size: 9.6 KB
Line 
1/*
2 *  This file contains the PowerPC 403GA console IO package.
3 *
4 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
5 *
6 *  COPYRIGHT (c) 1995 by i-cubed ltd.
7 *
8 *  To anyone who acknowledges that this file is provided "AS IS"
9 *  without any express or implied warranty:
10 *      permission to use, copy, modify, and distribute this file
11 *      for any purpose is hereby granted without fee, provided that
12 *      the above copyright notice and this notice appears in all
13 *      copies, and that the name of i-cubed limited not be used in
14 *      advertising or publicity pertaining to distribution of the
15 *      software without specific, written prior permission.
16 *      i-cubed limited makes no representations about the suitability
17 *      of this software for any purpose.
18 *
19 *  Derived from c/src/lib/libbsp/no_cpu/no_bsp/console/console.c:
20 *
21 *  COPYRIGHT (c) 1989-1998.
22 *  On-Line Applications Research Corporation (OAR).
23 *  Copyright assigned to U.S. Government, 1994.
24 *
25 *  The license and distribution terms for this file may be
26 *  found in the file LICENSE in this distribution or at
27 *  http://www.OARcorp.com/rtems/license.html.
28 *
29 *  $Id$
30 */
31
32#define NO_BSP_INIT
33
34#include <rtems.h>
35#include <rtems/libio.h>
36
37struct async {
38/*-----------------------------------------------------------------------------+
39| Line Status Register.
40+-----------------------------------------------------------------------------*/
41    unsigned char SPLS;
42    unsigned char SPLSset;
43#define LSRDataReady             0x80
44#define LSRFramingError          0x40
45#define LSROverrunError          0x20
46#define LSRParityError           0x10
47#define LSRBreakInterrupt        0x08
48#define LSRTxHoldEmpty           0x04
49#define LSRTxShiftEmpty          0x02
50
51/*-----------------------------------------------------------------------------+
52| Handshake Status Register.
53+-----------------------------------------------------------------------------*/
54    unsigned char SPHS;
55    unsigned char SPHSset;
56#define HSRDsr                   0x80
57#define HSRCts                   0x40
58
59/*-----------------------------------------------------------------------------+
60| Baud rate divisor registers
61+-----------------------------------------------------------------------------*/
62    unsigned char BRDH;
63    unsigned char BRDL;
64
65/*-----------------------------------------------------------------------------+
66| Control Register.
67+-----------------------------------------------------------------------------*/
68    unsigned char SPCTL;
69#define CRNormal                      0x00
70#define CRLoopback                    0x40
71#define CRAutoEcho                    0x80
72#define CRDtr                    0x20
73#define CRRts                    0x10
74#define CRWordLength7            0x00
75#define CRWordLength8            0x08
76#define CRParityDisable          0x00
77#define CRParityEnable           0x04
78#define CREvenParity             0x00
79#define CROddParity           0x02
80#define CRStopBitsOne            0x00
81#define CRStopBitsTwo            0x01
82#define CRDisableDtrRts       0x00
83
84/*-----------------------------------------------------------------------------+
85| Receiver Command Register.
86+-----------------------------------------------------------------------------*/
87    unsigned char SPRC;
88#define RCRDisable                    0x00
89#define RCREnable                     0x80
90#define RCRIntDisable         0x00
91#define RCRIntEnabled         0x20
92#define RCRDMACh2                     0x40
93#define RCRDMACh3                     0x60
94#define RCRErrorInt           0x10
95#define RCRPauseEnable        0x08
96
97/*-----------------------------------------------------------------------------+
98| Transmitter Command Register.
99+-----------------------------------------------------------------------------*/
100    unsigned char SPTC;
101#define TCRDisable                    0x00
102#define TCREnable                     0x80
103#define TCRIntDisable         0x00
104#define TCRIntEnabled         0x20
105#define TCRDMACh2                     0x40
106#define TCRDMACh3                     0x60
107#define TCRTxEmpty                    0x10
108#define TCRErrorInt           0x08
109#define TCRStopPause          0x04
110#define TCRBreakGen           0x02
111
112/*-----------------------------------------------------------------------------+
113| Miscellanies defines.
114+-----------------------------------------------------------------------------*/
115    unsigned char SPTB;
116#define SPRB    SPTB
117};
118
119#define XOFFchar                      0x13
120#define XONchar                       0x11
121
122typedef volatile struct async *pasync;
123static const pasync port = (pasync)0x40000000;
124
125/*  console_initialize
126 *
127 *  This routine initializes the console IO driver.
128 *
129 *  Input parameters: NONE
130 *
131 *  Output parameters:  NONE
132 *
133 *  Return values:
134 */
135
136rtems_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  register unsigned tmp;
144
145  /* Initialise the serial port */
146  asm volatile ("mfdcr %0, 0xa0" : "=r" (tmp)); /* IOCR */
147  tmp &= ~3;
148  tmp |= (rtems_cpu_configuration_get_serial_external_clock() ? 2 : 0) |
149      (rtems_cpu_configuration_get_serial_cts_rts() ? 1 : 0);
150  asm volatile ("mtdcr 0xa0, %0" : "=r" (tmp) : "0" (tmp)); /* IOCR */
151  port->SPLS = (LSRDataReady | LSRFramingError | LSROverrunError |
152         LSRParityError | LSRBreakInterrupt);
153  tmp = rtems_cpu_configuration_get_serial_per_sec() /
154          rtems_cpu_configuration_get_serial_rate();
155#if 0 /* replaced by IMD... */
156  tmp = ((tmp + 8) >> 4) - 1;
157  port->BRDL = tmp & 0x255;
158  port->BRDH = tmp >> 8;
159#else
160  tmp = ((tmp) >> 4) - 1;
161  port->BRDL = tmp & 0xff;
162  port->BRDH = tmp >> 8;
163#endif
164  port->SPCTL = (CRNormal | CRDtr | CRRts | CRWordLength8 | CRParityDisable |
165     CRStopBitsOne);
166  port->SPRC = (RCREnable | RCRIntDisable | RCRPauseEnable);
167  port->SPTC = (TCREnable | TCRIntDisable);
168  port->SPHS = (HSRDsr | HSRCts);
169
170  status = rtems_io_register_name(
171    "/dev/console",
172    major,
173    (rtems_device_minor_number) 0
174  );
175 
176  if (status != RTEMS_SUCCESSFUL)
177    rtems_fatal_error_occurred(status);
178 
179  return RTEMS_SUCCESSFUL;
180}
181
182
183/*  is_character_ready
184 *
185 *  This routine returns TRUE if a character is available.
186 *
187 *  Input parameters: NONE
188 *
189 *  Output parameters:  NONE
190 *
191 *  Return values:
192 */
193
194rtems_boolean is_character_ready(
195  char *ch
196)
197{
198  unsigned char status;
199
200  if ((status = port->SPLS) & LSRDataReady)
201    {
202      *ch = port->SPRB; 
203      return(TRUE);
204    }
205
206  /* Clean any dodgy status */
207  if ((status & (LSRFramingError | LSROverrunError | LSRParityError |
208                 LSRBreakInterrupt)) != 0)
209    {
210      port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError |
211                 LSRBreakInterrupt);
212    }
213
214  return FALSE;
215}
216
217/*  inbyte
218 *
219 *  This routine reads a character from the SOURCE.
220 *
221 *  Input parameters: NONE
222 *
223 *  Output parameters:  NONE
224 *
225 *  Return values:
226 *    character read from SOURCE
227 */
228
229char inbyte( void )
230{
231  unsigned char status;
232
233  while (1)
234    {
235      if ((status = port->SPLS) & LSRDataReady)
236              break;
237
238      /* Clean any dodgy status */
239      if ((status & (LSRFramingError | LSROverrunError | LSRParityError |
240                     LSRBreakInterrupt)) != 0)
241            {
242              port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError |
243                            LSRBreakInterrupt);
244            }
245    }
246
247  return port->SPRB; 
248}
249
250/*  outbyte
251 *
252 *  This routine transmits a character out the SOURCE.  It may support
253 *  XON/XOFF flow control.
254 *
255 *  Input parameters:
256 *    ch  - character to be transmitted
257 *
258 *  Output parameters:  NONE
259 */
260
261void outbyte(
262  char ch
263)
264{
265  unsigned char status;
266
267  while (port->SPHS)
268    port->SPHS = (HSRDsr | HSRCts);
269
270  while (1)
271    {
272      status = port->SPLS;
273
274      if (port->SPHS)
275        port->SPHS = (HSRDsr | HSRCts);
276      else if (status & LSRTxHoldEmpty)
277              break;
278    }
279
280  if (rtems_cpu_configuration_get_serial_xon_xoff())
281    while (is_character_ready(&status))
282    {
283            if (status == XOFFchar)
284              do {
285                while (!is_character_ready(&status));
286              } while (status != XONchar);
287    }
288
289  port->SPTB = ch;
290}
291
292/*
293 *  Open entry point
294 */
295 
296rtems_device_driver console_open(
297  rtems_device_major_number major,
298  rtems_device_minor_number minor,
299  void                    * arg
300)
301{
302  return RTEMS_SUCCESSFUL;
303}
304 
305/*
306 *  Close entry point
307 */
308 
309rtems_device_driver console_close(
310  rtems_device_major_number major,
311  rtems_device_minor_number minor,
312  void                    * arg
313)
314{
315  return RTEMS_SUCCESSFUL;
316}
317 
318/*
319 * read bytes from the serial port. We only have stdin.
320 */
321 
322rtems_device_driver console_read(
323  rtems_device_major_number major,
324  rtems_device_minor_number minor,
325  void                    * arg
326)
327{
328  rtems_libio_rw_args_t *rw_args;
329  char *buffer;
330  int maximum;
331  int count = 0;
332 
333  rw_args = (rtems_libio_rw_args_t *) arg;
334 
335  buffer = rw_args->buffer;
336  maximum = rw_args->count;
337 
338  for (count = 0; count < maximum; count++) {
339    buffer[ count ] = inbyte();
340    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
341      buffer[ count++ ]  = '\n';
342      buffer[ count ]  = 0;
343      break;
344    }
345  }
346 
347  rw_args->bytes_moved = count;
348  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
349}
350 
351/*
352 * write bytes to the serial port. Stdout and stderr are the same.
353 */
354 
355rtems_device_driver console_write(
356  rtems_device_major_number major,
357  rtems_device_minor_number minor,
358  void                    * arg
359)
360{
361  int count;
362  int maximum;
363  rtems_libio_rw_args_t *rw_args;
364  char *buffer;
365 
366  rw_args = (rtems_libio_rw_args_t *) arg;
367 
368  buffer = rw_args->buffer;
369  maximum = rw_args->count;
370 
371  for (count = 0; count < maximum; count++) {
372    if ( buffer[ count ] == '\n') {
373      outbyte('\r');
374    }
375    outbyte( buffer[ count ] );
376  }
377  return maximum;
378}
379 
380/*
381 *  IO Control entry point
382 */
383 
384rtems_device_driver console_control(
385  rtems_device_major_number major,
386  rtems_device_minor_number minor,
387  void                    * arg
388)
389{
390  return RTEMS_SUCCESSFUL;
391}
392
Note: See TracBrowser for help on using the repository browser.