]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dope/server/l4/timer.c
Inital import
[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 #if 0
24 #ifndef ARCH_arm
25 #include <l4/util/thread_time.h>
26 #endif
27 #endif
28
29 #include "timer.h"
30
31 int init_timer(struct dope_services *d);
32
33
34 /*************************
35  *** SERVICE FUNCTIONS ***
36  *************************/
37
38 /*** RETURN CURRENT SYSTEM TIME COUNTER IN MICROSECONDS ***/
39 static u32 get_time(void) {
40 //#ifdef ARCH_arm
41         return (u32)l4re_kip()->clock;
42 //#else
43 //      return l4_tsc_to_us(l4util_thread_time(l4re_kip()));
44 //#endif
45 }
46
47
48 /*** RETURN DIFFERENCE BETWEEN TWO TIMES ***/
49 static u32 get_diff(u32 time1, u32 time2) {
50
51         /* overflow check */
52         if (time1>time2) {
53                 time1 -= time2;
54                 return (u32)0xffffffff - time1;
55         }
56         return time2-time1;
57 }
58
59
60 /*** WAIT THE SPECIFIED NUMBER OF MICROSECONDS ***/
61 static void __usleep(u32 num_usec) {
62         usleep(num_usec);
63 }
64
65 /****************************************
66  *** SERVICE STRUCTURE OF THIS MODULE ***
67  ****************************************/
68
69 static struct timer_services services = {
70         get_time,
71         get_diff,
72         __usleep,
73 };
74
75
76 /**************************
77  *** MODULE ENTRY POINT ***
78  **************************/
79
80 int init_timer(struct dope_services *d) {
81 #if 0
82 #ifndef ARCH_arm
83         l4_calibrate_tsc(l4re_kip());
84 #endif
85 #endif
86
87         d->register_module("Timer 1.0", &services);
88         return 1;
89 }