]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_aquosa/fosa_clocks_and_timers.c
move all the time related issues to FOSA absolute and relative data types.
[frescor/fosa.git] / src_aquosa / fosa_clocks_and_timers.c
index 9c7e2930cda6e9cf384f21b41baad35610b746da..756d0a89c4211f7e4178359b499f002080f809d0 100644 (file)
 // FOSA(Frescor Operating System Adaptation layer)
 //================================================
 
+#include "fosa_time.h"
 #include "fosa_clocks_and_timers.h"
 
 /*************************
  * Timing: Clocks
  *************************/
 
+/**
+ * fosa_get_time()
+ *
+ * Get the time from a clock
+ *
+ * This function sets the variable pointed to by current_time to the
+ * current value of the clock specified by clockid, which may be the
+ * FOSA_CLOCK_REALTIME constant or a value obtained with
+ * fosa_get_cputime_clock()
+ *
+ * Returns 0 if successful; otherwise it returns an error code:
+ *     EINVAL: the value of clockid is invalid
+ **/
 int fosa_clock_get_time(fosa_clock_id_t clockid,
-                       struct timespec *current_time)
+                       fosa_abs_time_t *current_time)
 {
-       return clock_gettime(clockid, current_time);
+       int error;
+       struct timespec current_time_tspec;
+
+       if ((error = clock_gettime(clockid, &current_time_tspec)) != 0)
+               return error;
+
+       *current_time = fosa_timespec_to_abs_time(current_time_tspec);
+
+       return 0;
 }
 
+/**
+ * fosa_get_cputime_clock()
+ *
+ * Get the identifier of a cpu-time clock
+ *
+ * This function stores in the variable pointed to by clockid the
+ * identifier of a cpu-time clock for the thread specified by tid.
+ *
+ * Returns 0 if successful; otherwise it returns an error code:
+ *    EINVAL: the value of tid is invalid
+ **/
 int fosa_thread_get_cputime_clock(fosa_thread_id_t tid,
                                  fosa_clock_id_t *clockid)
 {
@@ -154,16 +187,16 @@ int fosa_timer_create(fosa_clock_id_t clockid,
        return ENOSYS;
 }
 
- /**
 * Delete a timer
 *
 * The function deletes the timer specified by timerid, which becomes
 * unusable. If the timer was armed, it is automatically disarmed before
 * deletion.
 *
 * Returns 0 if successful; otherwise it returns an error code:
 *     EINVAL: the value of timerid is not valid
 **/
+/**
+ * Delete a timer
+ *
+ * The function deletes the timer specified by timerid, which becomes
+ * unusable. If the timer was armed, it is automatically disarmed before
+ * deletion.
+ *
+ * Returns 0 if successful; otherwise it returns an error code:
+ *     EINVAL: the value of timerid is not valid
+ **/
 int fosa_timer_delete(fosa_timer_id_t  timerid)
 {
        return timer_delete(timerid);
@@ -196,12 +229,12 @@ int fosa_timer_delete(fosa_timer_id_t  timerid)
  **/
 int fosa_timer_arm (fosa_timer_id_t timerid,
                    bool abstime,
-                   const struct timespec *value)
+                   const fosa_abs_time_t *value)
 {
        struct itimerspec when;
 
        /* non-periodic one shot timer configuration */
-       when.it_value = *value;
+       when.it_value = fosa_abs_time_to_timespec(*value);
        when.it_interval.tv_sec = 0;
        when.it_interval.tv_nsec = 0;
 
@@ -226,7 +259,7 @@ int fosa_timer_arm (fosa_timer_id_t timerid,
  *    EINVAL: the value of timerid or value is invalid
  **/
 int fosa_timer_get_remaining_time(fosa_timer_id_t timerid,
-                                 struct timespec *remaining_time)
+                                 fosa_rel_time_t *remaining_time)
 {
        int error;
        struct itimerspec time;
@@ -235,7 +268,7 @@ int fosa_timer_get_remaining_time(fosa_timer_id_t timerid,
                if ((error = timer_gettime(timerid, &time)) == -1)
                        return error;
 
-               *remaining_time = time.it_value;
+               *remaining_time = fosa_timespec_to_rel_time(time.it_value);
        } else
                return EINVAL;
 
@@ -268,7 +301,7 @@ int fosa_timer_disarm(fosa_timer_id_t timerid,
                if ((error = timer_gettime(timerid, &time)) == -1)
                        return error;
 
-               *remaining_time = time.it_value;
+               *remaining_time = fosa_timespec_to_rel_time(time.it_value);
        }
 
        time.it_value.tv_sec = 0;