]> rtime.felk.cvut.cz Git - frescor/fosa.git/commitdiff
Time abstraction added to FOSA to replace timespec_operations
authortelleriam <telleriam@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Thu, 6 Mar 2008 11:32:16 +0000 (11:32 +0000)
committertelleriam <telleriam@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Thu, 6 Mar 2008 11:32:16 +0000 (11:32 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1041 35b4ef3e-fd22-0410-ab77-dab3279adceb

28 files changed:
include/fosa_app_def_sched.h
include/fosa_clocks_and_timers.h
include/fosa_mutexes_and_condvars.h
include/fosa_opaque_types.h
include/fosa_opaque_types_time.h [new file with mode: 0644]
include/fosa_threads_and_signals.h
include/fosa_time.h
include/fosa_time_numeric.h [new file with mode: 0644]
include/fosa_time_timespec.h [new file with mode: 0644]
include/fosa_types.h
include/timespec_operations.h [deleted file]
src_marte/Makefile
src_marte/fosa_app_def_sched.c
src_marte/fosa_clocks_and_timers.c
src_marte/fosa_mutexes_and_condvars.c
src_marte/fosa_threads_and_signals.c
src_marte/fosa_time.c
src_marte/tests/test_clock_and_timers/test_clock_and_timers.c
src_marte/tests/test_cpu_clocks/test_cpu_clocks.c
src_marte/tests/test_cpu_clocks/test_cpu_clocks_sigwait_from_different_thread.c
src_marte/tests/test_fosa_ads/test_fosa_ads.c
src_marte/tests/test_fosa_general/test_fosa.c
src_marte/tests/test_non_local_jump/simple_test_non_local_jump.c
src_marte/tests/test_non_local_jump/test_fosa_long_jump.c
src_marte/tests/test_non_local_jump/testbench_long_jump.c
src_marte/tests/test_queue_signal_fosa/test_queue_signal_fosa.c
src_marte/tests/test_time/Makefile [new file with mode: 0644]
src_marte/tests/test_time/fosa_test_time.c [new file with mode: 0644]

index ecb202b2122ac5484cd23ce8fcc4d12006856218..333bc6a452afa00437138629c55f18b67fbd3274 100644 (file)
@@ -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);
 
 
 /**
index d21caac82ec01f2d4180edee96ad75fdcb44e1c1..0a544a0db8c70b7cfb375e3ee21e0470e53f7a30 100644 (file)
@@ -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);
 
 
 /*@}*/
index a2cfadef4e799e532619627f6e674135f1199250..20d22d39e1c5b5340569bc1f9a87af9e506457d7 100644 (file)
@@ -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);
 
 /*@}*/
 
index 5d8c5035bdf8c8c9a6936e532e582a930b1fdffa..5f562ec70e2ad3cb56572212cd10a4453070a9dc 100644 (file)
@@ -71,6 +71,7 @@
 #include <stdbool.h>
 
 #include "fosa_cpp_macros.h"
+#include "fosa_opaque_types_time.h"
 
 ///////////////////////  MARTE_OS /////////////////////////////
 
 
 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 <errno.h>
 #include <rtl_timer.h>
 
-/* 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 (file)
index 0000000..5d2b146
--- /dev/null
@@ -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 */
index b2d685f24c5f2f2cc179a241882fec677e56236c..8f829c16a3f46e3557ed6551a6bdf25bfaa3c76f 100644 (file)
@@ -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);
 
 /*}*/
 
index 6c832507348071f60e89df68ddc06efc09cfcb5e..6dee321f2697f2b3db7f3fc1ad41478fb898f4b4 100644 (file)
@@ -1,23 +1,96 @@
-/*
-** fosa_time.h
-** 
-** Made by Miguel marciano
-** Login   <miguel@namir.ctr.unican.es>
-** 
-** 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 (file)
index 0000000..d78f7b9
--- /dev/null
@@ -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 (file)
index 0000000..4d5f2b5
--- /dev/null
@@ -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_ */
index 3968aae8049462968f7ce7878df573eadd3c560b..ab316256c195aed846f97ebf5bbb992f322c3f44 100644 (file)
@@ -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 (file)
index 8788f70..0000000
+++ /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 <time.h> // for timespec
-#include <string.h> // 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_ */
index 5923648be34e4e790db19969b760481c18625f65..e77bfeeee15e8e298da9ec97ae2848912cb8b61d 100644 (file)
@@ -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)
 
index 757f5beb7232e7eb87c9c75399bd54445a62e04e..85977e10f70eef0529b3432d07d4aebb93580d27 100644 (file)
@@ -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,&current_time,&event);
+             sched_actions.timeout_ptr,&current_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
index 53fac890cad642fae1007593065023f5251e753a..f518990a37e0f3a4581e50f288cbecba9636cb90 100644 (file)
@@ -68,6 +68,7 @@
 #include <time.h>
 #include <stdio.h>
 
+#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, &current_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;
index e8b4123f6cbf5f81409b4c316f2ea3c729149f8a..eb68db0337ed41a6ca9e495c87633e229dcf4858 100644 (file)
@@ -70,7 +70,7 @@
 
 #include <misc/error_checks.h>
 
-
+#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);
 }
index bb35efffc77d4cb46369f3df723cab18f58ab0fc..25f319bde39a6324c3c3a49d4c1c89a78be3f803 100644 (file)
@@ -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
index b62a9d6cedbe528fe3507611d740c1bdcb4aa997..1cc25a1ad44977b01eb858c5e77fc9d9dfdf521d 100644 (file)
 //================================================
 
 #include "fosa.h"
-#include <pthread.h>
-#include <stdio.h>
-#include <time.h>
 
-#include <timespec_operations.h> /* for incr_timespec */
 
-#include <misc/error_checks.h>
 
+#ifdef VIRTUAL_TIME
+    #include <fosa_vt.h>
+#endif
 
 /**
  * fosa_eat()
  *
  * Eat some time using system clock facilities
  **/
-#ifdef VIRTUAL_TIME
-    #include <fosa_vt.h>
-#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, &current_time);
 
-    err = clock_gettime(clock_id, &current_time);
-    add_timespec(&time_to_go, &current_time, cpu_time);
+    time_to_go = fosa_abs_time_incr(current_time, *cpu_time);
 
-    while (smaller_timespec(&current_time, &time_to_go)) {
-        err = clock_gettime(clock_id, &current_time);
+    /* We also spread smaller_timespec */
+    while ( fosa_abs_time_smaller_or_equal(current_time, time_to_go) )
+    {
+        fosa_clock_get_time(clock_id, &current_time);
     }
 #endif
 }
index d745e7abb5d270803811a6f0105f23b0b9ec8e9b..0451a5ed50e4175670a0ff070680bac1656f84ed 100644 (file)
@@ -1,9 +1,9 @@
-#include "fosa_threads_and_signals.h"
-#include "fosa_clocks_and_timers.h"
 #include <unistd.h>
 #include <stdio.h>
 #include <time.h> // for nanosleep
 
+#include "fosa.h"
+
 // TODO: use #include <assert.h> when it works for all architectures
 #include <stdlib.h> // 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;
index 2dfd6c5c08a2d0cf3d7f17109666573fae738eb5..d9c0ab137c2261cffc03c341601dc1e7ce1e4452 100644 (file)
@@ -1,14 +1,11 @@
-#include "fosa_threads_and_signals.h"
-#include "fosa_clocks_and_timers.h"
 #include <unistd.h>
 #include <stdio.h>
-#include <time.h> // for nanosleep
 
 #include <assert.h>
 #include <stdlib.h> // for exit in assert
 #include <string.h> // for memset
-#include <timespec_operations.h>
 
+#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;
 }
index 378004f34feb5fb64c6bedcd2fac2402223a11dd..254675a067b3c4ca6e6037a271dee38f5905c871 100644 (file)
@@ -1,5 +1,3 @@
-#include "fosa_threads_and_signals.h"
-#include "fosa_clocks_and_timers.h"
 #include <unistd.h>
 #include <stdio.h>
 #include <time.h> // for nanosleep
@@ -7,8 +5,8 @@
 #include <assert.h>
 #include <stdlib.h> // for exit in assert
 #include <string.h> // for memset
-#include <timespec_operations.h>
 
+#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;
index 486d7f0bf563a1fc0661e3d85b6e553aff71d520..e3a55c267df7ce7983e56aebed503734cc164a1a 100644 (file)
@@ -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;
index 6851a48b7a0d8f5182668aa8cf0344ba65061144..14f78a43c7c4b7c2e1b698b556d0cf91db6cf376 100644 (file)
 // 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 <unistd.h>
 #include <stdio.h>
 #include <time.h> // 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, &current_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, &current_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, &current_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, &current_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, &current_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,&current_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, &current_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);
index 525b213f576b1fd832b866753a9976ce33a6fb2b..44abc3b003de31fc2fe0915f41d4a3466aeacda4 100644 (file)
@@ -66,7 +66,6 @@
 //#include <frsh.h>
 
 #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
 }
 
index 8848b61717136bcc66f9bb7c9717f679e9ae4d28..87ae84df48bab6f44a6218d1aa440018ae25fd10 100644 (file)
@@ -14,7 +14,6 @@
 #include <time.h> // For clock_nanosleep
 
 #include "fosa.h"
-#include "timespec_operations.h"
 
 #include <misc/error_checks.h>
 
@@ -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");
index 4fef93453dff972c0dbfa00120006050007ead68..ddae7ab83522782de375e7de5d47bfbe6c25e6ba 100644 (file)
@@ -24,7 +24,6 @@
 #include <time.h> // For clock_nanosleep
 
 #include "fosa.h"
-#include "timespec_operations.h"
 
 #include <misc/error_checks.h>
 
@@ -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)
             {
index 7ec2a68d9e9df2458722c15fdde058798937d176..b54689763827215305ad90ab0d500687ca8c45a6 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
-#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(&current_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, &current_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 (file)
index 0000000..a5a4c0b
--- /dev/null
@@ -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 (file)
index 0000000..c335402
--- /dev/null
@@ -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 <assert.h>
+#include <time.h>   /* for timespec */
+#include <stdio.h>  /* for printf */
+#include <string.h> /* 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;
+    }
+}
+