Pulled out timer related functions -> now in clock.c
This commit is contained in:
parent
5194771d25
commit
f1106e3848
@ -34,7 +34,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)isa.c 7.2 (Berkeley) 5/13/91
|
||||
* $Id: isa.c,v 1.15 1994/04/02 07:00:46 davidg Exp $
|
||||
* $Id: isa.c,v 1.16 1994/04/02 20:43:25 ache Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -626,165 +626,6 @@ isa_strayintr(d)
|
||||
log(LOG_CRIT,"Too many ISA strayintr not logging any more\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait "n" microseconds.
|
||||
* Relies on timer 1 counting down from (TIMER_FREQ / hz) at
|
||||
* (1 * TIMER_FREQ) Hz.
|
||||
* Note: timer had better have been programmed before this is first used!
|
||||
* (The standard programming causes the timer to generate a square wave and
|
||||
* the counter is decremented twice every cycle.)
|
||||
*/
|
||||
#define CF (1 * TIMER_FREQ)
|
||||
#define TIMER_FREQ 1193182 /* XXX - should be elsewhere */
|
||||
|
||||
void
|
||||
DELAY(n)
|
||||
int n;
|
||||
{
|
||||
int counter_limit;
|
||||
int prev_tick;
|
||||
int tick;
|
||||
int ticks_left;
|
||||
int sec;
|
||||
int usec;
|
||||
|
||||
#ifdef DELAYDEBUG
|
||||
int getit_calls = 1;
|
||||
int n1;
|
||||
static int state = 0;
|
||||
|
||||
if (state == 0) {
|
||||
state = 1;
|
||||
for (n1 = 1; n1 <= 10000000; n1 *= 10)
|
||||
DELAY(n1);
|
||||
state = 2;
|
||||
}
|
||||
if (state == 1)
|
||||
printf("DELAY(%d)...", n);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read the counter first, so that the rest of the setup overhead is
|
||||
* counted. Guess the initial overhead is 20 usec (on most systems it
|
||||
* takes about 1.5 usec for each of the i/o's in getit(). The loop
|
||||
* takes about 6 usec on a 486/33 and 13 usec on a 386/20. The
|
||||
* multiplications and divisions to scale the count take a while).
|
||||
*/
|
||||
prev_tick = getit(0, 0);
|
||||
n -= 20;
|
||||
|
||||
/*
|
||||
* Calculate (n * (CF / 1e6)) without using floating point and without
|
||||
* any avoidable overflows.
|
||||
*/
|
||||
sec = n / 1000000;
|
||||
usec = n - sec * 1000000;
|
||||
ticks_left = sec * CF
|
||||
+ usec * (CF / 1000000)
|
||||
+ usec * ((CF % 1000000) / 1000) / 1000
|
||||
+ usec * (CF % 1000) / 1000000;
|
||||
|
||||
counter_limit = TIMER_FREQ / hz;
|
||||
while (ticks_left > 0) {
|
||||
tick = getit(0, 0);
|
||||
#ifdef DELAYDEBUG
|
||||
++getit_calls;
|
||||
#endif
|
||||
if (tick > prev_tick)
|
||||
ticks_left -= prev_tick - (tick - counter_limit);
|
||||
else
|
||||
ticks_left -= prev_tick - tick;
|
||||
prev_tick = tick;
|
||||
}
|
||||
#ifdef DELAYDEBUG
|
||||
if (state == 1)
|
||||
printf(" %d calls to getit() at %d usec each\n",
|
||||
getit_calls, (n + 5) / getit_calls);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
getit(unit, timer)
|
||||
int unit;
|
||||
int timer;
|
||||
{
|
||||
int high;
|
||||
int low;
|
||||
|
||||
/*
|
||||
* XXX - isa.h defines bogus timers. There's no such timer as
|
||||
* IO_TIMER_2 = 0x48. There's a timer in the CMOS RAM chip but
|
||||
* its interface is quite different. Neither timer is an 8252.
|
||||
* We actually only call this with unit = 0 and timer = 0. It
|
||||
* could be static...
|
||||
*/
|
||||
/*
|
||||
* Protect ourself against interrupts.
|
||||
* XXX - sysbeep() and sysbeepstop() need protection.
|
||||
*/
|
||||
disable_intr();
|
||||
/*
|
||||
* Latch the count for 'timer' (cc00xxxx, c = counter, x = any).
|
||||
*/
|
||||
outb(IO_TIMER1 + 3, timer << 6);
|
||||
|
||||
low = inb(IO_TIMER1 + timer);
|
||||
high = inb(IO_TIMER1 + timer);
|
||||
enable_intr();
|
||||
return ((high << 8) | low);
|
||||
}
|
||||
|
||||
static int beeping;
|
||||
|
||||
static void
|
||||
sysbeepstop(f, dummy)
|
||||
caddr_t f;
|
||||
int dummy;
|
||||
{
|
||||
/* disable counter 2 */
|
||||
outb(0x61, inb(0x61) & 0xFC);
|
||||
if (f)
|
||||
timeout(sysbeepstop, (caddr_t)0, (int)f);
|
||||
else
|
||||
beeping = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sysbeep(int pitch, int period)
|
||||
{
|
||||
|
||||
outb(0x61, inb(0x61) | 3); /* enable counter 2 */
|
||||
/*
|
||||
* XXX - move timer stuff to clock.c.
|
||||
* Program counter 2:
|
||||
* ccaammmb, c counter, a = access, m = mode, b = BCD
|
||||
* 1011x110, 11 for aa = LSB then MSB, x11 for mmm = square wave.
|
||||
*/
|
||||
outb(0x43, 0xb6); /* set command for counter 2, 2 byte write */
|
||||
|
||||
outb(0x42, pitch);
|
||||
outb(0x42, (pitch>>8));
|
||||
|
||||
if (!beeping) {
|
||||
beeping = period;
|
||||
timeout(sysbeepstop, (caddr_t)(period/2), period);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Pass command to keyboard controller (8042)
|
||||
*/
|
||||
unsigned
|
||||
kbc_8042cmd(val)
|
||||
int val;
|
||||
{
|
||||
|
||||
while (inb(KBSTATP)&KBS_IBF);
|
||||
if (val) outb(KBCMDP, val);
|
||||
while (inb(KBSTATP)&KBS_IBF);
|
||||
return (inb(KBDATAP));
|
||||
}
|
||||
|
||||
/*
|
||||
* find an ISA device in a given isa_devtab_* table, given
|
||||
* the table to search, the expected id_driver entry, and the unit number.
|
||||
|
@ -34,7 +34,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)isa.c 7.2 (Berkeley) 5/13/91
|
||||
* $Id: isa.c,v 1.15 1994/04/02 07:00:46 davidg Exp $
|
||||
* $Id: isa.c,v 1.16 1994/04/02 20:43:25 ache Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -626,165 +626,6 @@ isa_strayintr(d)
|
||||
log(LOG_CRIT,"Too many ISA strayintr not logging any more\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait "n" microseconds.
|
||||
* Relies on timer 1 counting down from (TIMER_FREQ / hz) at
|
||||
* (1 * TIMER_FREQ) Hz.
|
||||
* Note: timer had better have been programmed before this is first used!
|
||||
* (The standard programming causes the timer to generate a square wave and
|
||||
* the counter is decremented twice every cycle.)
|
||||
*/
|
||||
#define CF (1 * TIMER_FREQ)
|
||||
#define TIMER_FREQ 1193182 /* XXX - should be elsewhere */
|
||||
|
||||
void
|
||||
DELAY(n)
|
||||
int n;
|
||||
{
|
||||
int counter_limit;
|
||||
int prev_tick;
|
||||
int tick;
|
||||
int ticks_left;
|
||||
int sec;
|
||||
int usec;
|
||||
|
||||
#ifdef DELAYDEBUG
|
||||
int getit_calls = 1;
|
||||
int n1;
|
||||
static int state = 0;
|
||||
|
||||
if (state == 0) {
|
||||
state = 1;
|
||||
for (n1 = 1; n1 <= 10000000; n1 *= 10)
|
||||
DELAY(n1);
|
||||
state = 2;
|
||||
}
|
||||
if (state == 1)
|
||||
printf("DELAY(%d)...", n);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read the counter first, so that the rest of the setup overhead is
|
||||
* counted. Guess the initial overhead is 20 usec (on most systems it
|
||||
* takes about 1.5 usec for each of the i/o's in getit(). The loop
|
||||
* takes about 6 usec on a 486/33 and 13 usec on a 386/20. The
|
||||
* multiplications and divisions to scale the count take a while).
|
||||
*/
|
||||
prev_tick = getit(0, 0);
|
||||
n -= 20;
|
||||
|
||||
/*
|
||||
* Calculate (n * (CF / 1e6)) without using floating point and without
|
||||
* any avoidable overflows.
|
||||
*/
|
||||
sec = n / 1000000;
|
||||
usec = n - sec * 1000000;
|
||||
ticks_left = sec * CF
|
||||
+ usec * (CF / 1000000)
|
||||
+ usec * ((CF % 1000000) / 1000) / 1000
|
||||
+ usec * (CF % 1000) / 1000000;
|
||||
|
||||
counter_limit = TIMER_FREQ / hz;
|
||||
while (ticks_left > 0) {
|
||||
tick = getit(0, 0);
|
||||
#ifdef DELAYDEBUG
|
||||
++getit_calls;
|
||||
#endif
|
||||
if (tick > prev_tick)
|
||||
ticks_left -= prev_tick - (tick - counter_limit);
|
||||
else
|
||||
ticks_left -= prev_tick - tick;
|
||||
prev_tick = tick;
|
||||
}
|
||||
#ifdef DELAYDEBUG
|
||||
if (state == 1)
|
||||
printf(" %d calls to getit() at %d usec each\n",
|
||||
getit_calls, (n + 5) / getit_calls);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
getit(unit, timer)
|
||||
int unit;
|
||||
int timer;
|
||||
{
|
||||
int high;
|
||||
int low;
|
||||
|
||||
/*
|
||||
* XXX - isa.h defines bogus timers. There's no such timer as
|
||||
* IO_TIMER_2 = 0x48. There's a timer in the CMOS RAM chip but
|
||||
* its interface is quite different. Neither timer is an 8252.
|
||||
* We actually only call this with unit = 0 and timer = 0. It
|
||||
* could be static...
|
||||
*/
|
||||
/*
|
||||
* Protect ourself against interrupts.
|
||||
* XXX - sysbeep() and sysbeepstop() need protection.
|
||||
*/
|
||||
disable_intr();
|
||||
/*
|
||||
* Latch the count for 'timer' (cc00xxxx, c = counter, x = any).
|
||||
*/
|
||||
outb(IO_TIMER1 + 3, timer << 6);
|
||||
|
||||
low = inb(IO_TIMER1 + timer);
|
||||
high = inb(IO_TIMER1 + timer);
|
||||
enable_intr();
|
||||
return ((high << 8) | low);
|
||||
}
|
||||
|
||||
static int beeping;
|
||||
|
||||
static void
|
||||
sysbeepstop(f, dummy)
|
||||
caddr_t f;
|
||||
int dummy;
|
||||
{
|
||||
/* disable counter 2 */
|
||||
outb(0x61, inb(0x61) & 0xFC);
|
||||
if (f)
|
||||
timeout(sysbeepstop, (caddr_t)0, (int)f);
|
||||
else
|
||||
beeping = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sysbeep(int pitch, int period)
|
||||
{
|
||||
|
||||
outb(0x61, inb(0x61) | 3); /* enable counter 2 */
|
||||
/*
|
||||
* XXX - move timer stuff to clock.c.
|
||||
* Program counter 2:
|
||||
* ccaammmb, c counter, a = access, m = mode, b = BCD
|
||||
* 1011x110, 11 for aa = LSB then MSB, x11 for mmm = square wave.
|
||||
*/
|
||||
outb(0x43, 0xb6); /* set command for counter 2, 2 byte write */
|
||||
|
||||
outb(0x42, pitch);
|
||||
outb(0x42, (pitch>>8));
|
||||
|
||||
if (!beeping) {
|
||||
beeping = period;
|
||||
timeout(sysbeepstop, (caddr_t)(period/2), period);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Pass command to keyboard controller (8042)
|
||||
*/
|
||||
unsigned
|
||||
kbc_8042cmd(val)
|
||||
int val;
|
||||
{
|
||||
|
||||
while (inb(KBSTATP)&KBS_IBF);
|
||||
if (val) outb(KBCMDP, val);
|
||||
while (inb(KBSTATP)&KBS_IBF);
|
||||
return (inb(KBDATAP));
|
||||
}
|
||||
|
||||
/*
|
||||
* find an ISA device in a given isa_devtab_* table, given
|
||||
* the table to search, the expected id_driver entry, and the unit number.
|
||||
|
Loading…
x
Reference in New Issue
Block a user