1 //----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 by the FRESCOR consortium:
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
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org
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
24 // based on previous work (FSF) done in the FIRST project
26 // Copyright (C) 2005 Mälardalen University, SWEDEN
27 // Scuola Superiore S.Anna, ITALY
28 // Universidad de Cantabria, SPAIN
29 // University of York, UK
31 // This file is part of FOSA (Frsh Operating System Abstraction)
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.
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 // // /******/ //////// // //
63 // FOSA(Frescor Operating System Adaptation layer)
64 //================================================
67 #ifndef FOSA_CLOCKS_AND_TIMERS_H_
68 #define FOSA_CLOCKS_AND_TIMERS_H_
70 #include "fosa_types.h"
71 #include "fosa_configuration_parameters.h"
76 * @defgroup clocksandtimers Clocks and Timers
79 * This module defines the types and functions to abstract clocks and
80 * timers for the FRSH implementation.
87 /*************************
89 *************************/
94 * Get the time from a clock
96 * This function sets the variable pointed to by current_time to the
97 * current value of the clock specified by clockid, which may be the
98 * FOSA_CLOCK_REALTIME constant or a value obtained with
99 * fosa_get_cputime_clock()
101 * Returns 0 if successful; otherwise it returns an error code:
102 * FOSA_EINVAL: the value of clockid is invalid
104 * Alternatively, in case of error the implementation is allowed to
105 * notify it to the system console and then terminate the FRSH
106 * implementation and dependant applications
108 int fosa_clock_get_time(fosa_clock_id_t clockid, fosa_abs_time_t *current_time);
112 * fosa_get_cputime_clock()
114 * Get the identifier of a cpu-time clock
116 * This function stores in the variable pointed to by clockid the
117 * identifier of a cpu-time clock for the thread specified by tid.
119 * Returns 0 if successful; otherwise it returns an error code:
120 * FOSA_EINVAL: the value of tid is invalid
122 * Alternatively, in case of error the implementation is allowed to
123 * notify it to the system console and then terminate the FRSH
124 * implementation and dependant applications
126 int fosa_thread_get_cputime_clock(fosa_thread_id_t tid, fosa_clock_id_t *clockid);
129 /*************************
131 *************************/
134 * fosa_timer_create()
136 * Create a one-shot timer
138 * This function creates a timer based on the clock specified by clock,
139 * and associates to this timer a notification mechanism consisting of
140 * a signal and associated information. Initially, the timer is in the
141 * disarmed state, i.e., not counting time. It can be armed to start
142 * counting time with fosa_timer_arm().
144 * The function stores the identifier of the newly created timer in the
145 * variable pointed to by timerid.
147 * When the timer expires, the signal number specified by signal will be
148 * sent together with the information specified by info, to the thread
149 * that armed the timer (@see fosa_timer_arm()).
151 * In those implementations that do not support queueing a
152 * signal with information to a thread (such as POSIX), the signal may
153 * be sent to any thread that is waiting for this signal via
154 * fosa_signal_wait(). Portability can be ensured by having the receiver
155 * thread be the one who is waiting for the signal.
157 * Returns 0 if successful; otherwise it returns an error code:
158 * FOSA_EINVAL: the value of clockid or signal is invalid
160 * FOSA_EAGAIN: the system lacks enough resources to create the timer
162 * Alternatively, in case of error the implementation is allowed to
163 * notify it to the system console and then terminate the FRSH
164 * implementation and dependant applications
166 int fosa_timer_create
167 (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
168 fosa_timer_id_t *timerid);
171 * fosa_timer_create_with_receiver()
173 * Create a one-shot timer with a specific signal receiver thread
175 * This function creates a timer in the same way as fosa_timer_create,
176 * except that the signal generated when the timer expires is sent to
177 * the thread specified by receiver
179 * Returns 0 if successful; otherwise it returns an error code:
180 * FOSA_EINVAL: the value of clockid or signal is invalid
182 * FOSA_EAGAIN: the system lacks enough resources to create the timer
184 * Alternatively, in case of error the implementation is allowed to
185 * notify it to the system console and then terminate the FRSH
186 * implementation and dependant applications
188 int fosa_timer_create_with_receiver
189 (fosa_clock_id_t clockid, fosa_signal_t signal, fosa_signal_info_t info,
190 fosa_timer_id_t *timerid, fosa_thread_id_t receiver);
193 * fosa_timer_delete()
197 * The function deletes the timer specified by timerid, which becomes
198 * unusable. If the timer was armed, it is automatically disarmed before
201 * Returns 0 if successful; otherwise it returns an error code:
202 * FOSA_EINVAL: the value of timerid is not valid
204 * Alternatively, in case of error the implementation is allowed to
205 * notify it to the system console and then terminate the FRSH
206 * implementation and dependant applications
208 int fosa_timer_delete(fosa_timer_id_t timerid);
211 * fosa_rel_timer_arm()
213 * Arm a timer with a relative time interval
215 * The timer specified by timer is armed and starts counting time.
217 * The value pointed to by value is the relative interval that must
218 * elapse for the timer to expire. Negative values cause the timer to
219 * expire immediately.
221 * The time is measured with the clock associated with the timer when
224 * If the timer was already armed, the previous time or interval is discarded
225 * and the timer is rearmed with the new value.
227 * When the timer expires, it is disarmed.
229 * Returns 0 if successful; otherwise it returns an error code:
230 * FOSA_EINVAL: the value of timerid or value is invalid
232 * Alternatively, in case of error the implementation is allowed to
233 * notify it to the system console and then terminate the FRSH
234 * implementation and dependant applications
236 int fosa_rel_timer_arm
237 (fosa_timer_id_t timerid, const fosa_rel_time_t *value);
240 * fosa_abs_timer_arm()
242 * Arm a timer that will expire in an absolute time instant.
244 * The timer specified by timer is armed and starts counting time.
246 * The value pointed to by value is the absolute time at which the
247 * timer will expire. If value specifies a time instant in the past,
248 * the timer expires immediately.
250 * The time is measured with the clock associated with the timer when
253 * If the timer was already armed, the previous time or interval is discarded
254 * and the timer is rearmed with the new value.
256 * When the timer expires, it is disarmed.
258 * Returns 0 if successful; otherwise it returns an error code:
259 * FOSA_EINVAL: the value of timerid or value is invalid
261 * Alternatively, in case of error the implementation is allowed to
262 * notify it to the system console and then terminate the FRSH
263 * implementation and dependant applications
265 int fosa_abs_timer_arm
266 (fosa_timer_id_t timerid, const fosa_abs_time_t *value);
272 * fosa_timer_get_remaining_time()
274 * Get the remaining time for timer expiration
276 * Returns the relative remaining time for timer expiration. If the
277 * clock is a CPU clock it returns the time as if the thread was
278 * executing constantly.
280 * If the timer is disarmed it returns 0.
282 * Returns 0 if successful; otherwise it returns an error code:
283 * FOSA_EINVAL: the value of timerid or value is invalid
285 * Alternatively, in case of error the implementation is allowed to
286 * notify it to the system console and then terminate the FRSH
287 * implementation and dependant applications
289 int fosa_timer_get_remaining_time
290 (fosa_timer_id_t timerid, fosa_rel_time_t *remaining_time);
293 * fosa_timer_disarm()
295 * Disarm a timer and optionally obtain remaining time before expiration
297 * The timer specified by timer is disarmed, and will not expire unless
298 * it is rearmed. If the timer was already disramed, the function has
301 * If the pointer remaining_time is != NULL, the remaining time before
302 * expiration will be returned in that pointer. If the timer was
303 * disarmed a 0 value will be set.
305 * Returns 0 if successful; otherwise it returns an error code:
306 * FOSA_EINVAL: the value of timerid or value is invalid
308 * Alternatively, in case of error the implementation is allowed to
309 * notify it to the system console and then terminate the FRSH
310 * implementation and dependant applications
312 int fosa_timer_disarm(fosa_timer_id_t timerid,
313 fosa_rel_time_t *remaining_time);
320 #endif /* !FOSA_CLOCKS_AND_TIMERS_H_ */