changeset 3947:6b0bd5783160

libdevice/timer: updated dev_timer_get_sec
author Alexandre Becoulet <alexandre.becoulet@free.fr>
date Thu, 31 May 2018 22:51:43 +0200
parents f0df16897b9f
children 1b05a6f65559
files libdevice/device_timer.c libdevice/include/device/class/timer.h
diffstat 2 files changed, 8 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/libdevice/device_timer.c	Wed May 30 11:16:15 2018 +0200
+++ b/libdevice/device_timer.c	Thu May 31 22:51:43 2018 +0200
@@ -128,27 +128,17 @@
   return 0;
 }
 
-error_t dev_timer_get_sec(struct device_timer_s *accessor, dev_timer_delay_t *delay,
-                          dev_timer_cfgrev_t *rev, dev_timer_delay_t s_delay, uint32_t r_unit)
+error_t dev_timer_get_sec(struct device_timer_s *accessor, uint64_t *stime,
+                          dev_timer_cfgrev_t *rev, dev_timer_value_t tvalue, uint32_t r_unit)
 {
-  struct dev_timer_config_s cfg;
-  error_t err;
-
-  err = DEVICE_OP(accessor, config, &cfg, 0);
+  uint64_t num = tvalue * r_unit, denom = 1;
+  error_t err = dev_timer_frac(accessor, &denom, &num, rev, 0);
   if (err)
     return err;
-  if (!DEV_FREQ_IS_VALID(cfg.freq))
-    return -EIO;
 
-  uint64_t d = ((uint64_t)r_unit * cfg.res * cfg.freq.denom * s_delay)
-    / ((uint64_t)cfg.freq.num);
+  uint64_t d = num / denom;
 
-  if (d > (uint64_t)(dev_timer_delay_t)-1)
-    return -ERANGE;
-
-  *delay = d ? d : 1;
-  if (rev)
-    *rev = cfg.rev;
+  *stime = d;
 
   return 0;
 }
--- a/libdevice/include/device/class/timer.h	Wed May 30 11:16:15 2018 +0200
+++ b/libdevice/include/device/class/timer.h	Thu May 31 22:51:43 2018 +0200
@@ -377,8 +377,8 @@
 /** @This works like @ref dev_timer_init_sec but convert from timer
     unit to second based unit. */
 config_depend(CONFIG_DEVICE_TIMER)
-error_t dev_timer_get_sec(struct device_timer_s *accessor, dev_timer_delay_t *delay,
-                          dev_timer_cfgrev_t *rev, dev_timer_delay_t s_delay, uint32_t r_unit);
+error_t dev_timer_get_sec(struct device_timer_s *accessor, uint64_t *stime,
+                          dev_timer_cfgrev_t *rev, dev_timer_value_t tvalue, uint32_t r_unit);
 
 /** @This computes two shift amounts which can be used for fast
     conversion between a delay in second based unit and a delay in