From: telleriam Date: Thu, 6 Mar 2008 11:32:16 +0000 (+0000) Subject: Time abstraction added to FOSA to replace timespec_operations X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/fosa.git/commitdiff_plain/c8948702a2abdf14f152d9776ab91e3e6283e045 Time abstraction added to FOSA to replace timespec_operations git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1041 35b4ef3e-fd22-0410-ab77-dab3279adceb --- diff --git a/include/fosa_app_def_sched.h b/include/fosa_app_def_sched.h index ecb202b..333bc6a 100644 --- a/include/fosa_app_def_sched.h +++ b/include/fosa_app_def_sched.h @@ -495,7 +495,7 @@ int fosa_adsactions_add_suspend( 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); /** * fosa_adsactions_add_thread_notification() @@ -530,7 +530,7 @@ 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); /** diff --git a/include/fosa_clocks_and_timers.h b/include/fosa_clocks_and_timers.h index d21caac..0a544a0 100644 --- a/include/fosa_clocks_and_timers.h +++ b/include/fosa_clocks_and_timers.h @@ -105,7 +105,7 @@ FOSA_CPP_BEGIN_DECLS * notify it to the system console and then terminate the FRSH * implementation and dependant applications **/ -int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec *current_time); +int fosa_clock_get_time(fosa_clock_id_t clockid, fosa_abs_time_t *current_time); /** @@ -208,21 +208,47 @@ int fosa_thread_get_cputime_clock(fosa_thread_id_t tid, fosa_clock_id_t *clockid int fosa_timer_delete(fosa_timer_id_t timerid); /** - * fosa_timer_arm() + * fosa_rel_timer_arm() * - * Arm a timer + * Arm a timer with a relative time interval * * The timer specified by timer is armed and starts counting time. * - * If abstime is true, the value pointed to by value is the absolute - * time at which the timer will expire. If value specifies a time instant - * in the past, the timer expires immediately. + * The value pointed to by value is the relative interval that must + * elapse for the timer to expire. Negative values cause the timer to + * expire immediately. * - * If abstime is false, the value pointed to by value is the relative interval - * that must elapse for the timer to expire. + * The time is measured with the clock associated with the timer when + * it was created. * - * In both cases, absolute or relative, the time is measured with the clock - * associated with the timer when it was created. + * If the timer was already armed, the previous time or interval is discarded + * and the timer is rearmed with the new value. + * + * When the timer expires, it is disarmed. + * + * Returns 0 if successful; otherwise it returns an error code: + * FOSA_EINVAL: the value of timerid or value is invalid + * + * Alternatively, in case of error the implementation is allowed to + * notify it to the system console and then terminate the FRSH + * implementation and dependant applications + **/ +int fosa_rel_timer_arm + (fosa_timer_id_t timerid, const fosa_rel_time_t *value); + +/** + * fosa_abs_timer_arm() + * + * Arm a timer that will expire in an absolute time instant. + * + * The timer specified by timer is armed and starts counting time. + * + * The value pointed to by value is the absolute time at which the + * timer will expire. If value specifies a time instant in the past, + * the timer expires immediately. + * + * The time is measured with the clock associated with the timer when + * it was created. * * If the timer was already armed, the previous time or interval is discarded * and the timer is rearmed with the new value. @@ -236,9 +262,11 @@ int fosa_timer_delete(fosa_timer_id_t timerid); * notify it to the system console and then terminate the FRSH * implementation and dependant applications **/ -int fosa_timer_arm - (fosa_timer_id_t timerid, bool abstime, - const struct timespec *value); +int fosa_abs_timer_arm + (fosa_timer_id_t timerid, const fosa_abs_time_t *value); + + + /** * fosa_timer_get_remaining_time() @@ -259,7 +287,7 @@ int fosa_timer_arm * implementation and dependant applications **/ 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); /** * fosa_timer_disarm() @@ -281,8 +309,8 @@ int fosa_timer_get_remaining_time * notify it to the system console and then terminate the FRSH * implementation and dependant applications **/ -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); /*@}*/ diff --git a/include/fosa_mutexes_and_condvars.h b/include/fosa_mutexes_and_condvars.h index a2cfade..20d22d3 100644 --- a/include/fosa_mutexes_and_condvars.h +++ b/include/fosa_mutexes_and_condvars.h @@ -354,7 +354,7 @@ int fosa_cond_wait(fosa_cond_t *cond, fosa_mutex_t *mutex); * then terminate the FRSH implementation and dependant applications **/ int fosa_cond_timedwait(fosa_cond_t *cond, fosa_mutex_t *mutex, - const struct timespec *abstime); + const fosa_abs_time_t *abstime); /*@}*/ diff --git a/include/fosa_opaque_types.h b/include/fosa_opaque_types.h index 5d8c503..5f562ec 100644 --- a/include/fosa_opaque_types.h +++ b/include/fosa_opaque_types.h @@ -71,6 +71,7 @@ #include #include "fosa_cpp_macros.h" +#include "fosa_opaque_types_time.h" /////////////////////// MARTE_OS ///////////////////////////// @@ -84,10 +85,6 @@ FOSA_CPP_BEGIN_DECLS -/* Time */ -/********/ -// typedef struct timespec fosa_rel_time_t; -// typedef struct timespec fosa_abs_time_t; /* Thread and signals */ /**********************/ @@ -117,16 +114,16 @@ typedef pthread_cond_t FOSA_COND_T_OPAQUE; /* Application defined Scheduling */ /**********************************/ -typedef struct { - posix_appsched_actions_t actions; - struct timespec *timeout_ptr; - struct timespec timeout; - bool rejected; - bool suspended; - bool activated; -} fosa_ads_actions_internal_t; +#define FOSA_ADS_ACTIONS_T_OPAQUE struct \ +{ \ + posix_appsched_actions_t actions; \ + struct timespec *timeout_ptr; \ + struct timespec timeout; \ + bool rejected; \ + bool suspended; \ + bool activated; \ +} -#define FOSA_ADS_ACTIONS_T_OPAQUE fosa_ads_actions_internal_t /* Local jump */ /**************/ @@ -178,11 +175,6 @@ typedef struct { #include #include -/* Time */ -/********/ -// typedef struct timespec fosa_rel_time_t; -// typedef struct timespec fosa_abs_time_t; - /* Threads and signals */ /***********************/ @@ -235,10 +227,6 @@ typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE; #ifdef OSE -/* Time */ -/********/ -// typedef struct timespec fosa_rel_time_t; -// typedef struct timespec fosa_abs_time_t; /* Put OSE dependent includes and defines here */ diff --git a/include/fosa_opaque_types_time.h b/include/fosa_opaque_types_time.h new file mode 100644 index 0000000..5d2b146 --- /dev/null +++ b/include/fosa_opaque_types_time.h @@ -0,0 +1,356 @@ +//---------------------------------------------------------------------- +// 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_opaque_types_time.h +//============================================== +// ******** ****** ******** ********** +// **///// /** ** **////// /** /** +// ** /** ** /** /** /** +// ******* /** ** /********* /********** +// **//// /** ** ////////** /**//////** +// ** /** ** /** /** /** +// ** /** ** ******** /** /** +// // /******/ //////// // // +// +// FOSA(Frescor Operating System Adaptation layer) +//================================================ + +// Implementation dependent definitions + +#ifndef _FOSA_OPAQUE_TYPES_TIME_H_ +#define _FOSA_OPAQUE_TYPES_TIME_H_ + + +/////////////////////// MARTE_OS ///////////////////////////// + +#ifdef MARTE_OS + +/** + Choose between: + - struct timespec + - numeric type (long, .long long, short) +**/ + + +#define FOSA_TIME_TIMESPEC + +typedef struct timespec FOSA_REL_TIME_T_OPAQUE; +typedef struct timespec FOSA_ABS_TIME_T_OPAQUE; + + + + +/* +#define FOSA_TIME_NUMERIC +#define FOSA_TIME_BASE 9 // 9 for nanosecods + // 6 for microseconds + // 3 for miliseconds + +typedef long long FOSA_REL_TIME_T_OPAQUE; +typedef unsigned long long FOSA_ABS_TIME_T_OPAQUE; + +*/ + +/** + Possible additions: FOSA_ABS_TIME_MAX, FOSA_ABS_TIME_MIN, + FOSA_REL_TIME_MAX, FOSA_REL_TIME_MIN to protect + operations against possible overflows or handle circular + increments. +**/ + +#endif /* MARTE_OS */ + +/////////////////////// End of MARTE_OS ///////////////////////////// + + +/////////////////////// RT_LINUX /////////////////////////// + +#ifdef RT_LINUX + +/** + Choose between: + - struct timespec + - numeric type (long, .long long, short) +**/ + +#define FOSA_TIME_TIMESPEC + +typedef struct timespec FOSA_REL_TIME_T_OPAQUE; +typedef struct timespec FOSA_ABS_TIME_T_OPAQUE; + + +/* +#define FOSA_TIME_NUMERIC +#define FOSA_TIME_BASE 9 // 9 for nanosecods + // 6 for microseconds + // 3 for miliseconds + +typedef long long FOSA_REL_TIME_T_OPAQUE; +typedef unsigned long long FOSA_ABS_TIME_T_OPAQUE; + +*/ +/** + Possible additions: FOSA_ABS_TIME_MAX, FOSA_ABS_TIME_MIN, + FOSA_REL_TIME_MAX, FOSA_REL_TIME_MIN to protect + operations against possible overflows or handle circular + increments. +**/ + +#endif /* RT_LINUX */ + + +/////////////////////// End of RT_LINUX ///////////////////////////// + + + +////////////////////////// OSE ////////////////////////////////////// + +#ifdef OSE + +/** + Choose between: + - struct timespec + - numeric type (long, .long long, short) +**/ + +#define FOSA_TIME_TIMESPEC + +typedef struct timespec FOSA_REL_TIME_T_OPAQUE; +typedef struct timespec FOSA_ABS_TIME_T_OPAQUE; + +/* +#define FOSA_TIME_NUMERIC +#define FOSA_TIME_BASE 9 // 9 for nanosecods + // 6 for microseconds + // 3 for miliseconds + +typedef long long FOSA_REL_TIME_T_OPAQUE; +typedef unsigned long long FOSA_ABS_TIME_T_OPAQUE; + +*/ + +/** + Possible additions: FOSA_ABS_TIME_MAX, FOSA_ABS_TIME_MIN, + FOSA_REL_TIME_MAX, FOSA_REL_TIME_MIN to protect + operations against possible overflows or handle circular + increments. +**/ + + +#endif /* OSE */ + +/////////////////////// End of OSE /////////////////////////////////// + +/////////////////////// AQuoSA /////////////////////////// + +#ifdef AQuoSA + +/** + Choose between: + - struct timespec + - numeric type (long, .long long, short) +**/ + + +#define FOSA_TIME_TIMESPEC + +typedef struct timespec FOSA_REL_TIME_T_OPAQUE; +typedef struct timespec FOSA_ABS_TIME_T_OPAQUE; + + +/* + +#define FOSA_TIME_NUMERIC +#define FOSA_TIME_BASE 9 // 9 for nanosecods + // 6 for microseconds + // 3 for miliseconds + +typedef long long FOSA_REL_TIME_T_OPAQUE; +typedef unsigned long long FOSA_ABS_TIME_T_OPAQUE; + +*/ +/** + Possible additions: FOSA_ABS_TIME_MAX, FOSA_ABS_TIME_MIN, + FOSA_REL_TIME_MAX, FOSA_REL_TIME_MIN to protect + operations against possible overflows or handle circular + increments. +**/ + + +#endif /* AQuoSA */ + +/////////////////////// End of AQuoSA //////////////////////////////// + + +/////////////////////// PARTIKLE /////////////////////////// + +#ifdef PARTIKLE + +/** + Choose between: + - struct timespec + - numeric type (long, .long long, short) +**/ + + +#define FOSA_TIME_TIMESPEC + +typedef struct timespec FOSA_REL_TIME_T_OPAQUE; +typedef struct timespec FOSA_ABS_TIME_T_OPAQUE; + +/* + +#define FOSA_TIME_NUMERIC +#define FOSA_TIME_BASE 9 // 9 for nanosecods + // 6 for microseconds + // 3 for miliseconds + +typedef long long FOSA_REL_TIME_T_OPAQUE; +typedef unsigned long long FOSA_ABS_TIME_T_OPAQUE; + +*/ + +/** + Possible additions: FOSA_ABS_TIME_MAX, FOSA_ABS_TIME_MIN, + FOSA_REL_TIME_MAX, FOSA_REL_TIME_MIN to protect + operations against possible overflows or handle circular + increments. +**/ + + +#endif /* PARTIKLE */ + +/////////////////////// End of PARTIKLE //////////////////////////////// + +/////////////////////// VIRTUAL_TIME /////////////////////////// + +#ifdef VIRTUAL_TIME + +/** + Choose between: + - struct timespec + - numeric type (long, .long long, short) +**/ + + + +#define FOSA_TIME_TIMESPEC + +typedef struct timespec FOSA_REL_TIME_T_OPAQUE; +typedef struct timespec FOSA_ABS_TIME_T_OPAQUE; + + +/* + +#define FOSA_TIME_NUMERIC +#define FOSA_TIME_BASE 9 // 9 for nanosecods + // 6 for microseconds + // 3 for miliseconds + +typedef long long FOSA_REL_TIME_T_OPAQUE; +typedef unsigned long long FOSA_ABS_TIME_T_OPAQUE; + +*/ + +/** + Possible additions: FOSA_ABS_TIME_MAX, FOSA_ABS_TIME_MIN, + FOSA_REL_TIME_MAX, FOSA_REL_TIME_MIN to protect + operations against possible overflows or handle circular + increments. +**/ + + +#endif /* VIRTUAL_TIME */ + +/////////////////////// End of VIRTUAL_TIME ////////////////////////// + +/////////////////////// DUMMY_OS /////////////////////////// + +#ifdef DUMMY_OS + +/** + Choose between: + - struct timespec + - numeric type (long, .long long, short) +**/ + + +#define FOSA_TIME_TIMESPEC + +typedef struct timespec FOSA_REL_TIME_T_OPAQUE; +typedef struct timespec FOSA_ABS_TIME_T_OPAQUE; + + +/* + +#define FOSA_TIME_NUMERIC +#define FOSA_TIME_BASE 9 // 9 for nanosecods + // 6 for microseconds + // 3 for miliseconds + +typedef long long FOSA_REL_TIME_T_OPAQUE; +typedef unsigned long long FOSA_ABS_TIME_T_OPAQUE; + +*/ + +/** + Possible additions: FOSA_ABS_TIME_MAX, FOSA_ABS_TIME_MIN, + FOSA_REL_TIME_MAX, FOSA_REL_TIME_MIN to protect + operations against possible overflows or handle circular + increments. +**/ + + +#endif /* DUMMY_OS */ + +/////////////////////// End of DUMMY_OS ////////////////////////// + +#endif /* FOSA_OPAQUE_TYPES_TIME_H */ diff --git a/include/fosa_threads_and_signals.h b/include/fosa_threads_and_signals.h index b2d685f..8f829c1 100644 --- a/include/fosa_threads_and_signals.h +++ b/include/fosa_threads_and_signals.h @@ -489,7 +489,7 @@ int fosa_signal_queue * * This function behaves the same as fosa_signal_wait(), except that * the suspension time is limited to the time interval specified in - * the timespec structure referenced by timeout. + * the fosa_rel_time_t value referenced by timeout. * * Returns 0 if successful; otherwise it returns an error code: * FOSA_EINVAL: the array contains one or more values which are not @@ -503,7 +503,7 @@ int fosa_signal_queue **/ 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_info_t *info, const fosa_rel_time_t *timeout); /*}*/ diff --git a/include/fosa_time.h b/include/fosa_time.h index 6c83250..6dee321 100644 --- a/include/fosa_time.h +++ b/include/fosa_time.h @@ -1,23 +1,96 @@ -/* -** fosa_time.h -** -** Made by Miguel marciano -** Login -** -** Started on Mon Jan 21 20:01:04 2008 Miguel marciano -** Last update Mon Jan 21 20:01:04 2008 Miguel marciano -*/ +//---------------------------------------------------------------------- +// 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.h +//============================================== +// ******** ****** ******** ********** +// **///// /** ** **////// /** /** +// ** /** ** /** /** /** +// ******* /** ** /********* /********** +// **//// /** ** ////////** /**//////** +// ** /** ** /** /** /** +// ** /** ** ******** /** /** +// // /******/ //////// // // +// +// FOSA(Frescor Operating System Adaptation layer) +//================================================ #ifndef FOSA_TIME_H_ #define FOSA_TIME_H_ +#include "fosa_types.h" + FOSA_CPP_BEGIN_DECLS +/* Arithmetic, comparison and conversion functions are defined in + subincludes */ + +#ifdef FOSA_TIME_NUMERIC + +#include "fosa_time_numeric.h" + +#endif + +#ifdef FOSA_TIME_TIMESPEC + +#include "fosa_time_timespec.h" + +#endif + + /** * fosa_eat() * * Eat some time using system clock facilities **/ -void inline fosa_eat(const struct timespec *cpu_time); +void fosa_eat(const fosa_rel_time_t *cpu_time); FOSA_CPP_END_DECLS diff --git a/include/fosa_time_numeric.h b/include/fosa_time_numeric.h new file mode 100644 index 0000000..d78f7b9 --- /dev/null +++ b/include/fosa_time_numeric.h @@ -0,0 +1,378 @@ +//---------------------------------------------------------------------- +// 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_numeric.h +//============================================== +// ******** ****** ******** ********** +// **///// /** ** **////// /** /** +// ** /** ** /** /** /** +// ******* /** ** /********* /********** +// **//// /** ** ////////** /**//////** +// ** /** ** /** /** /** +// ** /** ** ******** /** /** +// // /******/ //////// // // +// +// FOSA(Frescor Operating System Adaptation layer) +//================================================ +#ifndef FOSA_TIME_NUMERIC_H_ +#define FOSA_TIME_NUMERIC_H_ + +#include "fosa_types.h" + +/***************************************/ +/* C O N V E R S I O N M A C R O S */ +/***************************************/ + +#if FOSA_TIME_BASE == 9 /* nanoseconds */ + +#define fosa_time_to_msec(time) (time) / 1000000 +#define msec_to_fosa_time(msec) (msec) * 1000000 +#define fosa_time_to_usec(time) (time) / 1000 +#define usec_to_fosa_time(usec) (usec) * 1000 + +#define timespec_to_fosa_time(time_type, tspec) ((time_type) (tspec).tv_sec) * 1000000000 + (time_type) (tspec).tv_nsec + +#define fosa_time_to_timespec(tspec, time) \ +do { \ + (tspec).tv_sec = (time) / 1000000000; \ + (tspec).tv_nsec = (time) % 1000000000; \ +} while(0) + + + +#endif + +#if FOSA_TIME_BASE == 6 /* microseconds */ + +#define fosa_time_to_msec(time) (time) / 1000 +#define msec_to_fosa_time(msec) (msec) * 1000 +#define fosa_time_to_usec(time) (time) +#define usec_to_fosa_time(usec) (usec) + +#define timespec_to_fosa_time(time_type, tspec) ( (time_type) (tspec).tv_sec) * 1000000 + (time_type) (tspec).tv_nsec/1000 + +#define fosa_time_to_timespec(tspec,time) \ +do { \ + (tspec).tv_sec = (time) / 1000000; \ + (tspec).tv_nsec = ( (time) % 1000000) * 1000; \ +} while(0) + + +#endif + +#if FOSA_TIME_BASE == 3 /* miliseconds */ + +#define fosa_time_to_msec(time) (time) +#define msec_to_fosa_time(msec) (msec) +#define fosa_time_to_usec(time) (time) * 1000 +#define usec_to_fosa_time(usec) (usec) / 1000 + +#define timespec_to_fosa_time(time_type, tspec) ( (time_type) (tspec).tv_sec) * 1000 + (time_type) (tspec).tv_nsec/1000000 + +#define fosa_time_to_timespec(tspec, time) \ +do { \ + (tspec).tv_sec = (time) / 1000; \ + (tspec).tv_nsec = ( (time) % 1000) * 1000000; \ +} while(0) + + +#endif + + + +/* Arithmetic and comparison */ +/*****************************/ +static inline fosa_abs_time_t fosa_abs_time_incr(fosa_abs_time_t base, fosa_rel_time_t interval) +{ + fosa_abs_time_t result; + + result = base + interval; + + return result; +} + + +// --------------------------------------------------------- + +static inline fosa_abs_time_t fosa_abs_time_decr(fosa_abs_time_t base, fosa_rel_time_t interval) +{ + fosa_abs_time_t result; + + result = base - interval; + + return result; +} + + + +// --------------------------------------------------------- + +static inline fosa_rel_time_t fosa_abs_time_extract_interval(fosa_abs_time_t past, fosa_abs_time_t future) +{ + fosa_rel_time_t result; + + result = future - past; + + return result; +} + + +// --------------------------------------------------------- + +static inline fosa_rel_time_t fosa_rel_time_add(fosa_rel_time_t relt1, fosa_rel_time_t relt2) +{ + fosa_rel_time_t result; + + result = relt1 + relt2; + + return result; +} + + + +// --------------------------------------------------------- + +static inline fosa_rel_time_t fosa_rel_time_decr(fosa_rel_time_t total, fosa_rel_time_t part) +{ + fosa_rel_time_t result; + + result = total - part; + + return result; +} + + +/* Comparison */ +/**************/ +static inline bool fosa_abs_time_smaller(fosa_abs_time_t abst1, fosa_abs_time_t abst2) +{ + bool result; + + result = abst1 < abst2; + + return result; +} + +// ----------------------------------------------------------- + +static inline bool fosa_rel_time_smaller(fosa_rel_time_t relt1, fosa_rel_time_t relt2) +{ + bool result; + + result = relt1 < relt2; + + return result; +} + + +// ----------------------------------------------------------- + +static inline bool fosa_abs_time_smaller_or_equal(fosa_abs_time_t abst1, fosa_abs_time_t abst2) +{ + bool result; + + result = abst1 <= abst2; + + return result; +} + + +// ----------------------------------------------------------- + +static inline bool fosa_rel_time_smaller_or_equal(fosa_rel_time_t relt1, fosa_rel_time_t relt2) +{ + bool result; + + result = relt1 <= relt2; + + return result; +} + + +/* Conversion */ +/**************/ +static inline fosa_rel_time_t fosa_msec_to_rel_time(long msec) +{ + fosa_rel_time_t result; + + result = msec_to_fosa_time( (fosa_rel_time_t) msec ); + + return result; +} + +// -------------------------------------------------- + +static inline long fosa_rel_time_to_msec(fosa_rel_time_t relt) +{ + long result; + + result = fosa_time_to_msec(relt); + + return result; +} + + +// -------------------------------------------------- + + +static inline fosa_rel_time_t fosa_msec_to_abs_time(long msec) +{ + fosa_abs_time_t result; + + result = msec_to_fosa_time( (fosa_abs_time_t) msec); + + return result; +} + +// -------------------------------------------------- + +static inline long fosa_abs_time_to_msec(fosa_abs_time_t abst) +{ + long result; + + result = fosa_time_to_msec(abst); + + return result; +} + + +// -------------------------------------------------- + +static inline fosa_rel_time_t fosa_usec_to_rel_time(long usec) +{ + fosa_rel_time_t result; + + result = usec_to_fosa_time((fosa_rel_time_t ) usec); + + return result; +} + +// -------------------------------------------------- + +static inline long fosa_rel_time_to_usec(fosa_rel_time_t relt) +{ + long result; + + result = fosa_time_to_usec(relt); + + return result; +} + + +// -------------------------------------------------- + +static inline fosa_abs_time_t fosa_usec_to_abs_time(long usec) +{ + fosa_abs_time_t result; + + result = usec_to_fosa_time( (fosa_abs_time_t) usec); + + return result; +} + +// -------------------------------------------------- + +static inline long fosa_abs_time_to_usec(fosa_abs_time_t abst) +{ + long result; + + result = fosa_time_to_usec(abst); + + return result; +} + + +// -------------------------------------------------- + +static inline fosa_rel_time_t fosa_timespec_to_rel_time(struct timespec time_tspec) +{ + fosa_rel_time_t result; + + result = timespec_to_fosa_time(fosa_rel_time_t, time_tspec); + + return result; +} + +// -------------------------------------------------- + +static inline struct timespec fosa_rel_time_to_timespec(fosa_rel_time_t relt) +{ + struct timespec result; + + fosa_time_to_timespec(result, relt); + + return result; +} + +// -------------------------------------------------- + +static inline fosa_abs_time_t fosa_timespec_to_abs_time(struct timespec time_tspec) +{ + fosa_abs_time_t result; + + result = timespec_to_fosa_time(fosa_abs_time_t, time_tspec); + + return result; +} + +// -------------------------------------------------- + +static inline struct timespec fosa_abs_time_to_timespec(fosa_abs_time_t abst) +{ + struct timespec result; + + fosa_time_to_timespec(result, abst); + + return result; +} + + +#endif /* !FOSA_TIME_H_ */ diff --git a/include/fosa_time_timespec.h b/include/fosa_time_timespec.h new file mode 100644 index 0000000..4d5f2b5 --- /dev/null +++ b/include/fosa_time_timespec.h @@ -0,0 +1,391 @@ +//---------------------------------------------------------------------- +// 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_timespec.h +//============================================== +// ******** ****** ******** ********** +// **///// /** ** **////// /** /** +// ** /** ** /** /** /** +// ******* /** ** /********* /********** +// **//// /** ** ////////** /**//////** +// ** /** ** /** /** /** +// ** /** ** ******** /** /** +// // /******/ //////// // // +// +// FOSA(Frescor Operating System Adaptation layer) +//================================================ +#ifndef FOSA_TIME_TIMESPEC_H_ +#define FOSA_TIME_TIMESPEC_H_ + + +/**********************************/ +/* T I M E S P E C M A C R O S */ +/**********************************/ + +#define add_timespec(sum, t1, t2) \ +do { \ + (sum).tv_sec = (t1).tv_sec + (t2).tv_sec; \ + (sum).tv_nsec = (t1).tv_nsec + (t2).tv_nsec; \ + if ((sum).tv_nsec >= 1000000000) \ + { \ + (sum).tv_sec++; \ + (sum).tv_nsec -= 1000000000; \ + } \ +} while(0) + + +// ------------------------------------------------------------------- + +/* TODO: Test that for past > future we obtain a correct negative + * interval */ +#define substract_timespec(diff, base, interval) \ +do { \ + if ((base).tv_nsec < (interval).tv_nsec) \ + { \ + (diff).tv_sec = (base).tv_sec - (interval).tv_sec + 1; \ + (diff).tv_nsec = (base).tv_nsec + 1000000000 - (interval).tv_nsec; \ + } \ + else \ + { \ + (diff).tv_sec = (base).tv_sec - (interval).tv_sec; \ + (diff).tv_nsec = (base).tv_nsec - (interval).tv_nsec; \ + } \ +} while(0) + + +// --------------------------------------------------------- + +#define smaller_timespec(t1, t2) \ + ((t1).tv_sec < (t2).tv_sec || ((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec < (t2).tv_nsec) ) + +// --------------------------------------------------------- + +#define smaller_or_equal_timespec(t1, t2) \ + ((t1).tv_sec < (t2).tv_sec || ((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec <= (t2).tv_nsec) ) + +// --------------------------------------------------------- + +#define msec_to_timespec(tspec, msec) \ +do { \ + if ((msec) >= 1000) { \ + (tspec).tv_sec = (msec)/1000; \ + (tspec).tv_nsec = ((msec) % 1000) * 1000000; \ + } else { \ + (tspec).tv_sec = 0; \ + (tspec).tv_nsec = (msec) * 1000000; \ + } \ +} while (0) + +// --------------------------------------------------------- + +#define timespec_to_msec(t1) \ + ( ((t1).tv_sec % 2147482) * 1000 + (t1).tv_nsec/1000000 ) + + +// --------------------------------------------------------- + +#define usec_to_timespec(tspec, usec) \ +do { \ + if ((usec) >= 1000000) { \ + (tspec).tv_sec = (usec)/1000000; \ + (tspec).tv_nsec = ((usec) % 1000000) * 1000; \ + } else { \ + (tspec).tv_sec = 0; \ + (tspec).tv_nsec = (usec) * 1000; \ + } \ +} while(0) + +// --------------------------------------------------------- + +#define timespec_to_usec(t1) \ + ( ((t1).tv_sec % 2148) * 1000000 + (t1).tv_nsec/1000 ) + + + +/***************************************/ +/* T I M E S P E C F U N C T I O N S */ +/***************************************/ + + +static inline fosa_abs_time_t fosa_abs_time_incr(fosa_abs_time_t base, fosa_rel_time_t interval) +{ + fosa_abs_time_t result; + + add_timespec(result, base, interval); + + return result; +} + + +// --------------------------------------------------------- + +static inline fosa_abs_time_t fosa_abs_time_decr(fosa_abs_time_t base, fosa_rel_time_t interval) +{ + fosa_abs_time_t result; + + + + substract_timespec(result, base, interval); + + return result; +} + + + +// --------------------------------------------------------- + +static inline fosa_rel_time_t fosa_abs_time_extract_interval(fosa_abs_time_t past, fosa_abs_time_t future) +{ + fosa_rel_time_t result; + + substract_timespec(result, future, past); + + return result; +} + + +// --------------------------------------------------------- + +static inline fosa_rel_time_t fosa_rel_time_add(fosa_rel_time_t relt1, fosa_rel_time_t relt2) +{ + fosa_rel_time_t result; + + add_timespec(result, relt1, relt2); + + return result; +} + + + +// --------------------------------------------------------- + +static inline fosa_rel_time_t fosa_rel_time_decr(fosa_rel_time_t total, fosa_rel_time_t part) +{ + fosa_rel_time_t result; + + substract_timespec(result, total, part); + + return result; +} + + +/* Comparison */ +/**************/ +static inline bool fosa_abs_time_smaller(fosa_abs_time_t abst1, fosa_abs_time_t abst2) +{ + bool result; + + result = smaller_timespec(abst1, abst2); + + return result; +} + +// ----------------------------------------------------------- + +static inline bool fosa_rel_time_smaller(fosa_rel_time_t relt1, fosa_rel_time_t relt2) +{ + bool result; + + result = smaller_timespec(relt1, relt2); + + return result; +} + + +// ----------------------------------------------------------- + +static inline bool fosa_abs_time_smaller_or_equal(fosa_abs_time_t abst1, fosa_abs_time_t abst2) +{ + bool result; + + result = smaller_or_equal_timespec(abst1, abst2); + + return result; +} + + +// ----------------------------------------------------------- + +static inline bool fosa_rel_time_smaller_or_equal(fosa_rel_time_t relt1, fosa_rel_time_t relt2) +{ + bool result; + + result = smaller_or_equal_timespec(relt1, relt2); + + return result; +} + + +/* Conversion */ +/**************/ +static inline fosa_rel_time_t fosa_msec_to_rel_time(long msec) +{ + fosa_rel_time_t result; + + msec_to_timespec(result, msec); + + return result; + + +} + +// -------------------------------------------------- + +static inline long fosa_rel_time_to_msec(fosa_rel_time_t relt) +{ + long result; + + result = timespec_to_msec(relt); + + return result; +} + + +// -------------------------------------------------- + + +static inline fosa_rel_time_t fosa_msec_to_abs_time(long msec) +{ + fosa_abs_time_t result; + + msec_to_timespec(result, msec); + + return result; +} + +// -------------------------------------------------- + +static inline long fosa_abs_time_to_msec(fosa_abs_time_t abst) +{ + long result; + + result = timespec_to_msec(abst); + + return result; +} + + +// -------------------------------------------------- + +static inline fosa_rel_time_t fosa_usec_to_rel_time(long usec) +{ + fosa_rel_time_t result; + + usec_to_timespec(result, usec); + + return result; +} + +// -------------------------------------------------- + +static inline long fosa_rel_time_to_usec(fosa_rel_time_t relt) +{ + long result; + + result = timespec_to_usec(relt); + + return result; +} + + +// -------------------------------------------------- + +static inline fosa_abs_time_t fosa_usec_to_abs_time(long usec) +{ + fosa_abs_time_t result; + + usec_to_timespec(result, usec); + + return result; +} + +// -------------------------------------------------- + +static inline long fosa_abs_time_to_usec(fosa_abs_time_t abst) +{ + long result; + + result = timespec_to_usec(abst); + + return result; +} + + +// -------------------------------------------------- + +static inline fosa_rel_time_t fosa_timespec_to_rel_time(struct timespec time_tspec) +{ + return (fosa_rel_time_t) time_tspec; +} + +// -------------------------------------------------- + +static inline struct timespec fosa_rel_time_to_timespec(fosa_rel_time_t relt) +{ + return (struct timespec) relt; +} + +// -------------------------------------------------- + +static inline fosa_abs_time_t fosa_timespec_to_abs_time(struct timespec time_tspec) +{ + return (fosa_abs_time_t) time_tspec; +} + +// -------------------------------------------------- + +static inline struct timespec fosa_abs_time_to_timespec(fosa_abs_time_t abst) +{ + return (struct timespec) abst; +} + + +#endif /* !FOSA_TIME_TIMESPEC_H_ */ diff --git a/include/fosa_types.h b/include/fosa_types.h index 3968aae..ab31625 100644 --- a/include/fosa_types.h +++ b/include/fosa_types.h @@ -118,6 +118,10 @@ typedef union {int sival_int; void * sival_ptr; } fosa_signal_info_t; **/ // identifier of a clock // either a real-time clock or a cpu-time clock + +typedef FOSA_REL_TIME_T_OPAQUE fosa_rel_time_t; +typedef FOSA_ABS_TIME_T_OPAQUE fosa_abs_time_t; + typedef FOSA_CLOCK_ID_T_OPAQUE fosa_clock_id_t; #define FOSA_SYSTEM_CLOCK FOSA_SYSTEM_CLOCK_OPAQUE @@ -324,66 +328,66 @@ typedef struct { void (*new_thread) (void * sched_data, fosa_thread_id_t thread, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); void (*thread_terminate) (void * sched_data, fosa_thread_id_t thread, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); void (*thread_ready) (void * sched_data, fosa_thread_id_t thread, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); void (*thread_block) (void * sched_data, fosa_thread_id_t thread, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); //void (*thread_yield) (void * sched_data, // fosa_thread_id_t thread, // fosa_ads_actions_t * actions, - // struct timespec *current_time); + // fosa_abs_time_t *current_time); void (*change_sched_param_thread) (void * sched_data, fosa_thread_id_t thread, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); //void msg_from_scheduler(void * sched_data, // fosa_ads_scheduler_id_t scheduler_id, // const void * msg, size_t msg_size, // fosa_ads_actions_t * actions, - // struct timespec *current_time); + // fosa_bas_time_t *current_time); //void (*explicit_call) (void * sched_data, // fosa_thread_id_t thread, // int user_event_code, // fosa_ads_actions_t * actions, - // struct timespec *current_time); + // fosa_abs_time_t *current_time); void (*explicit_call_with_data) (void * sched_data, fosa_thread_id_t thread, const void * msg, size_t msg_size, void *reply, size_t *reply_size, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); void (*notification_for_thread) (void * sched_data, fosa_thread_id_t thread, fosa_clock_id_t clock, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); void (*timeout) (void * sched_data, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); void (*signal) (void * sched_data, fosa_signal_t signal, fosa_signal_info_t siginfo, fosa_ads_actions_t * actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); //void (*priority_inherit) (void * sched_data, // fosa_thread_id_t thread, // int sched_priority, // fosa_ads_actions_t * actions, - // struct timespec *current_time); + // fosa_abs_time_t *current_time); //void (*priority_uninherit) (void * sched_data, // fosa_thread_id_t thread, // int sched_priority, // fosa_ads_actions_t * actions, - // struct timespec *current_time); + // fosa_abs_time_t *current_time); void (*appsched_error) (void * sched_data, fosa_thread_id_t thread, fosa_ads_error_cause_t cause, diff --git a/include/timespec_operations.h b/include/timespec_operations.h deleted file mode 100644 index 8788f70..0000000 --- a/include/timespec_operations.h +++ /dev/null @@ -1,273 +0,0 @@ -// ----------------------------------------------------------------------- -// Copyright (C) 2006 - 2007 FRESCOR consortium partners: -// -// Universidad de Cantabria, SPAIN -// University of York, UK -// Scuola Superiore Sant'Anna, ITALY -// Kaiserslautern University, GERMANY -// Univ. Politécnica 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 for a link to partners' websites -// -// 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 -// -// FSF API web pages: http://marte.unican.es/fsf/docs -// http://shark.sssup.it/contrib/first/docs/ -// -// This file is part of FRSH API -// -// FRSH API is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2, or (at your option) -// any later version. -// -// FRSH API 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 -// distributed with FRSH API; see file COPYING. If not, write to the -// Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. -// -// As a special exception, if you include this header file into source -// files to be compiled, this header file does not by itself cause -// the resulting executable 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 General -// Public License. -// ----------------------------------------------------------------------- -/*----------------------------------------------------------------------- - * V1.0 Dec 2001 - * - * 't i m e s p e c _ o p e r a t i o n s' - * - * H - * - * File 'timespec_operations.h' by MAR. - * (july 2002) transformed into macros by Jul. - * Some basic operations with the type 'timespec'. - * - * ---------------------------------------------------------------------- - * Copyright (C) 2001 Universidad de Cantabria, SPAIN - * - * Authors: Mario Aldea Rivas aldeam@ctr.unican.es - * Michael Gonzalez Harbour mgh@ctr.unican.es - * - * MaRTE OS is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2, or (at your option) any - * later version. - * - * MaRTE OS 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 - * distributed with MaRTE OS; see file COPYING. If not, write to the - * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * As a special exception, if you link this unit with other files to - * produce an executable, this unit does not by itself cause the - * resulting executable 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. - * - *---------------------------------------------------------------------------*/ -// 16-Jul-2007 SANGORRIN corrections to msec_addto_timespec and msec2timespec -// 23-Jul-2007 SANGORRIN moved t2d and d2t from frsh_time_operations -// (TODO: test for __ALL__ the functions) -// ----------------------------------------------------------------------- - -#ifndef _MARTE_MISC_TIMESPEC_OPERATIONS_H_ -#define _MARTE_MISC_TIMESPEC_OPERATIONS_H_ - -/** - * @file timespec_operations.h - **/ - -#include // for timespec -#include // for memset - -FOSA_CPP_BEGIN_DECLS - -#define smaller_timespec(t1, t2) \ - ( \ - (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \ - (t1)->tv_nsec < (t2)->tv_nsec) \ - ) - -#define smaller_or_equal_timespec(t1, t2) \ - ( \ - (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \ - (t1)->tv_nsec <= (t2)->tv_nsec) \ - ) - -#define incr_timespec(t1, t2) \ -do { \ - (t1)->tv_sec += (t2)->tv_sec; \ - (t1)->tv_nsec += (t2)->tv_nsec; \ - if ((t1)->tv_nsec >= 1000000000) { \ - (t1)->tv_sec ++; \ - (t1)->tv_nsec -= 1000000000; \ - } \ -} while (0) - -#define decr_timespec(t1, t2) \ -do { \ - if ((t1)->tv_nsec < (t2)->tv_nsec) { \ - (t1)->tv_sec -= (t2)->tv_sec + 1; \ - (t1)->tv_nsec = (t1)->tv_nsec + 1000000000 - (t2)->tv_nsec; \ - } else { \ - (t1)->tv_sec -= (t2)->tv_sec; \ - (t1)->tv_nsec -= (t2)->tv_nsec; \ - } \ -} while (0) - -#define add_timespec( sum , t1 , t2 ) \ -do { \ - (sum)->tv_sec = (t1)->tv_sec + (t2)->tv_sec; \ - (sum)->tv_nsec = (t1)->tv_nsec + (t2)->tv_nsec; \ - if ((sum)->tv_nsec >= 1000000000) { \ - (sum)->tv_sec ++; \ - (sum)->tv_nsec -= 1000000000; \ - } \ -} while (0) - -#define float_to_timespec( f1 , t1 ) \ -( \ - (t1)->tv_sec = (int)(f1), \ - (t1)->tv_nsec = (int)(((f1)-(float)((t1)->tv_sec))*1000000000.0), \ - (t1) \ -) - -#define float_to_timespec_value(f1, t1) \ -( \ - (t1).tv_sec = (int)(f1), \ - (t1).tv_nsec = (int)(((f1)-(float)((t1).tv_sec))*1000000000.0), \ - (t1) \ -) - -//---------------// -// msec2timespec // -//---------------// - -static inline struct timespec msec2timespec(long msec) -{ - struct timespec result = {-1, -1}; - - if (msec >= 1000) { - result.tv_sec = msec/1000; - result.tv_nsec = (msec % 1000) * 1000000; - } else { - result.tv_sec = 0; - result.tv_nsec = msec * 1000000; - } - - return result; -} - -static inline long timespec2msec(const struct timespec *timespec) -{ - - return (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000; -} - - -#define HOURS_IN_MSECS 3600000 -#define MINUTES_IN_MSECS 60000 - -#define HOURS_IN_TS 1000000 -#define MINUTES_IN_TS 100000 - -static inline long timespec2msects(const struct timespec *timespec) -{ - long msec_total = -1; - long minutes = -1; - long hours = -1; - - long remainder_msecs = -1; - long timestamp = -1; - - msec_total = (timespec->tv_sec % 2147482) * 1000 + timespec->tv_nsec/1000000; - - hours = msec_total / HOURS_IN_MSECS; - minutes = (msec_total % HOURS_IN_MSECS) / MINUTES_IN_MSECS; - remainder_msecs = ( (msec_total % HOURS_IN_MSECS) % MINUTES_IN_MSECS); - - timestamp = hours*HOURS_IN_TS + minutes*MINUTES_IN_TS + remainder_msecs; - - return timestamp; -} - - -//------------------------// -// timespec_lessthan_msec // -//------------------------// - -static inline int timespec_lessthan_msec(struct timespec *timespec, long msec) -{ - struct timespec msec_timespec = {0, 0}; - - msec_timespec = msec2timespec(msec); - return smaller_timespec(timespec, &msec_timespec); -} - -//---------------------// -// msec_addto_timespec // -//---------------------// - -static inline void msec_addto_timespec(long msec, struct timespec *timespec) -{ - struct timespec msec_timespec = {0, 0}; - - msec_timespec = msec2timespec(msec); - incr_timespec(timespec, &msec_timespec); -} - -//--------------------------// -// t2d (timespec to double) // -//--------------------------// - -static inline double t2d(struct timespec time) -{ - return time.tv_nsec*0.000000001 + (double)time.tv_sec; -} - -//--------------------------// -// d2t (double to timespec) // -//--------------------------// - -static inline struct timespec d2t(double time) -{ - struct timespec tmp; - - tmp.tv_sec = (long) time; - tmp.tv_nsec = (long)((time - (double)tmp.tv_sec) * 1000000000); - - return tmp; -} - -FOSA_CPP_BEGIN_DECLS - -#endif /* _MARTE_MISC_TIMESPEC_OPERATIONS_H_ */ diff --git a/src_marte/Makefile b/src_marte/Makefile index 5923648..e77bfee 100644 --- a/src_marte/Makefile +++ b/src_marte/Makefile @@ -8,7 +8,7 @@ CFLAGS += -I$(FOSA_PATH)/src_marte SRCS := $(wildcard *.c) OBJS := $(patsubst %.c,%.o,$(wildcard *.c)) LIBFOSA_SRCS := $(wildcard *.c) -LIBFOSA_HDRS := $(wildcard $(FOSA_PATH)/include/*.h) $(wildcard *.h) $(wildcard $(FRSH_PATH)/include/*.h) +LIBFOSA_HDRS := $(wildcard $(FOSA_PATH)/include/*.h) $(wildcard *.h) objs: $(OBJS) diff --git a/src_marte/fosa_app_def_sched.c b/src_marte/fosa_app_def_sched.c index 757f5be..85977e1 100644 --- a/src_marte/fosa_app_def_sched.c +++ b/src_marte/fosa_app_def_sched.c @@ -154,7 +154,8 @@ void * scheduler_thread_code(void *arg) { (struct scheduler_thread_data *) arg; void * scheduler_data = sch_thread_data->scheduler_data; posix_appsched_eventset_t event_set; - struct timespec current_time; + fosa_abs_time_t current_time; + struct timespec current_time_tspec; struct explicit_call_info *call_info; clockid_t clk; int err; @@ -232,7 +233,9 @@ void * scheduler_thread_code(void *arg) { // execute pending scheduling actions and wait for next event err=posix_appsched_execute_actions (&(sched_actions.actions),&(sch_thread_data->sch_signal_set), - sched_actions.timeout_ptr,¤t_time,&event); + sched_actions.timeout_ptr,¤t_time_tspec,&event); + + current_time = fosa_timespec_to_abs_time(current_time_tspec); // clear the scheduling actions data structure CHK(posix_appsched_actions_destroy (&(sched_actions.actions))); @@ -944,9 +947,9 @@ int fosa_adsactions_add_suspend( 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; } @@ -983,7 +986,7 @@ 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) { #ifdef FULL_ERROR_CHECKING // check errors diff --git a/src_marte/fosa_clocks_and_timers.c b/src_marte/fosa_clocks_and_timers.c index 53fac89..f518990 100644 --- a/src_marte/fosa_clocks_and_timers.c +++ b/src_marte/fosa_clocks_and_timers.c @@ -68,6 +68,7 @@ #include #include +#include "fosa_time.h" #include "fosa_clocks_and_timers.h" static const struct timespec zero_time={0,0}; @@ -94,9 +95,15 @@ static const struct timespec zero_time={0,0}; * notify it to the system console and then terminate the FRSH * implementation and dependant applications **/ -int fosa_clock_get_time(fosa_clock_id_t clockid, struct timespec *current_time) +int fosa_clock_get_time(fosa_clock_id_t clockid, fosa_abs_time_t *current_time) { - return clock_gettime(clockid,current_time); + struct timespec current_time_tspec; + int ret_value; + + ret_value = clock_gettime(clockid, ¤t_time_tspec); + *current_time = fosa_timespec_to_abs_time(current_time_tspec); + + return ret_value; } @@ -218,22 +225,20 @@ int fosa_timer_delete(fosa_timer_id_t timerid) return timer_delete(timerid); } + /** - * fosa_timer_arm() + * fosa_rel_timer_arm() * - * Arm a timer + * Arm a timer with a relative time interval * * The timer specified by timer is armed and starts counting time. * - * If abstime is true, the value pointed to by value is the absolute - * time at which the timer will expire. If value specifies a time instant - * in the past, the timer expires immediately. + * The value pointed to by value is the relative interval that must + * elapse for the timer to expire. Negative values cause the timer to + * expire immediately. * - * If abstime is false, the value pointed to by value is the relative interval - * that must elapse for the timer to expire. - * - * In both cases, absolute or relative, the time is measured with the clock - * associated with the timer when it was created. + * The time is measured with the clock associated with the timer when + * it was created. * * If the timer was already armed, the previous time or interval is discarded * and the timer is rearmed with the new value. @@ -241,32 +246,68 @@ int fosa_timer_delete(fosa_timer_id_t timerid) * When the timer expires, it is disarmed. * * Returns 0 if successful; otherwise it returns an error code: - * EINVAL: the value of timerid or value is invalid + * FOSA_EINVAL: the value of timerid or value is invalid * * Alternatively, in case of error the implementation is allowed to * notify it to the system console and then terminate the FRSH * implementation and dependant applications **/ -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) { - int timer_abstime=0; struct itimerspec timer_value; - // set the abstime flag if necessary - if (abstime) { - timer_abstime=TIMER_ABSTIME; - } + // set the timer to the specified value, one shot only + timer_value.it_value= fosa_rel_time_to_timespec(*value); + timer_value.it_interval=zero_time; + + // arm the timer + return timer_settime(timerid, 0, &timer_value,NULL); +} + + +/** + * fosa_abs_timer_arm() + * + * Arm a timer that will expire in an absolute time instant. + * + * The timer specified by timer is armed and starts counting time. + * + * The value pointed to by value is the absolute time at which the + * timer will expire. If value specifies a time instant in the past, + * the timer expires immediately. + * + * The time is measured with the clock associated with the timer when + * it was created. + * + * If the timer was already armed, the previous time or interval is discarded + * and the timer is rearmed with the new value. + * + * When the timer expires, it is disarmed. + * + * Returns 0 if successful; otherwise it returns an error code: + * FOSA_EINVAL: the value of timerid or value is invalid + * + * Alternatively, in case of error the implementation is allowed to + * notify it to the system console and then terminate the FRSH + * implementation and dependant applications + **/ +int fosa_abs_timer_arm + (fosa_timer_id_t timerid, const fosa_abs_time_t *value) +{ + struct itimerspec timer_value; // set the timer to the specified value, one shot only - timer_value.it_value=*value; + timer_value.it_value= fosa_abs_time_to_timespec(*value); timer_value.it_interval=zero_time; // arm the timer - return timer_settime(timerid,timer_abstime,&timer_value,NULL); + return timer_settime(timerid, TIMER_ABSTIME,&timer_value,NULL); } + + + /** * fosa_timer_get_remaining_time() * @@ -286,18 +327,19 @@ int fosa_timer_arm * implementation and dependant applications **/ 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 timer_value; int error_code; - if (remaining_time!=NULL) { - error_code=timer_gettime(timerid,&timer_value); - if (error_code==-1) return errno; - *remaining_time=timer_value.it_value; - } else { + if (remaining_time == NULL) { return EINVAL; } + error_code=timer_gettime(timerid,&timer_value); + if (error_code==-1) return errno; + + *remaining_time = fosa_timespec_to_rel_time(timer_value.it_value); + return 0; } @@ -323,7 +365,7 @@ int fosa_timer_get_remaining_time **/ int fosa_timer_disarm (fosa_timer_id_t timerid, - struct timespec *remaining_time) + fosa_rel_time_t *remaining_time) { struct itimerspec timer_value; int error_code; @@ -331,7 +373,7 @@ int fosa_timer_disarm if (remaining_time!=NULL) { error_code=timer_gettime(timerid,&timer_value); if (error_code==-1) return errno; - *remaining_time=timer_value.it_value; + *remaining_time = fosa_timespec_to_rel_time(timer_value.it_value); } timer_value.it_value=zero_time; timer_value.it_interval=zero_time; diff --git a/src_marte/fosa_mutexes_and_condvars.c b/src_marte/fosa_mutexes_and_condvars.c index e8b4123..eb68db0 100644 --- a/src_marte/fosa_mutexes_and_condvars.c +++ b/src_marte/fosa_mutexes_and_condvars.c @@ -70,7 +70,7 @@ #include - +#include "fosa_time.h" /******************************************************* * Mutexes with priority ceiling @@ -391,7 +391,11 @@ int fosa_cond_wait(fosa_cond_t *cond, fosa_mutex_t *mutex) * then terminate the FRSH implementation and dependant applications **/ int fosa_cond_timedwait(fosa_cond_t *cond, fosa_mutex_t *mutex, - const struct timespec *abstime) + const fosa_abs_time_t *abstime) { - return pthread_cond_timedwait(cond,mutex,abstime); + struct timespec abstime_tspec; + + abstime_tspec = fosa_abs_time_to_timespec(*abstime); + + return pthread_cond_timedwait(cond,mutex, &abstime_tspec); } diff --git a/src_marte/fosa_threads_and_signals.c b/src_marte/fosa_threads_and_signals.c index bb35eff..25f319b 100644 --- a/src_marte/fosa_threads_and_signals.c +++ b/src_marte/fosa_threads_and_signals.c @@ -719,7 +719,7 @@ int fosa_signal_wait **/ 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_info_t *info, const fosa_rel_time_t *timeout) { // the implementation of sigtimedwait is not yet available in MaRTE OS diff --git a/src_marte/fosa_time.c b/src_marte/fosa_time.c index b62a9d6..1cc25a1 100644 --- a/src_marte/fosa_time.c +++ b/src_marte/fosa_time.c @@ -64,44 +64,39 @@ //================================================ #include "fosa.h" -#include -#include -#include -#include /* for incr_timespec */ -#include +#ifdef VIRTUAL_TIME + #include +#endif /** * fosa_eat() * * Eat some time using system clock facilities **/ -#ifdef VIRTUAL_TIME - #include -#endif - -void inline fosa_eat(const struct timespec *cpu_time) +void fosa_eat(const fosa_rel_time_t *cpu_time) { #ifdef VIRTUAL_TIME vt_time_t vt_clock; timespec_2_vtime(cpu_time, vt_clock); vt_use_time((unsigned long long)vt_clock); #else - int err; - clockid_t clock_id; - struct timespec current_time, time_to_go; + 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' - err = pthread_getcpuclockid(pthread_self(), &clock_id); + fosa_thread_get_cputime_clock(fosa_thread_self(), &clock_id); + fosa_clock_get_time(clock_id, ¤t_time); - err = clock_gettime(clock_id, ¤t_time); - add_timespec(&time_to_go, ¤t_time, cpu_time); + time_to_go = fosa_abs_time_incr(current_time, *cpu_time); - while (smaller_timespec(¤t_time, &time_to_go)) { - err = clock_gettime(clock_id, ¤t_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); } #endif } diff --git a/src_marte/tests/test_clock_and_timers/test_clock_and_timers.c b/src_marte/tests/test_clock_and_timers/test_clock_and_timers.c index d745e7a..0451a5e 100644 --- a/src_marte/tests/test_clock_and_timers/test_clock_and_timers.c +++ b/src_marte/tests/test_clock_and_timers/test_clock_and_timers.c @@ -1,9 +1,9 @@ -#include "fosa_threads_and_signals.h" -#include "fosa_clocks_and_timers.h" #include #include #include // for nanosleep +#include "fosa.h" + // TODO: use #include when it works for all architectures #include // for exit in assert @@ -22,8 +22,7 @@ int main () { fosa_signal_t received; fosa_signal_info_t info, info_received; fosa_timer_id_t timerid; - bool abstime = false; - struct timespec timerval; + fosa_rel_time_t timerval; fosa_signal_t set[1]; info.sival_int=69; @@ -32,10 +31,9 @@ int main () { printf("timer created, err=%d\n", err); assert(err == 0); - timerval.tv_sec=1; - timerval.tv_nsec=300000000; + timerval = fosa_msec_to_rel_time(1300); - err = fosa_timer_arm (timerid, abstime, &timerval); + err = fosa_rel_timer_arm (timerid, &timerval); printf("timer armed for 1.3 secs, err=%d\n", err); set[0] = signal; diff --git a/src_marte/tests/test_cpu_clocks/test_cpu_clocks.c b/src_marte/tests/test_cpu_clocks/test_cpu_clocks.c index 2dfd6c5..d9c0ab1 100644 --- a/src_marte/tests/test_cpu_clocks/test_cpu_clocks.c +++ b/src_marte/tests/test_cpu_clocks/test_cpu_clocks.c @@ -1,14 +1,11 @@ -#include "fosa_threads_and_signals.h" -#include "fosa_clocks_and_timers.h" #include #include -#include // for nanosleep #include #include // for exit in assert #include // for memset -#include +#include "fosa.h" /*****************************/ /* D E F I N I T I O N S */ @@ -24,8 +21,8 @@ static void * thread_body(void *thread_arg); -static struct timespec start_execution; -static struct timespec signal_reception; +static fosa_abs_time_t start_execution; +static fosa_abs_time_t signal_reception; int main () { @@ -36,26 +33,14 @@ int main () fosa_signal_t signal_received; fosa_signal_info_t info_programmed, info_received; - struct timespec work_interval = {3, 200000000}; // 3.2 seconds + fosa_rel_time_t work_interval = fosa_msec_to_rel_time(3200); // 3.2 seconds fosa_clock_id_t clockid; fosa_timer_id_t timerid; - struct timespec budget = {-1, -1}; + fosa_rel_time_t budget; + fosa_rel_time_t elapsed_time; fosa_signal_t signal_set[1]; - - - memset(&attr, 0, sizeof(attr) ); - memset(&tid, 0, sizeof(tid) ); - memset(&signal_received, 0, sizeof(signal_received) ); - memset(&info_programmed, 0, sizeof(info_programmed) ); - memset(&info_received, 0, sizeof(info_received) ); - memset(&clockid, 0, sizeof(clockid) ); - memset(&timerid, 0, sizeof(timerid) ); - - memset(&start_execution, 0xFF, sizeof(start_execution) ); - memset(&signal_received, 0xFF, sizeof(signal_received) ); - /* Set the signal mask */ /***********************/ signal_set[0] = SIGNAL_TIMER; @@ -100,9 +85,8 @@ int main () printf("timer created, err=%d\n", err); assert(err == 0); - budget.tv_sec = 2; - budget.tv_nsec = 500000000; - err = fosa_timer_arm(timerid, 0, &budget); + budget = fosa_msec_to_rel_time(2500); + err = fosa_rel_timer_arm(timerid, &budget); printf("timer armed for 2.5 secs, err=%d\n", err); assert(err == 0); @@ -118,13 +102,13 @@ int main () err = fosa_signal_wait(signal_set, 1 ,&signal_received, &info_received); fosa_clock_get_time(FOSA_CLOCK_REALTIME, &signal_reception); - decr_timespec(&signal_reception, &start_execution); + elapsed_time = fosa_abs_time_extract_interval(start_execution, signal_reception); printf("signal received=%d value=%d (42?), err=%d\n", signal_received, info_received.sival_int, err); - printf("Elapsed time between sigwait and timer expiration: %d %d\n", - signal_reception.tv_sec, signal_reception.tv_nsec); + printf("Elapsed time between sigwait and timer expiration: %ld msecs\n", + fosa_rel_time_to_msec(elapsed_time) ); return 0; } @@ -134,32 +118,30 @@ int main () static void * thread_body(void *thread_arg) { - struct timespec before_work_time = {-1, -1}; - struct timespec after_work_time = {-1, -1}; - struct timespec work_interval = {1, 400000000}; // 1.4 seconds + fosa_abs_time_t before_work_time; + fosa_abs_time_t after_work_time; + fosa_rel_time_t work_interval = fosa_msec_to_rel_time(1400); + fosa_rel_time_t elapsed_time; int err; - fosa_clock_get_time(FOSA_CLOCK_REALTIME, &start_execution); while(1) { err = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &before_work_time); assert(err == 0); - printf("Start periodic work at %d, %d\n", - before_work_time.tv_sec, before_work_time.tv_nsec); + printf("Start periodic work at %ld msecs\n", fosa_abs_time_to_msec(before_work_time) ); fosa_eat(&work_interval); err = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_work_time); assert(err == 0); - printf("End periodic work at %d, %d\n", - after_work_time.tv_sec, after_work_time.tv_nsec); + printf("End periodic work at %ld msecs\n", fosa_abs_time_to_msec(after_work_time) ); + elapsed_time = fosa_abs_time_extract_interval(before_work_time, after_work_time); + + printf("Elapsed time: %ld msecs\n", fosa_rel_time_to_msec(elapsed_time) ); - decr_timespec(&after_work_time, &before_work_time); - printf("Elapsed time: %d %d\n", after_work_time.tv_sec, - after_work_time.tv_nsec); } // while return NULL; } diff --git a/src_marte/tests/test_cpu_clocks/test_cpu_clocks_sigwait_from_different_thread.c b/src_marte/tests/test_cpu_clocks/test_cpu_clocks_sigwait_from_different_thread.c index 378004f..254675a 100644 --- a/src_marte/tests/test_cpu_clocks/test_cpu_clocks_sigwait_from_different_thread.c +++ b/src_marte/tests/test_cpu_clocks/test_cpu_clocks_sigwait_from_different_thread.c @@ -1,5 +1,3 @@ -#include "fosa_threads_and_signals.h" -#include "fosa_clocks_and_timers.h" #include #include #include // for nanosleep @@ -7,8 +5,8 @@ #include #include // for exit in assert #include // for memset -#include +#include "fosa.h" /*****************************/ /* D E F I N I T I O N S */ @@ -26,8 +24,8 @@ static void * thread_body(void *thread_arg); /*************************************/ /* S T A T I C V A R I A B L E S */ /*************************************/ -static struct timespec start_execution; -static struct timespec signal_reception; +static fosa_abs_time_t start_execution; +static fosa_abs_time_t signal_reception; int main () { @@ -39,20 +37,11 @@ int main () fosa_signal_t signal_received; fosa_signal_info_t info_received; - struct timespec work_interval = {3, 200000000}; // 3.2 seconds + fosa_rel_time_t work_interval = fosa_msec_to_rel_time(3200); + fosa_rel_time_t elapsed_time; fosa_signal_t signal_set[1]; - - - memset(&attr, 0, sizeof(attr) ); - memset(&tid, 0, sizeof(tid) ); - memset(&signal_received, 0, sizeof(signal_received) ); - memset(&info_received, 0, sizeof(info_received) ); - - memset(&start_execution, 0xFF, sizeof(start_execution) ); - memset(&signal_received, 0xFF, sizeof(signal_received) ); - /* Set the signal mask */ /***********************/ signal_set[0] = SIGNAL_TIMER; @@ -99,13 +88,13 @@ int main () err = fosa_signal_wait(signal_set, 1 ,&signal_received, &info_received); fosa_clock_get_time(FOSA_CLOCK_REALTIME, &signal_reception); - decr_timespec(&signal_reception, &start_execution); + elapsed_time = fosa_abs_time_extract_interval(start_execution, signal_reception); printf("signal received=%d value=%d (42?), err=%d\n", signal_received, info_received.sival_int, err); - printf("Elapsed time between sigwait and timer expiration: %d %d\n", - signal_reception.tv_sec, signal_reception.tv_nsec); + printf("Elapsed time between sigwait and timer expiration: %ld msecs\n", + fosa_rel_time_to_msec(elapsed_time) ); return 0; } @@ -115,22 +104,20 @@ int main () static void * thread_body(void *thread_arg) { - struct timespec before_work_time = {-1, -1}; - struct timespec after_work_time = {-1, -1}; - struct timespec work_interval = {1, 400000000}; // 1.4 seconds + fosa_abs_time_t before_work_time; + fosa_abs_time_t after_work_time; + fosa_rel_time_t work_interval = fosa_msec_to_rel_time(1400); + fosa_clock_id_t clockid; fosa_timer_id_t timerid; - struct timespec budget = {-1, -1}; + fosa_rel_time_t budget; + fosa_rel_time_t elapsed_time; fosa_signal_info_t info_programmed; - - memset(&clockid, 0, sizeof(clockid) ); - memset(&timerid, 0, sizeof(timerid) ); - memset(&info_programmed, 0, sizeof(info_programmed) ); - int err; + /* Get the thread's cputime clock */ /**********************************/ if (fosa_thread_get_cputime_clock(fosa_thread_self(), &clockid) !=0) @@ -145,9 +132,8 @@ static void * thread_body(void *thread_arg) printf("timer created, err=%d\n", err); assert(err == 0); - budget.tv_sec = 2; - budget.tv_nsec = 500000000; - err = fosa_timer_arm(timerid, 0, &budget); + budget = fosa_msec_to_rel_time(2500); + err = fosa_rel_timer_arm(timerid, &budget); printf("timer armed for 2.5 secs, err=%d\n", err); assert(err == 0); @@ -157,20 +143,19 @@ static void * thread_body(void *thread_arg) { err = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &before_work_time); assert(err == 0); - printf("Start periodic work at %d, %d\n", - before_work_time.tv_sec, before_work_time.tv_nsec); + printf("Start periodic work at %ld msecs\n", fosa_abs_time_to_msec(before_work_time) ); fosa_eat(&work_interval); err = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_work_time); assert(err == 0); - printf("End periodic work at %d, %d\n", - after_work_time.tv_sec, after_work_time.tv_nsec); + printf("End periodic work at %ld msecs\n", fosa_abs_time_to_msec(after_work_time) ); + + elapsed_time = fosa_abs_time_extract_interval(before_work_time, after_work_time); + + printf("Elapsed time: %ld msec\n", fosa_rel_time_to_msec(elapsed_time) ); - decr_timespec(&after_work_time, &before_work_time); - printf("Elapsed time: %d %d\n", after_work_time.tv_sec, - after_work_time.tv_nsec); } // while return NULL; diff --git a/src_marte/tests/test_fosa_ads/test_fosa_ads.c b/src_marte/tests/test_fosa_ads/test_fosa_ads.c index 486d7f0..e3a55c2 100644 --- a/src_marte/tests/test_fosa_ads/test_fosa_ads.c +++ b/src_marte/tests/test_fosa_ads/test_fosa_ads.c @@ -82,31 +82,31 @@ static void fosa_callback_new_thread (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_thread_terminate (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_thread_ready (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_thread_block (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_change_sched_param_thread (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_explicit_call_with_data (void *sched_data, @@ -116,26 +116,26 @@ static void fosa_callback_explicit_call_with_data void *reply, size_t *reply_size, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_notification_for_thread (void *sched_data, fosa_thread_id_t thread, fosa_clock_id_t clock, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_timeout (void *sched_data, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_signal (void *sched_data, fosa_signal_t signal, fosa_signal_info_t siginfo, fosa_ads_actions_t *actions, - struct timespec *current_time); + fosa_abs_time_t *current_time); static void fosa_callback_appsched_error (void *sched_data, @@ -202,7 +202,7 @@ int main () { appsched_params_t params; fosa_signal_info_t timer_info; fosa_timer_id_t timerid; - struct timespec timerval; + fosa_rel_time_t timerval; signal_action_t signal_action; @@ -326,17 +326,16 @@ int main () { printf("timer created, err=%d\n", err); assert(err == 0); - timerval.tv_sec = 0; - timerval.tv_nsec = 500000000; + timerval = fosa_msec_to_rel_time(500); - err=fosa_timer_arm(timerid, false, &timerval); + err=fosa_rel_timer_arm(timerid, &timerval); printf("suspend thread 1 in 0.5 secs, err=%d\n", err); assert(err == 0); sleep (5); signal_action.command = ACTIVATE; - err=fosa_timer_arm(timerid, false, &timerval); + err=fosa_rel_timer_arm(timerid, &timerval); printf("activate thread 1 in 0.5 secs, err=%d\n", err); assert(err == 0); @@ -349,7 +348,7 @@ int main () { printf("2e) Cause error\n"); signal_action.command = CAUSE_ERROR; - err=fosa_timer_arm(timerid, false, &timerval); + err=fosa_rel_timer_arm(timerid, &timerval); printf("causing an ERROR callback in 0.5 secs, err=%d\n", err); assert(err == 0); @@ -390,7 +389,7 @@ static void *thread_code (void * arg) char whoami[] = "who am i?"; int reply; size_t reply_size; - struct timespec one_second = {1, 0}; + fosa_rel_time_t one_second = fosa_msec_to_rel_time(1000); printf("THREAD %d - starts\n", (int)arg); for (i=1;i<50;i++) { @@ -448,7 +447,7 @@ static void fosa_callback_new_thread (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { int err; unsigned int i, index; @@ -485,16 +484,17 @@ static void fosa_callback_thread_terminate (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { - struct timespec at_time; + fosa_abs_time_t at_time; int err; printf ("BEGIN CALLBACK: %s \n", __func__); fosa_clock_get_time(FOSA_CLOCK_REALTIME, &at_time); - printf("current time sec=%d nsec=%d\n", at_time.tv_sec, at_time.tv_nsec); - at_time.tv_sec = at_time.tv_sec + 1; + printf("current time %ld msec\n", fosa_abs_time_to_msec(at_time) ); + at_time = fosa_abs_time_incr(at_time, fosa_msec_to_rel_time(1000) ); + err = fosa_adsactions_add_timeout(actions, FOSA_CLOCK_REALTIME, &at_time); printf("put a timeout of one second, err=%d\n", err); @@ -506,7 +506,7 @@ static void fosa_callback_thread_ready (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { printf ("BEGIN CALLBACK: %s \n", __func__); printf ("END CALLBACK: %s \n", __func__); @@ -516,16 +516,16 @@ static void fosa_callback_thread_block (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { int err; - struct timespec at_time; + fosa_abs_time_t at_time; printf ("BEGIN CALLBACK: %s \n", __func__); fosa_clock_get_time(FOSA_CLOCK_REALTIME, &at_time); - printf("current time sec=%d nsec=%d\n", at_time.tv_sec, at_time.tv_nsec); - at_time.tv_sec = at_time.tv_sec + 1; + printf("current time %ld msec\n", fosa_abs_time_to_msec(at_time) ); + at_time = fosa_abs_time_incr(at_time, fosa_msec_to_rel_time(1000) ); err = fosa_adsactions_add_timeout(actions, FOSA_CLOCK_REALTIME, &at_time); printf("put a timeout of one second, err=%d\n", err); @@ -537,7 +537,7 @@ static void fosa_callback_change_sched_param_thread (void *sched_data, fosa_thread_id_t thread, fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { printf ("BEGIN CALLBACK: %s \n", __func__); // HOW DO I KNOW THE REASON IS SETPRIO OR SETSCHEDPARAMS???? @@ -552,7 +552,7 @@ static void fosa_callback_explicit_call_with_data void *reply, size_t *reply_size, fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { printf ("BEGIN CALLBACK: %s \n", __func__); *((int *)reply) = (int)thread; @@ -566,7 +566,7 @@ static void fosa_callback_notification_for_thread fosa_thread_id_t thread, fosa_clock_id_t clock, fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { printf ("BEGIN CALLBACK: %s \n", __func__); printf ("END CALLBACK: %s \n", __func__); @@ -575,11 +575,10 @@ static void fosa_callback_notification_for_thread static void fosa_callback_timeout // WHY NOT WATCHDOG???? (void *sched_data, fosa_ads_actions_t *actions, - struct timespec *current_time) // WHY IS IN OUT and not IN??? + fosa_abs_time_t *current_time) // WHY IS IN OUT and not IN??? { printf ("BEGIN CALLBACK: %s \n", __func__); - printf("current time sec=%d nsec=%d\n", - current_time->tv_sec, current_time->tv_nsec); + printf("current time %ld msec", fosa_abs_time_to_msec(*current_time) ); printf ("END CALLBACK: %s \n", __func__); } @@ -588,7 +587,7 @@ static void fosa_callback_signal fosa_signal_t signal, fosa_signal_info_t siginfo, // HOW DO I KNOW THE ORIGIN (see signal_info type) fosa_ads_actions_t *actions, - struct timespec *current_time) + fosa_abs_time_t *current_time) { int err; signal_action_t *signal_action = (signal_action_t *)siginfo.sival_ptr; diff --git a/src_marte/tests/test_fosa_general/test_fosa.c b/src_marte/tests/test_fosa_general/test_fosa.c index 6851a48..14f78a4 100644 --- a/src_marte/tests/test_fosa_general/test_fosa.c +++ b/src_marte/tests/test_fosa_general/test_fosa.c @@ -50,14 +50,12 @@ // covered by the GNU Public License. // ----------------------------------------------------------------------- -#include "fosa_threads_and_signals.h" -#include "fosa_clocks_and_timers.h" -#include "fosa_mutexes_and_condvars.h" -#include "fosa_app_def_sched.h" #include #include #include // for nanosleep +#include "fosa.h" + void * thread_code(void *arg) { printf("Thread executing\n"); sleep(1); @@ -81,19 +79,19 @@ int main () { printf("--------------------------------------------------\n"); printf("test get_time\n"); - struct timespec current_time; + fosa_abs_time_t current_time; int err; void * obtained; fosa_clock_id_t cpu_clock; err=fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time); - printf("fosa_clock_get_time for CLOCK_REALTIME sec=%d nsec=%d err=%d\n", - current_time.tv_sec, current_time.tv_nsec,err); + printf("fosa_clock_get_time for CLOCK_REALTIME %ld msec err=%d\n", + fosa_rel_time_to_msec(current_time), err); fosa_thread_get_cputime_clock(fosa_thread_self(), &cpu_clock); err=fosa_clock_get_time(cpu_clock, ¤t_time); - printf("fosa_clock_get_time for CPU-time clock sec=%d nsec=%d err=%d\n", - current_time.tv_sec, current_time.tv_nsec,err); + printf("fosa_clock_get_time for CPU-time clock %ld msec err=%d\n", + fosa_rel_time_to_msec(current_time), err); ///////////////////////////////////////////// // Test thread ids, attributes and creation @@ -142,7 +140,7 @@ int main () { fosa_signal_t received; fosa_signal_info_t sigvalue, value_received; - struct timespec timeout; + fosa_rel_time_t timeout; fosa_signal_t sig=FOSA_SIGNAL_MIN+1; fosa_signal_t timer_sig=FOSA_SIGNAL_MIN+3; fosa_signal_t siglist[2]; @@ -150,8 +148,7 @@ int main () { siglist[0]=sig; siglist[1]=timer_sig; - timeout.tv_sec=1; - timeout.tv_nsec=0; + timeout = fosa_msec_to_rel_time(1000); sigvalue.sival_int=55; @@ -177,22 +174,20 @@ int main () { fosa_signal_info_t timer_info; fosa_timer_id_t timerid; - struct timespec timerval, remaining_time; + fosa_rel_time_t timerval, remaining_time; timer_info.sival_int=88; - timerval.tv_sec=1; - timerval.tv_nsec=300000000; + timerval = fosa_msec_to_rel_time(1300); err=fosa_timer_create (FOSA_CLOCK_REALTIME, timer_sig, timer_info,&timerid); printf("timer created, err=%d\n",err); - err=fosa_timer_arm(timerid,false,&timerval); + err=fosa_rel_timer_arm(timerid, &timerval); printf("timer armed for 1.3 secs, err=%d\n",err); fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time); - printf("current time sec=%d nsec=%d\n", - current_time.tv_sec, current_time.tv_nsec); + printf("current time %ld msec\n", fosa_rel_time_to_msec(current_time) ); printf("wait for timer to expire...\n"); siglist[0]=timer_sig; @@ -201,32 +196,29 @@ int main () { err,received,value_received.sival_int); fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time); - printf("current time sec=%d nsec=%d\n", - current_time.tv_sec, current_time.tv_nsec); + printf("current time: %ld msec\n", fosa_rel_time_to_msec(current_time) ); - timerval.tv_sec=6; - timerval.tv_nsec=0; - err=fosa_timer_arm(timerid,false,&timerval); + timerval = fosa_msec_to_rel_time(6000); + err=fosa_rel_timer_arm(timerid, &timerval); printf("timer armed for 6 secs, err=%d\n",err); - timerval.tv_sec=1; + struct timespec timerval_tspec = {1, 0}; printf("sleeping 1 second\n"); - nanosleep(&timerval, NULL); + nanosleep(&timerval_tspec, NULL); err=fosa_timer_get_remaining_time(timerid, &remaining_time); - printf("timer remaining time sec=%d nsec=%d, err=%d\n", - remaining_time.tv_sec, remaining_time.tv_nsec, err); + printf("timer remaining time: %ld msec\n", fosa_rel_time_to_msec(remaining_time) ); printf("sleeping 1 second\n"); - nanosleep(&timerval, NULL); + nanosleep(&timerval_tspec, NULL); err=fosa_timer_disarm(timerid,&remaining_time); - printf("timer disarmed, remaining time sec=%d nsec=%d, err=%d\n", - remaining_time.tv_sec, remaining_time.tv_nsec, err); + printf("timer disarmed, remaining time: %ld msec, err=%d\n", + fosa_rel_time_to_msec(remaining_time), err); err=fosa_timer_get_remaining_time(timerid, &remaining_time); - printf("timer remaining time after disarm (0?) sec=%d nsec=%d, err=%d\n", - remaining_time.tv_sec, remaining_time.tv_nsec, err); + printf("timer remaining time after disarm (0?) %ld msec, err=%d\n", + fosa_rel_time_to_msec(remaining_time), err); fosa_timer_delete(timerid); @@ -317,10 +309,9 @@ int main () { printf("cond broadcast. err=%d\n",err); fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time); - printf("current time sec=%d nsec=%d\n", - current_time.tv_sec, current_time.tv_nsec); + printf("current time %ld msec\n", fosa_abs_time_to_msec(current_time) ); - current_time.tv_sec=current_time.tv_sec+2; + current_time = fosa_abs_time_incr(current_time, fosa_msec_to_rel_time(2000) ); fosa_mutex_lock(&lock); err=fosa_cond_timedwait(&cond,&lock,¤t_time); @@ -328,8 +319,7 @@ int main () { printf("cond timedwait with timeout=2 sec. err=%d\n",err); fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time); - printf("current time sec=%d nsec=%d\n", - current_time.tv_sec, current_time.tv_nsec); + printf("current time %ld msec\n", fosa_abs_time_to_msec(current_time) ); err=fosa_mutex_destroy(&lock); printf("mutex destroyed. err=%d\n",err); diff --git a/src_marte/tests/test_non_local_jump/simple_test_non_local_jump.c b/src_marte/tests/test_non_local_jump/simple_test_non_local_jump.c index 525b213..44abc3b 100644 --- a/src_marte/tests/test_non_local_jump/simple_test_non_local_jump.c +++ b/src_marte/tests/test_non_local_jump/simple_test_non_local_jump.c @@ -66,7 +66,6 @@ //#include #include "fosa.h" -#include "timespec_operations.h" #include "marte_non_local_jmp.h" @@ -161,7 +160,7 @@ int main() // work to be aborted if too long void work() { static int i=0; - struct timespec exec_time={1,0}; // 1 second + fosa_rel_time_t exec_time = fosa_msec_to_rel_time(1000); // 1 second i++; printf("start regular code %d\n",i); @@ -183,9 +182,12 @@ void work() { static void * thread_body(void *thread_arg) { - struct timespec period={2,500000000}; // 2.5 seconds - struct timespec activation_time, old_activation_time; - struct timespec budget ={1,400000000}; // 1.4 seconds + fosa_rel_time_t period = fosa_msec_to_rel_time(2500); + fosa_rel_time_t budget = fosa_msec_to_rel_time(1400); + fosa_abs_time_t activation_time, after_activation_time; + fosa_rel_time_t elapsed_time; + struct timespec activation_time_tspec; + fosa_timer_id_t timerid; fosa_clock_id_t clockid; budget_timer_info_t timerinfo; @@ -198,58 +200,59 @@ static void * thread_body(void *thread_arg) fosa_clock_get_time(FOSA_CLOCK_REALTIME,&activation_time); if (fosa_thread_get_cputime_clock(timerinfo.tid,&clockid) !=0) { - error_status=RT_ERROR_TIMER; - pthread_exit ( (void*)&error_status); + error_status=RT_ERROR_TIMER; + pthread_exit ( (void*)&error_status); } // create budget timer siginfo.sival_ptr=(void *)(&timerinfo); if (fosa_timer_create (clockid,BUDGET_OVERRUN_SIGNAL,siginfo,&timerid) - != 0) - { - error_status=RT_ERROR_TIMER; - pthread_exit ( (void*)&error_status); - } + != 0) + { + error_status=RT_ERROR_TIMER; + pthread_exit ( (void*)&error_status); + } printf("Start periodic thread body\n"); // main loop while(1) { - // set the budget timer - if (fosa_timer_arm(timerid, false, &budget) != 0) { - error_status=RT_ERROR_TIMER; - pthread_exit ( (void*)&error_status); - } + // set the budget timer + if (fosa_rel_timer_arm(timerid, &budget) != 0) { + error_status=RT_ERROR_TIMER; + pthread_exit ( (void*)&error_status); + } - printf("Begin thread %d,%d\n",(int)activation_time.tv_sec, - (int)(activation_time.tv_nsec/1000000)); - i++; - timerinfo.dummy=i; + printf("Begin thread %ld msec\n", fosa_abs_time_to_msec(activation_time) ); + i++; + timerinfo.dummy=i; - // save context + // save context - marte_nonlocaljmp_savecontext(&context); - printf ("salvado\n"); - - if (marte_nonlocaljmp_afterjmp(&context)==0) { - printf("start regular code\n"); - work(); - } else { - // code executed if asynchronous jump instruction invoked */ - printf("Aborted thread\n"); - } - - //printf("after block %d\n",marte_nonlocaljmp_afterjmp(&context)); - printf("after block\n"); - fosa_clock_get_time(FOSA_CLOCK_REALTIME,&old_activation_time); - decr_timespec(&old_activation_time,&activation_time); - printf("End thread %6.3f\n",old_activation_time.tv_sec+(float) - (float)old_activation_time.tv_nsec/1000000000.0); - // sleep for a while - incr_timespec(&activation_time,&period); - clock_nanosleep(FOSA_CLOCK_REALTIME,TIMER_ABSTIME, - &activation_time,&old_activation_time); + marte_nonlocaljmp_savecontext(&context); + printf ("salvado\n"); + + if (marte_nonlocaljmp_afterjmp(&context)==0) { + printf("start regular code\n"); + work(); + } else { + // code executed if asynchronous jump instruction invoked */ + printf("Aborted thread\n"); + } + + //printf("after block %d\n",marte_nonlocaljmp_afterjmp(&context)); + printf("after block\n"); + fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_activation_time); + elapsed_time = fosa_abs_time_extract_interval(activation_time, after_activation_time); + printf("End thread %ld msec\n", fosa_abs_time_to_msec(after_activation_time) ); + + // sleep for a while + activation_time = fosa_abs_time_incr(activation_time, period); + activation_time_tspec = fosa_abs_time_to_timespec(activation_time); + + clock_nanosleep(FOSA_CLOCK_REALTIME,TIMER_ABSTIME, + &activation_time_tspec, NULL); } // while } diff --git a/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c b/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c index 8848b61..87ae84d 100644 --- a/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c +++ b/src_marte/tests/test_non_local_jump/test_fosa_long_jump.c @@ -14,7 +14,6 @@ #include // For clock_nanosleep #include "fosa.h" -#include "timespec_operations.h" #include @@ -74,7 +73,8 @@ int main() static void *periodic_code(void *thread_arg) { - struct timespec period = {2, 500000000}; // 2.5 secs + fosa_rel_time_t period = fosa_msec_to_rel_time(2500); + fosa_thread_id_t jump_handler_thread; fosa_signal_t jump_signal; @@ -115,11 +115,11 @@ static void *periodic_code(void *thread_arg) while (1) { int jumped = -1; - struct timespec budget = {1, 400000000}; // 1.4 secs - struct timespec activation_time = {-1, -1}; - struct timespec old_activation_time = {-1, -1}; - - + fosa_rel_time_t budget = fosa_msec_to_rel_time(1400); + fosa_abs_time_t activation_time; + struct timespec activation_time_tspec; + fosa_abs_time_t after_activation_time; + fosa_rel_time_t elapsed_time; jumped = 0; @@ -132,7 +132,7 @@ static void *periodic_code(void *thread_arg) /************************************/ /* We arm the jump_timer */ - CHK( fosa_timer_arm(jump_timer, false, &budget) ); + CHK( fosa_rel_timer_arm(jump_timer, &budget) ); /* This is the point where the jump returns */ CHK( fosa_long_jump_save_context(&context) ); @@ -159,14 +159,15 @@ static void *periodic_code(void *thread_arg) /* Now we measure the time duration of the block */ /*************************************************/ - CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &old_activation_time) ); - decr_timespec(&old_activation_time, &activation_time); - printf("Execution time: %6.3f\n", t2d(old_activation_time) ); + CHK( fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_activation_time) ); + elapsed_time = fosa_abs_time_extract_interval(activation_time, after_activation_time); + printf("Execution time: %ld msec\n", fosa_rel_time_to_msec(after_activation_time) ); /* And we program the next loop */ - incr_timespec(&activation_time, &period); - clock_nanosleep(FOSA_CLOCK_REALTIME, TIMER_ABSTIME, &activation_time, - &old_activation_time); + activation_time = fosa_abs_time_incr(activation_time, period); + activation_time_tspec = fosa_abs_time_to_timespec(activation_time); + clock_nanosleep(FOSA_CLOCK_REALTIME, TIMER_ABSTIME, &activation_time_tspec, + NULL); } return NULL; @@ -178,7 +179,7 @@ static void *periodic_code(void *thread_arg) static void work_under_a_interruptible_budget() { static int i = 0; - struct timespec exec_time = {1, 0}; // 1 seg + fosa_rel_time_t exec_time = fosa_msec_to_rel_time(1000); // 1 sec i++; printf("Start regular work\n"); diff --git a/src_marte/tests/test_non_local_jump/testbench_long_jump.c b/src_marte/tests/test_non_local_jump/testbench_long_jump.c index 4fef934..ddae7ab 100644 --- a/src_marte/tests/test_non_local_jump/testbench_long_jump.c +++ b/src_marte/tests/test_non_local_jump/testbench_long_jump.c @@ -24,7 +24,6 @@ #include // For clock_nanosleep #include "fosa.h" -#include "timespec_operations.h" #include @@ -60,7 +59,7 @@ static void *periodic_code(void *thread_arg); static fosa_long_jump_context_t context; static void work_under_a_interruptible_budget(); -struct timespec before_jump_timestamp = {-1, -1}; +fosa_abs_time_t before_jump_timestamp; int main() @@ -72,10 +71,6 @@ int main() memset(&context, 0, sizeof(context) ); - memset(&periodic_attr, 0, sizeof(periodic_attr) ); - memset(&signal_set, 0, sizeof(signal_set) ); - memset(&periodic_tid, 0, sizeof(periodic_tid) ); - memset(&results, 0, sizeof(results) ); /* We set the signal mask */ signal_set[0] = FOSA_LONG_JUMP_SIGNAL; @@ -121,12 +116,6 @@ static void *periodic_code(void *thread_arg) int first_time = 1; - memset(&jump_signal, 0, sizeof(jump_signal) ); - memset(&jump_signal_info, 0, sizeof(jump_signal_info) ); - memset(&jump_handler_thread, 0, sizeof(jump_handler_thread) ); - memset(&clock_id, 0, sizeof(clock_id) ); - memset(&jump_timer, 0, sizeof(jump_timer) ); - results = (results_t *) thread_arg; /* We install a long jump handler */ @@ -155,9 +144,10 @@ static void *periodic_code(void *thread_arg) while (results->number_of_jumps < NUMBER_OF_JUMPS) { int jumped = -1; - struct timespec budget = {0, 20000000}; // 20 ms + fosa_rel_time_t budget = fosa_msec_to_rel_time(20); // 20 ms - struct timespec after_jump_timestamp = {-1, -1 }; + fosa_abs_time_t after_jump_timestamp; + fosa_rel_time_t jump_interval; double jump_interval_ms = 0.0; @@ -171,7 +161,7 @@ static void *periodic_code(void *thread_arg) /************************************/ /* We arm the jump_timer */ - fosa_timer_arm(jump_timer, false, &budget); + fosa_rel_timer_arm(jump_timer, &budget); /* This is the point where the jump returns */ @@ -191,8 +181,8 @@ static void *periodic_code(void *thread_arg) fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_jump_timestamp); results->number_of_jumps++; - decr_timespec(&after_jump_timestamp, &before_jump_timestamp); - jump_interval_ms = t2d(after_jump_timestamp) * 1000; + jump_interval = fosa_abs_time_extract_interval(before_jump_timestamp, after_jump_timestamp); + jump_interval_ms = fosa_rel_time_to_msec(jump_interval); if (first_time) { diff --git a/src_marte/tests/test_queue_signal_fosa/test_queue_signal_fosa.c b/src_marte/tests/test_queue_signal_fosa/test_queue_signal_fosa.c index 7ec2a68..b546897 100644 --- a/src_marte/tests/test_queue_signal_fosa/test_queue_signal_fosa.c +++ b/src_marte/tests/test_queue_signal_fosa/test_queue_signal_fosa.c @@ -10,40 +10,32 @@ #include #include +#include -#include "frsh.h" #include "fosa.h" -#include "eat.h" -#include "frsh_debug.h" -#include "frsh_error.h" +#define TEST_SIGNAL (SIGRTMIN + 6) int main() { int terror = -1; - struct timespec past_time = {-1, 1}; - struct timespec current_time = {-1, 1}; + fosa_abs_time_t past_time; + fosa_abs_time_t current_time; fosa_timer_id_t timer; - frsh_signal_t signal_set[1]; - frsh_signal_info_t signal_info; - frsh_signal_t signal_received; + fosa_signal_t signal_set[1]; + fosa_signal_info_t signal_info; + fosa_signal_t signal_received; int my_test_value = 42; - struct timespec eat_time = {2, 0}; + fosa_rel_time_t eat_time = fosa_msec_to_rel_time(2000); - memset(¤t_time, 0, sizeof(current_time) ); - memset(&signal_info, 0, sizeof(signal_info) ); - memset(&timer, 0, sizeof(timer) ); - memset(&signal_set, 0, sizeof(signal_set) ); - memset(&signal_received, 0, sizeof(signal_received) ); - /* We block the signals that we are going to process */ /*****************************************************/ - signal_set[0] = FRSH_SCHEDULER_SIGNAL; + signal_set[0] = TEST_SIGNAL; terror = fosa_set_accepted_signals(signal_set, 1); if (terror != 0) exit(1); @@ -52,30 +44,30 @@ int main() /* We create a timer based on the FOSA_CLOCK_REALTIME */ /******************************************************/ signal_info.sival_int = my_test_value; - terror = fosa_timer_create(FOSA_CLOCK_REALTIME, FRSH_SCHEDULER_SIGNAL, signal_info, &timer); + terror = fosa_timer_create(FOSA_CLOCK_REALTIME, TEST_SIGNAL, signal_info, &timer); if (terror != 0) exit(1); /* I get the time BEFORE doing the eat */ /***************************************/ terror = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &past_time); if (terror != 0) exit(1); - printf("Current time: %d sec, %d nsec\n", past_time.tv_sec, past_time.tv_nsec); + printf("Current time: %ld msec\n", fosa_abs_time_to_msec(past_time) ); /* Now I do some work for some secs */ /************************************/ - frsh_eat(&eat_time); + fosa_eat(&eat_time); /* I read the time again */ /*************************/ terror = fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t_time); if (terror != 0) exit(1); - printf("Current time: %d sec, %d nsec\n", current_time.tv_sec, current_time.tv_nsec); + printf("Current time: %ld msec\n", fosa_abs_time_to_msec(current_time) ); /* I arm the timer to the past */ /* Since we have blocked this signal, the signal should be stored */ /******************************************************************/ printf("Arming the timer\n"); - terror = fosa_timer_arm(timer, true, &past_time); + terror = fosa_abs_timer_arm(timer, &past_time); /* Now I do the sigwait */ diff --git a/src_marte/tests/test_time/Makefile b/src_marte/tests/test_time/Makefile new file mode 100644 index 0000000..a5a4c0b --- /dev/null +++ b/src_marte/tests/test_time/Makefile @@ -0,0 +1,2 @@ +include ../../../config.mk +include ../../../rules.mk diff --git a/src_marte/tests/test_time/fosa_test_time.c b/src_marte/tests/test_time/fosa_test_time.c new file mode 100644 index 0000000..c335402 --- /dev/null +++ b/src_marte/tests/test_time/fosa_test_time.c @@ -0,0 +1,249 @@ +//---------------------------------------------------------------------- +// 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 FRSH (FRescor ScHeduler) +// +// FRSH 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. FRSH 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 FRSH; see file +// COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, +// Cambridge, MA 02139, USA. +// +// As a special exception, including FRSH header files in a file, +// instantiating FRSH generics or templates, or linking other files +// with FRSH 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. +// ----------------------------------------------------------------------- +#include "fosa.h" +#include +#include /* for timespec */ +#include /* for printf */ +#include /* for memcmp */ + +static int check_exact_abs_msec(fosa_abs_time_t abs_time, long msec); +static int check_exact_rel_msec(fosa_rel_time_t rel_time, long msec); + +int main() +{ + + struct timespec tspec1 = {1, 500000000}; + struct timespec tspec2 = {0, 400000000}; + struct timespec tspec_result; + + fosa_rel_time_t rel_time1 = fosa_msec_to_rel_time(1500); + fosa_rel_time_t rel_time2 = fosa_msec_to_rel_time(400); + fosa_rel_time_t rel_time_aux = fosa_msec_to_rel_time(1500); + fosa_rel_time_t rel_time_result; + + fosa_abs_time_t abs_time1 = fosa_msec_to_abs_time(1500); + fosa_abs_time_t abs_time2 = fosa_msec_to_abs_time(400); + fosa_abs_time_t abs_time_aux = fosa_msec_to_abs_time(1500); + fosa_abs_time_t abs_time_result; + + long numeric; + bool test; + + /* fosa_abs_time_incr */ + abs_time_result = fosa_abs_time_incr(abs_time1, rel_time2); + assert( check_exact_abs_msec(abs_time_result, 1900) ); + + /* fosa_abs_time_decr */ + abs_time_result = fosa_abs_time_decr(abs_time1, rel_time2); + assert( check_exact_abs_msec(abs_time_result, 1100) ); + + /* fosa_abs_time_decr (negative) */ + abs_time_result = fosa_abs_time_decr(abs_time2, rel_time1); +// assert( check_exact_abs_msec(abs_time_result, -1100) ); + + /* fosa_abs_time_extract_interval */ + rel_time_result = fosa_abs_time_extract_interval(abs_time2, abs_time1); + assert( check_exact_rel_msec(rel_time_result, 1100) ); + + /* fosa_abs_time_extract_interval (negative) */ + rel_time_result = fosa_abs_time_extract_interval(abs_time1, abs_time2); +// assert( check_exact_rel_msec(rel_time_result, -1100) ); + + /* fosa_rel_time_add */ + rel_time_result = fosa_rel_time_add(rel_time1, rel_time2); + assert( check_exact_rel_msec(rel_time_result, 1900) ); + + /* fosa_rel_time_decr */ + rel_time_result = fosa_rel_time_decr(rel_time1, rel_time2); + assert( check_exact_rel_msec(rel_time_result, 1100) ); + + /* fosa_rel_time_decr (negative) */ + rel_time_result = fosa_rel_time_decr(rel_time2, rel_time1); +// assert( check_exact_rel_msec(rel_time_result, 1100) ); + + /* fosa_abs_time_smaller */ + test = fosa_abs_time_smaller(abs_time1, abs_time2); + assert(test == false); + + test = fosa_abs_time_smaller(abs_time1, abs_time_aux); + assert(test == false); + + test = fosa_abs_time_smaller(abs_time2, abs_time1); + assert(test); + + /* fosa_rel_time_smaller */ + test = fosa_rel_time_smaller(rel_time1, rel_time2); + assert(test == false); + + test = fosa_rel_time_smaller(rel_time1, rel_time_aux); + assert(test == false); + + test = fosa_rel_time_smaller(rel_time2, rel_time1); + assert(test); + + /* fosa_abs_time_smaller_or_equal */ + test = fosa_abs_time_smaller_or_equal(abs_time1, abs_time2); + assert(test == false); + + test = fosa_abs_time_smaller_or_equal(abs_time1, abs_time_aux); + assert(test); + + test = fosa_abs_time_smaller_or_equal(abs_time2, abs_time1); + assert(test); + + /* fosa_rel_time_smaller_or_equal */ + test = fosa_rel_time_smaller_or_equal(rel_time1, rel_time2); + assert(test == false); + + test = fosa_rel_time_smaller_or_equal(rel_time1, rel_time_aux); + assert(test); + + test = fosa_rel_time_smaller_or_equal(rel_time2, rel_time1); + assert(test); + + /* fosa_msec_to_rel_time */ + rel_time_result = fosa_msec_to_rel_time(1850); + assert( check_exact_rel_msec(rel_time_result, 1850) ); + + /* fosa_rel_time_to_msec */ + numeric = fosa_rel_time_to_msec(rel_time1); + assert(numeric == 1500); + + /* fosa_msec_to_abs_time */ + abs_time_result = fosa_msec_to_rel_time(1320); + assert( check_exact_abs_msec(abs_time_result, 1320) ); + + /* fosa_abs_time_to_msec */ + numeric = fosa_abs_time_to_msec(abs_time2); + assert(numeric == 400); + + /* fosa_usec_to_rel_time */ + rel_time_result = fosa_usec_to_rel_time(1850000); + assert( check_exact_rel_msec(rel_time_result, 1850) ); + + /* fosa_rel_time_to_usec */ + numeric = fosa_rel_time_to_usec(rel_time1); + assert(numeric == 1500000); + + /* fosa_msec_to_abs_time */ + abs_time_result = fosa_usec_to_rel_time(1320000); + assert( check_exact_abs_msec(abs_time_result, 1320) ); + + /* fosa_abs_time_to_msec */ + numeric = fosa_abs_time_to_usec(abs_time2); + assert(numeric == 400000); + + /* fosa_timespec_to_rel_time */ + struct timespec tspec_aux = {1, 750000000}; + rel_time_result = fosa_timespec_to_rel_time(tspec_aux); + assert( check_exact_rel_msec(rel_time_result, 1750) ); + + /* fosa_rel_time_to_timespec */ + tspec_result = fosa_rel_time_to_timespec(rel_time1); + test = memcmp(&tspec_result, &tspec1, sizeof(tspec_result) ); + assert(test == 0); + + /* fosa_timespec_to_abs_time */ + struct timespec tspec_aux_extra = {1, 200000000}; + abs_time_result = fosa_timespec_to_abs_time(tspec_aux_extra); + assert( check_exact_abs_msec(abs_time_result, 1200) ); + + /* fosa_abs_time_to_timespec */ + tspec_result = fosa_abs_time_to_timespec(abs_time2); + test = memcmp(&tspec_result, &tspec2, sizeof(tspec_result) ); + assert(test == 0); + + printf("End of test OK!!\n"); + + return 0; +} + +// ------------------------------------------------------------- + +static int check_exact_abs_msec(fosa_abs_time_t abs_time, long msec) +{ + fosa_abs_time_t time_check; + int cmp = -1; + + time_check = fosa_msec_to_abs_time(msec); + cmp = memcmp(&time_check, &abs_time, sizeof(time_check) ); + + if (cmp == 0) + { + return 1; + } + else + { + return 0; + } +} + +// ------------------------------------------------------------- + +static int check_exact_rel_msec(fosa_rel_time_t rel_time, long msec) +{ + fosa_rel_time_t time_check; + int cmp = -1; + + time_check = fosa_msec_to_rel_time(msec); + cmp = memcmp(&time_check, &rel_time, sizeof(time_check) ); + + if (cmp == 0) + { + return 1; + } + else + { + return 0; + } +} +