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

4.104.114.95
Last change on this file since 42bf1b9 was 42bf1b9, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 05/15/08 at 15:10:38

adapted gen83xx to new board

  • Property mode set to 100644
File size: 7.1 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     * transfer the real internal bus frequency into the
177     * console port table
178     */
179    Console_Port_Tbl[minor].ulClock = BSP_bus_frequency;
180    /*
181     * First perform the configuration dependant probe, then the
182     * device dependant probe
183     */
184    if((!Console_Port_Tbl[minor].deviceProbe ||
185         Console_Port_Tbl[minor].deviceProbe(minor)) &&
186         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
187    {
188      /*
189       * Use this device for the console
190       */
191      break;
192    }
193  }
194  if(minor==Console_Port_Count)
195  {
196    /*
197     * Failed to find a working device
198     */
199    rtems_fatal_error_occurred(RTEMS_IO_ERROR);
200  }
201       
202  Console_Port_Minor=minor;
203
204  /*
205   *  Register Device Names
206   */
207
208  status = rtems_io_register_name("/dev/console",
209           major,
210           Console_Port_Minor );
211  if (status != RTEMS_SUCCESSFUL)
212  {
213    rtems_fatal_error_occurred(status);
214  }
215  if ( Console_Port_Tbl[Console_Port_Minor].pDeviceFns->deviceInitialize ) {
216    Console_Port_Tbl[Console_Port_Minor]
217      .pDeviceFns->deviceInitialize(Console_Port_Minor);
218    Console_Is_Initialized = TRUE;
219  }
220
221  for(minor++;minor<Console_Port_Count;minor++)
222  {
223    /*
224     * First perform the configuration dependant probe, then the
225     * device dependant probe
226     */
227    if((!Console_Port_Tbl[minor].deviceProbe ||
228         Console_Port_Tbl[minor].deviceProbe(minor)) &&
229         Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor))
230    {
231      status = rtems_io_register_name(
232        Console_Port_Tbl[minor].sDeviceName,
233        major,
234        minor );
235      if (status != RTEMS_SUCCESSFUL)
236      {
237        rtems_fatal_error_occurred(status);
238      }
239
240      /*
241       * Initialize the hardware device.
242       */
243      if ( Console_Port_Tbl[minor].pDeviceFns->deviceInitialize )
244        Console_Port_Tbl[minor].pDeviceFns->deviceInitialize( minor);
245    }
246  }
247
248  return RTEMS_SUCCESSFUL;
249}
250
251void debug_putc_onlcr(const char c)
252{
253  uint32_t Irql;
254  if (Console_Is_Initialized) {
255    rtems_interrupt_disable(Irql);
256   
257    Console_Port_Tbl[Console_Port_Minor].pDeviceFns->
258      deviceWritePolled(Console_Port_Minor,c);
259   
260    rtems_interrupt_enable(Irql);
261  }
262}
263
264BSP_output_char_function_type   BSP_output_char = debug_putc_onlcr;
265/* const char arg to be compatible with BSP_output_char decl. */
266
Note: See TracBrowser for help on using the repository browser.