1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 by the FRESCOR consortium:
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
18 // The 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 // All rights reserved.
25 // Redistribution and use in source and binary forms, with or
26 // without modification, are permitted provided that the
27 // following conditions are met:
29 // * Redistributions of source code must retain the above
30 // copyright notice, this list of conditions and the
31 // following disclaimer.
32 // * Redistributions in binary form must reproduce the above
33 // copyright notice, this list of conditions and the
34 // following disclaimer in the documentation and/or other
35 // materials provided with the distribution.
36 // * Neither the name of FRESCOR nor the names of its
37 // contributors may be used to endorse or promote products
38 // derived from this software without specific prior
39 // written permission.
41 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
42 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
43 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
44 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
46 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
47 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
48 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
49 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
50 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
51 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54 // POSSIBILITY OF SUCH DAMAGE.
55 // -----------------------------------------------------------------------
56 //fosa_ose_implementation_specific.c
57 //==============================================
58 // ******** ****** ******** **********
59 // **///// /** ** **////// /** /**
60 // ** /** ** /** /** /**
61 // ******* /** ** /********* /**********
62 // **//// /** ** ////////** /**//////**
63 // ** /** ** /** /** /**
64 // ** /** ** ******** /** /**
65 // // /******/ //////// // //
67 // FOSA(Frescor Operating System Adaptation layer)
68 //================================================
74 #include "fosa_ose_implementation_specific.h"
77 #include "frsh_scheduler.h"
80 //For debug purpose only.
83 //The following function is placed in the fosa_app_def_sched.c file.
84 extern int fosa_ose_adsactions_add(fosa_ads_actions_t* sched_actions,
86 frsh_thread_id_t thread,
87 fosa_ads_urgency_t urgency,
88 fosa_clock_id_t clock_id,
92 /* Application Defined Scheduling Callbacks */
93 /********************************************/
94 //extern void frsh_callback_init(void *sched_data, void *arg);
96 extern void frsh_callback_new_thread(void *sched_data, frsh_thread_id_t thread,
97 fosa_ads_actions_t *actions, struct timespec *current_time);
99 extern static void frsh_callback_thread_terminate(void *sched_data, frsh_thread_id_t thread,
100 fosa_ads_actions_t *actions, struct timespec *current_time);
102 extern static void frsh_callback_thread_ready(void *sched_data, frsh_thread_id_t thread,
103 fosa_ads_actions_t *actions, struct timespec *current_time);
105 extern static void frsh_callback_thread_block(void *sched_data, frsh_thread_id_t thread,
106 fosa_ads_actions_t *actions, struct timespec *current_time);
108 extern static void frsh_callback_change_sched_param_thread(void *sched_data, frsh_thread_id_t thread,
109 fosa_ads_actions_t *actions,
110 struct timespec *current_time);
112 extern static void frsh_callback_explicit_call_with_data(void * sched_data,
113 frsh_thread_id_t thread,
114 const void * msg, size_t msg_size,
115 void **reply, size_t *reply_size,
116 fosa_ads_actions_t * actions,
117 struct timespec *current_time);
120 extern static void frsh_callback_notification_for_thread(void * sched_data,
121 frsh_thread_id_t thread,
122 fosa_clock_id_t clock,
123 fosa_ads_actions_t * actions,
124 struct timespec *current_time);
127 extern static void frsh_callback_timeout(void *sched_data, fosa_ads_actions_t *actions,
128 struct timespec *current_time);
130 extern static void frsh_callback_signal(void *sched_data, frsh_signal_t signal, frsh_signal_info_t siginfo,
131 fosa_ads_actions_t *actions, struct timespec *current_time);
133 extern static void frsh_callback_appsched_error(void *sched_data, frsh_thread_id_t thread,
134 fosa_ads_error_cause_t cause, fosa_ads_actions_t *actions);
138 //Osäker på hur dessa funktioner skall implementeras...........................
141 * fosa_ose_convert_prio_to_ose()
143 * Maps fosa priority to ose priority. FOSA internal function.
144 * Faster if defined as a macro?...............................................
146 //OSPRIORITY fosa_ose_convert_prio_to_ose(int fosa_prio)
148 // return (OSPRIORITY) fosa_get_priority_max() +
149 // fosa_get_priority_min() - fosa_prio;
153 * fosa_ose_convert_prio_to_fosa()
155 * Maps ose priority to fosa priority. FOSA internal function.
157 //int fosa_ose_convert_prio_to_fosa(OSPRIORITY ose_prio)
159 // return fosa_get_priority_max() +
160 // fosa_get_priority_min() - (int) ose_prio;
163 unsigned int process_name_number = 0;
165 bool fosa_ose_keys_initialized = false;
166 bool fosa_ose_keys_taken[FOSA_MAX_KEYS];
168 bool fosa_ose_is_process(PROCESS Pid)
170 switch (get_ptype(Pid))
183 void fosa_ose_ads_actions_init(fosa_ads_actions_t *sched_actions)
185 sched_actions->FirstAction = NULL;
186 sched_actions->LastAction = NULL;
189 void fosa_ose_adsactions_remove_first(fosa_ads_actions_t *sched_actions)
191 fosa_ose_action_t* action_to_remove;
193 action_to_remove = sched_actions->FirstAction;
194 sched_actions->FirstAction = sched_actions->FirstAction->NextAction;
195 if (sched_actions->FirstAction == NULL) {
196 sched_actions->LastAction = NULL;
199 heap_free_shared(action_to_remove);
202 void fosa_ose_systime_to_timespec(unsigned long ticks,
203 unsigned long microsec, struct timespec* time)
205 // If the unsigned long are 32 bit then this function can measure up
206 // to 1,36 years before it loops to zero.
207 unsigned long microsec_per_tick = system_tick();
208 unsigned long tics_per_sec = (1000000 / microsec_per_tick);
209 time->tv_sec = ticks / tics_per_sec;
210 time->tv_nsec = (ticks % tics_per_sec) * 10000000 + microsec * 1000;
213 void fosa_ose_execute_action_activate(PROCESS pid)
218 void fosa_ose_execute_action_suspend(PROCESS pid)
223 * A check to see that the process have not locked a mutex before the
224 * stop command are executed would be good to avoid deadlooks.
229 void fosa_ose_execute_action_reject(PROCESS pid)
231 //Send signal to the pid with the message to reject it.
232 fosa_ose_event_signal_t *reply_sig;
233 reply_sig = (fosa_ose_event_signal_t *)
234 alloc(sizeof(fosa_ose_event_signal_t),
236 send((union SIGNAL **)&reply_sig, pid);
239 void fosa_ose_execute_action_accept(PROCESS pid)
241 //Send signal to the pid with the message to accept it.
242 fosa_ose_event_signal_t *reply_sig;
243 reply_sig = (fosa_ose_event_signal_t *)
244 alloc(sizeof(fosa_ose_event_signal_t),
246 send((union SIGNAL **)&reply_sig, pid);
249 fosa_ose_process_info_t* fosa_ose_processes = NULL;
251 fosa_ose_process_info_t* fosa_ose_process_get_node(frsh_thread_id_t pid) {
252 if (fosa_ose_processes == NULL) return NULL; //Not found.
253 fosa_ose_process_info_t* node = fosa_ose_processes;
255 while(node->pid != pid) {
256 node = node->NextProcess;
257 if (node == NULL) break;
262 int fosa_ose_process_list_node_remove(frsh_thread_id_t pid) {
263 if (fosa_ose_processes == NULL) return FOSA_EINVAL;
264 fosa_ose_process_info_t* node = fosa_ose_processes;
265 fosa_ose_process_info_t* prev_node = NULL;
267 while(node->pid != pid) {
268 if (node->NextProcess == NULL) return FOSA_EINVAL;
270 node = node->NextProcess;
273 if (prev_node == NULL) {
274 //New first node in list, or now list gets empty.
275 fosa_ose_processes = node->NextProcess;
278 prev_node->NextProcess = node->NextProcess;
281 if(node->appsched_param != NULL)
282 heap_free_shared(node->appsched_param);
283 heap_free_shared(node);
288 int frsh_ose_callback_test() {
289 ramlog_printf("Sucess by: frsh_ose_callback_test()");
293 int fosa_ose_adsactions_add_test(
294 fosa_ads_actions_t *sched_actions,
297 return fosa_ose_adsactions_add( sched_actions, //sched_actions
299 current_process(), //thread
307 void fosa_ose_scheduler_ops_init(fosa_ads_scheduler_ops_t *scheduler_ops)
309 //Cnage functions to point to here!..........................................
310 scheduler_ops->init = (void *) &frsh_ose_callback_test;
311 scheduler_ops->new_thread = (void *) &frsh_ose_callback_test;
312 scheduler_ops->thread_terminate = (void *) &frsh_ose_callback_test;
313 scheduler_ops->thread_ready = (void *) &frsh_ose_callback_test;
314 scheduler_ops->thread_block = (void *) &frsh_ose_callback_test;
315 scheduler_ops->signal = (void *) &frsh_ose_callback_test;
316 scheduler_ops->change_sched_param_thread = (void *) NULL;
317 scheduler_ops->explicit_call_with_data = (void *) NULL;
318 scheduler_ops->notification_for_thread = (void *) NULL;
319 scheduler_ops->timeout = (void *) NULL;
320 scheduler_ops->appsched_error = (void *) NULL;
323 void fosa_ose_send_event_to_scheduler( PROCESS event_pid,
326 //Send signal to fosa scheduler.
327 fosa_ose_event_signal_t *sig;
328 sig = (fosa_ose_event_signal_t *)
329 alloc(sizeof(fosa_ose_event_signal_t),
331 sig->pid = event_pid;
332 PROCESS scheduler_pid;
333 hunt("fosa_scheduler_process", 0,
334 &scheduler_pid, (union SIGNAL **) NULL);
335 if (scheduler_pid != 0) {
336 send((union SIGNAL **)&sig, scheduler_pid);
339 "Failiure by: fosa_scheduler_process not found.\n");