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

4.104.114.84.95
Last change on this file since 76e552d3 was 76e552d3, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 17, 2007 at 2:09:32 PM

2007-09-17 Joel Sherrill <joel.sherrill@…>

  • console/console.c: Eliminate DEBUG_puts.
  • Property mode set to 100644
File size: 7.0 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
48/*
49 * Load configuration table
50 */
51#include "config.c"
52
53#define NUM_CONSOLE_PORTS (sizeof(Console_Port_Tbl)/sizeof(console_tbl))
54
55console_data    Console_Port_Data[NUM_CONSOLE_PORTS];
56unsigned long   Console_Port_Count;
57rtems_device_minor_number  Console_Port_Minor;
58rtems_boolean Console_Is_Initialized = FALSE;           
59/* PAGE
60 *
61 *  console_open
62 *
63 *  open a port as a termios console.
64 *
65 */
66rtems_device_driver console_open(
67  rtems_device_major_number major,
68  rtems_device_minor_number minor,
69  void                    * arg
70)
71{
72        rtems_status_code status;
73        rtems_libio_open_close_args_t *args = arg;
74        rtems_termios_callbacks Callbacks;
75        console_fns *c;
76
77        /*
78         * Verify the port number is valid.
79         */
80        if(minor>Console_Port_Count)
81        {
82                return RTEMS_INVALID_NUMBER;
83        }
84
85        /*
86         *  open the port as a termios console driver.
87         */
88        c = Console_Port_Tbl[minor].pDeviceFns;
89        Callbacks.firstOpen     = c->deviceFirstOpen;
90        Callbacks.lastClose     = c->deviceLastClose;
91        Callbacks.pollRead      = c->deviceRead;
92        Callbacks.write         = c->deviceWrite;
93        Callbacks.setAttributes = c->deviceSetAttributes;
94        Callbacks.stopRemoteTx  = 
95                Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx;
96        Callbacks.startRemoteTx = 
97                Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx;
98        Callbacks.outputUsesInterrupts = c->deviceOutputUsesInterrupts;
99        status = rtems_termios_open ( major, minor, arg, &Callbacks);
100        Console_Port_Data[minor].termios_data = args->iop->data1;
101
102        return status;
103}
104 
105rtems_device_driver console_close(
106  rtems_device_major_number major,
107  rtems_device_minor_number minor,
108  void                    * arg
109)
110{
111        rtems_libio_open_close_args_t *args = arg;
112
113        if((args->iop->flags&LIBIO_FLAGS_READ) &&
114           Console_Port_Tbl[minor].pDeviceFlow &&
115           Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx)
116        {
117                Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor);
118        }
119
120        return rtems_termios_close (arg);
121}
122 
123rtems_device_driver console_read(
124  rtems_device_major_number major,
125  rtems_device_minor_number minor,
126  void                    * arg
127)
128{
129  return rtems_termios_read (arg);
130}
131 
132rtems_device_driver console_write(
133  rtems_device_major_number major,
134  rtems_device_minor_number minor,
135  void                    * arg
136)
137{
138  return rtems_termios_write (arg);
139}
140 
141rtems_device_driver console_control(
142  rtems_device_major_number major,
143  rtems_device_minor_number minor,
144  void                    * arg
145)
146{
147  return rtems_termios_ioctl (arg);
148}
149
150/* PAGE
151 *
152 *  console_initialize
153 *
154 *  Routine called to initialize the console device driver.
155 */
156rtems_device_driver console_initialize(
157  rtems_device_major_number  major,
158  rtems_device_minor_number  minor,
159  void                      *arg
160)
161{
162  rtems_status_code          status;
163
164  /*
165   * initialize the termio interface.
166   */
167  rtems_termios_initialize();
168
169  Console_Port_Count=NUM_CONSOLE_PORTS;
170
171  for(minor=0;
172    minor<Console_Port_Count;
173    minor++)
174  {
175    /*
176     * First perform the configuration dependant probe, then the
177     * device dependant probe
178     */
179    if((!Console_Port_Tbl[minor].deviceProbe ||
180         Console_Port_Tbl[minor].deviceProbe(minor)) &&
181         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
182    {
183      /*
184       * Use this device for the console
185       */
186      break;
187    }
188  }
189  if(minor==Console_Port_Count)
190  {
191    /*
192     * Failed to find a working device
193     */
194    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
195  }
196       
197  Console_Port_Minor=minor;
198
199  /*
200   *  Register Device Names
201   */
202
203  status = rtems_io_register_name("/dev/console",
204           major,
205           Console_Port_Minor );
206  if (status != RTEMS_SUCCESSFUL)
207  {
208    rtems_fatal_error_occurred(status);
209  }
210  if ( Console_Port_Tbl[Console_Port_Minor].pDeviceFns->deviceInitialize ) {
211    Console_Port_Tbl[Console_Port_Minor]
212      .pDeviceFns->deviceInitialize(Console_Port_Minor);
213    Console_Is_Initialized = TRUE;
214  }
215
216  for(minor++;minor<Console_Port_Count;minor++)
217  {
218    /*
219     * First perform the configuration dependant probe, then the
220     * device dependant probe
221     */
222    if((!Console_Port_Tbl[minor].deviceProbe ||
223         Console_Port_Tbl[minor].deviceProbe(minor)) &&
224         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
225    {
226      status = rtems_io_register_name(
227        Console_Port_Tbl[minor].sDeviceName,
228        major,
229        minor );
230      if (status != RTEMS_SUCCESSFUL)
231      {
232        rtems_fatal_error_occurred(status);
233      }
234
235      /*
236       * Initialize the hardware device.
237       */
238      if ( Console_Port_Tbl[minor].pDeviceFns->deviceInitialize )
239        Console_Port_Tbl[minor].pDeviceFns->deviceInitialize( minor);
240    }
241  }
242
243  return RTEMS_SUCCESSFUL;
244}
245
246debug_putc_onlcr(const char c)
247{
248  uint32_t Irql;
249  if (Console_Is_Initialized) {
250    rtems_interrupt_disable(Irql);
251   
252    Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
253      deviceWritePolled(Console_Port_Minor,c);
254   
255    rtems_interrupt_enable(Irql);
256  }
257}
258
259BSP_output_char_function_type   BSP_output_char = debug_putc_onlcr;
260/* const char arg to be compatible with BSP_output_char decl. */
261
Note: See TracBrowser for help on using the repository browser.