Add /dev/leds (closes PR#2172 from der Mouse)
This commit is contained in:
parent
98730721d9
commit
c960be72aa
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.sun3,v 1.37 1997/03/17 19:46:51 gwr Exp $
|
||||
# $NetBSD: files.sun3,v 1.38 1997/03/18 22:21:50 gwr Exp $
|
||||
|
||||
#
|
||||
# sun3-specific configuration info
|
||||
@ -23,6 +23,7 @@ file arch/sun3/sun3/dvma.c
|
||||
file arch/sun3/sun3/fpu.c
|
||||
file arch/sun3/sun3/isr.c
|
||||
file arch/sun3/sun3/kgdb_machdep.c kgdb
|
||||
file arch/sun3/sun3/leds.c
|
||||
file arch/sun3/sun3/machdep.c
|
||||
file arch/sun3/sun3/mem.c
|
||||
file arch/sun3/sun3/pmap.c
|
||||
|
45
sys/arch/sun3/include/leds.h
Normal file
45
sys/arch/sun3/include/leds.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* $NetBSD: leds.h,v 1.1 1997/03/18 22:21:51 gwr Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Gordon W. Ross and der Mouse.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Data structure supported by /dev/leds */
|
||||
|
||||
struct led_patterns {
|
||||
u_char divisor; /* divides 100 Hz clock (0 means 256). */
|
||||
u_char patlen; /* patterns to use (0 means 256). */
|
||||
u_char pat[256]; /* the patters... */
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: clock.c,v 1.38 1997/03/05 19:00:07 gwr Exp $ */
|
||||
/* $NetBSD: clock.c,v 1.39 1997/03/18 22:21:53 gwr Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Gordon W. Ross
|
||||
@ -73,7 +73,6 @@
|
||||
|
||||
void _isr_clock __P((void)); /* in locore.s */
|
||||
void clock_intr __P((struct clockframe));
|
||||
static void frob_leds __P((void));
|
||||
|
||||
static volatile void *intersil_va;
|
||||
|
||||
@ -269,7 +268,7 @@ setstatclockrate(newhz)
|
||||
/*
|
||||
* This is is called by the "custom" interrupt handler.
|
||||
* Note that we can get ZS interrupts while this runs,
|
||||
* and those may touch the interrupt_reg, so we have to
|
||||
* and zshard may touch the interrupt_reg, so we must
|
||||
* be careful to use the single_inst_* macros to modify
|
||||
* the interrupt register atomically.
|
||||
*/
|
||||
@ -292,23 +291,7 @@ clock_intr(cf)
|
||||
hardclock(&cf);
|
||||
|
||||
/* Entertainment! */
|
||||
frob_leds();
|
||||
}
|
||||
|
||||
static void
|
||||
frob_leds()
|
||||
{
|
||||
static unsigned char led_pattern = 0xFE;
|
||||
extern int ticks;
|
||||
|
||||
if ((ticks & 7) != 0)
|
||||
return;
|
||||
|
||||
/* XXX - Move this LED frobbing to the idle loop? */
|
||||
led_pattern = (led_pattern << 1) | 1;
|
||||
if (led_pattern == 0xFF)
|
||||
led_pattern = 0xFE;
|
||||
set_control_byte((char *) DIAG_REG, led_pattern);
|
||||
leds_intr();
|
||||
}
|
||||
|
||||
|
||||
|
116
sys/arch/sun3/sun3/leds.c
Normal file
116
sys/arch/sun3/sun3/leds.c
Normal file
@ -0,0 +1,116 @@
|
||||
/* $NetBSD: leds.c,v 1.1 1997/03/18 22:21:52 gwr Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Gordon W. Ross and der Mouse.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Functions to flash the LEDs with some pattern.
|
||||
* (LED = Light Emitting Diode)
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
#include <machine/control.h>
|
||||
#include <machine/leds.h>
|
||||
#include <machine/machdep.h>
|
||||
|
||||
static u_char led_countdown = 0;
|
||||
static u_char led_px = 0;
|
||||
|
||||
/* Initial value is the default pattern set. */
|
||||
static struct led_patterns ledpat = {
|
||||
8, /* divisor */
|
||||
8, /* patlen */
|
||||
{ /* patterns */
|
||||
0xF0, 0xE1, 0xC3, 0x87,
|
||||
0x0F, 0x1E, 0x3C, 0x78
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* This is called by the clock interrupt.
|
||||
*/
|
||||
void
|
||||
leds_intr()
|
||||
{
|
||||
register u_char i;
|
||||
|
||||
if (led_countdown) {
|
||||
led_countdown--;
|
||||
return;
|
||||
}
|
||||
|
||||
led_countdown = ledpat.divisor - 1;
|
||||
|
||||
i = led_px;
|
||||
set_control_byte((char *) DIAG_REG, ledpat.pat[i]);
|
||||
|
||||
i = i+1;
|
||||
if (i == ledpat.patlen)
|
||||
i = 0;
|
||||
led_px = i;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called by mem.c to handle /dev/leds
|
||||
*/
|
||||
int
|
||||
leds_uio(struct uio *uio)
|
||||
{
|
||||
int cnt, error;
|
||||
int off; /* NOT off_t */
|
||||
caddr_t va;
|
||||
|
||||
off = uio->uio_offset;
|
||||
if ((off < 0) || (off > sizeof(ledpat)))
|
||||
return (EFAULT);
|
||||
|
||||
cnt = min(uio->uio_resid, (sizeof(ledpat) - off));
|
||||
if (cnt == 0)
|
||||
return (0); /* EOF */
|
||||
|
||||
va = ((char*)(&ledpat)) + off;
|
||||
error = uiomove(va, cnt, uio);
|
||||
|
||||
return (error);
|
||||
}
|
Loading…
Reference in New Issue
Block a user