po_hi_task.h 6.93 KB
Newer Older
1
2
3
4
5
/*
 * This is a part of PolyORB-HI-C distribution, a minimal
 * middleware written for generated code from AADL models.
 * You should use it with the Ocarina toolsuite.
 *
yoogx's avatar
yoogx committed
6
 * For more informations, please visit http://taste.tuxfamily.org/wiki
7
 *
8
 * Copyright (C) 2010-2015 ESA & ISAE.
9
10
11
12
13
 */

#ifndef __PO_HI_TASK_H__
#define __PO_HI_TASK_H__

14
/*
15
 * Define some values that are dependant of the
16
17
 * underlying executive.
 */
18
#if defined(POSIX) || defined (XENO_POSIX) || defined (SIMULATOR)
19
20
21
22
23
24
25
   #include <stdlib.h>
   #include <stdio.h>
   #define __PO_HI_MAIN_NAME main
   #define __PO_HI_MAIN_TYPE int
   #define __PO_HI_MAIN_ARGS int argc , char *argv[] , char **arge
   #define __PO_HI_MAIN_RETURN EXIT_SUCCESS
   #define __ERRORMSG(s, args...) fprintf(stderr, s, ##args)
jdelange's avatar
jdelange committed
26
27
28
29
30
31
32
#elif defined(_WIN32)
   #include <tchar.h>
   #include <windows.h>
   #include <stdlib.h>
   #include <stdio.h>
   #define __PO_HI_MAIN_NAME _tmain
   #define __PO_HI_MAIN_TYPE int
33
   #define __PO_HI_MAIN_ARGS
jdelange's avatar
jdelange committed
34
35
   #define __PO_HI_MAIN_RETURN EXIT_SUCCESS
   #define __ERRORMSG(s, args...) fprintf(stderr, s, ##args)
36
37
38
39
40
41
42
43
#elif defined (XENO_NATIVE)
   #include <native/task.h>
   #include <native/timer.h>
   #define __PO_HI_MAIN_NAME main
   #define __PO_HI_MAIN_TYPE int
   #define __PO_HI_MAIN_ARGS int argc , char *argv[] , char **arge
   #define __PO_HI_MAIN_RETURN 0
   #define __ERRORMSG(s, args...) fprintf(stderr, s, ##args)
44
45
46
47
48
49
50
51
52
#elif defined(RTEMS_PURE)
   #define __PO_HI_MAIN_NAME Init
   #define __PO_HI_MAIN_TYPE rtems_task
   #define __PO_HI_MAIN_ARGS rtems_task_argument argument
   #define __PO_HI_MAIN_RETURN 0
   #define __ERRORMSG(s, args...) fprintf(stderr, s, ##args)
#elif defined(RTEMS_POSIX)
   #define __PO_HI_MAIN_NAME POSIX_Init
   #define __PO_HI_MAIN_TYPE int
53
   #define __PO_HI_MAIN_ARGS
54
55
56
57
58
59
   #define __PO_HI_MAIN_RETURN 0
   #define __ERRORMSG(s, args...) fprintf(stderr, s, ##args)
#endif



60
#if defined(POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
61
62
63
64
65
66
67
   #include <semaphore.h>
   #include <po_hi_time.h>
   #include <pthread.h>
   #include <sched.h>
   #define __PO_HI_MAX_PRIORITY sched_get_priority_max(SCHED_FIFO)
   #define __PO_HI_MIN_PRIORITY sched_get_priority_min(SCHED_FIFO)
   #define __PO_HI_DEFAULT_PRIORITY ((sched_get_priority_min(SCHED_FIFO) + sched_get_priority_max(SCHED_FIFO))/2)
68
69
70
71
72
73
74

#elif defined (SIMULATOR)
   #include <po_hi_time.h>
   #define __PO_HI_MAX_PRIORITY 255
   #define __PO_HI_MIN_PRIORITY 1
   #define __PO_HI_DEFAULT_PRIORITY 128

jdelange's avatar
jdelange committed
75
76
77
78
79
80
81
#elif defined(_WIN32)
   #include <inttypes.h>
   #include <po_hi_time.h>
   #define __PO_HI_DEFAULT_PRIORITY 0
   #define __PO_HI_MAX_PRIORITY 2
   #define __PO_HI_MIN_PRIORITY 0

82
#elif defined(RTEMS_PURE)
83
84
85
86
87
88
89
90
91
92
93
94
   #include <rtems.h>
   #include <inttypes.h>
   #include <po_hi_time.h>
   #define __PO_HI_DEFAULT_PRIORITY RTEMS_NO_PRIORITY
   #define __PO_HI_MAX_PRIORITY RTEMS_NO_PRIORITY
   #define __PO_HI_MIN_PRIORITY RTEMS_NO_PRIORITY
#elif defined(XENO_NATIVE)
   #include <inttypes.h>
   #include <po_hi_time.h>
   #define __PO_HI_DEFAULT_PRIORITY 50
   #define __PO_HI_MAX_PRIORITY 99
   #define __PO_HI_MIN_PRIORITY 0
95
96
97
98
99
100
101
102
103
104
105
106
#endif

#include <po_hi_types.h>
#include <deployment.h>

typedef __po_hi_uint16_t __po_hi_priority_t;
typedef size_t __po_hi_stack_t;

/*
 * Initialize tasking entities
 * Returns SUCCESS if there is no error.
 */
jdelange's avatar
jdelange committed
107
int __po_hi_initialize_tasking(void);
108
109

/*
110
111
 * Create a periodic task.
 *
112
113
114
115
116
117
 * The task created have the identifier given by the first
 * parameter. It is created according to the period created
 * with __po_hi_* functions (like __po_hi_milliseconds())
 * and priority parameters (use the OS priority). The task execute
 * periodically start_routine.
 *
118
 * This function returns SUCCESS if there is no error. Else,
119
120
 * it returns the negative value ERROR_CREATE_TASK.
 */
121
122
123
int __po_hi_create_periodic_task (const __po_hi_task_id      id,
                                  const __po_hi_time_t*      period,
                                  const __po_hi_priority_t   priority,
124
                                  const __po_hi_stack_t      stack_size,
125
                                  const __po_hi_int8_t      core_id,
126
                                  void*                (*start_routine)(void));
127
128

/*
129
 * Create a sporadic task.
130
131
132
133
134
 *
 * The identifier of the task is the first parameter. The period and
 * the priority of the task are stored in the second and third
 * parameter.  The code executed by the task is stored in the
 * start_routine pointer.
135
 *
136
137
138
 * Returns SUCCESS value if there is no error. Else, returns the negative
 * value ERROR_CREATE_TASK
 */
139
int __po_hi_create_sporadic_task (const __po_hi_task_id      id,
140
141
				                      const __po_hi_time_t*      period,
                                  const __po_hi_priority_t   priority,
142
                                  const __po_hi_stack_t      stack_size,
143
                                  const __po_hi_int8_t       core_id,
144
                                  void*                      (*start_routine)(void));
145
146
147
148
149
150
151
152

/*
 * Create a generic task
 *
 * The identifier of the task is the first parameter. The period and
 * the priority of the task are stored in the second and third
 * parameter.  The code executed by the task is stored in the
 * start_routine pointer.
153
 *
154
155
156
 * Returns SUCCESS value if there is no error. Else, returns the negative
 * value ERROR_CREATE_TASK
 */
157
158
159
int __po_hi_create_generic_task (const __po_hi_task_id      id,
                                 const __po_hi_time_t*      period,
                                 const __po_hi_priority_t   priority,
160
                                 const __po_hi_stack_t      stack_size,
161
                                 const __po_hi_int8_t      core_id,
jdelange's avatar
jdelange committed
162
163
                                 void*                      (*start_routine)(void),
                                 void*                      arg);
164
165
166
167
168
169
170

/*
 * Wait the end of all tasks.
 * This function typically never ends, because all tasks
 * are doing an infinite loop and never ends. It just
 * used to avoid an infinite loop in the main thread.
 */
jdelange's avatar
jdelange committed
171
void __po_hi_wait_for_tasks (void);
172
173
174
175
176
177
178
179
180
181
182
183
184
185

/*
 * Called by a periodic task, to wait for its next period
 * The argument is the task identifier
 * Returns SUCCESS value, and if fails, returns a negative value
 */
int __po_hi_wait_for_next_period (__po_hi_task_id task);

/*
 * Sleep until the time given in argument. The second
 * argument is the task identifier which will sleep.
 * Return SUCCESS if there is no error. Else, it returns
 * a negative value : ERROR_CLOCK or ERROR_PTHREAD_COND
 */
186
 int __po_hi_task_delay_until (__po_hi_time_t* time, __po_hi_task_id task);
187
188
189
190
191
192
193
194

/*
 * Computer the next period for a task, according to the period
 * argument given at initialization time. The argument task
 * is the task-identifier in the node (__po_hi_task_id type).
 */
 int __po_hi_compute_next_period (__po_hi_task_id task);

195
196
197
 /*
  * Delete all the tasks that were created within the system.
  */
jdelange's avatar
jdelange committed
198
void __po_hi_tasks_killall (void);
199

jdelange's avatar
jdelange committed
200
201
202
203
204
 /*
  * Wait a given amount of time.
  */
void __po_hi_task_wait_offset (const __po_hi_time_t* time);

205

206
#endif /* __PO_HI_TASK_H__ */