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

4.104.114.84.95
Last change on this file since aecfa2b was aecfa2b, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 30, 1998 at 9:55:53 PM

BSP submitted by Thomas Doerfler <td@…>:

Finally I am through: I have found the last bugs that made RTEMS-
4.0-beta3 start on my ppc403 board from ROM. So now the '403
support is up to date again.

Roughly I have added the following features:

  • support for the on-chip interrupt controller (in a separate module)
  • interrupt support for the console device
  • termios support for the console device

==============================================
Since the BSP behaivour changed in some details (console no
longer is polling, other memory layout etc) I have created a new
BSP "helas403" rather than changing the "papyrus" BSP. The old
"polled" console driver still sticks around in "console.c.polled"

To get the BSP up and running, I had to create the new BSP files
(derived from papyrus). Besides that, the following source areas
have been changed:

  • c/src/lib/libcpu/powerpc/ppc403: changes to console driver, small changes to clock driver, new "ictrl" interrupt controller driver
  • c/src/exec/score/cpu/powerpc/ppc.h: some small changes (added ppc403 characteristics like a exception vector prefix register, some special register definitions). I am quite sure, they are compatible with the existing sources, although I did not check
  • c/src/exec/score/cpu/powerpc/cpu.c: There is one severe limitation in the exception entries: Due to the current code arrangement, the "branch absolute" to the ISR handler may only jump to the first 128MByte or the last 128MByte of the 4GByte address range. When the ppc403 is running out of ROM, the ROM functions are located in the last 128MByte (0xFFF00000 and up). These addresses were not handled correctly (sign reduced) in "install_raw_handler". The change I added should work on existing ppc BSPs aswell...
  • c/src/lib/libc/termios.c: During my tests, I added one change you sent me, so this patch will already be incorporated in the current source tree.

There are some smaller changes, see the attached diff file.

=========================================
Concerning the GNU toolchain:

I tried several tool chains. Finally I almost succeeded with

egcs-1.0.3a with patch egcs-1.0.3-rtems-diff-19980527

I had to add the following lines to the egcs files. Without them
configure complaint that the cross compiler could not generate
executable output.

  • additional lines needed in egcs distribution in file gcc/config/rs6000/rtems.h:

+++ lines start
#undef STARTFILE_DEFAULT_SPEC
#define STARTFILE_DEFAULT_SPEC "ecrti.o%s"

#undef ENDFILE_DEFAULT_SPEC
#define ENDFILE_DEFAULT_SPEC "ecrtn.o%s"
++++ lines end

As far as I have seen in the Changelog of egcs, you have recently
sent two patches affecting the powerpc support, but they were
added in the wrong order.... :-(

egcs-19980628 with patch egcs-19980628-rtems-diff-19980707 does
not work!

I used binutils 2.9.1 with patch binutils-2.9.1-rtems-diff-19980515

(binutils 2.8.1 does not work, internal error in gas)

and newlib-1.8.0 with patch newlib-1.8.0-rtems-diff-19980707

Finally I had to poke a line in the "bit" script, since, on my LINUX
machine, the GNU make is only available as "make", not as
"gmake"...

For all the tools and newlib I selected configuration "powerpc-
rtems".


IMD Ingenieurbuero fuer Microcomputertechnik
Thomas Doerfler Herbststrasse 8
D-82178 Puchheim Germany
email: td@…

  • 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 <bsp.h>
35#include <rtems/libio.h>
36
37extern rtems_cpu_table           Cpu_table;             /* owned by BSP */
38
39struct async {
40/*-----------------------------------------------------------------------------+
41| Line Status Register.
42+-----------------------------------------------------------------------------*/
43    unsigned char SPLS;
44    unsigned char SPLSset;
45#define LSRDataReady             0x80
46#define LSRFramingError          0x40
47#define LSROverrunError          0x20
48#define LSRParityError           0x10
49#define LSRBreakInterrupt        0x08
50#define LSRTxHoldEmpty           0x04
51#define LSRTxShiftEmpty          0x02
52
53/*-----------------------------------------------------------------------------+
54| Handshake Status Register.
55+-----------------------------------------------------------------------------*/
56    unsigned char SPHS;
57    unsigned char SPHSset;
58#define HSRDsr                   0x80
59#define HSRCts                   0x40
60
61/*-----------------------------------------------------------------------------+
62| Baud rate divisor registers
63+-----------------------------------------------------------------------------*/
64    unsigned char BRDH;
65    unsigned char BRDL;
66
67/*-----------------------------------------------------------------------------+
68| Control Register.
69+-----------------------------------------------------------------------------*/
70    unsigned char SPCTL;
71#define CRNormal                      0x00
72#define CRLoopback                    0x40
73#define CRAutoEcho                    0x80
74#define CRDtr                    0x20
75#define CRRts                    0x10
76#define CRWordLength7            0x00
77#define CRWordLength8            0x08
78#define CRParityDisable          0x00
79#define CRParityEnable           0x04
80#define CREvenParity             0x00
81#define CROddParity           0x02
82#define CRStopBitsOne            0x00
83#define CRStopBitsTwo            0x01
84#define CRDisableDtrRts       0x00
85
86/*-----------------------------------------------------------------------------+
87| Receiver Command Register.
88+-----------------------------------------------------------------------------*/
89    unsigned char SPRC;
90#define RCRDisable                    0x00
91#define RCREnable                     0x80
92#define RCRIntDisable         0x00
93#define RCRIntEnabled         0x20
94#define RCRDMACh2                     0x40
95#define RCRDMACh3                     0x60
96#define RCRErrorInt           0x10
97#define RCRPauseEnable        0x08
98
99/*-----------------------------------------------------------------------------+
100| Transmitter Command Register.
101+-----------------------------------------------------------------------------*/
102    unsigned char SPTC;
103#define TCRDisable                    0x00
104#define TCREnable                     0x80
105#define TCRIntDisable         0x00
106#define TCRIntEnabled         0x20
107#define TCRDMACh2                     0x40
108#define TCRDMACh3                     0x60
109#define TCRTxEmpty                    0x10
110#define TCRErrorInt           0x08
111#define TCRStopPause          0x04
112#define TCRBreakGen           0x02
113
114/*-----------------------------------------------------------------------------+
115| Miscellanies defines.
116+-----------------------------------------------------------------------------*/
117    unsigned char SPTB;
118#define SPRB    SPTB
119};
120
121#define XOFFchar                      0x13
122#define XONchar                       0x11
123
124typedef volatile struct async *pasync;
125static const pasync port = (pasync)0x40000000;
126
127/*  console_initialize
128 *
129 *  This routine initializes the console IO driver.
130 *
131 *  Input parameters: NONE
132 *
133 *  Output parameters:  NONE
134 *
135 *  Return values:
136 */
137
138rtems_device_driver console_initialize(
139  rtems_device_major_number  major,
140  rtems_device_minor_number  minor,
141  void                      *arg
142)
143{
144  rtems_status_code status;
145  register unsigned tmp;
146
147  /* Initialise the serial port */
148  asm volatile ("mfdcr %0, 0xa0" : "=r" (tmp)); /* IOCR */
149  tmp &= ~3;
150  tmp |= (Cpu_table.serial_external_clock ? 2 : 0) |
151      (Cpu_table.serial_cts_rts ? 1 : 0);
152  asm volatile ("mtdcr 0xa0, %0" : "=r" (tmp) : "0" (tmp)); /* IOCR */
153  port->SPLS = (LSRDataReady | LSRFramingError | LSROverrunError |
154         LSRParityError | LSRBreakInterrupt);
155  tmp = Cpu_table.serial_per_sec / Cpu_table.serial_rate;
156#if 0 /* replaced by IMD... */
157  tmp = ((tmp + 8) >> 4) - 1;
158  port->BRDL = tmp & 0x255;
159  port->BRDH = tmp >> 8;
160#else
161  tmp = ((tmp) >> 4) - 1;
162  port->BRDL = tmp & 0xff;
163  port->BRDH = tmp >> 8;
164#endif
165  port->SPCTL = (CRNormal | CRDtr | CRRts | CRWordLength8 | CRParityDisable |
166     CRStopBitsOne);
167  port->SPRC = (RCREnable | RCRIntDisable | RCRPauseEnable);
168  port->SPTC = (TCREnable | TCRIntDisable);
169  port->SPHS = (HSRDsr | HSRCts);
170
171  status = rtems_io_register_name(
172    "/dev/console",
173    major,
174    (rtems_device_minor_number) 0
175  );
176 
177  if (status != RTEMS_SUCCESSFUL)
178    rtems_fatal_error_occurred(status);
179 
180  return RTEMS_SUCCESSFUL;
181}
182
183
184/*  is_character_ready
185 *
186 *  This routine returns TRUE if a character is available.
187 *
188 *  Input parameters: NONE
189 *
190 *  Output parameters:  NONE
191 *
192 *  Return values:
193 */
194
195rtems_boolean is_character_ready(
196  char *ch
197)
198{
199  unsigned char status;
200
201  if ((status = port->SPLS) & LSRDataReady)
202    {
203      *ch = port->SPRB; 
204      return(TRUE);
205    }
206
207  /* Clean any dodgy status */
208  if ((status & (LSRFramingError | LSROverrunError | LSRParityError |
209                 LSRBreakInterrupt)) != 0)
210    {
211      port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError |
212                 LSRBreakInterrupt);
213    }
214
215  return FALSE;
216}
217
218/*  inbyte
219 *
220 *  This routine reads a character from the SOURCE.
221 *
222 *  Input parameters: NONE
223 *
224 *  Output parameters:  NONE
225 *
226 *  Return values:
227 *    character read from SOURCE
228 */
229
230char inbyte( void )
231{
232  unsigned char status;
233
234  while (1)
235    {
236      if ((status = port->SPLS) & LSRDataReady)
237              break;
238
239      /* Clean any dodgy status */
240      if ((status & (LSRFramingError | LSROverrunError | LSRParityError |
241                     LSRBreakInterrupt)) != 0)
242            {
243              port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError |
244                            LSRBreakInterrupt);
245            }
246    }
247
248  return port->SPRB; 
249}
250
251/*  outbyte
252 *
253 *  This routine transmits a character out the SOURCE.  It may support
254 *  XON/XOFF flow control.
255 *
256 *  Input parameters:
257 *    ch  - character to be transmitted
258 *
259 *  Output parameters:  NONE
260 */
261
262void outbyte(
263  char ch
264)
265{
266  unsigned char status;
267
268  while (port->SPHS)
269    port->SPHS = (HSRDsr | HSRCts);
270
271  while (1)
272    {
273      status = port->SPLS;
274
275      if (port->SPHS)
276        port->SPHS = (HSRDsr | HSRCts);
277      else if (status & LSRTxHoldEmpty)
278              break;
279    }
280
281  if (Cpu_table.serial_xon_xoff)
282    while (is_character_ready(&status))
283    {
284            if (status == XOFFchar)
285              do {
286                while (!is_character_ready(&status));
287              } while (status != XONchar);
288    }
289
290  port->SPTB = ch;
291}
292
293/*
294 *  Open entry point
295 */
296 
297rtems_device_driver console_open(
298  rtems_device_major_number major,
299  rtems_device_minor_number minor,
300  void                    * arg
301)
302{
303  return RTEMS_SUCCESSFUL;
304}
305 
306/*
307 *  Close entry point
308 */
309 
310rtems_device_driver console_close(
311  rtems_device_major_number major,
312  rtems_device_minor_number minor,
313  void                    * arg
314)
315{
316  return RTEMS_SUCCESSFUL;
317}
318 
319/*
320 * read bytes from the serial port. We only have stdin.
321 */
322 
323rtems_device_driver console_read(
324  rtems_device_major_number major,
325  rtems_device_minor_number minor,
326  void                    * arg
327)
328{
329  rtems_libio_rw_args_t *rw_args;
330  char *buffer;
331  int maximum;
332  int count = 0;
333 
334  rw_args = (rtems_libio_rw_args_t *) arg;
335 
336  buffer = rw_args->buffer;
337  maximum = rw_args->count;
338 
339  for (count = 0; count < maximum; count++) {
340    buffer[ count ] = inbyte();
341    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
342      buffer[ count++ ]  = '\n';
343      buffer[ count ]  = 0;
344      break;
345    }
346  }
347 
348  rw_args->bytes_moved = count;
349  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
350}
351 
352/*
353 * write bytes to the serial port. Stdout and stderr are the same.
354 */
355 
356rtems_device_driver console_write(
357  rtems_device_major_number major,
358  rtems_device_minor_number minor,
359  void                    * arg
360)
361{
362  int count;
363  int maximum;
364  rtems_libio_rw_args_t *rw_args;
365  char *buffer;
366 
367  rw_args = (rtems_libio_rw_args_t *) arg;
368 
369  buffer = rw_args->buffer;
370  maximum = rw_args->count;
371 
372  for (count = 0; count < maximum; count++) {
373    if ( buffer[ count ] == '\n') {
374      outbyte('\r');
375    }
376    outbyte( buffer[ count ] );
377  }
378  return maximum;
379}
380 
381/*
382 *  IO Control entry point
383 */
384 
385rtems_device_driver console_control(
386  rtems_device_major_number major,
387  rtems_device_minor_number minor,
388  void                    * arg
389)
390{
391  return RTEMS_SUCCESSFUL;
392}
393
Note: See TracBrowser for help on using the repository browser.