source: rtems/bsps/sparc/shared/uart/cons.c @ 9ed109c

5
Last change on this file since 9ed109c was 9ed109c, checked in by Daniel Hellstrom <daniel@…>, on 09/19/18 at 13:18:38

leon: remove warning missing string.h

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*  This file contains the TTY driver for the serial ports. The driver
2 *  is layered so that different UART hardware can be used. It is implemented
3 *  using the Driver Manager.
4 *
5 *  This driver uses the termios pseudo driver.
6 *
7 *  COPYRIGHT (c) 2010.
8 *  Cobham Gaisler AB.
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.org/license/LICENSE.
13 */
14
15#include <bsp.h>
16#include <stdlib.h>
17#include <string.h>
18#include <bsp/cons.h>
19#include <rtems/console.h>
20
21#ifdef RTEMS_DRVMGR_STARTUP
22
23/* Note that it is not possible to use the interrupt mode of the driver
24 * together with the "old" APBUART and -u to GRMON. However the new
25 * APBUART core (from 1.0.17-b2710) has the GRMON debug bit and can
26 * handle interrupts.
27 */
28
29static int console_initialized = 0;
30
31#define FLAG_SYSCON 0x01
32struct console_priv {
33        int flags; /* 0x1=SystemConsole */
34        int minor;
35        struct console_dev *dev;
36};
37
38#define CONSOLE_MAX BSP_NUMBER_OF_TERMIOS_PORTS
39struct console_priv cons[CONSOLE_MAX] = {{0,0},};
40
41/* Install Console in TERMIOS layer */
42static void console_dev_init(struct console_priv *con)
43{
44        char name[16], *fsname;
45        rtems_status_code status;
46        int minor;
47
48        minor = con->minor;
49        if (!con->dev->fsname) {
50                strcpy(name, "/dev/console_a");
51                /* Special console name and MINOR for SYSTEM CONSOLE */
52                if (minor == 0)
53                        name[12] = '\0'; /* /dev/console */
54                name[13] += minor; /* when minor=0, this has no effect... */
55                fsname = name;
56        } else {
57                fsname = con->dev->fsname;
58        }
59        status = rtems_termios_device_install(
60                fsname,
61                con->dev->handler,
62                NULL,
63                &con->dev->base
64        );
65        if (status != RTEMS_SUCCESSFUL) {
66                rtems_fatal_error_occurred(status);
67        }
68}
69
70/* Called by device driver to register itself to the cons interface. */
71void console_dev_register(struct console_dev *dev)
72{
73        int i, minor = 0;
74        struct console_priv *con = NULL;
75
76        if ((dev->flags & CONSOLE_FLAG_SYSCON) && !cons[0].dev) {
77                con = &cons[0];
78                con->flags = FLAG_SYSCON;
79        } else {
80                for (i=1; i<CONSOLE_MAX; i++) {
81                        if (!cons[i].dev) {
82                                con = &cons[i];
83                                con->flags = 0;
84                                minor = i;
85                                break;
86                        }
87                }
88        }
89        if (con == NULL) {
90                /* Not enough console structures */
91                return;
92        }
93        dev->flags &= ~CONSOLE_FLAG_SYSCON_GRANT;
94        if (con->flags & FLAG_SYSCON) {
95                dev->flags |= CONSOLE_FLAG_SYSCON_GRANT;
96        }
97
98        /* Assign Console */
99        con->dev = dev;
100        con->minor = minor;
101
102        if (console_initialized) {
103                /* Console layer is already initialized, that means that we can
104                 * register termios interface directly.
105                 */
106                console_dev_init(con);
107        }
108}
109
110#if 0
111void console_dev_unregister(struct console_dev *dev)
112{
113
114}
115#endif
116
117rtems_device_driver console_initialize(
118        rtems_device_major_number       major,
119        rtems_device_minor_number       minor,
120        void                            *arg)
121{
122        int i;
123
124        rtems_termios_initialize();
125
126        /* Register all Console a file system device node */
127        for (i=0; i<CONSOLE_MAX; i++) {
128                if (cons[i].dev)
129                        console_dev_init(&cons[i]);
130        }
131
132        console_initialized = 1;
133
134        return RTEMS_SUCCESSFUL;
135}
136
137#endif
Note: See TracBrowser for help on using the repository browser.