* cormen book
[mascara-docs.git] / i86 / mtx-16-bit / mtx / samples / SERIAL / timer.c
blob530d8d41c8c724b1ea06945a300618c023ed8de7
1 /* timer parameters. */
2 #define LATCH_COUNT 0x00 /* cc00xxxx, c = channel, x = any */
3 #define SQUARE_WAVE 0x36 /* ccaammmb, a = access, m = mode, b = BCD */
5 /************************ NOTICE THE DIVISOR VALUE ***********************/
6 #define TIMER_FREQ 1193182L /* timer frequency for timer in PC and AT */
7 #define TIMER_COUNT ((unsigned) (TIMER_FREQ/10)) /* initial value for counter*/
9 #define TIMER0 0x40
10 #define TIMER_MODE 0x43
11 #define TIMER_IRQ 0
14 int enable_irq(irq_nr) unsigned irq_nr;
16 lock();
17 out_byte(0x21, in_byte(0x21) & ~(1 << irq_nr));
21 /*===========================================================================*
22 * timer_init *
23 *===========================================================================*/
25 ushort tick;
27 int timer_init()
29 /* Initialize channel 0 of the 8253A timer to e.g. 60 Hz. */
31 printf("timer init\n");
32 tick = 0;
34 out_byte(TIMER_MODE, SQUARE_WAVE); /* set timer to run continuously */
35 out_byte(TIMER0, TIMER_COUNT); /* load timer low byte */
36 out_byte(TIMER0, TIMER_COUNT >> 8); /* load timer high byte */
37 enable_irq(TIMER_IRQ);
40 /*===========================================================================*
41 * timer_handler *
42 *===========================================================================*/
44 int thandler()
46 tick++;
47 tick %= 60;
49 if (tick % 60 == 0)
50 printf("1 second timer interrupt\n");
52 out_byte(0x20, 0x20);