1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2008 FRESCOR consortium partners:
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
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org for a link to partners' websites
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
24 // based on previous work (FSF) done in the FIRST project
26 // Copyright (C) 2005 Mälardalen University, SWEDEN
27 // Scuola Superiore S.Anna, ITALY
28 // Universidad de Cantabria, SPAIN
29 // University of York, UK
31 // FSF API web pages: http://marte.unican.es/fsf/docs
32 // http://shark.sssup.it/contrib/first/docs/
34 // This file is part of FOSA (Frsh Operating System Adaption)
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.
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 // -----------------------------------------------------------------------
56 //==============================================
57 // ******** ****** ******** **********
58 // **///// /** ** **////// /** /**
59 // ** /** ** /** /** /**
60 // ******* /** ** /********* /**********
61 // **//// /** ** ////////** /**//////**
62 // ** /** ** /** /** /**
63 // ** /** ** ******** /** /**
64 // // /******/ //////// // //
66 // FOSA(Frescor Operating System Adaptation layer)
67 //================================================
70 #ifndef _FOSA_TYPES_H_
71 #define _FOSA_TYPES_H_
73 #include "fosa_opaque_types.h"
78 * @addtogroup threadandsignals
83 /* Coming from FRSH-FOSA */
85 /** identifier of a FOSA thread **/
86 typedef FOSA_THREAD_ID_T_OPAQUE fosa_thread_id_t;
89 /** thread attributes object **/
90 typedef FOSA_THREAD_ATTR_T_OPAQUE fosa_thread_attr_t;
92 typedef FOSA_SIGNAL_T_OPAQUE fosa_signal_t;
95 * The type references a function that may become a thread's
98 typedef void * (*fosa_thread_code_t) (void *);
101 /** information associated to a signal **/
102 #if defined(VIRTUAL_TIME)
105 typedef vt_posix_signal_info_t fosa_signal_info_t;
109 typedef union {int sival_int; void * sival_ptr; } fosa_signal_info_t;
110 /* typedef FOSA_SIGNAL_INFO_T_OPAQUE fosa_signal_info_t; */
118 * @addtogroup clocksandtimers
122 // identifier of a clock
123 // either a real-time clock or a cpu-time clock
125 typedef FOSA_REL_TIME_T_OPAQUE fosa_rel_time_t;
126 typedef FOSA_ABS_TIME_T_OPAQUE fosa_abs_time_t;
128 typedef FOSA_CLOCK_ID_T_OPAQUE fosa_clock_id_t;
130 #define FOSA_SYSTEM_CLOCK FOSA_SYSTEM_CLOCK_OPAQUE
132 // identifier of a one-shot timer
133 typedef FOSA_TIMER_ID_T_OPAQUE fosa_timer_id_t;
138 * @addtrogroup mutexesandcondvars
142 // a condition variable
143 /** Mutex object. Attributes are handled by FOSA **/
144 typedef FOSA_MUTEX_T_OPAQUE fosa_mutex_t;
146 typedef FOSA_COND_T_OPAQUE fosa_cond_t;
150 * @addtogroup appdefsched
162 * This type is used to represent a list of scheduling actions that the
163 * scheduler will later request to be executed by the system. The pos-
164 * sible actions are of the following kinds:
165 * - reject a thread that has requested attachment to this scheduler
166 * - activate an application-scheduled thread with the desired value
168 * - suspend an application-scheduled thread
169 * - program a timeout
170 * - program a timed notification associated to a particular
171 * application-scheduled thread.
173 * No comparison or assignment operators are defined for this type
175 typedef FOSA_ADS_ACTIONS_T_OPAQUE fosa_ads_actions_t;
177 /* FOSA_ADS_ACTIONS_T_OPAQUE */
180 * Causes of error in the appsched_error primitive operation
182 typedef enum {FOSA_ADS_THREAD_NOT_ATTACHED, FOSA_ADS_INVALID_ACTION}
183 fosa_ads_error_cause_t;
187 * The urgency used to orde the threads of the same priority in the
188 * underlying scheduler. Support for urgency scheduling is required
189 * for supporting the hierarchhical scheduling module
191 typedef int fosa_ads_urgency_t;
195 * Scheduler primitive operations
197 * This structure is used to create application schedulers. It
198 * contains pointers to the primitive operations that are invoked by
199 * the system when a scheduling event occurs:
201 * - The \b init() primitive operation is invoked by the system just after
202 * the scheduler has been created using fosa_ads_scheduler_create().
204 * - The \b new_thread() primitive operation is invoked by the system when
205 * a thread has requested attachment to this scheduler; this can be a
206 * newly created thread (via fosa_thread_create()), or an existing thread
207 * that was not running under ads scheduler (via
208 * fosa_ads_set_appscheduled()).\n \n
210 * The thread can be rejected by the scheduler adding a
211 * reject-thread action to the actions parameter using
212 * fosa_ads_actions_add_reject(). If no reject-thread action is
213 * added, the thread is accepted.\n \n
215 * Newly created threads shall be activated by the system after the
216 * execution of the new_thread() primitive operation. The urgency of
217 * an accepted thread (either newly created or existing) shall be set
218 * to a value of zero, unless an activate-thread action with a
219 * different value of urgency is added via
220 * fosa_ads_actions_add_activate().\n \n
222 * If a request to attach a thread to this scheduler was made via
223 * fosa_ads_set_appscheduled(), at the finalization of the new_thread()
224 * primitive operation if the newly attached thread is blocked by the
225 * system (not by the scheduler itself via a suspend scheduling
226 * action), a thread-block event shall be generated for the scheduler
227 * immediately and, consequently, the thread_block() primitive
228 * operation shall be invoked by the system.
230 * - The \b thread_terminate() primitive operation is invoked by the system
231 * when a thread attached to this scheduler is terminating (via an
232 * explicit or implicit thread termination, or cancellation, or when
233 * it is no longer sceduled by the ads scheduler (via
234 * fosa_ads_setappscheduled()). \n\n
236 * Before the thread_terminate() primitive operation is invoked by
237 * the system, all the thread-notification events programmed for that
238 * thread are cancelled. \n\n
240 * In the case of a thread that is terminating, the
241 * thread_terminate() primitive operation is executed before the
242 * execution of the cleanup handlers and of the thread-specific data
243 * destructor functions. In that way, the thread parameter corresponds
244 * to a valid thread Id and the thread-specific data is valid and can
245 * be accessed from the thread_terminate() primitive operation. \n\n
247 * Also for terminating threads, after the thread_terminate() primitive
248 * operation finishes, the system shall lower the urgency of the
249 * thread identified by thread to a value of zero, and shall deattach
250 * it from the ads scheduler. Then, the thread shall execute the
251 * cleanup handlers and the thread-specific data destructor functions
252 * outside the management of its former scheduler. Notice that in a
253 * multiprocessor system this may imply the suspension of the thread
254 * identified by parameter thread during the execution of the
255 * thread_terminate() primitive operation.
257 * - The \b thread_ready() primitive operation is invoked by the system
258 * when a thread attached to this scheduler that was blocked has
259 * become unblocked by the system.
261 * - The \b thread_block() primitive operation is invoked by the system
262 * when a thread attached to this scheduler has blocked.
264 * - The \b change_sched_param_thread() primitive operation is invoked
265 * by the system when the scheduling parameters of a thread attached
266 * to this scheduler have been changed OUTSIDE OF AN SCHEDULER
267 * CALLBACK, and the thread continues to run under this scheduler.
269 * The change includes either the regular scheduling parameters
270 * (fosa_thread_set_prio() or the application-defined scheduling
271 * parameters, via fosa_ads_set_appsched_param().
273 * - The \b explicit_call_with_data() primitive operation is invoked by the
274 * system when a thread (identified by the thread parameter) has
275 * explicitly invoked the scheduler with a message containing
276 * scheduling information, and possibly requesting a reply message,
277 * via fosa_ads_invoke_withdata().
279 * - The \b notification_for_thread() primitive operation is invoked by the
280 * system when the time for a thread-notification previously programed
281 * by the scheduler via fosa_ads_actions_add_thread_notification()
282 * is reached. Parameter clock identifies the clock for which the
283 * thread-notification was programmed.
285 * - The \b timeout() primitive operation is invoked by the system when a
286 * timeout requested by the scheduler (via
287 * fosa_ads_actions_add_timeout()) has expired.
289 * - The \b signal() primitive operation is invoked by the system when a
290 * signal belonging to the set of signals for which the scheduler is
291 * waiting (via fosa_ads_set_handled_signal_set()) has been
294 * The signal number and its associated information (if any) are
295 * passed in the arguments signal and siginfo.\n\n
297 * The signal is consumed with the invocation of this primitive
298 * operation, which implies that it will not cause the execution of
299 * any signal handler, nor it may be accepted by any thread waiting
300 * for this signal number.
302 * - The \b appsched_error() primitive operation is invoked by the system
303 * when an error in the scheduling actions list specified in a
304 * previous primitive operation is detected. The cause of the error is
305 * notified in the parameter cause. The defined causes of error are
306 * described fosa_ads_error_cause_t
308 * Every primitive operation receives the argument sched_data. It is a
309 * pointer to a memory area containing information shared by all the
310 * scheduler operations. It can be used to store the data structures
311 * required by the scheduler (for example, a ready queue and a delay
312 * queue). Scheduler operations should not use any other global data out
313 * of this memory area.
315 * The actions argument is used by the scheduler to request the operating
316 * system to execute a set of scheduling actions at the end of the
317 * primitive operation. It is passed empty by the system, and the
318 * scheduler may add multiple scheduling actions.
320 * The current_time argument contains the system time
321 * measured immediately before the invocation of the primitive operation
322 * using the FOSA_CLOCK_REALTIME clock
324 * In addition to these common parameters, most of the primitive
325 * operations receive a thread argument. This argument allows the
326 * primitive operations to know which is the thread that has produced or
327 * is related to the event.
330 void (*init) (void * sched_data, void * arg);
331 void (*new_thread) (void * sched_data,
332 fosa_thread_id_t thread,
333 fosa_ads_actions_t * actions,
334 fosa_abs_time_t *current_time);
335 void (*thread_terminate) (void * sched_data,
336 fosa_thread_id_t thread,
337 fosa_ads_actions_t * actions,
338 fosa_abs_time_t *current_time);
339 void (*thread_ready) (void * sched_data,
340 fosa_thread_id_t thread,
341 fosa_ads_actions_t * actions,
342 fosa_abs_time_t *current_time);
343 void (*thread_block) (void * sched_data,
344 fosa_thread_id_t thread,
345 fosa_ads_actions_t * actions,
346 fosa_abs_time_t *current_time);
347 //void (*thread_yield) (void * sched_data,
348 // fosa_thread_id_t thread,
349 // fosa_ads_actions_t * actions,
350 // fosa_abs_time_t *current_time);
351 void (*change_sched_param_thread) (void * sched_data,
352 fosa_thread_id_t thread,
353 fosa_ads_actions_t * actions,
354 fosa_abs_time_t *current_time);
355 //void msg_from_scheduler(void * sched_data,
356 // fosa_ads_scheduler_id_t scheduler_id,
357 // const void * msg, size_t msg_size,
358 // fosa_ads_actions_t * actions,
359 // fosa_bas_time_t *current_time);
360 //void (*explicit_call) (void * sched_data,
361 // fosa_thread_id_t thread,
362 // int user_event_code,
363 // fosa_ads_actions_t * actions,
364 // fosa_abs_time_t *current_time);
365 void (*explicit_call_with_data) (void * sched_data,
366 fosa_thread_id_t thread,
367 const void * msg, size_t msg_size,
368 void *reply, size_t *reply_size,
369 fosa_ads_actions_t * actions,
370 fosa_abs_time_t *current_time);
371 void (*notification_for_thread) (void * sched_data,
372 fosa_thread_id_t thread,
373 fosa_clock_id_t clock,
374 fosa_ads_actions_t * actions,
375 fosa_abs_time_t *current_time);
376 void (*timeout) (void * sched_data,
377 fosa_ads_actions_t * actions,
378 fosa_abs_time_t *current_time);
379 void (*signal) (void * sched_data,
380 fosa_signal_t signal,
381 fosa_signal_info_t siginfo,
382 fosa_ads_actions_t * actions,
383 fosa_abs_time_t *current_time);
384 //void (*priority_inherit) (void * sched_data,
385 // fosa_thread_id_t thread,
386 // int sched_priority,
387 // fosa_ads_actions_t * actions,
388 // fosa_abs_time_t *current_time);
389 //void (*priority_uninherit) (void * sched_data,
390 // fosa_thread_id_t thread,
391 // int sched_priority,
392 // fosa_ads_actions_t * actions,
393 // fosa_abs_time_t *current_time);
394 void (*appsched_error) (void * sched_data,
395 fosa_thread_id_t thread,
396 fosa_ads_error_cause_t cause,
397 fosa_ads_actions_t * actions);
398 } fosa_ads_scheduler_ops_t;
403 /*********************
405 *********************/
408 * The fosa_jump_context_t type defines a data area where the context
409 * of a thread can be saved, so that a long jump to recover that context
410 * may be executed in the future, from a long jump handler.
413 typedef FOSA_LONG_JUMP_CONTEXT_T_OPAQUE fosa_long_jump_context_t;
419 #endif // _FOSA_TYPES_H_