Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Restructure speaker devices so that there can be multipl...
details: https://anonhg.NetBSD.org/src/rev/edaa82d8926a
branches: trunk
changeset: 349531:edaa82d8926a
user: christos <christos%NetBSD.org@localhost>
date: Tue Dec 13 20:20:34 2016 +0000
description:
Restructure speaker devices so that there can be multiple of them, and have
proper softc's.
diffstat:
sys/conf/files | 6 +-
sys/dev/files.audio | 8 +-
sys/dev/isa/spkr_pcppi.c | 76 ++++--
sys/dev/spkr.c | 525 +++++++++++++++++++++++-----------------------
sys/dev/spkr_synth.c | 217 +++++++-----------
sys/dev/spkrvar.h | 25 +-
6 files changed, 414 insertions(+), 443 deletions(-)
diffs (truncated from 1172 to 300 lines):
diff -r 05ad365d8533 -r edaa82d8926a sys/conf/files
--- a/sys/conf/files Tue Dec 13 20:18:32 2016 +0000
+++ b/sys/conf/files Tue Dec 13 20:20:34 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1166 2016/11/02 00:11:59 pgoyette Exp $
+# $NetBSD: files,v 1.1167 2016/12/13 20:20:34 christos Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20150846
@@ -331,6 +331,10 @@
define pckbport_machdep_cnattach
define firmload
+# speaker devices, attaches to audio or pcppi drivers
+device spkr
+file dev/spkr.c spkr
+
include "dev/files.audio"
# High definition audio
diff -r 05ad365d8533 -r edaa82d8926a sys/dev/files.audio
--- a/sys/dev/files.audio Tue Dec 13 20:18:32 2016 +0000
+++ b/sys/dev/files.audio Tue Dec 13 20:20:34 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.audio,v 1.7 2016/12/11 06:30:11 christos Exp $
+# $NetBSD: files.audio,v 1.8 2016/12/13 20:20:34 christos Exp $
define audiobus { }
define midibus { }
@@ -17,8 +17,7 @@
attach audio at audiobus
device midi: audio
attach midi at midibus
-device spkr: audiobell
-attach spkr at audio with spkr_synth
+attach spkr at audio with spkr_synth
# console bell via audio device
#
@@ -26,12 +25,11 @@
file dev/auconv.c auconv
file dev/audio.c audio needs-flag
-file dev/audiobell.c audiobell needs-flag
+file dev/audiobell.c spkr_synth needs-flag
file dev/aurateconv.c aurateconv needs-flag
file dev/auvolconv.c auvolconv
file dev/midi.c midi needs-flag
file dev/midictl.c midisyn
file dev/midisyn.c midisyn
file dev/mulaw.c mulaw needs-flag
-file dev/spkr.c spkr needs-flag
file dev/spkr_synth.c spkr_synth needs-flag
diff -r 05ad365d8533 -r edaa82d8926a sys/dev/isa/spkr_pcppi.c
--- a/sys/dev/isa/spkr_pcppi.c Tue Dec 13 20:18:32 2016 +0000
+++ b/sys/dev/isa/spkr_pcppi.c Tue Dec 13 20:20:34 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spkr_pcppi.c,v 1.4 2016/12/09 05:17:03 christos Exp $ */
+/* $NetBSD: spkr_pcppi.c,v 1.5 2016/12/13 20:20:34 christos Exp $ */
/*
* Copyright (c) 1990 Eric S. Raymond (esr%snark.thyrsus.com@localhost)
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spkr_pcppi.c,v 1.4 2016/12/09 05:17:03 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr_pcppi.c,v 1.5 2016/12/13 20:20:34 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -64,11 +64,18 @@
#include <dev/spkrvar.h>
#include <dev/spkrio.h>
-extern int spkr_attached;
-static void spkrattach(device_t, device_t, void *);
-static int spkrdetach(device_t, int);
+struct spkr_pcppi_softc {
+ device_t sc_dev;
+ device_t sc_spkr_dev;
+ pcppi_tag_t sc_pcppicookie;
+};
-#include "ioconf.h"
+static int spkr_pcppi_probe(device_t, cfdata_t, void *);
+static void spkr_pcppi_attach(device_t, device_t, void *);
+static int spkr_pcppi_detach(device_t, int);
+
+CFATTACH_DECL_NEW(spkr_pcppi, sizeof(struct spkr_pcppi_softc),
+ spkr_pcppi_probe, spkr_pcppi_attach, spkr_pcppi_detach, NULL);
MODULE(MODULE_CLASS_DRIVER, spkr, NULL /* "pcppi" */);
@@ -78,53 +85,62 @@
return spkr__modcmd(cmd, arg);
}
-CFATTACH_DECL_NEW(spkr_pcppi, 0, spkr_probe, spkrattach, spkrdetach, NULL);
-
-static pcppi_tag_t ppicookie;
-
#define SPKRPRI (PZERO - 1)
-void
-spkr_tone(u_int xhz, u_int ticks)
/* emit tone of frequency hz for given number of ticks */
+static void
+spkr_pcppi_tone(device_t self, u_int xhz, u_int ticks)
{
- pcppi_bell(ppicookie, xhz, ticks, PCPPI_BELL_SLEEP);
+#ifdef SPKRDEBUG
+ aprint_debug_dev(self, "%s: %u %u\n", __func__, xhz, ticks);
+#endif /* SPKRDEBUG */
+ struct spkr_pcppi_softc *sc = device_private(self);
+ pcppi_bell(sc->sc_pcppicookie, xhz, ticks, PCPPI_BELL_SLEEP);
}
-void
-spkr_rest(int ticks)
/* rest for given number of ticks */
+static void
+spkr_pcppi_rest(device_t self, int ticks)
{
- /*
- * Set timeout to endrest function, then give up the timeslice.
- * This is so other processes can execute while the rest is being
- * waited out.
- */
+ /*
+ * Set timeout to endrest function, then give up the timeslice.
+ * This is so other processes can execute while the rest is being
+ * waited out.
+ */
#ifdef SPKRDEBUG
- printf("%s: %d\n", __func__, ticks);
+ aprint_debug_dev(self, "%s: %d\n", __func__, ticks);
#endif /* SPKRDEBUG */
- if (ticks > 0)
- tsleep(spkr_rest, SPKRPRI | PCATCH, "rest", ticks);
+ if (ticks > 0)
+ tsleep(self, SPKRPRI | PCATCH, device_xname(self), ticks);
+}
+
+static int
+spkr_pcppi_probe(device_t parent, cfdata_t cf, void *aux)
+{
+ return 1;
}
static void
-spkrattach(device_t parent, device_t self, void *aux)
+spkr_pcppi_attach(device_t parent, device_t self, void *aux)
{
+ struct pcppi_attach_args *pa = aux;
+ struct spkr_pcppi_softc *sc = device_private(self);
+
aprint_naive("\n");
aprint_normal("\n");
- ppicookie = ((struct pcppi_attach_args *)aux)->pa_cookie;
- spkr_attached = 1;
+
+ sc->sc_pcppicookie = pa->pa_cookie;
+ spkr_attach(self, spkr_pcppi_tone, spkr_pcppi_rest);
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "couldn't establish power handler\n");
}
static int
-spkrdetach(device_t self, int flags)
+spkr_pcppi_detach(device_t self, int flags)
{
+ struct spkr_pcppi_softc *sc = device_private(self);
+ sc->sc_pcppicookie = NULL;
pmf_device_deregister(self);
- spkr_attached = 0;
- ppicookie = NULL;
-
return 0;
}
diff -r 05ad365d8533 -r edaa82d8926a sys/dev/spkr.c
--- a/sys/dev/spkr.c Tue Dec 13 20:18:32 2016 +0000
+++ b/sys/dev/spkr.c Tue Dec 13 20:20:34 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spkr.c,v 1.3 2016/12/09 05:17:03 christos Exp $ */
+/* $NetBSD: spkr.c,v 1.4 2016/12/13 20:20:34 christos Exp $ */
/*
* Copyright (c) 1990 Eric S. Raymond (esr%snark.thyrsus.com@localhost)
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.3 2016/12/09 05:17:03 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.4 2016/12/13 20:20:34 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -82,9 +82,9 @@
.d_flag = D_OTHER
};
-static void playinit(void);
-static void playtone(int, int, int);
-static void playstring(char *, int);
+static void playinit(struct spkr_softc *);
+static void playtone(struct spkr_softc *, int, int, int);
+static void playstring(struct spkr_softc *, const char *, size_t);
/**************** PLAY STRING INTERPRETER BEGINS HERE **********************
*
@@ -96,13 +96,6 @@
#define dtoi(c) ((c) - '0')
-static int octave; /* currently selected octave */
-static int whole; /* whole-note time at current tempo, in ticks */
-static int value; /* whole divisor for note time, quarter note = 1 */
-static int fill; /* controls spacing of notes */
-static bool octtrack; /* octave-tracking on? */
-static bool octprefix; /* override current octave-tracking state? */
-
/*
* Magic number avoidance...
*/
@@ -144,221 +137,211 @@
#define NOCTAVES (int)(__arraycount(pitchtab) / OCTAVE_NOTES)
static void
-playinit(void)
+playinit(struct spkr_softc *sc)
{
- octave = DFLT_OCTAVE;
- whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO;
- fill = NORMAL;
- value = DFLT_VALUE;
- octtrack = false;
- octprefix = true; /* act as though there was an initial O(n) */
+ sc->sc_octave = DFLT_OCTAVE;
+ sc->sc_whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO;
+ sc->sc_fill = NORMAL;
+ sc->sc_value = DFLT_VALUE;
+ sc->sc_octtrack = false;
+ sc->sc_octprefix = true;/* act as though there was an initial O(n) */
}
+/* play tone of proper duration for current rhythm signature */
static void
-playtone(int pitch, int val, int sustain)
-/* play tone of proper duration for current rhythm signature */
+playtone(struct spkr_softc *sc, int pitch, int val, int sustain)
{
- int sound, silence, snum = 1, sdenom = 1;
+ int sound, silence, snum = 1, sdenom = 1;
- /* this weirdness avoids floating-point arithmetic */
- for (; sustain; sustain--)
- {
- snum *= NUM_MULT;
- sdenom *= DENOM_MULT;
- }
+ /* this weirdness avoids floating-point arithmetic */
+ for (; sustain; sustain--) {
+ snum *= NUM_MULT;
+ sdenom *= DENOM_MULT;
+ }
- if (pitch == -1)
- spkr_rest(whole * snum / (val * sdenom));
- else
- {
- sound = (whole * snum) / (val * sdenom)
- - (whole * (FILLTIME - fill)) / (val * FILLTIME);
- silence = whole * (FILLTIME-fill) * snum / (FILLTIME * val * sdenom);
+ if (pitch == -1) {
+ (*sc->sc_rest)(sc->sc_dev, sc->sc_whole
+ * snum / (val * sdenom));
+ return;
+ }
+
+ int fac = sc->sc_whole * (FILLTIME - sc->sc_fill);
+ int fval = FILLTIME * val;
+ sound = (sc->sc_whole * snum) / (val * sdenom) - fac / fval;
+ silence = fac * snum / (fval * sdenom);
#ifdef SPKRDEBUG
- printf("playtone: pitch %d for %d ticks, rest for %d ticks\n",
+ aprint_debug_dev(sc->sc_dev,
+ "%s: pitch %d for %d ticks, rest for %d ticks\n", __func__,
pitch, sound, silence);
#endif /* SPKRDEBUG */
- spkr_tone(pitchtab[pitch], sound);
- if (fill != LEGATO)
- spkr_rest(silence);
- }
+ (*sc->sc_tone)(sc->sc_dev, pitchtab[pitch], sound);
+ if (sc->sc_fill != LEGATO)
+ (*sc->sc_rest)(sc->sc_dev, silence);
Home |
Main Index |
Thread Index |
Old Index