]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - include/fosa_opaque_types.h
4c349d0b9bbdcd7819a39dc131f4d5e91f63ac78
[frescor/fosa.git] / include / fosa_opaque_types.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2008 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. Politécnica  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 //
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 //   FSF API web pages: http://marte.unican.es/fsf/docs
32 //                      http://shark.sssup.it/contrib/first/docs/
33 //
34 //   This file is part of FOSA (Frsh Operating System Adaption)
35 //
36 //  FOSA is free software; you can redistribute it and/or modify it
37 //  under terms of the GNU General Public License as published by the
38 //  Free Software Foundation; either version 2, or (at your option) any
39 //  later version.  FOSA is distributed in the hope that it will be
40 //  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
41 //  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 //  General Public License for more details. You should have received a
43 //  copy of the GNU General Public License along with FOSA; see file
44 //  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
45 //  Cambridge, MA 02139, USA.
46 //
47 //  As a special exception, including FOSA header files in a file,
48 //  instantiating FOSA generics or templates, or linking other files
49 //  with FOSA objects to produce an executable application, does not
50 //  by itself cause the resulting executable application to be covered
51 //  by the GNU General Public License. This exception does not
52 //  however invalidate any other reasons why the executable file might be
53 //  covered by the GNU Public License.
54 // -----------------------------------------------------------------------
55 //fosa_opaque_types.h
56 //==============================================
57 //  ********  ******    ********  **********
58 //  **///// /**    **  **//////  /**     /**
59 //  **      /**    ** /**        /**     /**
60 //  ******* /**    ** /********* /**********
61 //  **////  /**    ** ////////** /**//////**
62 //  **      /**    **        /** /**     /**
63 //  **      /**    **  ********  /**     /**
64 //  //       /******/  ////////   //      //
65 //
66 // FOSA(Frescor Operating System Adaptation layer)
67 //================================================
68
69 // Implementation dependent definitions
70
71 #ifndef _FOSA_OPAQUE_TYPES_H_
72 #define _FOSA_OPAQUE_TYPES_H_
73
74 #include <stdbool.h>
75
76 #include "fosa_cpp_macros.h"
77 #include "fosa_opaque_types_time.h"
78
79 ///////////////////////  MARTE_OS /////////////////////////////
80
81 #ifdef MARTE_OS
82
83 #include <pthread.h>
84 #include <signal.h>
85 #include <time.h>
86 #include <sched.h>
87 #include <errno.h>
88
89 FOSA_CPP_BEGIN_DECLS
90
91
92 /* Thread and signals */
93 /**********************/
94 typedef pthread_t FOSA_THREAD_ID_T_OPAQUE;
95 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
96
97 typedef int FOSA_SIGNAL_T_OPAQUE;
98 /* Signal info is defined as a union in thread_and_signals */
99
100 #define FOSA_SIGNAL_MIN       SIGRTMIN
101 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
102
103 #define FOSA_NULL_SIGNAL 0
104
105 /* Clocks and timers */
106 /**********************/
107 typedef clockid_t FOSA_CLOCK_ID_T_OPAQUE;
108 typedef timer_t FOSA_TIMER_ID_T_OPAQUE;
109
110 #define FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
111
112 /* Mutex and conditional variables */
113 /***********************************/
114 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
115 typedef pthread_cond_t FOSA_COND_T_OPAQUE;
116
117
118 /* Application defined Scheduling */
119 /**********************************/
120 #define FOSA_ADS_ACTIONS_T_OPAQUE  struct \
121 { \
122     posix_appsched_actions_t actions; \
123     struct timespec *timeout_ptr; \
124     struct timespec timeout; \
125     bool rejected; \
126     bool suspended; \
127     bool activated; \
128
129
130
131 /* Local jump */
132 /**************/
133 #include "misc/marte_non_local_jmp.h"
134
135 #define FOSA_LONG_JUMP_CONTEXT_T_OPAQUE  struct { \
136   marte_nonlocaljmp_context_t marte_context;      \
137   fosa_thread_id_t tid;                            \
138 }
139
140
141 /* Group clocks */
142 /****************/
143 typedef marte_thread_set_t FOSA_THREAD_SET_ID_T_OPAQUE;
144
145 #define FOSA_NULL_THREAD_SET_ID_OPAQUE 0 /* In MaRTE-OS thread_set_t are
146                                      * pointers */
147
148 /* FOSA errors */
149 /***************/
150 /** Not enough memory available **/
151 #define FOSA_ENOMEM   ENOMEM
152
153 /** Invalid parameter **/
154 #define FOSA_EINVAL   EINVAL
155
156 /** Still pending information **/
157 #define FOSA_EAGAIN   EAGAIN
158
159 /** FOSA ADS errors **/
160 #ifdef MARTE_OS
161 #define EREJECT   201 /* (for linux_lib_arch) Appsched has rejected object */
162 #endif
163
164 #define FOSA_EREJECT   EREJECT
165 #define FOSA_EMASKED   -2
166 #define FOSA_EPOLICY   -3
167
168 #define FOSA_ETIMEDOUT ETIMEDOUT
169
170 /* Not found in search (non existing thread, thread_set...) */
171 #define FOSA_ESRCH   ESRCH
172 #define FOSA_ENOTSUP ENOTSUP
173
174 #endif
175
176 ///////////////////////  End of MARTE_OS  /////////////////////////////
177
178
179 /////////////////////// RT_LINUX ///////////////////////////
180
181 #ifdef RT_LINUX
182
183 /* Very similar to MARTE_OS but I leave separate for clarity */
184
185 #include <pthread.h>
186 #include <signal.h>
187 #include <time.h>
188 #include <sched.h>
189 #include <errno.h>
190 #include <rtl_timer.h>
191
192
193 /* Threads and signals */
194 /***********************/
195 #define    FOSA_THREAD_ID_T_OPAQUE pthread_t
196
197 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
198 typedef int FOSA_SIGNAL_T_OPAQUE;
199 /* Signal info is defined as a union in fosa_types.h */
200
201 // The minimum and maximum signal numbers that may be used by the FRSH
202 // implementation
203 #define FOSA_SIGNAL_MIN       SIGRTMIN
204 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
205 #define FOSA_NULL_SIGNAL 0
206
207 /* Clocks and timers */
208 /*********************/
209 #define    FOSA_CLOCK_ID_T_OPAQUE    clockid_t
210 #define    FOSA_TIMER_ID_T_OPAQUE    timer_t
211 #define    FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
212
213 /* Mutex and cond vars */
214 /***********************/
215 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
216 #define    FOSA_COND_T_OPAQUE        pthread_cond_t
217
218 /* Thread groups */
219 /*****************/
220 typedef int FOSA_THREAD_SET_ID_T_OPAQUE
221
222 /* FOSA Errors */
223 /***************/
224 /** Not enough memory available **/
225 #define FOSA_ENOMEM   ENOMEM
226 /** Invalid parameter **/
227 #define FOSA_EINVAL   EINVAL
228 /** Still pending information **/
229 #define FOSA_EAGAIN   EAGAIN
230
231 /** FOSA ADS errors **/
232 #define FOSA_EREJECT   EREJECT
233 #define FOSA_EMASKED   -2
234 #define FOSA_EPOLICY   -3
235
236 #define FOSA_ETIMEDOUT ETIMEDOUT
237
238 #endif
239
240 ///////////////////////  End of RT_LINUX  /////////////////////////////
241
242
243 ////////////////////////// OSE    //////////////////////////////////////
244
245 #ifdef OSE
246
247
248
249 /* Put OSE dependent includes and defines here */
250
251 #endif /* OSE */
252
253
254
255 /////////////////////// AQuoSA ///////////////////////////
256
257 #ifdef AQuoSA
258
259 #include <unistd.h>
260 #include <linux/unistd.h>
261
262 #ifndef _XOPEN_SOURCE
263 #define _XOPEN_SOURCE 500
264 #endif
265 #ifndef __USE_UNIX98
266 #define __USE_UNIX98
267 #endif
268 #include <pthread.h>
269
270 #include <signal.h>
271 #include <setjmp.h>
272 #include <errno.h>
273 #include <time.h>
274
275 FOSA_CPP_BEGIN_DECLS
276
277 /* Local Jump */
278 /**************/
279 typedef struct {
280         sigjmp_buf setjmp_context;
281         int setjmp_retvalue;
282 } FOSA_LONG_JUMP_CONTEXT_T_OPAQUE;
283
284
285 /* Threads and signals */
286 /***********************/
287 typedef struct {
288         pthread_t pthread_id;
289         pid_t linux_pid;
290         pid_t linux_tid;
291 } FOSA_THREAD_ID_T_OPAQUE;
292
293
294 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
295 typedef int FOSA_SIGNAL_T_OPAQUE;
296
297
298 // The minimum and maximum signal numbers that may be used by the FRSH
299 // implementation
300 #define FOSA_SIGNAL_MIN       SIGRTMIN
301 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
302
303 #define FOSA_NULL_SIGNAL 0
304
305
306 /* Thread groups */
307 /*****************/
308 typedef int FOSA_THREAD_SET_ID_T_OPAQUE;
309
310 /* Clocks and signals */
311 /**********************/
312 #define    FOSA_CLOCK_ID_T_OPAQUE    clockid_t
313 #define    FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
314 #define    FOSA_TIMER_ID_T_OPAQUE    timer_t
315
316
317
318 /* Mutex and cond vars */
319 /***********************/
320 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
321 #define    FOSA_COND_T_OPAQUE        pthread_cond_t
322
323
324 /* Application Defined Scheduling */
325 /**********************************/
326 /* hack to get AQuoSA sources compile without having none
327  * of the application level scheduler header files and symbols */
328 #define posix_appsched_actions_t int
329
330 #define FOSA_ADS_ACTIONS_T_OPAQUE posix_appsched_actions_t
331
332
333 /* FOSA Errors */
334
335 /** Not enough memory available **/
336 #define FOSA_ENOMEM   ENOMEM
337
338 /** Invalid parameter **/
339 #define FOSA_EINVAL   EINVAL
340
341 /** Still pending information **/
342 #define FOSA_EAGAIN   EAGAIN
343
344 #define FOSA_EREJECT   EREJECT
345 #define FOSA_EMASKED   -2
346 #define FOSA_EPOLICY   -3
347
348 #define FOSA_ETIMEDOUT ETIMEDOUT
349
350
351 #endif 
352 ////////////////// END of AQuoSA //////////////////////
353
354
355
356 ///////////////////////////////// PARTIKLE /////////////////////////////////////
357 #if defined(PARTIKLE)
358
359 #include <pthread.h>
360 #include <signal.h>
361 #include <time.h>
362 #include <sched.h>
363 #include <stdlib.h>
364 #include <setjmp.h>
365 #include <limits.h>
366
367 typedef struct {
368     posix_appsched_actions_t actions;
369     struct timespec * timeout_ptr;
370     struct timespec timeout;
371     bool rejected;
372     bool suspended;
373     bool activated;
374 } FOSA_ADS_ACTIONS_T_OPAQUE;
375
376
377 typedef pthread_t                   FOSA_THREAD_ID_T_OPAQUE;
378 typedef pthread_attr_t              FOSA_THREAD_ATTR_T_OPAQUE;
379 typedef int                         FOSA_SIGNAL_T_OPAQUE;
380 typedef clockid_t                   FOSA_CLOCK_ID_T_OPAQUE;
381 typedef timer_t                     FOSA_TIMER_ID_T_OPAQUE;
382 typedef pthread_cond_t              FOSA_COND_T_OPAQUE;
383 typedef pthread_mutex_t             FOSA_MUTEX_T_OPAQUE;
384 typedef unsigned long               FOSA_LONG_JUMP_CONTEXT_T_OPAQUE [32];
385 typedef group_clock_t               FOSA_THREAD_SET_ID_T_OPAQUE;
386
387 #define FOSA_NULL_THREAD_SET_ID_OPAQUE 0x0;
388
389 enum _fosa_clocks_e {
390   FOSA_SYSTEM_CLOCK_OPAQUE = CLOCK_MONOTONIC
391 };
392
393 #define LONGJMP_NSIG 3
394
395 #if LONGJMP_NSIG > (RTSIG_MAX - 1)
396 #   error LONGJMP_NSIG too big (LONGJMP_NSIG > RTSIG_MAX - 1)
397 #endif
398
399 enum _fosa_signal_limits_e {
400   LONGJMP_FIRSTSIG = SIGRTMAX - LONGJMP_NSIG + 1,
401   FOSA_SIGNAL_MAX = LONGJMP_FIRSTSIG - 1,
402   FOSA_SIGNAL_MIN = SIGRTMIN,
403   FOSA_NULL_SIGNAL = -1,
404 };
405
406
407 enum _fosa_errors_e {
408   FOSA_EINVAL = EINVAL,
409   FOSA_EAGAIN = EAGAIN,
410   FOSA_EREJECT = EREJECT,
411   FOSA_EMASKED = EMASKED,
412   FOSA_EPOLICY = EPOLICY, 
413   FOSA_ETIMEDOUT = ETIMEDOUT,
414   FOSA_ENOMEM = ENOMEM,
415 };
416
417
418 #endif
419 /////////////////////////////// PARTIKLE  END //////////////////////////////////
420
421
422
423 ////////////////////////// VIRTUAL TIME    //////////////////////////////////////
424 #ifdef VIRTUAL_TIME
425
426 /* Time */
427 /********/
428 // typedef struct timespec fosa_rel_time_t;
429 // typedef struct timespec fosa_abs_time_t;
430
431 #include <fosa_vt.h>
432
433 #define FOSA_THREAD_ID_T_OPAQUE   vt_posix_process_t
434 #define FOSA_THREAD_ATTR_T_OPAQUE fosa_thread_attr_t
435 #define FOSA_SIGNAL_T_OPAQUE      int
436
437 #define FOSA_MUTEX_T_OPAQUE fosa_mutex_t
438
439 // The minimum and maximum signal numbers that may be used by the FRSH
440 // implementation
441 #define FOSA_SIGNAL_MIN       8
442 #define FOSA_SIGNAL_MAX       31
443
444 // the min. and max. priority a fosa thread can have
445 #define FOSA_PRIORITY_MAX VT_PRIORITY_MIN - 1
446 #define FOSA_PRIORITY_MIN VT_PRIORITY_MAX
447
448 #define FOSA_NULL_SIGNAL        0
449
450 /* FOSA Errors and return values*/
451
452 /** Invalid parameter **/
453 #define FOSA_EINVAL   -1
454
455 /** Not enough memory available **/
456 #define FOSA_ENOMEM   -2
457
458 /** Still pending information **/
459 #define FOSA_EAGAIN   -3
460
461 /** Mutex not available **/
462 #define FOSA_EBUSY         -4
463
464 /** Cond var timedout **/
465 #define FOSA_ETIMEDOUT  -5
466
467 /** FOSA ADS errors **/
468 #define FOSA_EREJECT   -6
469 #define FOSA_EMASKED   -7
470
471
472 /** Sched policy not correct */
473 #define FOSA_EPOLICY    -8
474
475 /** the value given by thread_id is not valid for ADS */
476 #define FOSA_ESRCH              -9
477
478 /** retval if no action performed **/
479 #define FOSA_NO_ACTION  0
480
481 #endif /* VIRTUAL_TIME */
482 //////////////////////////End of VIRTUAL TIME ///////////////////////////////////
483
484
485 ////////////////////////// DUMMY_OS    //////////////////////////////////////
486
487 #if defined(DUMMY_OS)
488
489 /* With this define we make sure that we are truly POSIX and OSE */
490 /* independent at the FRSH code.                                 */
491 /*****************************************************************/
492
493 /* Time */
494 /********/
495 // typedef struct timespec fosa_rel_time_t;
496 // typedef struct timespec fosa_abs_time_t;
497
498 /* Thread and signals */
499 /**********************/
500 typedef int FOSA_THREAD_ID_T_OPAQUE;
501 typedef int FOSA_THREAD_ATTR_T_OPAQUE;
502
503 typedef int FOSA_SIGNAL_T_OPAQUE;
504 typedef int FOSA_SIGNAL_INFO_T_OPAQUE;
505
506 /* Signal info is defined as a union in thread_and_signals */
507
508 #define FOSA_SIGNAL_MIN     42
509 #define FOSA_SIGNAL_MAX     44
510
511 #define FOSA_NULL_SIGNAL 0
512
513 /* Clocks and timers */
514 /**********************/
515 typedef int FOSA_CLOCK_ID_T_OPAQUE;
516 typedef int FOSA_TIMER_ID_T_OPAQUE;
517
518 #define FOSA_SYSTEM_CLOCK_OPAQUE  25
519
520 /* Mutex and conditional variables */
521 /***********************************/
522 typedef int FOSA_MUTEX_T_OPAQUE;
523 typedef int FOSA_COND_T_OPAQUE;
524
525 /* Application defined Scheduling */
526 /**********************************/
527 #define FOSA_ADS_ACTIONS_T_OPAQUE  int
528
529
530 #endif /* DUMMY */
531 //////////////////////////End of DUMMY_OS ////////////////////////////////////
532
533 FOSA_CPP_END_DECLS
534
535
536 #endif // _FOSA_OPAQUE_TYPES_H_