• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Defines for routines to implement a low-overhead timer for drivers */
2 
3  /*
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2, or (at
7  * your option) any later version.
8  */
9 
10 #ifndef	TIMER_H
11 #define TIMER_H
12 
13 /* Ports for the 8254 timer chip */
14 #define	TIMER2_PORT	0x42
15 #define	TIMER_MODE_PORT	0x43
16 
17 /* Meaning of the mode bits */
18 #define	TIMER0_SEL	0x00
19 #define	TIMER1_SEL	0x40
20 #define	TIMER2_SEL	0x80
21 #define	READBACK_SEL	0xC0
22 
23 #define	LATCH_COUNT	0x00
24 #define	LOBYTE_ACCESS	0x10
25 #define	HIBYTE_ACCESS	0x20
26 #define	WORD_ACCESS	0x30
27 
28 #define	MODE0		0x00
29 #define	MODE1		0x02
30 #define	MODE2		0x04
31 #define	MODE3		0x06
32 #define	MODE4		0x08
33 #define	MODE5		0x0A
34 
35 #define	BINARY_COUNT	0x00
36 #define	BCD_COUNT	0x01
37 
38 /* Timers tick over at this rate */
39 #define	TICKS_PER_MS	1193
40 
41 /* Parallel Peripheral Controller Port B */
42 #define	PPC_PORTB	0x61
43 
44 /* Meaning of the port bits */
45 #define	PPCB_T2OUT	0x20	/* Bit 5 */
46 #define	PPCB_SPKR	0x02	/* Bit 1 */
47 #define	PPCB_T2GATE	0x01	/* Bit 0 */
48 
49 /* Ticks must be between 0 and 65535 (0 == 65536)
50    because it is a 16 bit counter */
51 extern void load_timer2(unsigned int ticks);
timer2_running(void)52 extern inline int timer2_running(void)
53 {
54 	return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
55 }
56 
waiton_timer2(unsigned int ticks)57 extern inline void waiton_timer2(unsigned int ticks)
58 {
59 	load_timer2(ticks);
60 	while ((inb(PPC_PORTB) & PPCB_T2OUT) == 0)
61 		;
62 }
63 
64 #endif	/* TIMER_H */
65