source: rtems/c/src/lib/libcpu/powerpc/ppc403/console/console.c @ 3235ad9

4.104.114.84.95
Last change on this file since 3235ad9 was 3235ad9, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 23, 1995 at 7:30:23 PM

Support for variable length names added to Object Handler. This supports
both fixed length "raw" names and strings from the API's point of view.

Both inline and macro implementations were tested.

  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 *  This file contains the PowerPC 403GA console IO package.
3 *
4 *  Author:     Andrew Bray <andy@i-cubed.demon.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, 1990, 1991, 1992, 1993, 1994.
22 *  On-Line Applications Research Corporation (OAR).
23 *  All rights assigned to U.S. Government, 1994.
24 *
25 *  This material may be reproduced by or for the U.S. Government pursuant
26 *  to the copyright license under the clause at DFARS 252.227-7013.  This
27 *  notice must appear in all copies of this file and its derivatives.
28 *
29 *  console.c,v 1.2 1995/05/31 16:56:07 joel Exp
30 */
31
32#define NO_BSP_INIT
33
34#include <rtems.h>
35#include "console.h"
36#include "bsp.h"
37
38extern rtems_cpu_table           Cpu_table;             /* owned by BSP */
39
40struct async {
41/*-----------------------------------------------------------------------------+
42| Line Status Register.
43+-----------------------------------------------------------------------------*/
44    unsigned char SPLS;
45    unsigned char SPLSset;
46#define LSRDataReady             0x80
47#define LSRFramingError          0x40
48#define LSROverrunError          0x20
49#define LSRParityError           0x10
50#define LSRBreakInterrupt        0x08
51#define LSRTxHoldEmpty           0x04
52#define LSRTxShiftEmpty          0x02
53
54/*-----------------------------------------------------------------------------+
55| Handshake Status Register.
56+-----------------------------------------------------------------------------*/
57    unsigned char SPHS;
58    unsigned char SPHSset;
59#define HSRDsr                   0x80
60#define HSRCts                   0x40
61
62/*-----------------------------------------------------------------------------+
63| Baud rate divisor registers
64+-----------------------------------------------------------------------------*/
65    unsigned char BRDH;
66    unsigned char BRDL;
67
68/*-----------------------------------------------------------------------------+
69| Control Register.
70+-----------------------------------------------------------------------------*/
71    unsigned char SPCTL;
72#define CRNormal                      0x00
73#define CRLoopback                    0x40
74#define CRAutoEcho                    0x80
75#define CRDtr                    0x20
76#define CRRts                    0x10
77#define CRWordLength7            0x00
78#define CRWordLength8            0x08
79#define CRParityDisable          0x00
80#define CRParityEnable           0x04
81#define CREvenParity             0x00
82#define CROddParity           0x02
83#define CRStopBitsOne            0x00
84#define CRStopBitsTwo            0x01
85#define CRDisableDtrRts       0x00
86
87/*-----------------------------------------------------------------------------+
88| Receiver Command Register.
89+-----------------------------------------------------------------------------*/
90    unsigned char SPRC;
91#define RCRDisable                    0x00
92#define RCREnable                     0x80
93#define RCRIntDisable         0x00
94#define RCRIntEnabled         0x20
95#define RCRDMACh2                     0x40
96#define RCRDMACh3                     0x60
97#define RCRErrorInt           0x10
98#define RCRPauseEnable        0x08
99
100/*-----------------------------------------------------------------------------+
101| Transmitter Command Register.
102+-----------------------------------------------------------------------------*/
103    unsigned char SPTC;
104#define TCRDisable                    0x00
105#define TCREnable                     0x80
106#define TCRIntDisable         0x00
107#define TCRIntEnabled         0x20
108#define TCRDMACh2                     0x40
109#define TCRDMACh3                     0x60
110#define TCRTxEmpty                    0x10
111#define TCRErrorInt           0x08
112#define TCRStopPause          0x04
113#define TCRBreakGen           0x02
114
115/*-----------------------------------------------------------------------------+
116| Miscellanies defines.
117+-----------------------------------------------------------------------------*/
118    unsigned char SPTB;
119#define SPRB    SPTB
120};
121
122#define XOFFchar                      0x13
123#define XONchar                       0x11
124
125typedef volatile struct async *pasync;
126static const pasync port = (pasync)0x40000000;
127
128/*  console_initialize
129 *
130 *  This routine initializes the console IO driver.
131 *
132 *  Input parameters: NONE
133 *
134 *  Output parameters:  NONE
135 *
136 *  Return values:
137 */
138
139rtems_device_driver console_initialize(
140  rtems_device_major_number  major,
141  rtems_device_minor_number  minor,
142  void                      *arg,
143  rtems_id                   self,
144  rtems_unsigned32          *status
145)
146{
147  register unsigned tmp;
148
149  /* Initialise the serial port */
150  asm volatile ("mfiocr %0" : "=r" (tmp));
151  tmp &= ~3;
152  tmp |= (Cpu_table.serial_external_clock ? 2 : 0) |
153      (Cpu_table.serial_cts_rts ? 1 : 0);
154  asm volatile ("mtiocr %0" : "=r" (tmp) : "0" (tmp));
155  port->SPLS = (LSRDataReady | LSRFramingError | LSROverrunError |
156               LSRParityError | LSRBreakInterrupt);
157  tmp = Cpu_table.serial_per_sec / Cpu_table.serial_rate;
158  tmp = ((tmp + 8) >> 4) - 1;
159  port->BRDL = tmp & 0x255;
160  port->BRDH = tmp >> 8;
161  port->SPCTL = (CRNormal | CRDtr | CRRts | CRWordLength8 | CRParityDisable |
162                 CRStopBitsOne);
163  port->SPRC = (RCREnable | RCRIntDisable | RCRPauseEnable);
164  port->SPTC = (TCREnable | TCRIntDisable);
165  port->SPHS = (HSRDsr | HSRCts);
166
167  *status = RTEMS_SUCCESSFUL;
168}
169
170
171/*  is_character_ready
172 *
173 *  This routine returns TRUE if a character is available.
174 *
175 *  Input parameters: NONE
176 *
177 *  Output parameters:  NONE
178 *
179 *  Return values:
180 */
181
182rtems_boolean is_character_ready(
183  char *ch
184)
185{
186  unsigned char status;
187
188  if ((status = port->SPLS) & LSRDataReady)
189    {
190      *ch = port->SPRB; 
191      return(TRUE);
192    }
193
194  /* Clean any dodgy status */
195  if ((status & (LSRFramingError | LSROverrunError | LSRParityError |
196                 LSRBreakInterrupt)) != 0)
197    {
198      port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError |
199                 LSRBreakInterrupt);
200    }
201
202  return FALSE;
203}
204
205/*  inbyte
206 *
207 *  This routine reads a character from the SOURCE.
208 *
209 *  Input parameters: NONE
210 *
211 *  Output parameters:  NONE
212 *
213 *  Return values:
214 *    character read from SOURCE
215 */
216
217char inbyte( void )
218{
219  unsigned char status;
220
221  while (1)
222    {
223      if ((status = port->SPLS) & LSRDataReady)
224        break;
225
226      /* Clean any dodgy status */
227      if ((status & (LSRFramingError | LSROverrunError | LSRParityError |
228                     LSRBreakInterrupt)) != 0)
229        {
230          port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError |
231                        LSRBreakInterrupt);
232        }
233    }
234
235  return port->SPRB; 
236}
237
238/*  outbyte
239 *
240 *  This routine transmits a character out the SOURCE.  It may support
241 *  XON/XOFF flow control.
242 *
243 *  Input parameters:
244 *    ch  - character to be transmitted
245 *
246 *  Output parameters:  NONE
247 */
248
249void outbyte(
250  char ch
251)
252{
253  unsigned char status;
254
255  while (port->SPHS)
256    port->SPHS = (HSRDsr | HSRCts);
257
258  while (1)
259    {
260      status = port->SPLS;
261
262      if (port->SPHS)
263        port->SPHS = (HSRDsr | HSRCts);
264      else if (status & LSRTxHoldEmpty)
265        break;
266    }
267
268  if (Cpu_table.serial_xon_xoff)
269    while (is_character_ready(&status))
270      {
271        if (status == XOFFchar)
272          do
273            {
274              while (!is_character_ready(&status));
275            }
276          while (status != XONchar);
277      }
278
279  port->SPTB = ch;
280}
281
282/*
283 * __read  -- read bytes from the serial port. Ignore fd, since
284 *            we only have stdin.
285 */
286
287int __read(
288  int fd,
289  char *buf,
290  int nbytes
291)
292{
293  int i = 0;
294
295  for (i = 0; i < nbytes; i++) {
296    *(buf + i) = inbyte();
297    if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
298      (*(buf + i++)) = '\n';
299      (*(buf + i)) = 0;
300      break;
301    }
302  }
303  return (i);
304}
305
306/*
307 * __write -- write bytes to the serial port. Ignore fd, since
308 *            stdout and stderr are the same. Since we have no filesystem,
309 *            open will only return an error.
310 */
311
312int __write(
313  int fd,
314  char *buf,
315  int nbytes
316)
317{
318  int i;
319
320  for (i = 0; i < nbytes; i++) {
321    if (*(buf + i) == '\n') {
322      outbyte ('\r');
323    }
324    outbyte (*(buf + i));
325  }
326  return (nbytes);
327}
Note: See TracBrowser for help on using the repository browser.