]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_partikle/fosa_clocks_and_timers.c
bfa0e70176de3f375994006d86889298979afccf
[frescor/fosa.git] / src_partikle / fosa_clocks_and_timers.c
1 /** fosa_clocks_and_timers.c
2  *
3  * < description >
4  * < author >
5  * < date >
6  */
7
8 #include <fosa_clocks_and_timers.h>
9
10 /*************************
11  * Timing: Clocks
12  *************************/
13 int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec *current_time)
14 {
15         if (clock_gettime (clockid, current_time))
16                 return FOSA_EINVAL;
17         
18         return 0;
19 }
20
21
22
23 int fosa_thread_get_cputime_clock(frsh_thread_id_t tid, fosa_clock_id_t *clockid)
24 {
25 //      if (tid == thread_invalid) 
26 //              return FOSA_EINVAL;
27         
28         *clockid = CLOCK_THREAD_CPUTIME_ID;
29         return 0;
30 }
31
32 /*************************
33  * Timing: Timers
34  *************************/
35 int fosa_timer_create
36                  (fosa_clock_id_t clockid, frsh_signal_t signal, frsh_signal_info_t info,
37                   fosa_timer_id_t *timerid);
38
39 int fosa_timer_delete(fosa_timer_id_t timerid)
40 {
41         if (timer_delete (timerid))
42                 return FOSA_EINVAL;
43         return 0;
44 }
45
46
47 int fosa_timer_arm
48                 (fosa_timer_id_t timerid, bool abstime,
49                  const struct timespec *value)
50 {
51         struct itimerspec value = 
52         {
53                 .it_value = (struct timespec) *value,
54                 .it_interval = 0,
55         }
56         
57         if (timer_settime (timerid, abstime, &value, NULL))
58                 return EINVAL;
59         
60         return 0;
61 }
62
63
64 // TODO: CPU-clock ???
65 int fosa_timer_get_remaining_time
66                 (fosa_timer_id_t timerid, struct timespec *remaining_time)
67 {
68         struct itimerspec value;
69         
70         if (timer_gettime (timerid, &value))
71                 return EINVAL;
72         
73         *remaining_time = value.it_value;
74         return 0;
75 }
76
77 int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec
78                 *remaining_time)
79 {
80         struct itimerspec null_timer, old;
81         
82         // NULL timer -> disarm
83         value = (struct itimerspec) {
84                 .it_value = {0, 0},
85                 .it_interval = 0,
86         }
87         
88         if (timer_settime (timerid, 0, &null_timer, &old))
89                 return EINVAL;
90         
91         if (remaining_time)
92                 *remaining_time = old.it_value; 
93                 
94         return 0;
95 }