The only conversion I'm having trouble with is the tsleep().
The comment says "20ms", but then we use some arithmetic
to derive a count of ticks.
Given
hz * MIDI_MAXWRITE / MIDI_RATE
You have hz ticks/second, and 32 bytes, and 3125 bytes/second, so you
have
hz ticks 32 bytes 3125 bytes
-------- * -------- / ----------
second 1 second
= 32 * hz ticks
-------------
3125
= 1 ticks
if hz = 100, with integer division.
I'm not sure how to use the constants to produce a count of
milliseconds. Maybe I'm just having a slow day.
Ideas?
Index: midi.c
===================================================================
RCS file: /cvs/src/sys/dev/midi.c,v
retrieving revision 1.43
diff -u -p -r1.43 midi.c
--- midi.c 19 Jul 2017 22:23:54 -0000 1.43
+++ midi.c 18 Dec 2019 00:54:54 -0000
@@ -126,7 +126,8 @@ midiread(dev_t dev, struct uio *uio, int
goto done_mtx;
}
sc->rchan = 1;
- error = msleep(&sc->rchan, &audio_lock, PWAIT | PCATCH,
"mid_rd", 0);
+ error = msleep_nsec(&sc->rchan, &audio_lock, PWAIT | PCATCH,
+ "mid_rd", INFSLP);
if (!(sc->dev.dv_flags & DVF_ACTIVE))
error = EIO;
if (error)
@@ -270,8 +271,8 @@ midiwrite(dev_t dev, struct uio *uio, in
goto done_mtx;
}
sc->wchan = 1;
- error = msleep(&sc->wchan, &audio_lock,
- PWAIT | PCATCH, "mid_wr", 0);
+ error = msleep_nsec(&sc->wchan, &audio_lock,
+ PWAIT | PCATCH, "mid_wr", INFSLP);
if (!(sc->dev.dv_flags & DVF_ACTIVE))
error = EIO;
if (error)
@@ -476,8 +477,8 @@ midiclose(dev_t dev, int fflag, int devt
midi_out_start(sc);
while (sc->isbusy) {
sc->wchan = 1;
- error = msleep(&sc->wchan, &audio_lock,
- PWAIT, "mid_dr", 5 * hz);
+ error = msleep_nsec(&sc->wchan, &audio_lock,
+ PWAIT, "mid_dr", SEC_TO_NSEC(5));
if (!(sc->dev.dv_flags & DVF_ACTIVE))
error = EIO;
if (error)
@@ -492,7 +493,7 @@ midiclose(dev_t dev, int fflag, int devt
* sleep 20ms (around 64 bytes) to give the time to the
* uart to drain its internal buffers.
*/
- tsleep(&sc->wchan, PWAIT, "mid_cl", hz * MIDI_MAXWRITE / MIDI_RATE);
+ tsleep_nsec(&sc->wchan, PWAIT, "mid_cl", MSEC_TO_NSEC(20));
sc->hw_if->close(sc->hw_hdl);
sc->flags = 0;
device_unref(&sc->dev);