]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - include/fosa_clocks_and_timers.h
Uploading first version of FOSA code !!
[frescor/fosa.git] / include / fosa_clocks_and_timers.h
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 //fosa_clocks_and_timers.h
48 //==============================================
49 //  ********  ******    ********  **********
50 //  **///// /**    **  **//////  /**     /**
51 //  **      /**    ** /**        /**     /**
52 //  ******* /**    ** /********* /**********
53 //  **////  /**    ** ////////** /**//////**
54 //  **      /**    **        /** /**     /**
55 //  **      /**    **  ********  /**     /**
56 //  //       /******/  ////////   //      // 
57 //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
60
61
62 #ifndef         FOSA_CLOCKS_AND_TIMERS_H_
63 #define         FOSA_CLOCKS_AND_TIMERS_H_
64
65 /**
66  * @defgroup clocksandtimers Clocks and Timers
67  *
68  * This module defines the types and functions to abstract clocks and
69  * timers for the FRSH implementation.
70  *
71  * @{
72  **/
73
74
75
76 /*************************
77  * Timing: Clocks
78  *************************/
79
80 /**
81  * fosa_get_time()
82  *
83  * Get the time from a clock
84  *
85  * This function sets the variable pointed to by current_time to the 
86  * current value of the clock specified by clockid, which may be the 
87  * FOSA_CLOCK_REALTIME constant or a value obtained with 
88  * fosa_get_cputime_clock()
89  *
90  * Returns 0 if successful; otherwise it returns an error code:
91  *     EINVAL: the value of clockid is invalid
92  *
93  * Alternatively, in case of error the implementation is allowed to
94  * notify it to the system console and then terminate the FRSH
95  * implementation and dependant applications
96  **/
97 int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec current_time);
98
99
100 /**
101  * fosa_get_cputime_clock()
102  *
103  * Get the identifier of a cpu-time clock
104  *
105  * This function stores in the variable pointed to by clockid the 
106  * identifier of a cpu-time clock for the thread specified by tid.
107  *
108  * Returns 0 if successful; otherwise it returns an error code:
109  *    EINVAL: the value of tid is invalid
110  * 
111  * Alternatively, in case of error the implementation is allowed to
112  * notify it to the system console and then terminate the FRSH
113  * implementation and dependant applications
114  **/
115 int fosa_thread_get_cputime_clock(frsh_thread_id_t tid, fosa_clock_id_t *clockid);
116
117
118 /*************************
119  * Timing: Timers
120  *************************/
121
122 /**
123  * fosa_create_timer()
124  *
125  * Create a one-shot timer
126  *
127  * This function creates a timer based on the clock specified by clock,
128  * and associates to this timer a notification mechanism consisting of
129  * a signal and associated information. Initially, the timer is in the
130  * disarmed state, i.e., not counting time. It can be armed to start
131  * counting time with fosa_timer_arm().
132  *
133  * The function stores the identifier of the newly created timer in the 
134  * variable pointed to by timerid.
135  *
136  * When the timer expires, the signal number specified by signal will be
137  * sent together with the information specified by info, to the thread
138  * that armed the timer (@see fosa_timer_arm()). 
139  *
140  * In those implementations that do not support queueing a
141  * signal with information to a thread (such as POSIX), the signal may
142  * be sent to any thread that is waiting for this signal via
143  * fosa_signal_wait(). Portability can be ensured by having the receiver
144  * thread be the one who is waiting for the signal. 
145  * 
146  * Returns 0 if successful; otherwise it returns an error code:
147  *     EINVAL: the value of clockid or signal is invalid
148  * 
149  *     EAGAIN: the system lacks enough resources to create the timer
150  *
151  * Alternatively, in case of error the implementation is allowed to
152  * notify it to the system console and then terminate the FRSH
153  * implementation and dependant applications
154  **/
155  int fosa_timer_create
156       (fosa_clock_id_t clockid, frsh_signal_t signal, frsh_signal_info_t info,
157        fosa_timer_id_t *timerid);
158
159 /**
160  * Delete a timer
161  * 
162  * The function deletes the timer specified by timerid, which becomes 
163  * unusable. If the timer was armed, it is automatically disarmed before
164  * deletion.
165  * 
166  * Returns 0 if successful; otherwise it returns an error code:
167  *     EINVAL: the value of timerid is not valid
168  *
169  * Alternatively, in case of error the implementation is allowed to
170  * notify it to the system console and then terminate the FRSH
171  * implementation and dependant applications
172  **/
173 int fosa_timer_delete(fosa_timer_id_t timerid);
174
175 /**
176  * fosa_timer_arm()
177  *
178  * Arm a timer
179  *
180  * The timer specified by timer is armed and starts counting time.
181  *
182  * If abstime is true, the value pointed to by value is the absolute
183  * time at which the timer will expire. If value specifies a time instant 
184  * in the past, the timer expires immediately.
185  *
186  * If abstime is false, the value pointed to by value is the relative interval
187  * that must elapse for the timer to expire. 
188  *
189  * In both cases, absolute or relative, the time is measured with the clock 
190  * associated with the timer when it was created.
191  *
192  * If the timer was already armed, the previous time or interval is discarded
193  * and the timer is rearmed with the new value.
194  *
195  * When the timer expires, it is disarmed.
196  *
197  * Returns 0 if successful; otherwise it returns an error code:
198  *    EINVAL: the value of timerid or value is invalid
199  *
200  * Alternatively, in case of error the implementation is allowed to
201  * notify it to the system console and then terminate the FRSH
202  * implementation and dependant applications
203  **/
204 int fosa_timer_arm
205       (fosa_timer_id_t timerid, bool abstime,
206        const struct timespec *value);
207
208 /**
209  * fosa_timer_disarm()
210  *
211  * Disarm a timer
212  * 
213  * The timer specified by timer is disarmed, and will not expire unless 
214  * it is rearmed. If the timer was already disramed, the function has 
215  * no effect.
216  *
217  * Returns 0 if successful; otherwise it returns an error code:
218  *    EINVAL: the value of timerid or value is invalid
219  *
220  * Alternatively, in case of error the implementation is allowed to
221  * notify it to the system console and then terminate the FRSH
222  * implementation and dependant applications
223  **/
224 int fosa_timer_disarm(fosa_timer_id_t timerid);
225
226 /*@}*/
227
228
229 #endif      /* !FOSA_CLOCKS_AND_TIMERS_H_ */