mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
Fix error with tsleep loop
This commit is contained in:
parent
76847ca3ae
commit
424e2d04fc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=1016
@ -4,7 +4,7 @@
|
||||
* v1.4 by Eric S. Raymond (esr@snark.thyrsus.com) Aug 1993
|
||||
* modified for FreeBSD by Andrew A. Chernov <ache@astral.msk.su>
|
||||
*
|
||||
* $Id: spkr.c,v 1.5 1993/11/15 01:33:11 ache Exp $
|
||||
* $Id: spkr.c,v 1.6 1993/11/29 19:26:32 ache Exp $
|
||||
*/
|
||||
|
||||
#include "speaker.h"
|
||||
@ -62,12 +62,12 @@
|
||||
#define SPKRPRI PSOCK
|
||||
static char endtone, endrest;
|
||||
|
||||
static int tone(thz, ticks)
|
||||
static void tone(thz, ticks)
|
||||
/* emit tone of frequency thz for given number of ticks */
|
||||
unsigned int thz, ticks;
|
||||
{
|
||||
unsigned int divisor = TIMER_CLK / thz;
|
||||
int sps, error;
|
||||
int sps;
|
||||
|
||||
#ifdef DEBUG
|
||||
(void) printf("tone: thz=%d ticks=%d\n", thz, ticks);
|
||||
@ -88,21 +88,14 @@ unsigned int thz, ticks;
|
||||
* This is so other processes can execute while the tone is being
|
||||
* emitted.
|
||||
*/
|
||||
while ((error = tsleep((caddr_t)&endtone,
|
||||
SPKRPRI | PCATCH, "spkrtn", ticks)) == ERESTART)
|
||||
;
|
||||
(void) tsleep((caddr_t)&endtone, SPKRPRI | PCATCH, "spkrtn", ticks);
|
||||
outb(PPI, inb(PPI) & ~PPI_SPKR);
|
||||
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
return error;
|
||||
}
|
||||
|
||||
static int rest(ticks)
|
||||
static void rest(ticks)
|
||||
/* rest for given number of ticks */
|
||||
int ticks;
|
||||
{
|
||||
int error;
|
||||
/*
|
||||
* Set timeout to endrest function, then give up the timeslice.
|
||||
* This is so other processes can execute while the rest is being
|
||||
@ -111,12 +104,7 @@ int ticks;
|
||||
#ifdef DEBUG
|
||||
(void) printf("rest: %d\n", ticks);
|
||||
#endif /* DEBUG */
|
||||
while ((error = tsleep((caddr_t)&endrest,
|
||||
SPKRPRI | PCATCH, "spkrrs", ticks)) == ERESTART)
|
||||
;
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
return error;
|
||||
(void) tsleep((caddr_t)&endrest, SPKRPRI | PCATCH, "spkrrs", ticks);
|
||||
}
|
||||
|
||||
/**************** PLAY STRING INTERPRETER BEGINS HERE **********************
|
||||
@ -192,12 +180,11 @@ static void playinit()
|
||||
octprefix = TRUE; /* act as though there was an initial O(n) */
|
||||
}
|
||||
|
||||
static int playtone(pitch, value, sustain)
|
||||
static void playtone(pitch, value, sustain)
|
||||
/* play tone of proper duration for current rhythm signature */
|
||||
int pitch, value, sustain;
|
||||
{
|
||||
register int sound, silence, snum = 1, sdenom = 1;
|
||||
int error;
|
||||
|
||||
/* this weirdness avoids floating-point arithmetic */
|
||||
for (; sustain; sustain--)
|
||||
@ -208,7 +195,7 @@ int pitch, value, sustain;
|
||||
}
|
||||
|
||||
if (pitch == -1)
|
||||
error = rest(whole * snum / (value * sdenom));
|
||||
rest(whole * snum / (value * sdenom));
|
||||
else
|
||||
{
|
||||
sound = (whole * snum) / (value * sdenom)
|
||||
@ -220,12 +207,10 @@ int pitch, value, sustain;
|
||||
pitch, sound, silence);
|
||||
#endif /* DEBUG */
|
||||
|
||||
error = tone(pitchtab[pitch], sound);
|
||||
if (error) return error;
|
||||
tone(pitchtab[pitch], sound);
|
||||
if (fill != LEGATO)
|
||||
error = rest(silence);
|
||||
rest(silence);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
static int abs(n)
|
||||
@ -237,13 +222,12 @@ int n;
|
||||
return(n);
|
||||
}
|
||||
|
||||
static int playstring(cp, slen)
|
||||
static void playstring(cp, slen)
|
||||
/* interpret and play an item from a notation string */
|
||||
char *cp;
|
||||
size_t slen;
|
||||
{
|
||||
int pitch, oldfill, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE;
|
||||
int error;
|
||||
|
||||
#define GETNUM(cp, v) for(v=0; isdigit(cp[1]) && slen > 0; ) \
|
||||
{v = v * 10 + (*++cp - '0'); slen--;}
|
||||
@ -321,10 +305,9 @@ size_t slen;
|
||||
}
|
||||
|
||||
/* time to emit the actual tone */
|
||||
error = playtone(pitch, timeval, sustain);
|
||||
playtone(pitch, timeval, sustain);
|
||||
|
||||
fill = oldfill;
|
||||
if (error) return error;
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
@ -375,9 +358,8 @@ size_t slen;
|
||||
++cp;
|
||||
slen--;
|
||||
}
|
||||
error = playtone(pitch - 1, value, sustain);
|
||||
playtone(pitch - 1, value, sustain);
|
||||
fill = oldfill;
|
||||
if (error) return error;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
@ -397,8 +379,7 @@ size_t slen;
|
||||
slen--;
|
||||
sustain++;
|
||||
}
|
||||
error = playtone(-1, timeval, sustain);
|
||||
if (error) return error;
|
||||
playtone(-1, timeval, sustain);
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
@ -430,7 +411,6 @@ size_t slen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************* UNIX DRIVER HOOKS BEGIN HERE **************************
|
||||
@ -487,7 +467,7 @@ struct uio *uio;
|
||||
n = uio->uio_resid;
|
||||
cp = spkr_inbuf->b_un.b_addr;
|
||||
if (!(error = uiomove(cp, n, uio)))
|
||||
error = playstring(cp, n);
|
||||
playstring(cp, n);
|
||||
return(error);
|
||||
}
|
||||
}
|
||||
@ -527,9 +507,10 @@ caddr_t cmdarg;
|
||||
tone_t *tp = (tone_t *)cmdarg;
|
||||
|
||||
if (tp->frequency == 0)
|
||||
return rest(tp->duration);
|
||||
rest(tp->duration);
|
||||
else
|
||||
return tone(tp->frequency, tp->duration);
|
||||
tone(tp->frequency, tp->duration);
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == SPKRTUNE)
|
||||
{
|
||||
@ -544,11 +525,9 @@ caddr_t cmdarg;
|
||||
if (ttp.duration == 0)
|
||||
break;
|
||||
if (ttp.frequency == 0)
|
||||
error = rest(ttp.duration);
|
||||
rest(ttp.duration);
|
||||
else
|
||||
error = tone(ttp.frequency, ttp.duration);
|
||||
if (error)
|
||||
return(error);
|
||||
tone(ttp.frequency, ttp.duration);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* v1.4 by Eric S. Raymond (esr@snark.thyrsus.com) Aug 1993
|
||||
* modified for FreeBSD by Andrew A. Chernov <ache@astral.msk.su>
|
||||
*
|
||||
* $Id: spkr.c,v 1.5 1993/11/15 01:33:11 ache Exp $
|
||||
* $Id: spkr.c,v 1.6 1993/11/29 19:26:32 ache Exp $
|
||||
*/
|
||||
|
||||
#include "speaker.h"
|
||||
@ -62,12 +62,12 @@
|
||||
#define SPKRPRI PSOCK
|
||||
static char endtone, endrest;
|
||||
|
||||
static int tone(thz, ticks)
|
||||
static void tone(thz, ticks)
|
||||
/* emit tone of frequency thz for given number of ticks */
|
||||
unsigned int thz, ticks;
|
||||
{
|
||||
unsigned int divisor = TIMER_CLK / thz;
|
||||
int sps, error;
|
||||
int sps;
|
||||
|
||||
#ifdef DEBUG
|
||||
(void) printf("tone: thz=%d ticks=%d\n", thz, ticks);
|
||||
@ -88,21 +88,14 @@ unsigned int thz, ticks;
|
||||
* This is so other processes can execute while the tone is being
|
||||
* emitted.
|
||||
*/
|
||||
while ((error = tsleep((caddr_t)&endtone,
|
||||
SPKRPRI | PCATCH, "spkrtn", ticks)) == ERESTART)
|
||||
;
|
||||
(void) tsleep((caddr_t)&endtone, SPKRPRI | PCATCH, "spkrtn", ticks);
|
||||
outb(PPI, inb(PPI) & ~PPI_SPKR);
|
||||
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
return error;
|
||||
}
|
||||
|
||||
static int rest(ticks)
|
||||
static void rest(ticks)
|
||||
/* rest for given number of ticks */
|
||||
int ticks;
|
||||
{
|
||||
int error;
|
||||
/*
|
||||
* Set timeout to endrest function, then give up the timeslice.
|
||||
* This is so other processes can execute while the rest is being
|
||||
@ -111,12 +104,7 @@ int ticks;
|
||||
#ifdef DEBUG
|
||||
(void) printf("rest: %d\n", ticks);
|
||||
#endif /* DEBUG */
|
||||
while ((error = tsleep((caddr_t)&endrest,
|
||||
SPKRPRI | PCATCH, "spkrrs", ticks)) == ERESTART)
|
||||
;
|
||||
if (error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
return error;
|
||||
(void) tsleep((caddr_t)&endrest, SPKRPRI | PCATCH, "spkrrs", ticks);
|
||||
}
|
||||
|
||||
/**************** PLAY STRING INTERPRETER BEGINS HERE **********************
|
||||
@ -192,12 +180,11 @@ static void playinit()
|
||||
octprefix = TRUE; /* act as though there was an initial O(n) */
|
||||
}
|
||||
|
||||
static int playtone(pitch, value, sustain)
|
||||
static void playtone(pitch, value, sustain)
|
||||
/* play tone of proper duration for current rhythm signature */
|
||||
int pitch, value, sustain;
|
||||
{
|
||||
register int sound, silence, snum = 1, sdenom = 1;
|
||||
int error;
|
||||
|
||||
/* this weirdness avoids floating-point arithmetic */
|
||||
for (; sustain; sustain--)
|
||||
@ -208,7 +195,7 @@ int pitch, value, sustain;
|
||||
}
|
||||
|
||||
if (pitch == -1)
|
||||
error = rest(whole * snum / (value * sdenom));
|
||||
rest(whole * snum / (value * sdenom));
|
||||
else
|
||||
{
|
||||
sound = (whole * snum) / (value * sdenom)
|
||||
@ -220,12 +207,10 @@ int pitch, value, sustain;
|
||||
pitch, sound, silence);
|
||||
#endif /* DEBUG */
|
||||
|
||||
error = tone(pitchtab[pitch], sound);
|
||||
if (error) return error;
|
||||
tone(pitchtab[pitch], sound);
|
||||
if (fill != LEGATO)
|
||||
error = rest(silence);
|
||||
rest(silence);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
static int abs(n)
|
||||
@ -237,13 +222,12 @@ int n;
|
||||
return(n);
|
||||
}
|
||||
|
||||
static int playstring(cp, slen)
|
||||
static void playstring(cp, slen)
|
||||
/* interpret and play an item from a notation string */
|
||||
char *cp;
|
||||
size_t slen;
|
||||
{
|
||||
int pitch, oldfill, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE;
|
||||
int error;
|
||||
|
||||
#define GETNUM(cp, v) for(v=0; isdigit(cp[1]) && slen > 0; ) \
|
||||
{v = v * 10 + (*++cp - '0'); slen--;}
|
||||
@ -321,10 +305,9 @@ size_t slen;
|
||||
}
|
||||
|
||||
/* time to emit the actual tone */
|
||||
error = playtone(pitch, timeval, sustain);
|
||||
playtone(pitch, timeval, sustain);
|
||||
|
||||
fill = oldfill;
|
||||
if (error) return error;
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
@ -375,9 +358,8 @@ size_t slen;
|
||||
++cp;
|
||||
slen--;
|
||||
}
|
||||
error = playtone(pitch - 1, value, sustain);
|
||||
playtone(pitch - 1, value, sustain);
|
||||
fill = oldfill;
|
||||
if (error) return error;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
@ -397,8 +379,7 @@ size_t slen;
|
||||
slen--;
|
||||
sustain++;
|
||||
}
|
||||
error = playtone(-1, timeval, sustain);
|
||||
if (error) return error;
|
||||
playtone(-1, timeval, sustain);
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
@ -430,7 +411,6 @@ size_t slen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************* UNIX DRIVER HOOKS BEGIN HERE **************************
|
||||
@ -487,7 +467,7 @@ struct uio *uio;
|
||||
n = uio->uio_resid;
|
||||
cp = spkr_inbuf->b_un.b_addr;
|
||||
if (!(error = uiomove(cp, n, uio)))
|
||||
error = playstring(cp, n);
|
||||
playstring(cp, n);
|
||||
return(error);
|
||||
}
|
||||
}
|
||||
@ -527,9 +507,10 @@ caddr_t cmdarg;
|
||||
tone_t *tp = (tone_t *)cmdarg;
|
||||
|
||||
if (tp->frequency == 0)
|
||||
return rest(tp->duration);
|
||||
rest(tp->duration);
|
||||
else
|
||||
return tone(tp->frequency, tp->duration);
|
||||
tone(tp->frequency, tp->duration);
|
||||
return 0;
|
||||
}
|
||||
else if (cmd == SPKRTUNE)
|
||||
{
|
||||
@ -544,11 +525,9 @@ caddr_t cmdarg;
|
||||
if (ttp.duration == 0)
|
||||
break;
|
||||
if (ttp.frequency == 0)
|
||||
error = rest(ttp.duration);
|
||||
rest(ttp.duration);
|
||||
else
|
||||
error = tone(ttp.frequency, ttp.duration);
|
||||
if (error)
|
||||
return(error);
|
||||
tone(ttp.frequency, ttp.duration);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user