Final cleanup; completely working on TINI now (243 dhry/sec)
[fw/sdcc] / support / tests / dhrystone / clock.c
1 #include <ds80c390.h>
2 #include <stdio.h>
3
4 #include "clock.h"
5
6 volatile unsigned long milliSeconds=0;
7
8 #define RELOAD_VALUE 18432000/2/CLOCKS_PER_SEC 
9
10 void Timer2Handler (void) interrupt 5 using 1 {
11   TF2=0; // reset overflow flag
12   milliSeconds++;
13   // that's all for now :)
14 }
15
16 // we can't just use milliSeconds
17 unsigned long clock(void) {
18   unsigned long ms;
19   ET2=0;
20   ms=milliSeconds;
21   ET2=1;
22   return ms;
23 }
24
25 void startTimer (void) 
26 {
27   // initialise timer
28   ET2=0; // disable timer interrupts initially
29   T2CON=0; // stop, timer mode, autoreload
30   T2MOD&=0xf4;
31   
32   TL2=RTL2=(-RELOAD_VALUE)&0xff;
33   TH2=RTH2=(-RELOAD_VALUE)>>8;
34   TR2=1; // run
35
36   ET2=1; // enable timer interrupts
37 }
38
39