source: mainline/kernel/arch/mips32/src/drivers/serial.c@ 06e1e95

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 06e1e95 was 06e1e95, checked in by Jakub Jermar <jakub@…>, 19 years ago

C99 compliant header guards (hopefully) everywhere in the kernel.
Formatting and indentation changes.
Small improvements in sparc64.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (C) 2005 Ondrej Palkovsky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup mips32
30 * @{
31 */
32/** @file
33 */
34
35#include <interrupt.h>
36#include <arch/cp0.h>
37#include <arch/drivers/serial.h>
38#include <console/chardev.h>
39#include <console/console.h>
40
41static chardev_t console;
42static serial_t sconf[SERIAL_MAX];
43static bool kb_enabled;
44
45static void serial_write(chardev_t *d, const char ch)
46{
47 serial_t *sd = (serial_t *)d->data;
48
49 if (ch == '\n')
50 serial_write(d, '\r');
51 /* Wait until transmit buffer empty */
52 while (! (SERIAL_READ_LSR(sd->port) & (1<<TRANSMIT_EMPTY_BIT)))
53 ;
54 SERIAL_WRITE(sd->port, ch);
55}
56
57static void serial_enable(chardev_t *d)
58{
59 kb_enabled = true;
60}
61
62static void serial_disable(chardev_t *d)
63{
64 kb_enabled = false;
65}
66
67int serial_init(void)
68{
69 int i = 0;
70 if (SERIAL_READ_LSR(SERIAL_COM1) == 0x60) {
71 sconf[i].port = SERIAL_COM1;
72 sconf[i].irq = SERIAL_COM1_IRQ;
73 /* Enable interrupt on available data */
74 i++;
75 }
76 return i;
77}
78
79/** Read character from serial port, wait until available */
80static char serial_do_read(chardev_t *dev)
81{
82 serial_t *sd = (serial_t *)dev->data;
83 char ch;
84
85 while (!(SERIAL_READ_LSR(sd->port) & 1))
86 ;
87 ch = SERIAL_READ(sd->port);
88
89 if (ch =='\r')
90 ch = '\n';
91 return ch;
92}
93
94
95/** Process keyboard interrupt. Does not work in simics? */
96static void serial_interrupt(int n, void *stack)
97{
98 serial_t *sd = (serial_t *)console.data;
99 char ch;
100
101 if (!(SERIAL_READ_LSR(sd->port) & 1))
102 return;
103 ch = SERIAL_READ(sd->port);
104
105 if (ch =='\r')
106 ch = '\n';
107 chardev_push_character(&console, ch);
108}
109
110
111
112static chardev_operations_t serial_ops = {
113 .resume = serial_enable,
114 .suspend = serial_disable,
115 .write = serial_write,
116 .read = serial_do_read
117};
118
119iroutine old_timer;
120/** Do polling on timer interrupt */
121static void timer_replace(int n, istate_t *istate)
122{
123 old_timer(n, istate);
124 serial_interrupt(n, istate);
125}
126
127void serial_console(void)
128{
129 serial_t *sd = &sconf[0];
130
131
132 chardev_initialize("serial_console", &console, &serial_ops);
133 console.data = sd;
134 kb_enabled = true;
135
136// int_register(2, "serial_drvr", serial_interrupt);
137 /* I don't know why, but the serial interrupts simply
138 * don't work on simics
139 */
140 old_timer = int_register(TIMER_IRQ, "serial_drvr_poll", timer_replace);
141
142 stdin = &console;
143 stdout = &console;
144}
145
146/** @}
147 */
Note: See TracBrowser for help on using the repository browser.