]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - include/fosa_clocks_and_timers.h
53f4d5560b4178acd533009ade18dd230a91a325
[frescor/fosa.git] / include / fosa_clocks_and_timers.h
1 //----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 by the FRESCOR consortium:
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
17 //
18 //        The 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 //
24 //  based on previous work (FSF) done in the FIRST project
25 //
26 //   Copyright (C) 2005  Mälardalen University, SWEDEN
27 //                       Scuola Superiore S.Anna, ITALY
28 //                       Universidad de Cantabria, SPAIN
29 //                       University of York, UK
30 //
31 // This file is part of FOSA (Frsh Operating System Abstraction)
32 //
33 // FOSA is free software; you can redistribute it and/or modify it
34 // under terms of the GNU General Public License as published by the
35 // Free Software Foundation; either version 2, or (at your option) any
36 // later version.  FOSA is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details. You should have received a
40 // copy of the GNU General Public License along with FOSA; see file
41 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
42 // Cambridge, MA 02139, USA.
43 //
44 // As a special exception, including FOSA header files in a file,
45 // instantiating FOSA generics or templates, or linking other files
46 // with FOSA objects to produce an executable application, does not
47 // by itself cause the resulting executable application to be covered
48 // by the GNU General Public License. This exception does not
49 // however invalidate any other reasons why the executable file might be
50 // covered by the GNU Public License.
51 // -----------------------------------------------------------------------
52 //fosa_clocks_and_timers.h
53 //==============================================
54 //  ********  ******    ********  **********
55 //  **///// /**    **  **//////  /**     /**
56 //  **      /**    ** /**        /**     /**
57 //  ******* /**    ** /********* /**********
58 //  **////  /**    ** ////////** /**//////**
59 //  **      /**    **        /** /**     /**
60 //  **      /**    **  ********  /**     /**
61 //  //       /******/  ////////   //      //
62 //
63 // FOSA(Frescor Operating System Adaptation layer)
64 //================================================
65
66
67 #ifndef         FOSA_CLOCKS_AND_TIMERS_H_
68 #define         FOSA_CLOCKS_AND_TIMERS_H_
69
70 #include "fosa_types.h"
71 #include "fosa_configuration_parameters.h"
72
73 /**
74  * @defgroup clocksandtimers Clocks and Timers
75  * @ingroup fosa
76  *
77  * This module defines the types and functions to abstract clocks and
78  * timers for the FRSH implementation.
79  *
80  * @{
81  **/
82
83
84
85 /*************************
86  * Timing: Clocks
87  *************************/
88
89 /**
90  * fosa_get_time()
91  *
92  * Get the time from a clock
93  *
94  * This function sets the variable pointed to by current_time to the
95  * current value of the clock specified by clockid, which may be the
96  * FOSA_CLOCK_REALTIME constant or a value obtained with
97  * fosa_get_cputime_clock()
98  *
99  * Returns 0 if successful; otherwise it returns an error code:
100  *     FOSA_EINVAL: the value of clockid is invalid
101  *
102  * Alternatively, in case of error the implementation is allowed to
103  * notify it to the system console and then terminate the FRSH
104  * implementation and dependant applications
105  **/
106 int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec *current_time);
107
108
109 /**
110  * fosa_get_cputime_clock()
111  *
112  * Get the identifier of a cpu-time clock
113  *
114  * This function stores in the variable pointed to by clockid the
115  * identifier of a cpu-time clock for the thread specified by tid.
116  *
117  * Returns 0 if successful; otherwise it returns an error code:
118  *    FOSA_EINVAL: the value of tid is invalid
119  *
120  * Alternatively, in case of error the implementation is allowed to
121  * notify it to the system console and then terminate the FRSH
122  * implementation and dependant applications
123  **/
124 int fosa_thread_get_cputime_clock(fosa_thread_id_t tid, fosa_clock_id_t *clockid);
125
126
127 /*************************
128  * Timing: Timers
129  *************************/
130
131 /**
132  * fosa_timer_create()
133  *
134  * Create a one-shot timer
135  *
136  * This function creates a timer based on the clock specified by clock,
137  * and associates to this timer a notification mechanism consisting of
138  * a signal and associated information. Initially, the timer is in the
139  * disarmed state, i.e., not counting time. It can be armed to start
140  * counting time with fosa_timer_arm().
141  *
142  * The function stores the identifier of the newly created timer in the
143  * variable pointed to by timerid.
144  *
145  * When the timer expires, the signal number specified by signal will be
146  * sent together with the information specified by info, to the thread
147  * that armed the timer (@see fosa_timer_arm()).
148  *
149  * In those implementations that do not support queueing a
150  * signal with information to a thread (such as POSIX), the signal may
151  * be sent to any thread that is waiting for this signal via
152  * fosa_signal_wait(). Portability can be ensured by having the receiver
153  * thread be the one who is waiting for the signal.
154  *
155  * Returns 0 if successful; otherwise it returns an error code:
156  *     FOSA_EINVAL: the value of clockid or signal is invalid
157  *
158  *     FOSA_EAGAIN: the system lacks enough resources to create the timer
159  *
160  * Alternatively, in case of error the implementation is allowed to
161  * notify it to the system console and then terminate the FRSH
162  * implementation and dependant applications
163  **/
164  int fosa_timer_create
165       (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
166        fosa_timer_id_t *timerid);
167
168 /**
169  * fosa_timer_create_with_receiver()
170  *
171  * Create a one-shot timer with a specific signal receiver thread
172  *
173  * This function creates a timer in the same way as fosa_timer_create,
174  * except that the signal generated when the timer expires is sent to
175  * the thread specified by receiver
176  *
177  * Returns 0 if successful; otherwise it returns an error code:
178  *     FOSA_EINVAL: the value of clockid or signal is invalid
179  *
180  *     FOSA_EAGAIN: the system lacks enough resources to create the timer
181  *
182  * Alternatively, in case of error the implementation is allowed to
183  * notify it to the system console and then terminate the FRSH
184  * implementation and dependant applications
185  **/
186  int fosa_timer_create_with_receiver
187       (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
188        fosa_timer_id_t *timerid, fosa_thread_id_t receiver);
189
190 /**
191  * fosa_timer_delete()
192  *
193  * Delete a timer
194  *
195  * The function deletes the timer specified by timerid, which becomes
196  * unusable. If the timer was armed, it is automatically disarmed before
197  * deletion.
198  *
199  * Returns 0 if successful; otherwise it returns an error code:
200  *     FOSA_EINVAL: the value of timerid is not valid
201  *
202  * Alternatively, in case of error the implementation is allowed to
203  * notify it to the system console and then terminate the FRSH
204  * implementation and dependant applications
205  **/
206 int fosa_timer_delete(fosa_timer_id_t timerid);
207
208 /**
209  * fosa_timer_arm()
210  *
211  * Arm a timer
212  *
213  * The timer specified by timer is armed and starts counting time.
214  *
215  * If abstime is true, the value pointed to by value is the absolute
216  * time at which the timer will expire. If value specifies a time instant
217  * in the past, the timer expires immediately.
218  *
219  * If abstime is false, the value pointed to by value is the relative interval
220  * that must elapse for the timer to expire.
221  *
222  * In both cases, absolute or relative, the time is measured with the clock
223  * associated with the timer when it was created.
224  *
225  * If the timer was already armed, the previous time or interval is discarded
226  * and the timer is rearmed with the new value.
227  *
228  * When the timer expires, it is disarmed.
229  *
230  * Returns 0 if successful; otherwise it returns an error code:
231  *    FOSA_EINVAL: the value of timerid or value is invalid
232  *
233  * Alternatively, in case of error the implementation is allowed to
234  * notify it to the system console and then terminate the FRSH
235  * implementation and dependant applications
236  **/
237 int fosa_timer_arm
238       (fosa_timer_id_t timerid, bool abstime,
239        const struct timespec *value);
240
241 /**
242  * fosa_timer_get_remaining_time()
243  *
244  * Get the remaining time for timer expiration
245  *
246  * Returns the relative remaining time for timer expiration.  If the
247  * clock is a CPU clock it returns the time as if the thread was
248  * executing constantly.
249  *
250  * If the timer is disarmed it returns 0.
251  *
252  * Returns 0 if successful; otherwise it returns an error code:
253  *    FOSA_EINVAL: the value of timerid or value is invalid
254  *
255  * Alternatively, in case of error the implementation is allowed to
256  * notify it to the system console and then terminate the FRSH
257  * implementation and dependant applications
258  **/
259 int fosa_timer_get_remaining_time
260     (fosa_timer_id_t timerid, struct timespec *remaining_time);
261
262 /**
263  * fosa_timer_disarm()
264  *
265  * Disarm a timer and optionally obtain remaining time before expiration
266  *
267  * The timer specified by timer is disarmed, and will not expire unless
268  * it is rearmed. If the timer was already disramed, the function has
269  * no effect.
270  *
271  * If the pointer remaining_time is != NULL, the remaining time before
272  * expiration will be returned in that pointer.  If the timer was
273  * disarmed a 0 value will be set.
274  *
275  * Returns 0 if successful; otherwise it returns an error code:
276  *    FOSA_EINVAL: the value of timerid or value is invalid
277  *
278  * Alternatively, in case of error the implementation is allowed to
279  * notify it to the system console and then terminate the FRSH
280  * implementation and dependant applications
281  **/
282 int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec
283                            *remaining_time);
284
285
286 /*@}*/
287
288
289 #endif      /* !FOSA_CLOCKS_AND_TIMERS_H_ */