include ../config.mk
include ../rules.mk
-FOSA_MODULES=fosa_clocks_and_timers fosa_threads_and_signals fosa_app_def_sched fosa_mutexes_and_condvars fosa_misc fosa_long_jump
+FOSA_MODULES=fosa_clocks_and_timers fosa_threads_and_signals fosa_app_def_sched fosa_mutexes_and_condvars fosa_misc fosa_long_jump fosa_time
FOSA_OBJS=$(addsuffix .o,$(FOSA_MODULES))
check_gcc = $(shell \
#include <fosa_configuration_parameters.h>
#include <fosa_app_def_sched.h>
#include <fosa_threads_and_signals.h>
+#include <fosa_time.h>
+
#include <sched.h>
#include <signal.h>
#include <unistd.h>
return posix_appsched_actions_addsuspend (&(sched_actions -> actions), thread);
}
-int fosa_adsactions_add_timeout
+int fosa_adsactions_add_timeout
(fosa_ads_actions_t *sched_actions,
fosa_clock_id_t clock_id,
- const struct timespec *at_time)
+ const fosa_abs_time_t *at_time)
{
- sched_actions -> timeout = *at_time;
+ sched_actions -> timeout = fosa_abs_time_to_timespec (*at_time);
sched_actions -> timeout_ptr = &(sched_actions -> timeout);
return 0;
}
-int fosa_adsactions_add_thread_notification
+int fosa_adsactions_add_thread_notification
(fosa_ads_actions_t *sched_actions,
fosa_thread_id_t thread,
fosa_clock_id_t clock_id,
- const struct timespec *at_time)
+ const fosa_abs_time_t *at_time)
{
printf ("BUG: fosa_adsactions_add_thread_notification: Not implemented\n");
exit (-21);
//================================================
#include <fosa_clocks_and_timers.h>
+#include <fosa_time.h>
+#include <stdlib.h>
/*************************
* Timing: Clocks
*************************/
-int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec *current_time)
-{
- if (clock_gettime (clockid, current_time))
- return FOSA_EINVAL;
+int fosa_clock_get_time(fosa_clock_id_t clockid, fosa_abs_time_t *current_time)
+{
+ int err;
+ struct timespec now;
+
+ err = clock_gettime (clockid, &now);
+ *current_time = fosa_timespec_to_abs_time(now);
return 0;
}
}
-int fosa_timer_arm
- (fosa_timer_id_t timerid, bool abstime,
- const struct timespec *value)
+int fosa_rel_timer_arm (fosa_timer_id_t timerid, const fosa_rel_time_t *value)
{
- struct timespec now;
+ struct itimerspec tvalue;
- clock_gettime (CLOCK_REALTIME, &now);
+ tvalue.it_value = fosa_rel_time_to_timespec(*value);
+ tvalue.it_interval = (struct timespec) {0,0};
- struct itimerspec tvalue =
- {
- .it_value = (struct timespec) *value,
- .it_interval = {0,0},
- };
+ if (timer_settime (timerid, 0, &tvalue, NULL))
+ return FOSA_EINVAL;
+
+ return 0;
+}
+
+int fosa_abs_timer_arm (fosa_timer_id_t timerid, const fosa_abs_time_t *value)
+{
+ struct itimerspec tvalue;
- if (timer_settime (timerid, abstime, &tvalue, NULL))
- return EINVAL;
+ tvalue.it_value = fosa_abs_time_to_timespec(*value);
+ tvalue.it_interval = (struct timespec) {0,0};
+
+ if (timer_settime (timerid, TIMER_ABSTIME, &tvalue, NULL))
+ return FOSA_EINVAL;
return 0;
}
int fosa_timer_get_remaining_time
- (fosa_timer_id_t timerid, struct timespec *remaining_time)
+ (fosa_timer_id_t timerid, fosa_rel_time_t *remaining_time)
{
struct itimerspec value;
if (timer_gettime (timerid, &value))
- return EINVAL;
+ return FOSA_EINVAL;
- *remaining_time = value.it_value;
+ *remaining_time = fosa_timespec_to_rel_time (value.it_value);
return 0;
}
-int fosa_timer_disarm(fosa_timer_id_t timerid, struct timespec
- *remaining_time)
+int fosa_timer_disarm (fosa_timer_id_t timerid, fosa_rel_time_t *remaining_time)
{
struct itimerspec null_timer, old;
};
if (timer_settime (timerid, 0, &null_timer, &old))
- return EINVAL;
+ return FOSA_EINVAL;
if (remaining_time)
- *remaining_time = old.it_value;
+ *remaining_time = fosa_timespec_to_rel_time (old.it_value);
return 0;
}
//================================================
#include <fosa_mutexes_and_condvars.h>
+#include <fosa_time.h>
/*******************************************************
* Mutexes with priority ceiling
return pthread_cond_wait (cond, mutex);
}
-int fosa_cond_timedwait
- (fosa_cond_t *cond,
- fosa_mutex_t *mutex,
- const struct timespec *abstime)
+int fosa_cond_timedwait (fosa_cond_t *cond, fosa_mutex_t *mutex,
+ const fosa_abs_time_t *abstime)
{
int err;
+ struct timespec tout = fosa_abs_time_to_timespec (*abstime);
- err = pthread_cond_timedwait (cond, mutex, abstime);
+ err = pthread_cond_timedwait (cond, mutex, &tout);
if (err == ETIMEDOUT)
- return ETIMEDOUT;
+ return FOSA_ETIMEDOUT;
if (err)
- return EINVAL;
+ return FOSA_EINVAL;
return 0;
}
#include <fosa_configuration_parameters.h>
#include <fosa_threads_and_signals.h>
+#include <fosa_time.h>
#include <unistd.h>
#include <signal.h>
}
int fosa_signal_timedwait
- (fosa_signal_t set[], int size, fosa_signal_t *signal_received,
- fosa_signal_info_t *info, const struct timespec *timeout)
+ (fosa_signal_t set[], int size, fosa_signal_t *signal_received,
+ fosa_signal_info_t *info, const fosa_rel_time_t *timeout)
{
int i, sig;
sigset_t wset;
siginfo_t nfo;
+ struct timespec tout = fosa_rel_time_to_timespec (*timeout);
if (size < 0)
return EINVAL;
sigaddset (&wset, set [i]);
}
- sig = sigtimedwait (&wset, &nfo, timeout);
+ sig = sigtimedwait (&wset, &nfo, &tout);
if (sig == -1)
return errno;
--- /dev/null
+//----------------------------------------------------------------------
+// Copyright (C) 2006 - 2007 by the FRESCOR consortium:
+//
+// Universidad de Cantabria, SPAIN
+// University of York, UK
+// Scuola Superiore Sant'Anna, ITALY
+// Kaiserslautern University, GERMANY
+// Univ. Politecnica Valencia, SPAIN
+// Czech Technical University in Prague, CZECH REPUBLIC
+// ENEA SWEDEN
+// Thales Communication S.A. FRANCE
+// Visual Tools S.A. SPAIN
+// Rapita Systems Ltd UK
+// Evidence ITALY
+//
+// See http://www.frescor.org
+//
+// The FRESCOR project (FP6/2005/IST/5-034026) is funded
+// in part by the European Union Sixth Framework Programme
+// The European Union is not liable of any use that may be
+// made of this code.
+//
+//
+// based on previous work (FSF) done in the FIRST project
+//
+// Copyright (C) 2005 Mälardalen University, SWEDEN
+// Scuola Superiore S.Anna, ITALY
+// Universidad de Cantabria, SPAIN
+// University of York, UK
+//
+// This file is part of FOSA (Frsh Operating System Abstraction)
+//
+// FOSA is free software; you can redistribute it and/or modify it
+// under terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option) any
+// later version. FOSA is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details. You should have received a
+// copy of the GNU General Public License along with FOSA; see file
+// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+// Cambridge, MA 02139, USA.
+//
+// As a special exception, including FOSA header files in a file,
+// instantiating FOSA generics or templates, or linking other files
+// with FOSA objects to produce an executable application, does not
+// by itself cause the resulting executable application to be covered
+// by the GNU General Public License. This exception does not
+// however invalidate any other reasons why the executable file might be
+// covered by the GNU Public License.
+// -----------------------------------------------------------------------
+// fosa_time.c
+//==============================================
+// ******** ****** ******** **********
+// **///// /** ** **////// /** /**
+// ** /** ** /** /** /**
+// ******* /** ** /********* /**********
+// **//// /** ** ////////** /**//////**
+// ** /** ** /** /** /**
+// ** /** ** ******** /** /**
+// // /******/ //////// // //
+//
+// FOSA(Frescor Operating System Adaptation layer)
+//================================================
+
+#include "fosa.h"
+
+/**
+ * fosa_eat()
+ *
+ * Eat some time using system clock facilities
+ **/
+void fosa_eat(const fosa_rel_time_t *cpu_time)
+{
+ fosa_clock_id_t clock_id;
+ fosa_abs_time_t current_time, time_to_go;
+
+ // NOTE: there should be a constant for the cpu_clock_id of the caller
+ // to avoid calling 'fosa_thread_get_cputime_clock'
+ fosa_thread_get_cputime_clock(fosa_thread_self(), &clock_id);
+ fosa_clock_get_time(clock_id, ¤t_time);
+
+ time_to_go = fosa_abs_time_incr(current_time, *cpu_time);
+
+ /* We also spread smaller_timespec */
+ while ( fosa_abs_time_smaller_or_equal(current_time, time_to_go) )
+ {
+ fosa_clock_get_time(clock_id, ¤t_time);
+ }
+}
+
+
+