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