source: rtems/c/src/lib/libbsp/powerpc/gen83xx/console/console.c @ d9be8024

4.104.114.9
Last change on this file since d9be8024 was d9be8024, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 21, 2008 at 4:16:47 PM

2008-08-21 Joel Sherrill <joel.sherrill@…>

  • Makefile.am: Added bspclean.c and use shared bsppretaskinghook.c.
  • console/console.c: Added poll for char helper.
  • include/bsp.h: Add macro definitions for optional reset behavior.
  • startup/bspstart.c: Split out bsp_cleanup(). Clean up.
  • startup/bspclean.c: New file. Not can press any key on normal shutdown to reset board when on MPC8313erdb.
  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic MPC83xx BSP                              |
3+-----------------------------------------------------------------+
4| This file has been adapted from the ep1a BSP to MPC83xx by      |
5|    Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>         |
6|                    Copyright (c) 2007                           |
7|                    Embedded Brains GmbH                         |
8|                    Obere Lagerstr. 30                           |
9|                    D-82178 Puchheim                             |
10|                    Germany                                      |
11|                    rtems@embedded-brains.de                     |
12|                                                                 |
13| See the other copyright notice below for the original parts.    |
14+-----------------------------------------------------------------+
15| The license and distribution terms for this file may be         |
16| found in the file LICENSE in this distribution or at            |
17|                                                                 |
18| http://www.rtems.com/license/LICENSE.                           |
19|                                                                 |
20+-----------------------------------------------------------------+
21| this file contains the console driver                           |
22\*===============================================================*/
23/* derived from: */
24/*
25 *  This file contains the TTY driver for the ep1a
26 *
27 *  This driver uses the termios pseudo driver.
28 *
29 *  COPYRIGHT (c) 1989-1999.
30 *  On-Line Applications Research Corporation (OAR).
31 *
32 *  The license and distribution terms for this file may be
33 *  found in the file LICENSE in this distribution or at
34 *  http://www.rtems.com/license/LICENSE.
35 *
36 *  $Id$
37 */
38
39#include <bsp.h>
40#include <rtems/libio.h>
41#include <stdlib.h>
42#include <assert.h>
43#include <termios.h>
44
45#include "console.h"
46#include <rtems/bspIo.h>
47#include <rtems/termiostypes.h>
48
49/*
50 * Load configuration table
51 */
52#include "config.c"
53
54#define NUM_CONSOLE_PORTS (sizeof(Console_Port_Tbl)/sizeof(console_tbl))
55
56console_data    Console_Port_Data[NUM_CONSOLE_PORTS];
57unsigned long   Console_Port_Count;
58rtems_device_minor_number  Console_Port_Minor;
59rtems_boolean Console_Is_Initialized = FALSE;           
60/* PAGE
61 *
62 *  console_open
63 *
64 *  open a port as a termios console.
65 *
66 */
67rtems_device_driver console_open(
68  rtems_device_major_number major,
69  rtems_device_minor_number minor,
70  void                    * arg
71)
72{
73        rtems_status_code status;
74        rtems_libio_open_close_args_t *args = arg;
75        rtems_termios_callbacks Callbacks;
76        console_fns *c;
77
78        /*
79         * Verify the port number is valid.
80         */
81        if(minor>Console_Port_Count)
82        {
83                return RTEMS_INVALID_NUMBER;
84        }
85
86        /*
87         *  open the port as a termios console driver.
88         */
89        c = Console_Port_Tbl[minor].pDeviceFns;
90        Callbacks.firstOpen     = c->deviceFirstOpen;
91        Callbacks.lastClose     = c->deviceLastClose;
92        Callbacks.pollRead      = c->deviceRead;
93        Callbacks.write         = c->deviceWrite;
94        Callbacks.setAttributes = c->deviceSetAttributes;
95        Callbacks.stopRemoteTx  = 
96                Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx;
97        Callbacks.startRemoteTx = 
98                Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx;
99        Callbacks.outputUsesInterrupts = c->deviceOutputUsesInterrupts;
100        status = rtems_termios_open ( major, minor, arg, &Callbacks);
101        Console_Port_Data[minor].termios_data = args->iop->data1;
102        if (status == 0) {
103                rtems_termios_set_initial_baud( Console_Port_Data [minor].termios_data, (int) Console_Port_Tbl [minor].pDeviceParams);
104        }
105
106        return status;
107}
108 
109rtems_device_driver console_close(
110  rtems_device_major_number major,
111  rtems_device_minor_number minor,
112  void                    * arg
113)
114{
115        rtems_libio_open_close_args_t *args = arg;
116
117        if((args->iop->flags&LIBIO_FLAGS_READ) &&
118           Console_Port_Tbl[minor].pDeviceFlow &&
119           Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx)
120        {
121                Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
122        }
123
124        return rtems_termios_close (arg);
125}
126 
127rtems_device_driver console_read(
128  rtems_device_major_number major,
129  rtems_device_minor_number minor,
130  void                    * arg
131)
132{
133  return rtems_termios_read (arg);
134}
135 
136rtems_device_driver console_write(
137  rtems_device_major_number major,
138  rtems_device_minor_number minor,
139  void                    * arg
140)
141{
142  return rtems_termios_write (arg);
143}
144 
145rtems_device_driver console_control(
146  rtems_device_major_number major,
147  rtems_device_minor_number minor,
148  void                    * arg
149)
150{
151  return rtems_termios_ioctl (arg);
152}
153
154/* PAGE
155 *
156 *  console_initialize
157 *
158 *  Routine called to initialize the console device driver.
159 */
160rtems_device_driver console_initialize(
161  rtems_device_major_number  major,
162  rtems_device_minor_number  minor,
163  void                      *arg
164)
165{
166  rtems_status_code          status;
167
168  /*
169   * initialize the termio interface.
170   */
171  rtems_termios_initialize();
172
173  Console_Port_Count=NUM_CONSOLE_PORTS;
174
175  for(minor=0;
176    minor<Console_Port_Count;
177    minor++)
178  {
179    /*
180     * transfer the real internal bus frequency into the
181     * console port table
182     */
183    Console_Port_Tbl[minor].ulClock = BSP_bus_frequency;
184    /*
185     * First perform the configuration dependant probe, then the
186     * device dependant probe
187     */
188    if((!Console_Port_Tbl[minor].deviceProbe ||
189         Console_Port_Tbl[minor].deviceProbe(minor)) &&
190         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
191    {
192      /*
193       * Use this device for the console
194       */
195      break;
196    }
197  }
198  if(minor==Console_Port_Count)
199  {
200    /*
201     * Failed to find a working device
202     */
203    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
204  }
205       
206  Console_Port_Minor=minor;
207
208  /*
209   *  Register Device Names
210   */
211
212  status = rtems_io_register_name("/dev/console",
213           major,
214           Console_Port_Minor );
215  if (status != RTEMS_SUCCESSFUL)
216  {
217    rtems_fatal_error_occurred(status);
218  }
219  if ( Console_Port_Tbl[Console_Port_Minor].pDeviceFns->deviceInitialize ) {
220    Console_Port_Tbl[Console_Port_Minor]
221      .pDeviceFns->deviceInitialize(Console_Port_Minor);
222    Console_Is_Initialized = TRUE;
223  }
224
225  for(minor++;minor<Console_Port_Count;minor++)
226  {
227    /*
228     * First perform the configuration dependant probe, then the
229     * device dependant probe
230     */
231    if((!Console_Port_Tbl[minor].deviceProbe ||
232         Console_Port_Tbl[minor].deviceProbe(minor)) &&
233         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
234    {
235      status = rtems_io_register_name(
236        Console_Port_Tbl[minor].sDeviceName,
237        major,
238        minor );
239      if (status != RTEMS_SUCCESSFUL)
240      {
241        rtems_fatal_error_occurred(status);
242      }
243
244      /*
245       * Initialize the hardware device.
246       */
247      if ( Console_Port_Tbl[minor].pDeviceFns->deviceInitialize )
248        Console_Port_Tbl[minor].pDeviceFns->deviceInitialize( minor);
249    }
250  }
251
252  return RTEMS_SUCCESSFUL;
253}
254
255void debug_putc_onlcr(const char c)
256{
257  uint32_t Irql;
258  if (Console_Is_Initialized) {
259    rtems_interrupt_disable(Irql);
260   
261    Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
262      deviceWritePolled(Console_Port_Minor,c);
263
264    if (c == '\n') {
265      Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
266        deviceWritePolled(Console_Port_Minor,'\r');
267    }
268   
269    rtems_interrupt_enable(Irql);
270  }
271}
272
273BSP_output_char_function_type   BSP_output_char = debug_putc_onlcr;
274/* const char arg to be compatible with BSP_output_char decl. */
275
276int bsp_uart_pollRead(int minor)
277{
278  return Console_Port_Tbl [0].pDeviceFns->deviceRead(0);
279}
Note: See TracBrowser for help on using the repository browser.