]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dope/server/linux/timer.c
Inital import
[l4.git] / l4 / pkg / dope / server / linux / 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 <unistd.h>
17 #include "SDL/SDL.h"
18 #include "dopestd.h"
19 #include "timer.h"
20
21 int init_timer(struct dope_services *d);
22
23
24 /*************************
25  *** SERVICE FUNCTIONS ***
26  *************************/
27
28 /*** RETURN CURRENT SYSTEM TIME COUNTER IN MICROSECONDS ***/
29 static u32 get_time(void) {
30   return SDL_GetTicks()*1000;
31 }
32
33
34 /*** RETURN DIFFERENCE BETWEEN TWO TIMES ***/
35 static u32 get_diff(u32 time1,u32 time2) {
36
37         /* overflow check */
38         if (time1>time2) {
39                 time1 -= time2;
40                 return (u32)0xffffffff - time1;
41         }
42         return time2-time1;
43 }
44
45
46 /*** WAIT SPECIFIED NUMBER OF MICROSECONDS ***/
47 static void wait_usec(u32 num_usec) {
48         usleep(num_usec);
49 }
50
51
52 /****************************************
53  *** SERVICE STRUCTURE OF THIS MODULE ***
54  ****************************************/
55
56 static struct timer_services services = {
57         get_time,
58         get_diff,
59         wait_usec,
60 };
61
62
63 /**************************
64  *** MODULE ENTRY POINT ***
65  **************************/
66
67 int init_timer(struct dope_services *d) {
68
69         d->register_module("Timer 1.0",&services);
70         return 1;
71 }