]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dope/server/l4/timer.c
update
[l4.git] / l4 / pkg / dope / server / l4 / timer.c
1 /*
2  * \brief   DOpE timer module
3  * \date    2002-11-13
4  * \author  Norman Feske <nf2@inf.tu-dresden.de>
5  */
6
7 /*
8  * Copyright (C) 2002-2004  Norman Feske  <nf2@os.inf.tu-dresden.de>
9  * Technische Universitaet Dresden, Operating Systems Research Group
10  *
11  * This file is part of the DOpE package, which is distributed under
12  * the  terms  of the  GNU General Public Licence 2.  Please see the
13  * COPYING file for details.
14  */
15
16 #include "dopestd.h"
17
18 #include <unistd.h>
19
20 #include <l4/re/env.h>
21 #include <l4/util/macros.h>
22
23 #include "timer.h"
24
25 int init_timer(struct dope_services *d);
26
27
28 /*************************
29  *** SERVICE FUNCTIONS ***
30  *************************/
31
32 /*** RETURN CURRENT SYSTEM TIME COUNTER IN MICROSECONDS ***/
33 static u32 get_time(void) {
34         return (u32)l4_kip_clock_lw(l4re_kip());
35 }
36
37
38 /*** RETURN DIFFERENCE BETWEEN TWO TIMES ***/
39 static u32 get_diff(u32 time1, u32 time2) {
40
41         /* overflow check */
42         if (time1>time2) {
43                 time1 -= time2;
44                 return (u32)0xffffffff - time1;
45         }
46         return time2-time1;
47 }
48
49
50 /*** WAIT THE SPECIFIED NUMBER OF MICROSECONDS ***/
51 static void __usleep(u32 num_usec) {
52         usleep(num_usec);
53 }
54
55 /****************************************
56  *** SERVICE STRUCTURE OF THIS MODULE ***
57  ****************************************/
58
59 static struct timer_services services = {
60         get_time,
61         get_diff,
62         __usleep,
63 };
64
65
66 /**************************
67  *** MODULE ENTRY POINT ***
68  **************************/
69
70 int init_timer(struct dope_services *d) {
71 #if 0
72 #ifndef ARCH_arm
73         l4_calibrate_tsc(l4re_kip());
74 #endif
75 #endif
76
77         d->register_module("Timer 1.0", &services);
78         return 1;
79 }