1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 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. Politecnica 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
23 // This file is part of the FRSH implementation
25 // FRSH is free software; you can redistribute it and/or modify
26 // it under the terms of the GNU General Public License as published by
27 // the Free Software Foundation; either version 2, or (at your option)
30 // FRSH is distributed in the hope that it will be useful, but
31 // WITHOUT ANY WARRANTY; without even the implied warranty of
32 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 // General Public License for more details.
35 // You should have received a copy of the GNU General Public License
36 // distributed with FRSH; see file COPYING. If not, write to the
37 // Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
40 // As a special exception, if you include this header file into source
41 // files to be compiled, this header file does not by itself cause
42 // the resulting executable to be covered by the GNU General Public
43 // License. This exception does not however invalidate any other
44 // reasons why the executable file might be covered by the GNU General
46 // -----------------------------------------------------------------------
48 //==============================================
49 // ******** ****** ******** **********
50 // **///// /** ** **////// /** /**
51 // ** /** ** /** /** /**
52 // ******* /** ** /********* /**********
53 // **//// /** ** ////////** /**//////**
54 // ** /** ** /** /** /**
55 // ** /** ** ******** /** /**
56 // // /******/ //////// // //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
62 #ifndef _FOSA_TYPES_H_
63 #define _FOSA_TYPES_H_
65 #include "fosa_opaque_types.h"
66 #include "frsh_fosa.h"
68 * @addtogroup clocksandtimers
72 // identifier of a clock
73 // either a real-time clock or a cpu-time clock
74 typedef FOSA_CLOCK_ID_T_OPAQUE fosa_clock_id_t;
76 #define FOSA_SYSTEM_CLOCK FOSA_SYSTEM_CLOCK_OPAQUE
78 // identifier of a one-shot timer
79 typedef FOSA_TIMER_ID_T_OPAQUE fosa_timer_id_t;
84 * @addtrogroup mutexesandcondvars
88 // a condition variable
89 typedef FOSA_COND_T_OPAQUE fosa_cond_t;
93 * @addtogroup appdefsched
105 * This type is used to represent a list of scheduling actions that the
106 * scheduler will later request to be executed by the system. The pos-
107 * sible actions are of the following kinds:
108 * - reject a thread that has requested attachment to this scheduler
109 * - activate an application-scheduled thread with the desired value
111 * - suspend an application-scheduled thread
112 * - program a timeout
113 * - program a timed notification associated to a particular
114 * application-scheduled thread.
116 * No comparison or assignment operators are defined for this type
118 typedef FOSA_ADS_ACTIONS_T_OPAQUE fosa_ads_actions_t;
120 /* FOSA_ADS_ACTIONS_T_OPAQUE */
123 * Causes of error in the appsched_error primitive operation
125 typedef enum {FOSA_ADS_THREAD_NOT_ATTACHED, FOSA_ADS_INVALID_ACTION}
126 fosa_ads_error_cause_t;
130 * The urgency used to orde the threads of the same priority in the
131 * underlying scheduler. Support for urgency scheduling is required
132 * for supporting the hierarchhical scheduling module
134 typedef int fosa_ads_urgency_t;
138 * Scheduler primitive operations
140 * This structure is used to create application schedulers. It
141 * contains pointers to the primitive operations that are invoked by
142 * the system when a scheduling event occurs:
144 * - The \b init() primitive operation is invoked by the system just after
145 * the scheduler has been created using fosa_ads_scheduler_create().
147 * - The \b new_thread() primitive operation is invoked by the system when
148 * a thread has requested attachment to this scheduler; this can be a
149 * newly created thread (via fosa_thread_create()), or an existing thread
150 * that was not running under ads scheduler (via
151 * fosa_ads_set_appscheduled()).\n \n
153 * The thread can be rejected by the scheduler adding a
154 * reject-thread action to the actions parameter using
155 * fosa_ads_actions_add_reject(). If no reject-thread action is
156 * added, the thread is accepted.\n \n
158 * Newly created threads shall be activated by the system after the
159 * execution of the new_thread() primitive operation. The urgency of
160 * an accepted thread (either newly created or existing) shall be set
161 * to a value of zero, unless an activate-thread action with a
162 * different value of urgency is added via
163 * fosa_ads_actions_add_activate().\n \n
165 * If a request to attach a thread to this scheduler was made via
166 * fosa_ads_set_appscheduled(), at the finalization of the new_thread()
167 * primitive operation if the newly attached thread is blocked by the
168 * system (not by the scheduler itself via a suspend scheduling
169 * action), a thread-block event shall be generated for the scheduler
170 * immediately and, consequently, the thread_block() primitive
171 * operation shall be invoked by the system.
173 * - The \b thread_terminate() primitive operation is invoked by the system
174 * when a thread attached to this scheduler is terminating (via an
175 * explicit or implicit thread termination, or cancellation, or when
176 * it is no longer sceduled by the ads scheduler (via
177 * fosa_ads_setappscheduled()). \n\n
179 * Before the thread_terminate() primitive operation is invoked by
180 * the system, all the thread-notification events programmed for that
181 * thread are cancelled. \n\n
183 * In the case of a thread that is terminating, the
184 * thread_terminate() primitive operation is executed before the
185 * execution of the cleanup handlers and of the thread-specific data
186 * destructor functions. In that way, the thread parameter corresponds
187 * to a valid thread Id and the thread-specific data is valid and can
188 * be accessed from the thread_terminate() primitive operation. \n\n
190 * Also for terminating threads, after the thread_terminate() primitive
191 * operation finishes, the system shall lower the urgency of the
192 * thread identified by thread to a value of zero, and shall deattach
193 * it from the ads scheduler. Then, the thread shall execute the
194 * cleanup handlers and the thread-specific data destructor functions
195 * outside the management of its former scheduler. Notice that in a
196 * multiprocessor system this may imply the suspension of the thread
197 * identified by parameter thread during the execution of the
198 * thread_terminate() primitive operation.
200 * - The \b thread_ready() primitive operation is invoked by the system
201 * when a thread attached to this scheduler that was blocked has
202 * become unblocked by the system.
204 * - The \b thread_block() primitive operation is invoked by the system
205 * when a thread attached to this scheduler has blocked.
207 * - The \b change_sched_param_thread() primitive operation is invoked by
208 * the system when the scheduling parameters of a thread attached to
209 * this scheduler have been changed, but the thread continues to run
210 * under this scheduler. The change includes either the regular
211 * scheduling parameters (fosa_thread_set_prio() or the application-
212 * defined scheduling parameters, via fosa_ads_set_appsched_param().
214 * - The \b explicit_call_with_data() primitive operation is invoked by the
215 * system when a thread (identified by the thread parameter) has
216 * explicitly invoked the scheduler with a message containing
217 * scheduling information, and possibly requesting a reply message,
218 * via fosa_ads_invoke_withdata().
220 * - The \b notification_for_thread() primitive operation is invoked by the
221 * system when the time for a thread-notification previously programed
222 * by the scheduler via fosa_ads_actions_add_thread_notification()
223 * is reached. Parameter clock identifies the clock for which the
224 * thread-notification was programmed.
226 * - The \b timeout() primitive operation is invoked by the system when a
227 * timeout requested by the scheduler (via
228 * fosa_ads_actions_add_timeout()) has expired.
230 * - The \b signal() primitive operation is invoked by the system when a
231 * signal belonging to the set of signals for which the scheduler is
232 * waiting (via fosa_ads_set_handled_signal_set()) has been
235 * The signal number and its associated information (if any) are
236 * passed in the arguments signal and siginfo.\n\n
238 * The signal is consumed with the invocation of this primitive
239 * operation, which implies that it will not cause the execution of
240 * any signal handler, nor it may be accepted by any thread waiting
241 * for this signal number.
243 * - The \b appsched_error() primitive operation is invoked by the system
244 * when an error in the scheduling actions list specified in a
245 * previous primitive operation is detected. The cause of the error is
246 * notified in the parameter cause. The defined causes of error are
247 * described fosa_ads_error_cause_tappdefsched
249 * Every primitive operation receives the argument sched_data. It is a
250 * pointer to a memory area containing information shared by all the
251 * scheduler operations. It can be used to store the data structures
252 * required by the scheduler (for example, a ready queue and a delay
253 * queue). Scheduler operations should not use any other global data out
254 * of this memory area.
256 * The actions argument is used by the scheduler to request the operating
257 * system to execute a set of scheduling actions at the end of the
258 * primitive operation. It is passed empty by the system, and the
259 * scheduler may add multiple scheduling actions.
261 * The current_time argument contains the system time
262 * measured immediately before the invocation of the primitive operation
263 * using the FOSA_CLOCK_REALTIME clock
265 * In addition to these common parameters, most of the primitive
266 * operations receive a thread argument. This argument allows the
267 * primitive operations to know which is the thread that has produced or
268 * is related to the event.
271 void (*init) (void * sched_data, void * arg);
272 void (*new_thread) (void * sched_data,
273 frsh_thread_id_t thread,
274 fosa_ads_actions_t * actions,
275 struct timespec *current_time);
276 void (*thread_terminate) (void * sched_data,
277 frsh_thread_id_t thread,
278 fosa_ads_actions_t * actions,
279 struct timespec *current_time);
280 void (*thread_ready) (void * sched_data,
281 frsh_thread_id_t thread,
282 fosa_ads_actions_t * actions,
283 struct timespec *current_time);
284 void (*thread_block) (void * sched_data,
285 frsh_thread_id_t thread,
286 fosa_ads_actions_t * actions,
287 struct timespec *current_time);
288 //void (*thread_yield) (void * sched_data,
289 // frsh_thread_id_t thread,
290 // fosa_ads_actions_t * actions,
291 // struct timespec *current_time);
292 void (*change_sched_param_thread) (void * sched_data,
293 frsh_thread_id_t thread,
294 fosa_ads_actions_t * actions,
295 struct timespec *current_time);
296 //void msg_from_scheduler(void * sched_data,
297 // fosa_ads_scheduler_id_t scheduler_id,
298 // const void * msg, size_t msg_size,
299 // fosa_ads_actions_t * actions,
300 // struct timespec *current_time);
301 //void (*explicit_call) (void * sched_data,
302 // frsh_thread_id_t thread,
303 // int user_event_code,
304 // fosa_ads_actions_t * actions,
305 // struct timespec *current_time);
306 void (*explicit_call_with_data) (void * sched_data,
307 frsh_thread_id_t thread,
308 const void * msg, size_t msg_size,
309 void *reply, size_t *reply_size,
310 fosa_ads_actions_t * actions,
311 struct timespec *current_time);
312 void (*notification_for_thread) (void * sched_data,
313 frsh_thread_id_t thread,
314 fosa_clock_id_t clock,
315 fosa_ads_actions_t * actions,
316 struct timespec *current_time);
317 void (*timeout) (void * sched_data,
318 fosa_ads_actions_t * actions,
319 struct timespec *current_time);
320 void (*signal) (void * sched_data,
321 frsh_signal_t signal,
322 frsh_signal_info_t siginfo,
323 fosa_ads_actions_t * actions,
324 struct timespec *current_time);
325 //void (*priority_inherit) (void * sched_data,
326 // frsh_thread_id_t thread,
327 // int sched_priority,
328 // fosa_ads_actions_t * actions,
329 // struct timespec *current_time);
330 //void (*priority_uninherit) (void * sched_data,
331 // frsh_thread_id_t thread,
332 // int sched_priority,
333 // fosa_ads_actions_t * actions,
334 // struct timespec *current_time);
335 void (*appsched_error) (void * sched_data,
336 frsh_thread_id_t thread,
337 fosa_ads_error_cause_t cause,
338 fosa_ads_actions_t * actions);
339 } fosa_ads_scheduler_ops_t;
344 #endif // _FOSA_TYPES_H_