summaryrefslogtreecommitdiffstats
path: root/sys/dev/isa
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-04-06 17:54:50 +0000
committercheloha <cheloha@openbsd.org>2020-04-06 17:54:50 +0000
commitaff96eed524fa871eebc4aed8a2099c7486bfde2 (patch)
tree095e64cb8f2345ffe0c16a5c0f04adebace21f7d /sys/dev/isa
parentChange copy mode to make copy of the pane history so it does not need to (diff)
downloadwireguard-openbsd-aff96eed524fa871eebc4aed8a2099c7486bfde2.tar.xz
wireguard-openbsd-aff96eed524fa871eebc4aed8a2099c7486bfde2.zip
pcppi(4), spkr(4): ticks -> milliseconds
In pcppi(4), convert from ticks to milliseconds. While we're doing this, we can also convert spkr(4), too. The spkr(4) conversion from ticks to milliseconds is trickier because the driver is written with musical intervals (whole notes, quarter notes, etc.), not the typical units (seconds, milliseconds, etc.) used in most software. I think the conversion is correct... but the code is a challenging read, so it might be subtly incorrect. ratchov@ intends to move spkr(4) into the attic sometime soon so I doubt it matters much if I got it wrong. Input from schwarze@, jsg@, and ratchov@. Tested by schwarze@. ok ratchov@
Diffstat (limited to 'sys/dev/isa')
-rw-r--r--sys/dev/isa/pcppi.c24
-rw-r--r--sys/dev/isa/spkr.c30
2 files changed, 27 insertions, 27 deletions
diff --git a/sys/dev/isa/pcppi.c b/sys/dev/isa/pcppi.c
index e6ac09a4a59..d57a9933d97 100644
--- a/sys/dev/isa/pcppi.c
+++ b/sys/dev/isa/pcppi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcppi.c,v 1.15 2019/12/31 10:05:32 mpi Exp $ */
+/* $OpenBSD: pcppi.c,v 1.16 2020/04/06 17:54:50 cheloha Exp $ */
/* $NetBSD: pcppi.c,v 1.1 1998/04/15 20:26:18 drochner Exp $ */
/*
@@ -184,9 +184,9 @@ pcppi_attach(parent, self, aux)
}
void
-pcppi_bell(self, pitch, period, slp)
+pcppi_bell(self, pitch, period_ms, slp)
pcppi_tag_t self;
- int pitch, period;
+ int pitch, period_ms;
int slp;
{
struct pcppi_softc *sc = self;
@@ -197,10 +197,10 @@ pcppi_bell(self, pitch, period, slp)
else if (pitch > INT_MAX - TIMER_FREQ)
pitch = INT_MAX - TIMER_FREQ;
- if (period < 0)
- period = 0;
- else if (period > INT_MAX / 1000000)
- period = INT_MAX / 1000000;
+ if (period_ms < 0)
+ period_ms = 0;
+ else if (period_ms > INT_MAX / 1000)
+ period_ms = INT_MAX / 1000;
s1 = spltty(); /* ??? */
if (sc->sc_bellactive) {
@@ -211,7 +211,7 @@ pcppi_bell(self, pitch, period, slp)
if (sc->sc_slp)
wakeup(pcppi_bell_stop);
}
- if (pitch == 0 || period == 0) {
+ if (pitch == 0 || period_ms == 0) {
pcppi_bell_stop(sc);
sc->sc_bellpitch = 0;
splx(s1);
@@ -236,11 +236,11 @@ pcppi_bell(self, pitch, period, slp)
sc->sc_bellactive = 1;
if (slp & PCPPI_BELL_POLL) {
- delay((period * 1000000) / hz);
+ delay(period_ms * 1000);
pcppi_bell_stop(sc);
} else {
sc->sc_timeout = 1;
- timeout_add(&sc->sc_bell_timeout, period);
+ timeout_add_msec(&sc->sc_bell_timeout, period_ms);
if (slp & PCPPI_BELL_SLEEP) {
sc->sc_slp = 1;
tsleep_nsec(pcppi_bell_stop, PCPPIPRI | PCATCH, "bell",
@@ -279,9 +279,9 @@ pcppi_kbd_bell(arg, pitch, period, volume, poll)
int poll;
{
/*
- * Comes in as ms, goes out as ticks; volume ignored.
+ * NB: volume ignored.
*/
- pcppi_bell(arg, volume ? pitch : 0, (period * hz) / 1000,
+ pcppi_bell(arg, volume ? pitch : 0, period,
poll ? PCPPI_BELL_POLL : 0);
}
#endif /* NPCKBD > 0 || NHIDKBD > 0 */
diff --git a/sys/dev/isa/spkr.c b/sys/dev/isa/spkr.c
index 880079a7227..ce61df8fe83 100644
--- a/sys/dev/isa/spkr.c
+++ b/sys/dev/isa/spkr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: spkr.c,v 1.24 2020/03/16 04:15:19 cheloha Exp $ */
+/* $OpenBSD: spkr.c,v 1.25 2020/04/06 17:54:50 cheloha Exp $ */
/* $NetBSD: spkr.c,v 1.1 1998/04/15 20:26:18 drochner Exp $ */
/*
@@ -81,18 +81,18 @@ static void playinit(void);
static void playtone(int, int, int);
static void playstring(char *, size_t);
-/* emit tone of frequency hz for given number of ticks */
+/* emit tone of frequency freq for given number of milliseconds */
static void
-tone(hz, nticks)
- u_int hz, nticks;
+tone(freq, ms)
+ u_int freq, ms;
{
- pcppi_bell(ppicookie, hz, nticks, PCPPI_BELL_SLEEP);
+ pcppi_bell(ppicookie, freq, ms, PCPPI_BELL_SLEEP);
}
-/* rest for given number of ticks */
+/* rest for given number of milliseconds */
static void
-rest(nticks)
- int nticks;
+rest(ms)
+ int ms;
{
/*
* Set timeout to endrest function, then give up the timeslice.
@@ -100,10 +100,10 @@ rest(nticks)
* waited out.
*/
#ifdef SPKRDEBUG
- printf("rest: %d\n", nticks);
+ printf("rest: %dms\n", ms);
#endif /* SPKRDEBUG */
- if (nticks > 0)
- tsleep(rest, SPKRPRI | PCATCH, "rest", nticks);
+ if (ms > 0)
+ tsleep_nsec(rest, SPKRPRI | PCATCH, "rest", MSEC_TO_NSEC(ms));
}
/**************** PLAY STRING INTERPRETER BEGINS HERE **********************
@@ -119,7 +119,7 @@ rest(nticks)
#define dtoi(c) ((c) - '0')
static int octave; /* currently selected octave */
-static int whole; /* whole-note time at current tempo, in ticks */
+static int whole; /* whole-note time at current tempo, in milliseconds */
static int value; /* whole divisor for note time, quarter note = 1 */
static int fill; /* controls spacing of notes */
static int octtrack; /* octave-tracking on? */
@@ -169,7 +169,7 @@ static void
playinit(void)
{
octave = DFLT_OCTAVE;
- whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO;
+ whole = (1000 * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO;
fill = NORMAL;
value = DFLT_VALUE;
octtrack = 0;
@@ -198,7 +198,7 @@ playtone(int pitch, int value, int sustain)
(FILLTIME * value * sdenom);
#ifdef SPKRDEBUG
- printf("playtone: pitch %d for %d ticks, rest for %d ticks\n",
+ printf("playtone: pitch %d for %dms, rest for %dms\n",
pitch, sound, silence);
#endif /* SPKRDEBUG */
@@ -353,7 +353,7 @@ do { \
GETNUM(cp, tempo);
if (tempo < MIN_TEMPO || tempo > MAX_TEMPO)
tempo = DFLT_TEMPO;
- whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / tempo;
+ whole = (1000 * SECS_PER_MIN * WHOLE_NOTE) / tempo;
break;
case 'M':