]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_aquosa/fosa_clocks_and_timers.c
6172c0bc5ccddb68ce2509cfed6f4bfadeb4ed2b
[frescor/fosa.git] / src_aquosa / fosa_clocks_and_timers.c
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
3 //
4 //    Universidad de Cantabria,              SPAIN
5 //    University of York,                    UK
6 //    Scuola Superiore Sant'Anna,            ITALY
7 //    Kaiserslautern University,             GERMANY
8 //    Univ. Politecnica  Valencia,           SPAIN
9 //    Czech Technical University in Prague,  CZECH REPUBLIC
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //    
16 //    See http://www.frescor.org for a link to partners' websites
17 //
18 //           FRESCOR project (FP6/2005/IST/5-034026) is funded
19 //        in part by the European Union Sixth Framework Programme
20 //        The European Union is not liable of any use that may be
21 //        made of this code.
22 //
23 //  This file is part of the FRSH implementation
24 //
25 //  FRSH is free software; you can  redistribute it and/or  modify
26 //  it under the terms of  the GNU General Public License as published by
27 //  the Free Software Foundation;  either  version 2, or (at  your option)
28 //  any later version.
29 //
30 //  FRSH  is distributed  in  the hope  that  it  will  be useful,  but
31 //  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
32 //  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
33 //  General Public License for more details.
34 //
35 //  You should have  received a  copy of  the  GNU  General Public License
36 //  distributed  with  FRSH;  see file COPYING.   If not,  write to the
37 //  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
38 //  02111-1307, USA.
39 //
40 //  As a special exception, if you include this header file into source
41 //  files to be compiled, this header file does not by itself cause
42 //  the resulting executable to be covered by the GNU General Public
43 //  License.  This exception does not however invalidate any other
44 //  reasons why the executable file might be covered by the GNU General
45 //  Public License.
46 // -----------------------------------------------------------------------
47 //
48 //==============================================
49 //  ********  ******    ********  **********
50 //  **///// /**    **  **//////  /**     /**
51 //  **      /**    ** /**        /**     /**
52 //  ******* /**    ** /********* /**********
53 //  **////  /**    ** ////////** /**//////**
54 //  **      /**    **        /** /**     /**
55 //  **      /**    **  ********  /**     /**
56 //  //       /******/  ////////   //      // 
57 //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
60
61 #include <fosa.h>
62
63 /*************************
64  * Timing: Clocks
65  *************************/
66
67 int fosa_clock_get_time(fosa_clock_id_t clockid,
68         struct timespec *current_time)
69 {
70         return clock_gettime(clockid, current_time);
71 }
72
73 int fosa_thread_get_cputime_clock(fosa_thread_id_t tid,
74         fosa_clock_id_t *clockid)
75 {
76         if (tid.linux_pid == tid.linux_tid) {
77                 /* we're in a standard UNIX process */
78                 *clockid = FOSA_CLOCK_REALTIME;
79
80                 return 0;
81         } else
82                 /* we're in a thread */
83                 return pthread_getcpuclockid(tid.pthread_id, clockid);
84 }
85
86 /*************************
87  * Timing: Timers
88  *************************/
89
90 int fosa_timer_create(fosa_clock_id_t clockid,
91         fosa_signal_t signal,
92         fosa_signal_info_t info,
93         fosa_timer_id_t *timerid)
94 {
95         struct sigevent event;
96
97         event.sigev_notify = SIGEV_SIGNAL;
98         event.sigev_signo = signal;
99         event.sigev_value.sival_int = info.sival_int;
100
101         return timer_create(clockid, &event, timerid);
102 }
103
104 int fosa_timer_delete(fosa_timer_id_t  timerid){
105      timer_delete(timerid);
106      return 0;
107 }
108
109 int fosa_timer_arm (fosa_timer_id_t timerid,
110         bool abstime,
111         const struct timespec *value)
112 {
113         int flags;
114         struct itimerspec when;
115
116         when.it_value = *value;         /* one shot timer */
117         when.it_interval.tv_sec = 0;
118         when.it_interval.tv_nsec = 0;   /* no periodic behaviour */
119         if (abstime)
120                 flags = TIMER_ABSTIME;
121         else
122                 flags = 0;
123
124         return timer_settime(timerid, flags, &when, NULL);
125 }
126
127 int fosa_timer_get_remaining_time(fosa_timer_id_t timerid, struct timespec *remaining_time)
128 {
129         errno = EINVAL;
130         return -1;
131 }
132
133 int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec *remaining_time)
134 {
135         struct itimerspec when;
136
137         /* maybe not needed but safer */
138         when.it_value.tv_sec = 0;
139         when.it_value.tv_nsec = 0;
140         when.it_interval = when.it_value;
141
142         return timer_settime(timerid, TIMER_ABSTIME , &when, NULL);
143 }
144