]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - include/fosa_opaque_types.h
5f562ec70e2ad3cb56572212cd10a4453070a9dc
[frescor/fosa.git] / include / fosa_opaque_types.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_opaque_types.h
53 //==============================================
54 //  ********  ******    ********  **********
55 //  **///// /**    **  **//////  /**     /**
56 //  **      /**    ** /**        /**     /**
57 //  ******* /**    ** /********* /**********
58 //  **////  /**    ** ////////** /**//////**
59 //  **      /**    **        /** /**     /**
60 //  **      /**    **  ********  /**     /**
61 //  //       /******/  ////////   //      //
62 //
63 // FOSA(Frescor Operating System Adaptation layer)
64 //================================================
65
66 // Implementation dependent definitions
67
68 #ifndef _FOSA_OPAQUE_TYPES_H_
69 #define _FOSA_OPAQUE_TYPES_H_
70
71 #include <stdbool.h>
72
73 #include "fosa_cpp_macros.h"
74 #include "fosa_opaque_types_time.h"
75
76 ///////////////////////  MARTE_OS /////////////////////////////
77
78 #ifdef MARTE_OS
79
80 #include <pthread.h>
81 #include <signal.h>
82 #include <time.h>
83 #include <sched.h>
84 #include <errno.h>
85
86 FOSA_CPP_BEGIN_DECLS
87
88
89 /* Thread and signals */
90 /**********************/
91 typedef pthread_t FOSA_THREAD_ID_T_OPAQUE;
92 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
93
94 typedef int FOSA_SIGNAL_T_OPAQUE;
95 /* Signal info is defined as a union in thread_and_signals */
96
97 #define FOSA_SIGNAL_MIN       SIGRTMIN
98 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
99
100 #define FOSA_NULL_SIGNAL 0
101
102 /* Clocks and timers */
103 /**********************/
104 typedef clockid_t FOSA_CLOCK_ID_T_OPAQUE;
105 typedef timer_t FOSA_TIMER_ID_T_OPAQUE;
106
107 #define FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
108
109 /* Mutex and conditional variables */
110 /***********************************/
111 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
112 typedef pthread_cond_t FOSA_COND_T_OPAQUE;
113
114
115 /* Application defined Scheduling */
116 /**********************************/
117 #define FOSA_ADS_ACTIONS_T_OPAQUE  struct \
118 { \
119     posix_appsched_actions_t actions; \
120     struct timespec *timeout_ptr; \
121     struct timespec timeout; \
122     bool rejected; \
123     bool suspended; \
124     bool activated; \
125
126
127
128 /* Local jump */
129 /**************/
130 #include "marte_non_local_jmp.h"
131
132 #define FOSA_LONG_JUMP_CONTEXT_T_OPAQUE  struct { \
133   marte_nonlocaljmp_context_t marte_context;      \
134   fosa_thread_id_t tid;                            \
135 }
136
137
138 /* FOSA errors */
139 /***************/
140 /** Not enough memory available **/
141 #define FOSA_ENOMEM   ENOMEM
142
143 /** Invalid parameter **/
144 #define FOSA_EINVAL   EINVAL
145
146 /** Still pending information **/
147 #define FOSA_EAGAIN   EAGAIN
148
149 /** FOSA ADS errors **/
150 #ifdef MARTE_OS
151 #define EREJECT   201 /* (for linux_lib_arch) Appsched has rejected object */
152 #endif
153
154 #define FOSA_EREJECT   EREJECT
155 #define FOSA_EMASKED   -2
156 #define FOSA_EPOLICY   -3
157
158 #define FOSA_ETIMEDOUT ETIMEDOUT
159
160 #endif
161
162 ///////////////////////  End of MARTE_OS  /////////////////////////////
163
164
165 /////////////////////// RT_LINUX ///////////////////////////
166
167 #ifdef RT_LINUX
168
169 /* Very similar to MARTE_OS but I leave separate for clarity */
170
171 #include <pthread.h>
172 #include <signal.h>
173 #include <time.h>
174 #include <sched.h>
175 #include <errno.h>
176 #include <rtl_timer.h>
177
178
179 /* Threads and signals */
180 /***********************/
181 #define    FOSA_THREAD_ID_T_OPAQUE pthread_t
182
183 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
184 typedef int FOSA_SIGNAL_T_OPAQUE;
185 /* Signal info is defined as a union in fosa_types.h */
186
187 // The minimum and maximum signal numbers that may be used by the FRSH
188 // implementation
189 #define FOSA_SIGNAL_MIN       SIGRTMIN
190 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
191 #define FOSA_NULL_SIGNAL 0
192
193 /* Clocks and timers */
194 /*********************/
195 #define    FOSA_CLOCK_ID_T_OPAQUE    clockid_t
196 #define    FOSA_TIMER_ID_T_OPAQUE    timer_t
197 #define    FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
198
199 /* Mutex and cond vars */
200 /***********************/
201 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
202 #define    FOSA_COND_T_OPAQUE        pthread_cond_t
203
204
205 /* FOSA Errors */
206 /***************/
207 /** Not enough memory available **/
208 #define FOSA_ENOMEM   ENOMEM
209 /** Invalid parameter **/
210 #define FOSA_EINVAL   EINVAL
211 /** Still pending information **/
212 #define FOSA_EAGAIN   EAGAIN
213
214 /** FOSA ADS errors **/
215 #define FOSA_EREJECT   EREJECT
216 #define FOSA_EMASKED   -2
217 #define FOSA_EPOLICY   -3
218
219 #define FOSA_ETIMEDOUT ETIMEDOUT
220
221 #endif
222
223 ///////////////////////  End of RT_LINUX  /////////////////////////////
224
225
226 ////////////////////////// OSE    //////////////////////////////////////
227
228 #ifdef OSE
229
230
231
232 /* Put OSE dependent includes and defines here */
233
234 #endif /* OSE */
235
236
237
238 /////////////////////// AQuoSA ///////////////////////////
239
240 #ifdef AQuoSA
241
242 #define __USE_UNIX98
243
244 #include <pthread.h>
245 #include <signal.h>
246 #include <errno.h>
247 #include <time.h>
248
249 /* Time */
250 /********/
251 // typedef struct timespec fosa_rel_time_t;
252 // typedef struct timespec fosa_abs_time_t;
253
254
255 /* Threads and signals */
256 /***********************/
257 typedef struct {
258         pthread_t pthread_id;
259         pid_t linux_pid;
260         pid_t linux_tid;
261 } FOSA_THREAD_ID_T_OPAQUE;
262
263
264 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
265 typedef int FOSA_SIGNAL_T_OPAQUE;
266
267
268 // The minimum and maximum signal numbers that may be used by the FRSH
269 // implementation
270 #define FOSA_SIGNAL_MIN       SIGRTMIN
271 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
272
273 #define FOSA_NULL_SIGNAL 0
274
275
276 /* Clocks and signals */
277 /**********************/
278 #define    FOSA_CLOCK_ID_T_OPAQUE    clockid_t
279 #define    FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
280 #define    FOSA_TIMER_ID_T_OPAQUE    timer_t
281
282
283
284 /* Mutex and cond vars */
285 /***********************/
286 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
287 #define    FOSA_COND_T_OPAQUE        pthread_cond_t
288
289
290 /* Application Defined Scheduling */
291 /**********************************/
292 /* hack to get AQuoSA sources compile without having none
293  * of the application level scheduler header files and symbols */
294 #define posix_appsched_actions_t int
295 #define FOSA_LONG_JUMP_CONTEXT_T_OPAQUE int
296
297 #define FOSA_ADS_ACTIONS_T_OPAQUE posix_appsched_actions_t
298
299
300 /* FOSA Errors */
301
302 /** Not enough memory available **/
303 #define FOSA_ENOMEM   ENOMEM
304
305 /** Invalid parameter **/
306 #define FOSA_EINVAL   EINVAL
307
308 /** Still pending information **/
309 #define FOSA_EAGAIN   EAGAIN
310
311 #define FOSA_EREJECT   EREJECT
312 #define FOSA_EMASKED   -2
313 #define FOSA_EPOLICY   -3
314
315 #define FOSA_ETIMEDOUT ETIMEDOUT
316
317
318 #endif 
319 ////////////////// END of AQuoSA //////////////////////
320
321
322
323 /////////////////////////////////// PARTIKLE ///////////////////////////////////////////
324 #if defined(PARTIKLE)
325
326 #include <pthread.h>
327 #include <signal.h>
328 #include <time.h>
329 #include <sched.h>
330 #include <stdlib.h>
331 #include <setjmp.h>
332
333 typedef struct {
334     posix_appsched_actions_t actions;
335     struct timespec * timeout_ptr;
336     struct timespec timeout;
337     bool rejected;
338     bool suspended;
339     bool activated;
340 } FOSA_ADS_ACTIONS_T_OPAQUE;
341
342 typedef struct {
343   jmp_buf jmp_context;
344   bool jmp_hasexecuted;
345   sigset_t jmp_sigmask;
346 } FOSA_LONG_JUMP_CONTEXT_T_OPAQUE;
347
348 typedef pthread_t                   FOSA_THREAD_ID_T_OPAQUE;
349 typedef pthread_attr_t              FOSA_THREAD_ATTR_T_OPAQUE;
350 typedef int                         FOSA_SIGNAL_T_OPAQUE;
351 typedef clockid_t                   FOSA_CLOCK_ID_T_OPAQUE;
352 typedef timer_t                     FOSA_TIMER_ID_T_OPAQUE;
353 typedef pthread_cond_t              FOSA_COND_T_OPAQUE;
354 typedef pthread_mutex_t             FOSA_MUTEX_T_OPAQUE;
355
356
357
358 enum _fosa_clocks_e {
359   FOSA_SYSTEM_CLOCK_OPAQUE = CLOCK_MONOTONIC
360 };
361
362 enum _fosa_signal_limits_e {
363   LONGJMP_NSIG = 3,
364   LONGJMP_FIRSTSIG = SIGRTMAX - LONGJMP_NSIG + 1,
365   FOSA_SIGNAL_MAX = LONGJMP_FIRSTSIG - 1,
366   FOSA_SIGNAL_MIN = FOSA_SIGNAL_MAX,
367 };
368
369 enum _fosa_errors_e {
370   FOSA_EINVAL = EINVAL,
371   FOSA_EAGAIN = EAGAIN,
372   FOSA_EREJECT = EREJECT,
373   FOSA_EMASKED = EMASKED,
374   FOSA_EPOLICY = EPOLICY, 
375   FOSA_ETIMEDOUT = ETIMEDOUT,
376   FOSA_ENOMEM = ENOMEM,
377 };
378
379 #endif
380 /////////////////////////////////// PARTIKLE  END //////////////////////////////////////
381
382
383
384 ////////////////////////// VIRTUAL TIME    //////////////////////////////////////
385 #ifdef VIRTUAL_TIME
386
387 /* Time */
388 /********/
389 // typedef struct timespec fosa_rel_time_t;
390 // typedef struct timespec fosa_abs_time_t;
391
392 #include <fosa_vt.h>
393
394 #define FOSA_THREAD_ID_T_OPAQUE   vt_posix_process_t
395 #define FOSA_THREAD_ATTR_T_OPAQUE fosa_thread_attr_t
396 #define FOSA_SIGNAL_T_OPAQUE      int
397
398 #define FOSA_MUTEX_T_OPAQUE fosa_mutex_t
399
400 // The minimum and maximum signal numbers that may be used by the FRSH
401 // implementation
402 #define FOSA_SIGNAL_MIN       8
403 #define FOSA_SIGNAL_MAX       31
404
405 // the min. and max. priority a fosa thread can have
406 #define FOSA_PRIORITY_MAX VT_PRIORITY_MIN - 1
407 #define FOSA_PRIORITY_MIN VT_PRIORITY_MAX
408
409 #define FOSA_NULL_SIGNAL        0
410
411 /* FOSA Errors and return values*/
412
413 /** Invalid parameter **/
414 #define FOSA_EINVAL   -1
415
416 /** Not enough memory available **/
417 #define FOSA_ENOMEM   -2
418
419 /** Still pending information **/
420 #define FOSA_EAGAIN   -3
421
422 /** Mutex not available **/
423 #define FOSA_EBUSY         -4
424
425 /** Cond var timedout **/
426 #define FOSA_ETIMEDOUT  -5
427
428 /** FOSA ADS errors **/
429 #define FOSA_EREJECT   -6
430 #define FOSA_EMASKED   -7
431
432
433 /** Sched policy not correct */
434 #define FOSA_EPOLICY    -8
435
436 /** the value given by thread_id is not valid for ADS */
437 #define FOSA_ESRCH              -9
438
439 /** retval if no action performed **/
440 #define FOSA_NO_ACTION  0
441
442 #endif /* VIRTUAL_TIME */
443 //////////////////////////End of VIRTUAL TIME ///////////////////////////////////
444
445
446 ////////////////////////// DUMMY_OS    //////////////////////////////////////
447
448 #if defined(DUMMY_OS)
449
450 /* With this define we make sure that we are truly POSIX and OSE */
451 /* independent at the FRSH code.                                 */
452 /*****************************************************************/
453
454 /* Time */
455 /********/
456 // typedef struct timespec fosa_rel_time_t;
457 // typedef struct timespec fosa_abs_time_t;
458
459 /* Thread and signals */
460 /**********************/
461 typedef int FOSA_THREAD_ID_T_OPAQUE;
462 typedef int FOSA_THREAD_ATTR_T_OPAQUE;
463
464 typedef int FOSA_SIGNAL_T_OPAQUE;
465 typedef int FOSA_SIGNAL_INFO_T_OPAQUE;
466
467 /* Signal info is defined as a union in thread_and_signals */
468
469 #define FOSA_SIGNAL_MIN     42
470 #define FOSA_SIGNAL_MAX     44
471
472 #define FOSA_NULL_SIGNAL 0
473
474 /* Clocks and timers */
475 /**********************/
476 typedef int FOSA_CLOCK_ID_T_OPAQUE;
477 typedef int FOSA_TIMER_ID_T_OPAQUE;
478
479 #define FOSA_SYSTEM_CLOCK_OPAQUE  25
480
481 /* Mutex and conditional variables */
482 /***********************************/
483 typedef int FOSA_MUTEX_T_OPAQUE;
484 typedef int FOSA_COND_T_OPAQUE;
485
486 /* Application defined Scheduling */
487 /**********************************/
488 #define FOSA_ADS_ACTIONS_T_OPAQUE  int
489
490
491 #endif /* DUMMY */
492 //////////////////////////End of DUMMY_OS ////////////////////////////////////
493
494 FOSA_CPP_END_DECLS
495
496
497 #endif // _FOSA_OPAQUE_TYPES_H_