FreeBSD/Linux Kernel Cross Reference
sys/i386ipsc/led.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * Copyright 1988, 1989, 1990, 1991 by Intel Corporation,
28 * Santa Clara, California.
29 *
30 * All Rights Reserved
31 *
32 * Permission to use, copy, modify, and distribute this software and its
33 * documentation for any purpose and without fee is hereby granted,
34 * provided that the above copyright notice appears in all copies and that
35 * both the copyright notice and this permission notice appear in
36 * supporting documentation, and that the name of Intel not be used in
37 * advertising or publicity pertaining to distribution of the software
38 * without specific, written prior permission.
39 *
40 * INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
41 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
42 * SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
43 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
44 * PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS
45 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
46 * THIS SOFTWARE.
47 */
48 /*
49 * HISTORY
50 * $Log: led.c,v $
51 * Revision 2.6 93/01/14 17:32:04 danner
52 * Proper spl typing.
53 * [92/12/10 17:53:44 af]
54 *
55 * Revision 2.5 91/12/10 16:29:55 jsb
56 * Fixes from Intel
57 * [91/12/10 15:32:14 jsb]
58 *
59 * Revision 2.4 91/06/18 20:50:22 jsb
60 * New copyright from Intel.
61 * [91/06/18 20:06:51 jsb]
62 *
63 * Revision 2.3 91/06/06 17:04:46 jsb
64 * Added led_idle, led_active.
65 * [91/05/13 17:07:21 jsb]
66 *
67 * Revision 2.2 90/12/04 14:47:29 jsb
68 * First checkin.
69 * [90/12/04 10:57:09 jsb]
70 *
71 */
72 #include <sys/varargs.h>
73
74 /* Send data out the LED */
75
76 /* Red and Green LED bits */
77 #define RED 0x40
78 #define GREEN 0x80
79
80 /* Port address for the trace port */
81 #define TRACE_PORT 0x84
82
83 #define BAUD_1200 0x1f0 /* best estimate for 1200 baud */
84
85 #define START_BIT 1
86 #define STOP_BIT 0
87
88 /* forward declaration */
89 static delay();
90
91 int led_state;
92
93 led(color)
94 int color;
95 {
96 led_state = color;
97 outb(TRACE_PORT, led_state);
98 }
99
100
101 led_idle()
102 {
103 led(RED);
104 }
105
106
107 led_active()
108 {
109 led(GREEN);
110 }
111
112
113 static delay(time)
114 volatile unsigned int time;
115 {
116 while(time--);
117 }
118
119
120 led_bit(b)
121 int b;
122 {
123 if (b) {
124 led(led_state | RED);
125 } else {
126 led(led_state & ~RED);
127 }
128 delay(BAUD_1200);
129 }
130
131
132 led_char(c)
133 char c;
134 {
135 int i;
136 spl_t s;
137
138 s = splhi();
139 led_bit(START_BIT);
140 for (i = 0; i < 8; i++) {
141 led_bit(!((c >> i) & 1));
142 }
143 led_bit(STOP_BIT);
144 delay(4 * BAUD_1200);
145 splx(s);
146 }
147
148
149 led_putchar(c)
150 int c;
151 {
152 spl_t s = splhi();
153
154 led_char((char) c);
155 if (c == '\n') {
156 led_char('\r');
157 }
158
159 splx(s);
160 }
161
162
163 /*VARARGS1*/
164 led_printf(fmt, va_alist)
165 char *fmt;
166 va_dcl
167 {
168 va_list listp;
169 spl_t s = splhi();
170
171 va_start(listp);
172 _doprnt(fmt, &listp, led_putchar, 0);
173 va_end(listp);
174
175 splx(s);
176 }
Cache object: 9cca9e031c95beccd0fb7b572f84b1e8
|