]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_rtlinux/fosa_types.h
Work in progress to adapt ADS in fosa
[frescor/fosa.git] / src_rtlinux / fosa_types.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 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. Politecnica  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 //  This file is part of the FRSH implementation
24 //
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)
28 //  any later version.
29 //
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.
34 //
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
38 //  02111-1307, USA.
39 //
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
45 //  Public License.
46 // -----------------------------------------------------------------------
47 //fosa_types.h
48 //==============================================
49 //  ********  ******    ********  **********
50 //  **///// /**    **  **//////  /**     /**
51 //  **      /**    ** /**        /**     /**
52 //  ******* /**    ** /********* /**********
53 //  **////  /**    ** ////////** /**//////**
54 //  **      /**    **        /** /**     /**
55 //  **      /**    **  ********  /**     /**
56 //  //       /******/  ////////   //      // 
57 //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
60
61
62 #ifndef         _FOSA_TYPES_H_
63 #define         _FOSA_TYPES_H_
64
65 // Include needed to have the "frsh_thread_t" type.
66 #include "../../../../frsh/trunk/include/frsh_fosa.h"
67
68 #include "fosa_opaque_types.h"
69
70 /**
71  * @addtogroup clocksandtimers
72  *
73  * @{
74  **/  
75 // identifier of a clock
76 // either a real-time clock or a cpu-time clock
77 typedef    FOSA_CLOCK_ID_T_OPAQUE    fosa_clock_id_t;
78
79 // identifier of a one-shot timer
80 typedef    FOSA_TIMER_ID_T_OPAQUE    fosa_timer_id_t;
81
82 /*@}*/
83
84 typedef    int       frsh_signal_t;
85 typedef    void *    frsh_signal_info_t;
86 typedef    int       bool;
87
88 /**
89  * @addtrogroup mutexesandcondvars
90  *
91  * @{
92  **/
93 // a condition variable
94 typedef    FOSA_COND_T_OPAQUE        fosa_cond_t;
95 /*@}*/
96
97 /**
98  * @addtogroup appdefsched
99  *
100  * @{
101  **/
102
103 /*********
104  *  ADS
105  *********/
106
107 /**
108  * ADS actions
109  *
110  * This type is used to represent a list of scheduling actions that the
111  * scheduler will later request to be executed by the system. The pos-
112  * sible actions are of the following kinds: 
113  *  - reject a thread that has requested attachment to this scheduler
114  *  - activate an application-scheduled thread with the desired value
115  *    of urgency
116  *  - suspend an application-scheduled thread
117  *  - program a timeout
118  *  - program a timed notification associated to a particular 
119  *    application-scheduled thread.
120  *
121  * No comparison or assignment operators are defined for this type
122  **/
123 typedef FOSA_ADS_ACTIONS_T_OPAQUE  fosa_ads_actions_t;
124
125
126 /**
127  * Causes of error in the appsched_error primitive operation
128  **/
129 typedef enum {FOSA_ADS_THREAD_NOT_ATTACHED, FOSA_ADS_INVALID_ACTION}
130     fosa_ads_error_cause_t;
131
132
133 /**
134  * The urgency used to orde the threads of the same priority in the
135  * underlying scheduler. Support for urgency scheduling is required
136  * for supporting the hierarchhical scheduling module
137  **/
138 typedef int fosa_ads_urgency_t;
139
140
141 /**
142  * Scheduler primitive operations
143  *
144  * This structure is used to create application schedulers. It
145  * contains pointers to the primitive operations that are invoked by
146  * the system when a scheduling event occurs:
147  *
148  * - The \b init() primitive operation is invoked by the system just after
149  *   the scheduler has been created using fosa_ads_scheduler_create().
150  *
151  * - The \b new_thread() primitive operation is invoked by the system when
152  *   a thread has requested attachment to this scheduler; this can be a
153  *   newly created thread (via fosa_thread_create()), or an existing thread
154  *   that was not running under ads scheduler (via
155  *   fosa_ads_set_appscheduled()).\n \n 
156  *   .
157  *   The thread can be rejected by the scheduler adding a
158  *   reject-thread action to the actions parameter using
159  *   fosa_ads_actions_add_reject(). If no reject-thread  action is
160  *   added, the thread is accepted.\n \n
161  *   .
162  *   Newly created threads shall be activated by the system after the
163  *   execution of the new_thread() primitive operation. The urgency of
164  *   an accepted thread (either newly created or existing) shall be set
165  *   to a value of zero, unless an activate-thread action with a
166  *   different value of urgency is added via
167  *   fosa_ads_actions_add_activate().\n \n
168  *   .
169  *   If a request to attach a thread to this scheduler was made via
170  *   fosa_ads_set_appscheduled(), at the finalization of the new_thread()
171  *   primitive operation if the newly attached thread is blocked by the
172  *   system (not by the scheduler itself via a suspend scheduling
173  *   action), a thread-block event shall be generated for the scheduler
174  *   immediately and, consequently, the thread_block() primitive
175  *   operation shall be invoked by the system.
176  *
177  * - The \b thread_terminate() primitive operation is invoked by the system
178  *   when a thread attached to this scheduler is terminating (via an
179  *   explicit or implicit thread termination, or cancellation, or when
180  *   it is no longer sceduled by the ads scheduler (via
181  *   fosa_ads_setappscheduled()). \n\n
182  *   .
183  *   Before the thread_terminate() primitive operation is invoked by
184  *   the system, all the thread-notification events programmed for that
185  *   thread are cancelled. \n\n
186  *   .
187  *   In the case of a thread that is terminating, the
188  *   thread_terminate() primitive operation is executed before the
189  *   execution of the cleanup handlers and of the thread-specific data
190  *   destructor functions. In that way, the thread parameter corresponds
191  *   to a valid thread Id and the thread-specific data is valid and can
192  *   be accessed from the thread_terminate() primitive operation. \n\n
193  *   .
194  *   Also for terminating threads, after the thread_terminate() primitive
195  *   operation finishes, the system shall lower the urgency of the
196  *   thread identified by thread to a value of zero, and shall deattach
197  *   it from the ads scheduler.  Then, the thread shall execute the
198  *   cleanup handlers and the thread-specific data destructor functions
199  *   outside the management of its former scheduler. Notice that in a
200  *   multiprocessor system this may imply the suspension of the thread
201  *   identified by parameter thread during the execution of the
202  *   thread_terminate() primitive operation.
203  *
204  * - The \b thread_ready() primitive operation is invoked by the system
205  *   when a thread attached to this scheduler that was blocked has
206  *   become unblocked by the system.
207  *
208  * - The \b thread_block() primitive operation is invoked by the system
209  *   when a thread attached to this scheduler has blocked.
210  *
211  * - The \b change_sched_param_thread() primitive operation is invoked by
212  *   the system when the scheduling parameters of a thread attached to
213  *   this scheduler have been changed, but the thread continues to run
214  *   under this scheduler. The change includes either the regular
215  *   scheduling parameters (fosa_thread_set_prio() or the application-
216  *   defined scheduling parameters, via fosa_ads_set_appsched_param(). 
217  *
218  * - The \b explicit_call_with_data() primitive operation is invoked by the
219  *   system when a thread (identified by the thread parameter) has
220  *   explicitly invoked the scheduler with a message containing
221  *   scheduling information, and possibly requesting a reply message,
222  *   via fosa_ads_invoke_withdata().
223  *
224  * - The \b notification_for_thread() primitive operation is invoked by the
225  *   system when the time for a thread-notification previously programed
226  *   by the scheduler via fosa_ads_actions_add_thread_notification()
227  *   is reached. Parameter clock identifies the clock for which the
228  *   thread-notification was programmed.
229  *
230  * - The \b timeout() primitive operation is invoked by the system when a
231  *   timeout requested by the scheduler (via
232  *   fosa_ads_actions_add_timeout()) has expired. 
233  *
234  * - The \b signal() primitive operation is invoked by the system when a
235  *   signal belonging to the set of signals for which the scheduler is
236  *   waiting (via fosa_ads_set_handled_signal_set()) has been
237  *   generated. \n\n
238  *   .
239  *   The signal number and its associated information (if any) are
240  *   passed in the arguments signal and siginfo.\n\n
241  *   .
242  *   The signal is consumed with the invocation of this primitive
243  *   operation, which implies that it will not cause the execution of
244  *   any signal handler, nor it may be accepted by any thread waiting
245  *   for this signal number.  
246  *
247  * - The \b appsched_error() primitive operation is invoked by the system
248  *   when an error in the scheduling actions list specified in a
249  *   previous primitive operation is detected. The cause of the error is
250  *   notified in the parameter cause. The defined causes of error are
251  *   described fosa_ads_error_cause_tappdefsched
252  *
253  * Every primitive operation receives the argument sched_data. It is a
254  * pointer to a memory area containing information shared by all the
255  * scheduler operations. It can be used to store the data structures
256  * required by the scheduler (for example, a ready queue and a delay
257  * queue). Scheduler operations should not use any other global data out
258  * of this memory area.  
259  *
260  * The actions argument is used by the scheduler to request the operating
261  * system to execute a set of scheduling actions at the end of the
262  * primitive operation. It is passed empty by the system, and the
263  * scheduler may add multiple scheduling actions.
264  *
265  * The current_time argument contains the system time
266  * measured immediately before the invocation of the primitive operation
267  * using the FOSA_CLOCK_REALTIME clock
268  *
269  * In addition to these common parameters, most of the primitive
270  * operations receive a thread argument. This argument allows the
271  * primitive operations to know which is the thread that has produced or
272  * is related to the event. 
273  **/
274 typedef struct {
275    void (*init) (void * sched_data, void * arg);
276    void (*new_thread) (void * sched_data,
277             frsh_thread_id_t thread,
278             fosa_ads_actions_t * actions,
279             struct timespec *current_time);
280    void (*thread_terminate) (void * sched_data,
281             frsh_thread_id_t thread,
282             fosa_ads_actions_t * actions,
283             struct timespec *current_time);
284    void (*thread_ready) (void * sched_data,
285             frsh_thread_id_t thread,
286             fosa_ads_actions_t * actions,
287             struct timespec *current_time);
288    void (*thread_block) (void * sched_data,
289             frsh_thread_id_t thread,
290             fosa_ads_actions_t * actions,
291             struct timespec *current_time);
292   //void (*thread_yield) (void * sched_data,
293   //          frsh_thread_id_t thread,
294   //          fosa_ads_actions_t * actions,
295   //          struct timespec *current_time);
296    void (*change_sched_param_thread) (void * sched_data,
297             frsh_thread_id_t thread,
298             fosa_ads_actions_t * actions,
299             struct timespec *current_time);
300   //void msg_from_scheduler(void * sched_data,
301   //          fosa_ads_scheduler_id_t scheduler_id,
302   //          const void * msg, size_t msg_size,
303   //          fosa_ads_actions_t * actions,
304   //          struct timespec *current_time);
305   //void (*explicit_call) (void * sched_data,
306   //          frsh_thread_id_t thread,
307   //         int user_event_code,
308   //         fosa_ads_actions_t * actions,
309   //         struct timespec *current_time);
310   void (*explicit_call_with_data) (void * sched_data,
311            frsh_thread_id_t thread,
312            const void * msg, size_t msg_size,
313            void **reply, size_t *reply_size,
314            fosa_ads_actions_t * actions,
315            struct timespec *current_time);
316   void (*notification_for_thread) (void * sched_data,
317            frsh_thread_id_t thread,
318            fosa_clock_id_t clock,
319            fosa_ads_actions_t * actions,
320            struct timespec *current_time);
321   void (*timeout) (void * sched_data,
322            fosa_ads_actions_t * actions,
323            struct timespec *current_time);
324   void (*signal) (void * sched_data,
325            frsh_signal_t signal,
326            frsh_signal_info_t siginfo,
327            fosa_ads_actions_t * actions,
328            struct timespec *current_time);
329   //void (*priority_inherit) (void * sched_data,
330   //         frsh_thread_id_t thread,
331   //         int sched_priority,
332   //         fosa_ads_actions_t * actions,
333   //         struct timespec *current_time);
334   //void (*priority_uninherit) (void * sched_data,
335   //         frsh_thread_id_t thread,
336   //         int sched_priority,
337   //         fosa_ads_actions_t * actions,
338   //         struct timespec *current_time);
339   void (*appshed_error) (void * sched_data,
340            frsh_thread_id_t thread,
341            fosa_ads_error_cause_t cause,
342            fosa_ads_actions_t * actions);
343 } fosa_ads_scheduler_ops_t;
344
345
346 /*@}*/
347
348 #endif // _FOSA_TYPES_H_